git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Calculate lines changed for cvs log command
@ 2008-04-13 15:27 Fredrik Noring
  2008-04-13 16:59 ` Jakub Narebski
  0 siblings, 1 reply; 5+ messages in thread
From: Fredrik Noring @ 2008-04-13 15:27 UTC (permalink / raw)
  To: git; +Cc: gitster

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

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(-)


[-- Attachment #2: 0001-Calculate-lines-changed-for-cvs-log-command.patch --]
[-- Type: application/octet-stream, Size: 3274 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-04-14 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-13 15:27 [PATCH] Calculate lines changed for cvs log command Fredrik Noring
2008-04-13 16:59 ` Jakub Narebski
2008-04-13 18:44   ` Fredrik Noring
2008-04-13 20:43     ` Jakub Narebski
2008-04-14 19:56       ` Fredrik Noring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).