# [PATCH] New script: git-changelog.perl - revised

5 messages from 2007-11-02 to 2007-11-03. Participants: Ronald Landheer-Cieslak, Andreas Ericsson, Johannes Schindelin, Alex Riesen.
Thread: https://gitlist.dev/t/10599

## Ronald Landheer-Cieslak, 2007-11-02 20:03

Subject: [PATCH] New script: git-changelog.perl - revised
Message-ID: <67837cd60711021303q488e0873lea363b93fc90d591@mail.gmail.com>
URL: https://gitlist.dev/e/67837cd60711021303q488e0873lea363b93fc90d591%40mail.gmail.com

```
I just noticed that I'd been sending personal replies to each and
every one of the replies I got - sorry about that.

Anyway, after Nicolas' suggestion, I moved the script into the contrib
directory and removed it from the Makefile, having the following patch
as net effect.
This is also available through git at
git://vlinder.landheer-cieslak.com/git/git.git#topic/git-log-changelog

As for difference wrt git2cl:
* less complicated
* less dependencies
* short hash for the commits are output in the change log
* git-changelog calls git-log with the proper parameters itself (no
need for the user to call it with a given set of parameters).

rlc

diff --git a/contrib/git-changelog/git-changelog.perl
b/contrib/git-changelog/git-changelog.perl
new file mode 100755
index 0000000..bffa1ab
--- /dev/null
+++ b/contrib/git-changelog/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"

```

## Andreas Ericsson, 2007-11-03 08:36

Subject: Re: [PATCH] New script: git-changelog.perl - revised
Message-ID: <472C3309.70109@op5.se>
URL: https://gitlist.dev/e/472C3309.70109%40op5.se
In-Reply-To: <67837cd60711021303q488e0873lea363b93fc90d591@mail.gmail.com>

```
Ronald Landheer-Cieslak wrote:
>
> This is also available through git at
> git://vlinder.landheer-cieslak.com/git/git.git#topic/git-log-changelog
> 

This mode of specifying a repository + branch was just thoroughly shot
down in a list discussion, and git certainly doesn't grok it. I'd be a
happier fella if you didn't use it.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

```

## Ronald Landheer-Cieslak, 2007-11-03 13:46

Subject: Re: [PATCH] New script: git-changelog.perl - revised
Message-ID: <67837cd60711030646p6d7dc8e3t8a5f5f336e8bbad6@mail.gmail.com>
URL: https://gitlist.dev/e/67837cd60711030646p6d7dc8e3t8a5f5f336e8bbad6%40mail.gmail.com
In-Reply-To: <472C3309.70109@op5.se>

```
On Nov 3, 2007 4:36 AM, Andreas Ericsson <ae@op5.se> wrote:
> Ronald Landheer-Cieslak wrote:
> >
> > This is also available through git at
> > git://vlinder.landheer-cieslak.com/git/git.git#topic/git-log-changelog
> >
>
> This mode of specifying a repository + branch was just thoroughly shot
> down in a list discussion, and git certainly doesn't grok it. I'd be a
> happier fella if you didn't use it.
>
Is there a canonical way to specify both the location and the branch
in one shot, then? I must admit that this is the way I've always seen
it specified, so I assumed that this is the way it was done
"canonically". If it isn't, please forgive my ignorance.

rlc


-- 
Ronald Landheer-Cieslak
Software Architect
http://www.landheer-cieslak.com/
New White Paper: "Three Good Reasons to Plan Ahead"

```

## Johannes Schindelin, 2007-11-03 13:58

Subject: Re: [PATCH] New script: git-changelog.perl - revised
Message-ID: <Pine.LNX.4.64.0711031357510.4362@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0711031357510.4362%40racer.site
In-Reply-To: <67837cd60711030646p6d7dc8e3t8a5f5f336e8bbad6@mail.gmail.com>

```
Hi,

On Sat, 3 Nov 2007, Ronald Landheer-Cieslak wrote:

> On Nov 3, 2007 4:36 AM, Andreas Ericsson <ae@op5.se> wrote:
> > Ronald Landheer-Cieslak wrote:
> > >
> > > This is also available through git at
> > > git://vlinder.landheer-cieslak.com/git/git.git#topic/git-log-changelog
> > >
> >
> > This mode of specifying a repository + branch was just thoroughly shot
> > down in a list discussion, and git certainly doesn't grok it. I'd be a
> > happier fella if you didn't use it.
> >
> Is there a canonical way to specify both the location and the branch
> in one shot, then?

Yes.  Create a repository containing only that branch, as "master", and 
point people to that repository.

Hth,
Dscho

```

## Alex Riesen, 2007-11-03 14:58

Subject: Re: [PATCH] New script: git-changelog.perl - revised
Message-ID: <20071103145848.GA3175@steel.home>
URL: https://gitlist.dev/e/20071103145848.GA3175%40steel.home
In-Reply-To: <67837cd60711030646p6d7dc8e3t8a5f5f336e8bbad6@mail.gmail.com>

```
Ronald Landheer-Cieslak, Sat, Nov 03, 2007 14:46:27 +0100:
> On Nov 3, 2007 4:36 AM, Andreas Ericsson <ae@op5.se> wrote:
> > Ronald Landheer-Cieslak wrote:
> > >
> > > This is also available through git at
> > > git://vlinder.landheer-cieslak.com/git/git.git#topic/git-log-changelog
> > >
> >
> > This mode of specifying a repository + branch was just thoroughly shot
> > down in a list discussion, and git certainly doesn't grok it. I'd be a
> > happier fella if you didn't use it.
> >
> Is there a canonical way to specify both the location and the branch
> in one shot, then? ...

Something like this:

    Please fetch from

    git://vlinder.landheer-cieslak.com/git/git.git topic/git-log-changelog

If one uses git-fetch the result will be in FETCH_HEAD, a pull will
merge it nicely with the commit message like:

    "Merge branch 'topic/git-log-changelog' of git://vlinder.landheer-cieslak.com/git/git"

which fits, I believe.

```
