Skip to content

Commit b0aefe7

Browse files
committed
Moves revision-matching to git
THis process now is slower than before as we need to change to the respective repos before executing a git-call for each file separately as the repos are not associated any more…
1 parent 55874da commit b0aefe7

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

scripts/revcheck.php

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ functionality in the PHP Documentation Howto:
5353

5454
// A file is criticaly "outdated' if
5555
//define("ALERT_REV", 10); // translation is 10 or more revisions behind the en one
56-
define("ALERT_REV", 60); // translation is 60 days behind the en one
56+
define("ALERT_REV", 5); // English original has 5 or more new revisions since the set revision
5757
define("ALERT_SIZE", 3); // translation is 3 or more kB smaller than the en one
5858
define("ALERT_DATE", -30); // translation is 30 or more days older than the en one
5959

@@ -96,10 +96,6 @@ function init_files_by_maint($persons) {
9696

9797
$file_sizes_by_mark = $files_by_mark = init_revisions();
9898

99-
// Option for the link to svn.php.net:
100-
define('SVN_OPT', '&view=patch');
101-
define('SVN_OPT_NOWS', '');
102-
10399
// Initializing variables from parameters
104100
$LANG = $argv[1];
105101
$MAINT = "";
@@ -131,6 +127,18 @@ function init_files_by_maint($persons) {
131127
// Functions to get revision info and credits from a file
132128
// =========================================================================
133129

130+
function get_original_info($file, $hash)
131+
{
132+
global $DOCDIR;
133+
134+
exec('cd ' . $DOCDIR . '/en/ && git log ' . $hash . '^.. --pretty=format:"%h %at" -- ' . $file, $result, $output);
135+
if ($output || ! $result) {
136+
return [new DateTimeImmutable(), 0];
137+
}
138+
return [new DateTimeImmutable('@' . explode(' ', $result[0])[1]), count($result) - 1];
139+
140+
}
141+
134142
// Grabs the revision tag and stores credits from the file given
135143
function get_tags($file, $val = "en-rev") {
136144

@@ -147,9 +155,7 @@ function get_tags($file, $val = "en-rev") {
147155
// Check for English SVN revision tag (. is for $ in the preg!),
148156
// Return if this was needed (it should be there)
149157
if ($val == "en-rev") {
150-
// exec('cd ' . $DOCDIR . '/' . $LANG . ' && git log --pretty=format:"%h %at" ' . $basefile, $result, $output);
151-
// return new DateTimeImmutable('@' . explode(' ', $result[0])[1]);
152-
exec('cd ' . $DOCDIR . '/' . $LANG . ' && git log --pretty=format:"%h %at" ' . $basefile, $result, $output);
158+
exec('cd ' . $DOCDIR . '/' . $LANG . ' && git log -1 --pretty=format:"%h %at" ' . $basefile, $result, $output);
153159
return new DateTimeImmutable('@' . explode(' ', $result[0])[1]);
154160
}
155161

@@ -166,6 +172,9 @@ function get_tags($file, $val = "en-rev") {
166172

167173
// Store all elements
168174
foreach ($credits as $num => $credit) {
175+
if (! isset($files_by_maint[trim($credit)][REV_CREDIT])) {
176+
$files_by_maint[trim($credit)][REV_CREDIT] = 0;
177+
}
169178
$files_by_maint[trim($credit)][REV_CREDIT]++;
170179
}
171180
}
@@ -184,7 +193,8 @@ function get_tags($file, $val = "en-rev") {
184193
// The tag with revision number is not found so search
185194
// for anonymous ID revision comment (comment where revision is not known)
186195
if (count($match) == 0) {
187-
preg_match ("'<!--\s*EN-Revision:\s*(n/a)\s*Maintainer:\s*(anonymous\s*"
196+
preg_match (
197+
"'<!--\s*EN-Revision:\s*(n/a)\s*Maintainer:\s*(anonymous\s*"
188198
. $val . ")\s*Status:\s*(.+)\s*-->'U",
189199
$line,
190200
$match
@@ -194,23 +204,29 @@ function get_tags($file, $val = "en-rev") {
194204
// The tag with revision number is not found so search
195205
// for n/a revision comment (comment where revision is not known)
196206
if (count($match) == 0) {
197-
preg_match ("'<!--\s*EN-Revision:\s*(n/a)\s*Maintainer:\s*("
207+
preg_match (
208+
"'<!--\s*EN-Revision:\s*(n/a)\s*Maintainer:\s*("
198209
. $val . ")\s*Status:\s*(.+)\s*-->'U",
199-
$line,
200-
$match
210+
$line,
211+
$match
201212
);
202213
}
203214

215+
$match[4] = new DateTimeImmutable();
216+
$match[5] = 0;
204217
if (isset($match[1]) && $match[1] && $match[1] !== 'n/a') {
205218
// We have a revision number of the english original and should now see to
206219
// Get the last change date of that revision…
207-
exec('cd ' . $DOCDIR . '/en && git log --pretty=format:"%h %at" ' . $basefile, $result, $output);
208-
209-
$match[1] = new DateTimeImmutable('@' . (explode(' ', $result[0]))[1]);
210220

221+
$info = get_original_info($basefile, $match[1]);
222+
$match[4] = $info[0];
223+
$match[5] = $info[1];
211224
}
212225

213-
// Return with found revision info (number, maint, status)
226+
//exec('cd ' . $DOCDIR . '/' . $LANG . ' && git log -1 --pretty=format:"%h %at" ' . $basefile, $result, $output);
227+
$match[1] = get_tags($file, 'en-rev');
228+
229+
// Return with found revision info (number, maint, status)
214230
return $match;
215231

216232
} // get_tags() function end
@@ -281,36 +297,30 @@ function get_file_status($file) {
281297
}
282298

283299
// Distribute values in separate vars for further processing
284-
list(, $this_rev, $this_maint, $this_status) = $trans_tag;
300+
list(, $this_rev, $this_maint, $this_status, $en_last_date, $rev_diff) = $trans_tag;
285301

286-
if ('n/a' === $this_rev) {
287-
$this_rev = new DateTimeImmutable();
288-
}
289-
// Get English file revision
290-
$en_rev = get_tags($file);
302+
if ('n/a' === $this_rev) {
303+
$this_rev = new DateTimeImmutable();
304+
}
291305

292-
// If we have a numeric revision number (not n/a), compute rev. diff
293306
if (is_numeric($this_rev)) {
294-
$rev_diff = intval($en_rev) - intval($this_rev);
295307
$trans_rev = $this_rev;
296-
$en_rev = $en_rev;
308+
$en_rev = $this_rev;
297309
} else {
298310
// If we have no numeric revision, make all revision
299311
// columns hold the rev from the translated file
300312
$trans_rev = $this_rev;
301-
$rev_diff = 0;
302-
$en_rev = $en_rev;
313+
$en_rev = 0;
303314
}
304315

305316
// Compute times and diffs
306-
$en_date = intval((time() - filemtime($file)) / 86400);
307-
$en_date = (new DateTimeImmutable())->diff($en_rev)->days;
317+
$en_date = (new DateTimeImmutable())->diff($en_last_date)->days;
308318
$trans_date = intval((time() - filemtime($trans_file)) / 86400);
309-
$trans_date = (new DateTimeImmutable())->diff($this_rev)->days;
319+
// $trans_date = (new DateTimeImmutable())->diff($this_rev)->days;
310320
$date_diff = $en_date - $trans_date;
311321
$date_diff = 0;
312322
if ($trans_rev instanceof DateTimeInterface) {
313-
$date_diff = $en_rev->diff($trans_rev)->days;
323+
$date_diff = $en_last_date->diff($trans_rev)->days;
314324
}
315325

316326
// If the file is up-to-date
@@ -330,6 +340,9 @@ function get_file_status($file) {
330340

331341
// Store files by status, and by maintainer too
332342
$files_by_mark[$status_mark]++;
343+
if (! isset($files_by_maint[$this_maint][$status_mark])) {
344+
$files_by_maint[$this_maint][$status_mark] = 0;
345+
}
333346
$files_by_maint[$this_maint][$status_mark]++;
334347
$file_sizes_by_mark[$status_mark] += $en_size;
335348

@@ -340,7 +353,7 @@ function get_file_status($file) {
340353
return array(
341354
"full_name" => $file,
342355
"short_name" => basename($trans_file),
343-
"revision" => array($en_rev, $trans_rev, $rev_diff),
356+
"revision" => array($en_rev, $rev_diff, $trans_rev),
344357
"size" => array($en_size, $trans_size, $size_diff),
345358
"date" => array($en_date, $trans_date, $date_diff),
346359
"maintainer" => $this_maint,
@@ -369,10 +382,11 @@ function get_dir_status($dir) {
369382

370383
// Walk through all names in the directory
371384
while ($file = @readdir($handle)) {
372-
373385
if (
374386
(!is_dir($dir.'/' .$file) && !in_array(substr($file, -3), array('xml','ent')) && substr($file, -13) != 'PHPEditBackup' )
375387
|| strpos($file, 'entities.') === 0
388+
|| strpos($file, '.git') === 0
389+
|| strpos($file, '.idea') === 0
376390
|| $dir == $DOCDIR.'en/chmonly/' || $dir == $DOCDIR.'en/internals/' || $dir == $DOCDIR.'en/internals2/'
377391
|| $file == 'contributors.ent' || $file == 'contributors.xml'
378392
|| ($dir == $DOCDIR.'en/appendices/' && ($file == 'reserved.constants.xml' || $file == 'extensions.xml'))
@@ -908,14 +922,18 @@ function parse_translation($DOCDIR, $LANG, $MAINT) {
908922
// If we have a 'numeric' revision diff and it is not zero,
909923
// make a link to the SVN repository's diff script
910924
if ($file["revision"][2] != "n/a" && $file["revision"][2] !== 0) {
911-
$url = 'http://svn.php.net/viewvc/' .
912-
preg_replace( "'^".$DOCDIR."en/'", 'phpdoc/en/trunk/', $file['full_name']);
913-
// '?r1=' . $file['revision'][1] . '&amp;r2=' . $file['revision'][0];
914-
$url_ws = $url . SVN_OPT_NOWS;
915-
$url .= SVN_OPT;
925+
$history_url = sprintf(
926+
'https://github.com/phpdoctest/en/commits/master/%1$s',
927+
$file['full_name']
928+
);
929+
930+
$url = sprintf(
931+
'https://github.com/phpdoctest/en/blob/master/%1$s',
932+
$file['full_name']
933+
);
916934

917935
$file['short_name'] = '<a href="' . $url . '">'. $file["short_name"] . '</a> '.
918-
'<a href="' . $url_ws . '">[NoWS]</a>';
936+
'<a href="' . $history_url . '">[History]</a>';
919937
}
920938

921939
// Guess the new directory from the full name of the file

0 commit comments

Comments
 (0)