diff --git a/scripts/translation/lib/GitLogParser.php b/scripts/translation/lib/GitLogParser.php index 65095f90c..8c3d841c9 100644 --- a/scripts/translation/lib/GitLogParser.php +++ b/scripts/translation/lib/GitLogParser.php @@ -26,10 +26,13 @@ static function parseInto( string $lang , RevcheckFileList & $list ) $cwd = getcwd(); chdir( $lang ); $fp = popen( "git log --name-only" , "r" ); + chdir( $cwd ); + $hash = ""; $date = ""; $skip = false; $mcnt = 0; + while ( ( $line = fgets( $fp ) ) !== false ) { // new commit block @@ -81,38 +84,9 @@ static function parseInto( string $lang , RevcheckFileList & $list ) if ( $info == null ) continue; - // Saves only the first commit hash of a file of git log, - // that is, the last commit hash in chronological order. - - if ( $info->head == "" ) - { - $info->head = $hash; - $info->date = $date; - - if ( FIXED_SKIP_REVCHECK ) - if ( $skip ) - $info->diff = "skip"; - } - - if ( !FIXED_SKIP_REVCHECK ) - { - // Also tracks the first commit hash of a file in git log - // that is *not* market with [skip-revcheck] (the diff hash) - // so it's possible to not bother translations with - // minutiae modifications. - - if ( $skip ) - continue; - - if ( $info->diff == "" ) - { - $info->diff = $hash; - $info->date = $date; - } - } + $info->addGitLogData( $hash , $date , $skip ); } pclose( $fp ); - chdir( $cwd ); } } diff --git a/scripts/translation/lib/RevcheckData.php b/scripts/translation/lib/RevcheckData.php index d3e19b977..0aa113e51 100644 --- a/scripts/translation/lib/RevcheckData.php +++ b/scripts/translation/lib/RevcheckData.php @@ -17,9 +17,6 @@ * +----------------------------------------------------------------------+ */ -// NOTE: This file MAY be used in more of one git repository in future. -// If it is the case, please make note of this in *both* places. - enum RevcheckStatus : string { case TranslatedOk = 'TranslatedOk'; diff --git a/scripts/translation/lib/RevcheckFileInfo.php b/scripts/translation/lib/RevcheckFileItem.php similarity index 62% rename from scripts/translation/lib/RevcheckFileInfo.php rename to scripts/translation/lib/RevcheckFileItem.php index 5ebc5c46e..83232b3a5 100644 --- a/scripts/translation/lib/RevcheckFileInfo.php +++ b/scripts/translation/lib/RevcheckFileItem.php @@ -19,17 +19,22 @@ require_once __DIR__ . '/all.php'; -class RevcheckFileInfo +class RevcheckFileItem { public string $file = ""; // from fs public int $size = 0 ; // from fs public string $head = ""; // from vcs, source only, head hash, may be skipped public string $diff = ""; // from vcs, source only, diff hash, no skips public int $date = 0 ; // from vcs, source only, date of head or diff commit + public string $hashLast = ""; // derived by addGitLogData + public string $hashDiff = ""; // derived by addGitLogData, isSyncHash public RevcheckStatus $status; // target only public RevtagInfo|null $revtag; // target only + private array $hashList; // source only + private bool $hashStop; // source only + function __construct( string $file , int $size ) { $this->file = $file; @@ -39,5 +44,38 @@ function __construct( string $file , int $size ) $this->date = 0; $this->status = RevcheckStatus::Untranslated; $this->revtag = null; + $this->hashList = []; + $this->hashStop = false; + } + + public function addGitLogData( string $hash , string $date , bool $skip ) : void + { + // Accumulates valid hashes for RevcheckStatus::TranslatedOk status. + // This includes topmost runs of [skip-revcheck] tags and one normal, + // unmarked hash. Stop after first normal hash is found. + + if ( $this->hashStop ) + return; + + $this->hashList[] = $hash; + + if ( $this->hashLast == "" ) + { + $this->date = $date; + $this->hashLast = $hash; + } + + if ( $skip ) + $this->diffHash = $hash; + else + $this->hashStop = true; + } + + public function isSyncHash( $hash ) + { + $sync = in_array( $hash , $this->hashList ); + if ( $sync ) + $this->hashDiff = $hash; + return $sync; } } diff --git a/scripts/translation/lib/RevcheckFileList.php b/scripts/translation/lib/RevcheckFileList.php index a227912b7..5e67ed304 100644 --- a/scripts/translation/lib/RevcheckFileList.php +++ b/scripts/translation/lib/RevcheckFileList.php @@ -28,7 +28,7 @@ function __construct( $lang ) $this->loadTree( $lang ); } - function get( $file ): RevcheckFileInfo|null + function get( $file ): RevcheckFileItem|null { return $this->list[ $file ] ?? null; } @@ -70,7 +70,7 @@ function loadTreeRecurse( $lang , $path ) if ( RevcheckIgnore::ignore( $key ) ) continue; - $file = new RevcheckFileInfo( $key , $entry->getSize() ); + $file = new RevcheckFileItem( $key , $entry->getSize() ); $this->list[ $key ] = $file; } diff --git a/scripts/translation/lib/RevcheckRun.php b/scripts/translation/lib/RevcheckRun.php index dc3c2ced6..b39d08b8a 100644 --- a/scripts/translation/lib/RevcheckRun.php +++ b/scripts/translation/lib/RevcheckRun.php @@ -36,20 +36,21 @@ class RevcheckRun public array $qaList = []; public RevcheckData $revData; + private int $slowPathCount = 0; function __construct( string $sourceDir , string $targetDir , bool $writeResults = false ) { $this->sourceDir = $sourceDir; $this->targetDir = $targetDir; - // load respective file tree + // Load respective file trees $this->sourceFiles = new RevcheckFileList( $sourceDir ); $this->targetFiles = new RevcheckFileList( $targetDir ); - // original files get info from version control + // Source files get info from version control GitLogParser::parseInto( $sourceDir , $this->sourceFiles ); - // translated files get info from file contents + // Target files get info from revtags RevtagParser::parseInto( $targetDir , $this->targetFiles ); // match and mix @@ -62,6 +63,9 @@ function __construct( string $sourceDir , string $targetDir , bool $writeResults QaFileInfo::cacheSave( $this->qaList ); $this->saveRevcheckData(); } + + if ( $this->slowPathCount > 1000 ) + fprintf( STDERR , "Warn: Slow path called {$this->slowPathCount} times.\n" ); } private function calculateStatus() @@ -94,6 +98,8 @@ private function calculateStatus() continue; } + // TODO remove $(source|target)H* with QA simplification + // Previous code compares uptodate on multiple hashs. The last hash or the last non-skipped hash. // See https://github.com/php/doc-base/blob/090ff07aa03c3e4ad7320a4ace9ffb6d5ede722f/scripts/revcheck.php#L374 // and https://github.com/php/doc-base/blob/090ff07aa03c3e4ad7320a4ace9ffb6d5ede722f/scripts/revcheck.php#L392 . @@ -110,7 +116,7 @@ private function calculateStatus() // TranslatedOk - if ( $target->revtag->status == "ready" && ( $sourceHsh1 == $targetHash || $sourceHsh2 == $targetHash ) ) + if ( $target->revtag->status == "ready" && $source->isSyncHash( $target->revtag->revision ) ) { $source->status = RevcheckStatus::TranslatedOk; $this->filesOk[] = $source; @@ -123,18 +129,9 @@ private function calculateStatus() if ( $target->revtag->status == "ready" ) { - if ( FIXED_SKIP_REVCHECK && $source->diff == "skip" && TestFixedHashMinusTwo( $source->file , $targetHash ) ) - { - $source->status = RevcheckStatus::TranslatedOk; - $this->filesOk[] = $source; - $this->addData( $source , $target->revtag ); - } - else - { - $source->status = RevcheckStatus::TranslatedOld; - $this->filesOld[] = $source; - $this->addData( $source , $target->revtag ); - } + $source->status = RevcheckStatus::TranslatedOld; + $this->filesOld[] = $source; + $this->addData( $source , $target->revtag ); } else { @@ -160,7 +157,7 @@ private function calculateStatus() asort( $this->revData->fileDetail ); } - private function addData( RevcheckFileInfo $info , RevtagInfo|null $revtag = null ) : void + private function addData( RevcheckFileItem $info , RevtagInfo|null $revtag = null ) : void { $file = new RevcheckDataFile; @@ -169,8 +166,8 @@ private function addData( RevcheckFileInfo $info , RevtagInfo|null $revtag = nul $file->size = $info->size; $file->days = floor( ( time() - $info->date ) / 86400 ); $file->status = $info->status; - $file->hashLast = $info->head; - $file->hashDiff = $info->diff; + $file->hashLast = $info->hashLast; + $file->hashDiff = $info->hashDiff; $this->revData->addFile( $info->file , $file ); @@ -199,6 +196,7 @@ private function addData( RevcheckFileInfo $info , RevtagInfo|null $revtag = nul { case RevcheckStatus::TranslatedOld: case RevcheckStatus::TranslatedWip: + $this->slowPathCount++; GitDiffParser::parseAddsDels( $this->sourceDir , $file ); } } @@ -240,16 +238,3 @@ private function saveRevcheckData() file_put_contents( __DIR__ . "/../../../.revcheck.json" , $json ); } } - -function TestFixedHashMinusTwo($filename, $hash) :bool -{ - assert( FIXED_SKIP_REVCHECK ); // if deleted, delete entire funciont. - - // See mentions of FIXED_SKIP_REVCHECK on all.php for an explanation - - $cwd = getcwd(); - chdir( 'en' ); - $hashes = explode ( "\n" , `git log -2 --format=%H -- {$filename}` ); - chdir( $cwd ); - return ( $hashes[1] == $hash ); // $trFile->hash -} diff --git a/scripts/translation/lib/all.php b/scripts/translation/lib/all.php index 62ec3177d..85b251f97 100644 --- a/scripts/translation/lib/all.php +++ b/scripts/translation/lib/all.php @@ -30,7 +30,7 @@ require_once __DIR__ . '/OutputIgnoreBuffer.php'; require_once __DIR__ . '/QaFileInfo.php'; require_once __DIR__ . '/RevcheckData.php'; -require_once __DIR__ . '/RevcheckFileInfo.php'; +require_once __DIR__ . '/RevcheckFileItem.php'; require_once __DIR__ . '/RevcheckFileList.php'; require_once __DIR__ . '/RevcheckIgnore.php'; require_once __DIR__ . '/RevcheckRun.php';