threads / patch / 10594

patchNew script: git-changelog.perl

Subject: [PATCH] New script: git-changelog.perl

## tl;dr

4 messages between Nov 2, 2007 and Nov 2, 2007. Diffs are folded; open one to read it.

replies: 3people: 4as markdown or json

Ronald Landheer-Cieslak· Nov 2, 2007, 15:55 UTC · lore
Hello all,

I've written a little script that will format the changes as reported by git-log in a ChangeLog-like format. Entries look like this: <date>\t<author>\n\t<sha1>: <subject>

An example taken from Gits own recent history:
2007-10-30      Junio C Hamano
        9c51414: Merge branch 'maint' into HEAD
        7eedc1c: Merge branch 'nd/worktree' into HEAD
        9725bb8: Merge branch 'cc/skip' into HEAD
        7ae4dd0: Merge branch 'jk/send-pack' into HEAD
        7e9a464: Merge branch 'lt/rename' into HEAD
        6beb669: Merge branch 'jn/web' into HEAD
        791e421: Merge branch 'ds/gitweb' into HEAD
        5153399: Merge branch 'js/rebase' into HEAD
        0bdb5af: Update GIT 1.5.3.5 Release Notes
2007-10-30      Gerrit Pape
        fee9832: No longer install git-svnimport, move to contrib/examples

I intend to use it for releases of my software, and I though others might like it as well.

I haven't implemented any help yet, but if any-one would like some documentation, I'll be glad to provide it.

rlc
Show changes to 2 files +69 −1

Makefile, git-changelog.perl

diff --git a/Makefile b/Makefile
index 71479a2..cf2cb32 100644
--- a/Makefile
+++ b/Makefile
@@ -226,7 +226,7 @@ SCRIPT_PERL = \
        git-add--interactive.perl \
        git-archimport.perl git-cvsimport.perl git-relink.perl \
        git-cvsserver.perl git-remote.perl git-cvsexportcommit.perl \
-       git-send-email.perl git-svn.perl
+       git-send-email.perl git-svn.perl git-changelog.perl

 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
          $(patsubst %.perl,%,$(SCRIPT_PERL)) \
diff --git a/git-changelog.perl b/git-changelog.perl
new file mode 100755
index 0000000..bffa1ab
--- /dev/null
+++ b/git-changelog.perl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+sub fetch_log {
+       my $command='git log --pretty=format:"%ai|%an|%h|%s" ';
+       foreach (@_) {
+               $command .= ' ' . $_;
+       }
+       $command .= " |";
+       my $fh;
+       open $fh, $command
+               or die "Failed to fetch logs";
+       # logs are presented as lines in which fields are separated by pipes.
+       # the fields are the date in ISO format (so the date as we
want it extends to the
+       # first space), the name of the author, the abbreviated SHA1
hash and the subject line
+       my $date_time;
+       my $date;
+       my $cruft;
+       my $author;
+       my $hash;
+       my $subject;
+       my $prev_date="";
+       my @cache; # a cache of the changes for the current date (i.e.
while $prev_date eq $date)
+       my %entry; # a cache entry; $entry{'author'} is the entry and
@$entry{'changes'} are the changes for the author in question
+       while (<$fh>) {
+               ($date_time, $author, $hash, $subject) = split(/\|/);
+               ($date, $cruft) = split(/\s/, $date_time, 2);
+               chomp $author;
+
+               if ($date ne $prev_date)
+               {
+                       foreach (@cache)
+                       {
+                               # print out the line with the date and
the author
+                               my $changes = $_->{'changes'};
+                               print "\n" . $prev_date . "\t" .
$_->{'author'} . "\n" if ($#{$changes} != -1);
+                               foreach (@{$changes})
+                               {
+                                       print "\t" . $_->{'hash'} . ':
' . $_->{'subject'};
+                               }
+                       }
+                       $prev_date = $date;
+                       @cache = ();
+               }
+               # try to find an entry with the same author in the cache
+               my $found = -1;
+               my $i;
+               for ($i = 0; $i <= $#cache && $found == -1; $i++)
+               {
+                       if ($cache[$i]->{'author'} eq $author)
+                       {
+                               $found = $i;
+                       }
+               }
+               if ($found == -1)
+               {
+                       my $changes = ();
+                       push @cache, { 'author', $author, 'changes', $changes };
+                       $found = $#cache;
+               }
+               push @{$cache[$found]->{'changes'}}, { 'hash', $hash,
'subject', $subject };
+       }
+}
+
+fetch_log @ARGV;
+
+
-- 
Ronald Landheer-Cieslak
Software Architect
http://www.landheer-cieslak.com/
New White Paper: "Three Good Reasons to Plan Ahead"
Jakub Narebski· Nov 2, 2007, 17:07 UTC · re: Ronald Landheer-Cieslak · lore

Re: [PATCH] New script: git-changelog.perl

[Cc: Ronald Landheer-Cieslak <ronald@landheer-cieslak.com>, 
 git@vger.kernel.org]
Ronald Landheer-Cieslak wrote:
> I've written a little script that will format the changes as reported
> by git-log in a ChangeLog-like format. Entries look like this:
> <date>\t<author>\n\t<sha1>: <subject>
How it compares to existing git2cl tool?:
  http://josefsson.org/git2cl/
  http://git.or.cz/gitwiki/InterfacesFrontendsAndTools

BTW. Do anyone has idea why on above wiki page table of contents does not display some sections at all?

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Johannes Schindelin· Nov 2, 2007, 18:27 UTC · re: Ronald Landheer-Cieslak · lore

Re: [PATCH] New script: git-changelog.perl

Hi,
On Fri, 2 Nov 2007, Ronald Landheer-Cieslak wrote:
> I've written a little script that will format the changes as reported
> by git-log in a ChangeLog-like format.

Jakub already commented on the availability of git2cl, but I thought I'd clarify: once upon a time I even wrote some builtin to perform that transformation, and it was met with unilateral disgus^Wagreement not to include it into core git.

Therefore I think it would be sanest to enhance git2cl until it does what you want to do.

Ciao, Dscho

Nicolas Pitre· Nov 2, 2007, 18:53 UTC · re: Johannes Schindelin · lore

Re: [PATCH] New script: git-changelog.perl

On Fri, 2 Nov 2007, Johannes Schindelin wrote:
Show 14 quoted lines
> Hi,
> 
> On Fri, 2 Nov 2007, Ronald Landheer-Cieslak wrote:
> 
> > I've written a little script that will format the changes as reported
> > by git-log in a ChangeLog-like format.
> 
> Jakub already commented on the availability of git2cl, but I thought I'd 
> clarify: once upon a time I even wrote some builtin to perform that 
> transformation, and it was met with unilateral disgus^Wagreement not to 
> include it into core git.
> 
> Therefore I think it would be sanest to enhance git2cl until it does what 
> you want to do.

The contrib directory is certainly a good place for such scripts as well.

Nicolas

← back to recent threads