Skip to content

Commit

Permalink
Changes revcheck to consider one or many hashes, instead of two.
Browse files Browse the repository at this point in the history
  • Loading branch information
André L F S Bacci committed Nov 11, 2024
1 parent e1f8400 commit 0460e4b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 111 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
43 changes: 0 additions & 43 deletions scripts/translation/lib/RevcheckFileInfo.php

This file was deleted.

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 > 100 )
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 @@ -211,6 +208,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 @@ -252,16 +250,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
}
3 changes: 2 additions & 1 deletion scripts/translation/lib/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
require_once __DIR__ . '/CacheUtil.php';
require_once __DIR__ . '/GitDiffParser.php';
require_once __DIR__ . '/GitLogParser.php';
require_once __DIR__ . '/GitUtils.php';
require_once __DIR__ . '/OutputIgnoreArgv.php';
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 0460e4b

Please sign in to comment.