Skip to content

Commit

Permalink
Avoid marking files as outdated on multiple [skip-revcheck] (#178)
Browse files Browse the repository at this point in the history
Changes revcheck to consider many hashes, instead of up to two. Fixes bumping files as Outdated on [skip-revcheck] runs.
  • Loading branch information
alfsb authored Nov 18, 2024
1 parent b457f42 commit eba8025
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 69 deletions.
34 changes: 4 additions & 30 deletions scripts/translation/lib/GitLogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}
}
3 changes: 0 additions & 3 deletions scripts/translation/lib/RevcheckData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions scripts/translation/lib/RevcheckFileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
49 changes: 17 additions & 32 deletions scripts/translation/lib/RevcheckRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 .
Expand All @@ -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;
Expand All @@ -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
{
Expand All @@ -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;

Expand All @@ -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 );

Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion scripts/translation/lib/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit eba8025

Please sign in to comment.