Skip to content

Avoid marking files as outdated on multiple [skip-revcheck] #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f9921a1
DTO for revcheck data.
Oct 25, 2024
d72bb52
Preparation for revcheck data exporting.
Oct 26, 2024
72453ce
Backport loose and fixed [skip-revcheck] modes
Oct 26, 2024
600714c
Additional revcheck data.
Nov 1, 2024
221e0dc
Revcheck deduplication: clean up, header.
Nov 1, 2024
83fb651
Revcheck deduplication: translators, file summary.
Nov 1, 2024
3b62b38
Revcheck deduplication: old/wip files.
Nov 5, 2024
156b0b5
Move backport code and docs to a separate file.
Nov 5, 2024
4405435
Revcheck deduplication: backport couting behaviour.
Nov 5, 2024
31cf0db
Revcheck deduplication: more backport couting woes.
Nov 5, 2024
324f48c
Revcheck deduplication: notinen, revtag, unstranslated.
Nov 5, 2024
60b5f1e
Revcheck deduplication: ignore, regex, xml.
Nov 6, 2024
a0ddca6
Revcheck deduplication: adds/dels, clean up.
Nov 6, 2024
55bae33
Revcheck deduplicatoin: genrevdb.php.
Nov 7, 2024
1ab908c
Revcheck deduplicatoin: genrevdb.php.
Nov 7, 2024
a08561f
More backport and small fixes.
Nov 7, 2024
d254ced
Review changes/fixes.
Nov 7, 2024
117a61d
Better log messages.
Nov 7, 2024
3eb4ef5
Remove unrelated filter.
Nov 8, 2024
bf4f663
Merge branch 'php:master' into master
alfsb Nov 11, 2024
e1f8400
Changes revcheck to consider one or many hashes, instead of two.
Nov 11, 2024
0460e4b
Changes revcheck to consider one or many hashes, instead of two.
Nov 11, 2024
0d5b26a
Changes revcheck to consider one or many hashes, instead of two.
Nov 11, 2024
a58d5a2
Merge branch 'php:master' into FIXED_SKIP_REVCHECK
alfsb Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading