[web-doc] master: Fixed additions and deletions counts. Thanks, Lucas Azevedo. Closes GH-32

[email protected] (Nilgün Belma Bugüner) Mon, 24 Jan 2022 06:02:56 +0000
Newsgroups php.doc.web
Message-ID <[email protected]>
Author: Nilgün Belma Bugüner (nilgun)
Date: 2022-01-24T09:02:22+03:00

Commit: https://github.com/php/web-doc/commit/4ab530cc4aa579aba74b5a1c9008409396e9b6d5
Raw diff: https://github.com/php/web-doc/commit/4ab530cc4aa579aba74b5a1c9008409396e9b6d5.diff

Fixed additions and deletions counts. Thanks, Lucas Azevedo. Closes GH-32

Changed paths:
  M  scripts/rev.php
  M  www/revcheck.php


Diff:

diff --git a/scripts/rev.php b/scripts/rev.php
index 3cfb580..2d21520 100644
--- a/scripts/rev.php
+++ b/scripts/rev.php
@@ -436,8 +436,8 @@ function captureGitValues( & $output )
     global $DOCS;
     $cwd = getcwd();
     chdir( $DOCS . 'en' );
-    $fp = popen( "git --no-pager log --no-renames --numstat" , "r" );
-    $hash = $filename = $additions = $deletions = null;
+    $fp = popen( "git --no-pager log --name-only" , "r" );
+    $hash = null;
     $skipThisCommit = false;
 
     while ( ( $line = fgets( $fp ) ) !== false )
@@ -462,16 +462,11 @@ function captureGitValues( & $output )
         }
         if ( strpos( $line , ': ' ) > 0 )
             continue;
-        preg_match('/(\d+)\s+(\d+)\s*(.+)\s*/', $line, $matches);
-        if ($matches) {
-            [$all, $additions, $deletions, $filename] = $matches;
-        }
+        $filename = trim( $line );
         if ( isset( $output[$filename] ) )
             continue;
         $output[$filename]['hash'] = $hash;
         $output[$filename]['skip'] = $skipThisCommit;
-        $output[$filename]['adds'] = $additions;
-        $output[$filename]['dels'] = $deletions;
     }
     pclose( $fp );
     chdir( $cwd );
@@ -503,8 +498,6 @@ function captureGitValues( & $output )
     {
         $en->hash = $gitData[ $filename ]['hash'];
         $en->skip = $gitData[ $filename ]['skip'];
-        $en->adds = $gitData[ $filename ]['adds'];
-        $en->dels = $gitData[ $filename ]['dels'];
     }
     else
         print "Warn: No hash for en/$filename\n";
@@ -519,11 +512,21 @@ function captureGitValues( & $output )
             $SQL_BUFF .= "INSERT INTO Untranslated VALUES ($id, '$lang',
             '$en->name', $size);\n";
         } else {
-            $additions = $deletions = 0;
+            $additions = $deletions = -1;
             if ( $en->hash == $trFile->hash ){
                 $trFile->syncStatus = FileStatusEnum::TranslatedOk;
             } elseif ( $trFile->hash != null and strlen( $trFile->hash ) == 40 ) {
                 $trFile->syncStatus = FileStatusEnum::TranslatedOld;
+
+                $cwd = getcwd();
+                chdir( $DOCS . 'en' );
+                $subject = `git diff --numstat $trFile->hash -- {$filename}`;
+                chdir( $cwd );
+                if ( $subject ) {
+                   preg_match('/(\d+)\s+(\d+)/', $subject, $matches);
+                   if ($matches)
+                       [, $additions, $deletions] = $matches;
+                }
             }
             if ( $trFile->completion != null && $trFile->completion != "ready" )
                 $trFile->syncStatus = FileStatusEnum::TranslatedWip;
@@ -537,7 +540,7 @@ function captureGitValues( & $output )
             }
             $SQL_BUFF .= "INSERT INTO translated VALUES ($id, '$lang',
             '$en->name', '$trFile->hash', $size, '$trFile->maintainer',
-            '$trFile->completion', '$trFile->syncStatus', $en->adds, $en->dels);\n";
+            '$trFile->completion', '$trFile->syncStatus', $additions, $deletions);\n";
         }
     }
 }
diff --git a/www/revcheck.php b/www/revcheck.php
index 17f6e9d..2bef309 100644
--- a/www/revcheck.php
+++ b/www/revcheck.php
@@ -369,7 +369,10 @@
 
         $nm = "<a href='$d2'>{$r['file']}</a> <a href='$d1'>[diff]</a>";
 
-        $ch = "<span style='color: darkgreen;'>+{$r['additions']}</span> <span style='color: firebrick;'>-{$r['deletions']}</span>";
+        if ($r['additions'] < 0)
+            $ch = "<span style='color: firebrick;'>no data</span>";
+        else
+            $ch = "<span style='color: darkgreen;'>+{$r['additions']}</span> <span style='color: firebrick;'>-{$r['deletions']}</span>";
 
         // Write out the line for the current file (get file name shorter)