git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ronald Landheer-Cieslak" <ronald@landheer-cieslak.com>
To: git@vger.kernel.org
Subject: [PATCH] New script: git-changelog.perl
Date: Fri, 2 Nov 2007 11:55:24 -0400	[thread overview]
Message-ID: <67837cd60711020855v5badf7a6o9b777f339df070f@mail.gmail.com> (raw)

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

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"

             reply	other threads:[~2007-11-02 15:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02 15:55 Ronald Landheer-Cieslak [this message]
2007-11-02 17:07 ` [PATCH] New script: git-changelog.perl Jakub Narebski
2007-11-02 18:27 ` Johannes Schindelin
2007-11-02 18:53   ` Nicolas Pitre
  -- strict thread matches above, loose matches on Subject: below --
2007-11-02 19:18 Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67837cd60711020855v5badf7a6o9b777f339df070f@mail.gmail.com \
    --to=ronald@landheer-cieslak.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).