Skip to content

Commit eba8025

Browse files
authored
Avoid marking files as outdated on multiple [skip-revcheck] (#178)
Changes revcheck to consider many hashes, instead of up to two. Fixes bumping files as Outdated on [skip-revcheck] runs.
1 parent b457f42 commit eba8025

File tree

6 files changed

+63
-69
lines changed

6 files changed

+63
-69
lines changed

scripts/translation/lib/GitLogParser.php

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ static function parseInto( string $lang , RevcheckFileList & $list )
2626
$cwd = getcwd();
2727
chdir( $lang );
2828
$fp = popen( "git log --name-only" , "r" );
29+
chdir( $cwd );
30+
2931
$hash = "";
3032
$date = "";
3133
$skip = false;
3234
$mcnt = 0;
35+
3336
while ( ( $line = fgets( $fp ) ) !== false )
3437
{
3538
// new commit block
@@ -81,38 +84,9 @@ static function parseInto( string $lang , RevcheckFileList & $list )
8184
if ( $info == null )
8285
continue;
8386

84-
// Saves only the first commit hash of a file of git log,
85-
// that is, the last commit hash in chronological order.
86-
87-
if ( $info->head == "" )
88-
{
89-
$info->head = $hash;
90-
$info->date = $date;
91-
92-
if ( FIXED_SKIP_REVCHECK )
93-
if ( $skip )
94-
$info->diff = "skip";
95-
}
96-
97-
if ( !FIXED_SKIP_REVCHECK )
98-
{
99-
// Also tracks the first commit hash of a file in git log
100-
// that is *not* market with [skip-revcheck] (the diff hash)
101-
// so it's possible to not bother translations with
102-
// minutiae modifications.
103-
104-
if ( $skip )
105-
continue;
106-
107-
if ( $info->diff == "" )
108-
{
109-
$info->diff = $hash;
110-
$info->date = $date;
111-
}
112-
}
87+
$info->addGitLogData( $hash , $date , $skip );
11388
}
11489

11590
pclose( $fp );
116-
chdir( $cwd );
11791
}
11892
}

scripts/translation/lib/RevcheckData.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
* +----------------------------------------------------------------------+
1818
*/
1919

20-
// NOTE: This file MAY be used in more of one git repository in future.
21-
// If it is the case, please make note of this in *both* places.
22-
2320
enum RevcheckStatus : string
2421
{
2522
case TranslatedOk = 'TranslatedOk';

scripts/translation/lib/RevcheckFileInfo.php renamed to scripts/translation/lib/RevcheckFileItem.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@
1919

2020
require_once __DIR__ . '/all.php';
2121

22-
class RevcheckFileInfo
22+
class RevcheckFileItem
2323
{
2424
public string $file = ""; // from fs
2525
public int $size = 0 ; // from fs
2626
public string $head = ""; // from vcs, source only, head hash, may be skipped
2727
public string $diff = ""; // from vcs, source only, diff hash, no skips
2828
public int $date = 0 ; // from vcs, source only, date of head or diff commit
29+
public string $hashLast = ""; // derived by addGitLogData
30+
public string $hashDiff = ""; // derived by addGitLogData, isSyncHash
2931

3032
public RevcheckStatus $status; // target only
3133
public RevtagInfo|null $revtag; // target only
3234

35+
private array $hashList; // source only
36+
private bool $hashStop; // source only
37+
3338
function __construct( string $file , int $size )
3439
{
3540
$this->file = $file;
@@ -39,5 +44,38 @@ function __construct( string $file , int $size )
3944
$this->date = 0;
4045
$this->status = RevcheckStatus::Untranslated;
4146
$this->revtag = null;
47+
$this->hashList = [];
48+
$this->hashStop = false;
49+
}
50+
51+
public function addGitLogData( string $hash , string $date , bool $skip ) : void
52+
{
53+
// Accumulates valid hashes for RevcheckStatus::TranslatedOk status.
54+
// This includes topmost runs of [skip-revcheck] tags and one normal,
55+
// unmarked hash. Stop after first normal hash is found.
56+
57+
if ( $this->hashStop )
58+
return;
59+
60+
$this->hashList[] = $hash;
61+
62+
if ( $this->hashLast == "" )
63+
{
64+
$this->date = $date;
65+
$this->hashLast = $hash;
66+
}
67+
68+
if ( $skip )
69+
$this->diffHash = $hash;
70+
else
71+
$this->hashStop = true;
72+
}
73+
74+
public function isSyncHash( $hash )
75+
{
76+
$sync = in_array( $hash , $this->hashList );
77+
if ( $sync )
78+
$this->hashDiff = $hash;
79+
return $sync;
4280
}
4381
}

scripts/translation/lib/RevcheckFileList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function __construct( $lang )
2828
$this->loadTree( $lang );
2929
}
3030

31-
function get( $file ): RevcheckFileInfo|null
31+
function get( $file ): RevcheckFileItem|null
3232
{
3333
return $this->list[ $file ] ?? null;
3434
}
@@ -70,7 +70,7 @@ function loadTreeRecurse( $lang , $path )
7070

7171
if ( RevcheckIgnore::ignore( $key ) )
7272
continue;
73-
$file = new RevcheckFileInfo( $key , $entry->getSize() );
73+
$file = new RevcheckFileItem( $key , $entry->getSize() );
7474
$this->list[ $key ] = $file;
7575
}
7676

scripts/translation/lib/RevcheckRun.php

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,21 @@ class RevcheckRun
3636

3737
public array $qaList = [];
3838
public RevcheckData $revData;
39+
private int $slowPathCount = 0;
3940

4041
function __construct( string $sourceDir , string $targetDir , bool $writeResults = false )
4142
{
4243
$this->sourceDir = $sourceDir;
4344
$this->targetDir = $targetDir;
4445

45-
// load respective file tree
46+
// Load respective file trees
4647
$this->sourceFiles = new RevcheckFileList( $sourceDir );
4748
$this->targetFiles = new RevcheckFileList( $targetDir );
4849

49-
// original files get info from version control
50+
// Source files get info from version control
5051
GitLogParser::parseInto( $sourceDir , $this->sourceFiles );
5152

52-
// translated files get info from file contents
53+
// Target files get info from revtags
5354
RevtagParser::parseInto( $targetDir , $this->targetFiles );
5455

5556
// match and mix
@@ -62,6 +63,9 @@ function __construct( string $sourceDir , string $targetDir , bool $writeResults
6263
QaFileInfo::cacheSave( $this->qaList );
6364
$this->saveRevcheckData();
6465
}
66+
67+
if ( $this->slowPathCount > 1000 )
68+
fprintf( STDERR , "Warn: Slow path called {$this->slowPathCount} times.\n" );
6569
}
6670

6771
private function calculateStatus()
@@ -94,6 +98,8 @@ private function calculateStatus()
9498
continue;
9599
}
96100

101+
// TODO remove $(source|target)H* with QA simplification
102+
97103
// Previous code compares uptodate on multiple hashs. The last hash or the last non-skipped hash.
98104
// See https://github.com/php/doc-base/blob/090ff07aa03c3e4ad7320a4ace9ffb6d5ede722f/scripts/revcheck.php#L374
99105
// and https://github.com/php/doc-base/blob/090ff07aa03c3e4ad7320a4ace9ffb6d5ede722f/scripts/revcheck.php#L392 .
@@ -110,7 +116,7 @@ private function calculateStatus()
110116

111117
// TranslatedOk
112118

113-
if ( $target->revtag->status == "ready" && ( $sourceHsh1 == $targetHash || $sourceHsh2 == $targetHash ) )
119+
if ( $target->revtag->status == "ready" && $source->isSyncHash( $target->revtag->revision ) )
114120
{
115121
$source->status = RevcheckStatus::TranslatedOk;
116122
$this->filesOk[] = $source;
@@ -123,18 +129,9 @@ private function calculateStatus()
123129

124130
if ( $target->revtag->status == "ready" )
125131
{
126-
if ( FIXED_SKIP_REVCHECK && $source->diff == "skip" && TestFixedHashMinusTwo( $source->file , $targetHash ) )
127-
{
128-
$source->status = RevcheckStatus::TranslatedOk;
129-
$this->filesOk[] = $source;
130-
$this->addData( $source , $target->revtag );
131-
}
132-
else
133-
{
134-
$source->status = RevcheckStatus::TranslatedOld;
135-
$this->filesOld[] = $source;
136-
$this->addData( $source , $target->revtag );
137-
}
132+
$source->status = RevcheckStatus::TranslatedOld;
133+
$this->filesOld[] = $source;
134+
$this->addData( $source , $target->revtag );
138135
}
139136
else
140137
{
@@ -160,7 +157,7 @@ private function calculateStatus()
160157
asort( $this->revData->fileDetail );
161158
}
162159

163-
private function addData( RevcheckFileInfo $info , RevtagInfo|null $revtag = null ) : void
160+
private function addData( RevcheckFileItem $info , RevtagInfo|null $revtag = null ) : void
164161
{
165162
$file = new RevcheckDataFile;
166163

@@ -169,8 +166,8 @@ private function addData( RevcheckFileInfo $info , RevtagInfo|null $revtag = nul
169166
$file->size = $info->size;
170167
$file->days = floor( ( time() - $info->date ) / 86400 );
171168
$file->status = $info->status;
172-
$file->hashLast = $info->head;
173-
$file->hashDiff = $info->diff;
169+
$file->hashLast = $info->hashLast;
170+
$file->hashDiff = $info->hashDiff;
174171

175172
$this->revData->addFile( $info->file , $file );
176173

@@ -199,6 +196,7 @@ private function addData( RevcheckFileInfo $info , RevtagInfo|null $revtag = nul
199196
{
200197
case RevcheckStatus::TranslatedOld:
201198
case RevcheckStatus::TranslatedWip:
199+
$this->slowPathCount++;
202200
GitDiffParser::parseAddsDels( $this->sourceDir , $file );
203201
}
204202
}
@@ -240,16 +238,3 @@ private function saveRevcheckData()
240238
file_put_contents( __DIR__ . "/../../../.revcheck.json" , $json );
241239
}
242240
}
243-
244-
function TestFixedHashMinusTwo($filename, $hash) :bool
245-
{
246-
assert( FIXED_SKIP_REVCHECK ); // if deleted, delete entire funciont.
247-
248-
// See mentions of FIXED_SKIP_REVCHECK on all.php for an explanation
249-
250-
$cwd = getcwd();
251-
chdir( 'en' );
252-
$hashes = explode ( "\n" , `git log -2 --format=%H -- {$filename}` );
253-
chdir( $cwd );
254-
return ( $hashes[1] == $hash ); // $trFile->hash
255-
}

scripts/translation/lib/all.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
require_once __DIR__ . '/OutputIgnoreBuffer.php';
3131
require_once __DIR__ . '/QaFileInfo.php';
3232
require_once __DIR__ . '/RevcheckData.php';
33-
require_once __DIR__ . '/RevcheckFileInfo.php';
33+
require_once __DIR__ . '/RevcheckFileItem.php';
3434
require_once __DIR__ . '/RevcheckFileList.php';
3535
require_once __DIR__ . '/RevcheckIgnore.php';
3636
require_once __DIR__ . '/RevcheckRun.php';

0 commit comments

Comments
 (0)