git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Calculate lines changed for cvs log command

From
FNFredrik Noring <noring@nocrew.org>
Date
Apr 13, 2008, 15:27 UTC
Message-ID
<3F0821AA-C11D-4C42-A415-D346A7CD89F8@nocrew.org>
Hi,

Attached patch attempts to report the correct lines changed when using the cvs log command with cvsserver. Is there any performance impact using "git-log -1 --shortstat <object>" instead of "git-cat-file commit <object>"?

(Also, it would be nice if git-log --pretty=format:XXX could display diff information such as shortstat, to make parsing more robust.)

Previously, cvs log reported "+2 -3" for all commits. This patch reports real values except when the commit is fetched from the SQLite DB, which remains "+2 -3" at all times.

(My mailer destroys inline patches, so I'm attaching it. Sorry about that.)

Signed-off-by: Fredrik Noring <noring@nocrew.org>
---
  git-cvsserver.perl |   32 ++++++++++++++++++++++----------
  1 files changed, 22 insertions(+), 10 deletions(-)
From 6ff024e5238e52f4b61226187ffa2d21b99fe081 Mon Sep 17 00:00:00 2001
From: Fredrik Noring <noring@nocrew.org>
Date: Sun, 13 Apr 2008 16:54:40 +0200
Subject: [PATCH] Calculate lines changed for cvs log command

Previously, "+2 -3" was reported for all commits. This patch reports lines changed except when the commit is fetched from the SQLite DB (which remains "+2 -3" at all times).

Signed-off-by: Fredrik Noring <noring@nocrew.org>
---
 git-cvsserver.perl |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 29dbfc9..5d31a95 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -1729,8 +1729,9 @@ sub req_log
             # reformat the date for log output
             $revision->{modified} = sprintf('%04d/%02d/%02d %s', $3, $DATE_LIST->{$2}, $1, $4 ) if ( $revision->{modified} =~ /(\d+)\s+(\w+)\s+(\d+)\s+(\S+)/ and defined($DATE_LIST->{$2}) );
             $revision->{author} = cvs_author($revision->{author});
-            print "M date: $revision->{modified};  author: $revision->{author};  state: " . ( $revision->{filehash} eq "deleted" ? "dead" : "Exp" ) . ";  lines: +2 -3\n";
-            my $commitmessage = $updater->commitmessage($revision->{commithash});
+            ( my $commitmessage, my $lines_changed ) =
+		$updater->commitinfo($revision->{commithash});
+            print "M date: $revision->{modified};  author: $revision->{author};  state: " . ( $revision->{filehash} eq "deleted" ? "dead" : "Exp" ) . ";  lines: " . $lines_changed . "\n";
             $commitmessage =~ s/^/M /mg;
             print $commitmessage . "\n";
         }
@@ -3023,12 +3024,13 @@ sub getmeta
     return $db_query->fetchrow_hashref;
 }
 
-=head2 commitmessage
+=head2 commitinfo
 
-this function takes a commithash and returns the commit message for that commit
+this function takes a commithash and returns the commit message and
+lines changed for that commit
 
 =cut
-sub commitmessage
+sub commitinfo
 {
     my $self = shift;
     my $commithash = shift;
@@ -3045,14 +3047,24 @@ sub commitmessage
     if ( defined ( $message ) )
     {
         $message .= " " if ( $message =~ /\n$/ );
-        return $message;
+        return ( $message, "+2 -3" );   # FIXME: What's the real lines changed?
     }
 
-    my @lines = safe_pipe_capture("git-cat-file", "commit", $commithash);
-    shift @lines while ( $lines[0] =~ /\S/ );
-    $message = join("",@lines);
+    my @lines = safe_pipe_capture("git-log", "-1", "--pretty=format:%s%n%b",
+				  "--shortstat", $commithash);
+    my $files_changed = 0;
+    my $insertions = 0;
+    my $deletions = 0;
+    ( $files_changed, $insertions, $deletions ) = ( $lines[-1] =~ / (\d+) files changed, (\d+) insertions.*, (\d+) deletions/ );
+    if ( $files_changed )
+    {
+	pop(@lines);   # Remove shortstat
+	pop(@lines);   # Remove extra newline prior to shortstat
+    }
+    map(s/\n$//s, @lines);
+    $message = join("\n", @lines);
     $message .= " " if ( $message =~ /\n$/ );
-    return $message;
+    return ( $message, sprintf("+%d -%d", $insertions, $deletions) );
 }
 
 =head2 gethistory
-- 
1.5.5.40.g4cdda.dirty
Next: Jakub Narebski
Message 1 of 5 in “Calculate lines changed for cvs log command”
  1. Calculate lines changed for cvs log commandFredrik Noring, Apr 13, 2008
  2. Jakub NarebskiApr 13, 2008
  3. Fredrik NoringApr 13, 2008
  4. Jakub NarebskiApr 13, 2008
  5. Fredrik NoringApr 14, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.