Browse Source

Generate ChangeLog from git log

* .gitignore: Add ChangeLog
* ChangeLog: Rename to ChangeLog-CVS.
* Makefile.am (gen-changelog): New rule.
(dist-hook): Depend on it.
(EXTRA_DIST): Add ChangeLog-CVS.
* README-hacking: Describe changes.
* gitlog-to-changelog: Import from gnulib.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin 10 years ago
parent
commit
08f922a574
5 changed files with 216 additions and 2 deletions
  1. 2
    0
      .gitignore
  2. 0
    0
      ChangeLog-CVS
  3. 11
    1
      Makefile.am
  4. 20
    1
      README-hacking
  5. 183
    0
      gitlog-to-changelog

+ 2
- 0
.gitignore View File

@@ -4,6 +4,8 @@
4 4
 .libs
5 5
 .*.swp
6 6
 
7
+ChangeLog
8
+
7 9
 Makefile
8 10
 Makefile.in
9 11
 

ChangeLog → ChangeLog-CVS View File


+ 11
- 1
Makefile.am View File

@@ -24,7 +24,7 @@ EXTRA_DIST = $(man_MANS) errnoent.sh signalent.sh syscallent.sh ioctlsort.c \
24 24
 	     debian/strace.docs debian/strace.examples debian/strace.install \
25 25
 	     debian/strace.manpages debian/strace-udeb.install \
26 26
 	     strace.spec \
27
-	     strace-graph COPYRIGHT CREDITS PORTING \
27
+	     strace-graph ChangeLog-CVS COPYRIGHT CREDITS PORTING \
28 28
 	     README-freebsd README-linux README-sunos4 README-svr4 \
29 29
 	     linux/ioctlsort.c linux/ioctlent.sh \
30 30
 	     linux/ioctlent.h linux/errnoent.h linux/signalent.h \
@@ -83,6 +83,16 @@ EXTRA_DIST = $(man_MANS) errnoent.sh signalent.sh syscallent.sh ioctlsort.c \
83 83
 	     svr4/signalent.h svr4/syscall.h svr4/syscallent.h \
84 84
 	     xlate.el
85 85
 
86
+gen_changelog_start_date = 2009-07-09
87
+gen-changelog:
88
+	if test -d .git; then \
89
+		$(top_srcdir)/gitlog-to-changelog \
90
+		  --since=$(gen_changelog_start_date) \
91
+		  > $(distdir)/ChangeLog; \
92
+	fi
93
+dist-hook: gen-changelog
94
+.PHONY: gen-changelog
95
+
86 96
 if MAINTAINER_MODE
87 97
 if LINUX
88 98
 

+ 20
- 1
README-hacking View File

@@ -1,5 +1,24 @@
1
-
1
+Requirements
2
+============
2 3
 If you use the GIT version of strace there will be some files missing
3 4
 that you need to build strace.  These files are generated by tools from
4 5
 the GNU Autoconf and Automake packages.  You need recent versions, which
5 6
 provide the `autoreconf -i' command that will do everything you need.
7
+
8
+
9
+No more ChangeLog file
10
+======================
11
+Do not create or modify the ChangeLog files.  Starting at 2009-07-09, the
12
+policy changed.  Before, we would insert the exact same text (or worse,
13
+sometimes slightly differing) into both the ChangeLog file and the commit
14
+log.  Now we put that information only in the commit log, and generate
15
+the top-level ChangeLog file from logs at "make dist" time.  As such,
16
+there are strict requirements on the form of the commit log messages.
17
+
18
+
19
+Commit log requirements
20
+=======================
21
+Each commit log should always start with a one-line summary, the second
22
+line should be blank, and the remaining lines are usually ChangeLog-style
23
+entries for all affected files, except the leading TABs which should
24
+be omitted.

+ 183
- 0
gitlog-to-changelog View File

@@ -0,0 +1,183 @@
1
+#!/usr/bin/perl
2
+# Convert git log output to ChangeLog format.
3
+
4
+my $VERSION = '2009-06-04 08:53'; # UTC
5
+# The definition above must lie within the first 8 lines in order
6
+# for the Emacs time-stamp write hook (at end) to update it.
7
+# If you change this file with Emacs, please let the write hook
8
+# do its job.  Otherwise, update this string manually.
9
+
10
+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
11
+
12
+# This program is free software: you can redistribute it and/or modify
13
+# it under the terms of the GNU General Public License as published by
14
+# the Free Software Foundation, either version 3 of the License, or
15
+# (at your option) any later version.
16
+
17
+# This program is distributed in the hope that it will be useful,
18
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+# GNU General Public License for more details.
21
+
22
+# You should have received a copy of the GNU General Public License
23
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
+
25
+# Written by Jim Meyering
26
+
27
+use strict;
28
+use warnings;
29
+use Getopt::Long;
30
+use POSIX qw(strftime);
31
+
32
+(my $ME = $0) =~ s|.*/||;
33
+
34
+# use File::Coda; # http://meyering.net/code/Coda/
35
+END {
36
+  defined fileno STDOUT or return;
37
+  close STDOUT and return;
38
+  warn "$ME: failed to close standard output: $!\n";
39
+  $? ||= 1;
40
+}
41
+
42
+sub usage ($)
43
+{
44
+  my ($exit_code) = @_;
45
+  my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
46
+  if ($exit_code != 0)
47
+    {
48
+      print $STREAM "Try `$ME --help' for more information.\n";
49
+    }
50
+  else
51
+    {
52
+      print $STREAM <<EOF;
53
+Usage: $ME [OPTIONS] [ARGS]
54
+
55
+Convert git log output to ChangeLog format.  If present, any ARGS
56
+are passed to "git log".  To avoid ARGS being parsed as options to
57
+$ME, they may be preceded by '--'.
58
+
59
+OPTIONS:
60
+
61
+   --since=DATE convert only the logs since DATE;
62
+                  the default is to convert all log entries.
63
+
64
+   --help       display this help and exit
65
+   --version    output version information and exit
66
+
67
+EXAMPLE:
68
+
69
+  $ME --since=2008-01-01 > ChangeLog
70
+  $ME -- -n 5 foo > last-5-commits-to-branch-foo
71
+
72
+EOF
73
+    }
74
+  exit $exit_code;
75
+}
76
+
77
+# If the string $S is a well-behaved file name, simply return it.
78
+# If it contains white space, quotes, etc., quote it, and return the new string.
79
+sub shell_quote($)
80
+{
81
+  my ($s) = @_;
82
+  if ($s =~ m![^\w+/.,-]!)
83
+    {
84
+      # Convert each single quote to '\''
85
+      $s =~ s/\'/\'\\\'\'/g;
86
+      # Then single quote the string.
87
+      $s = "'$s'";
88
+    }
89
+  return $s;
90
+}
91
+
92
+sub quoted_cmd(@)
93
+{
94
+  return join (' ', map {shell_quote $_} @_);
95
+}
96
+
97
+{
98
+  my $since_date = '1970-01-01 UTC';
99
+  GetOptions
100
+    (
101
+     help => sub { usage 0 },
102
+     version => sub { print "$ME version $VERSION\n"; exit },
103
+     'since=s' => \$since_date,
104
+    ) or usage 1;
105
+
106
+  my @cmd = (qw (git log --log-size), "--since=$since_date",
107
+             '--pretty=format:%ct  %an  <%ae>%n%n%s%n%b%n', @ARGV);
108
+  open PIPE, '-|', @cmd
109
+    or die ("$ME: failed to run `". quoted_cmd (@cmd) ."': $!\n"
110
+            . "(Is your Git too old?  Version 1.5.1 or later is required.)\n");
111
+
112
+  my $prev_date_line = '';
113
+  while (1)
114
+    {
115
+      defined (my $in = <PIPE>)
116
+        or last;
117
+      $in =~ /^log size (\d+)$/
118
+        or die "$ME:$.: Invalid line (expected log size):\n$in";
119
+      my $log_nbytes = $1;
120
+
121
+      my $log;
122
+      my $n_read = read PIPE, $log, $log_nbytes;
123
+      $n_read == $log_nbytes
124
+        or die "$ME:$.: unexpected EOF\n";
125
+
126
+      my @line = split "\n", $log;
127
+      my $author_line = shift @line;
128
+      defined $author_line
129
+        or die "$ME:$.: unexpected EOF\n";
130
+      $author_line =~ /^(\d+)  (.*>)$/
131
+        or die "$ME:$.: Invalid line "
132
+          . "(expected date/author/email):\n$author_line\n";
133
+
134
+      my $date_line = sprintf "%s  $2\n", strftime ("%F", localtime ($1));
135
+      # If this line would be the same as the previous date/name/email
136
+      # line, then arrange not to print it.
137
+      if ($date_line ne $prev_date_line)
138
+        {
139
+          $prev_date_line eq ''
140
+            or print "\n";
141
+          print $date_line;
142
+        }
143
+      $prev_date_line = $date_line;
144
+
145
+      # Omit "Signed-off-by..." lines.
146
+      @line = grep !/^Signed-off-by: .*>$/, @line;
147
+
148
+      # If there were any lines
149
+      if (@line == 0)
150
+        {
151
+          warn "$ME: warning: empty commit message:\n  $date_line\n";
152
+        }
153
+      else
154
+        {
155
+          # Remove leading and trailing blank lines.
156
+          while ($line[0] =~ /^\s*$/) { shift @line; }
157
+          while ($line[$#line] =~ /^\s*$/) { pop @line; }
158
+
159
+          # Prefix each non-empty line with a TAB.
160
+          @line = map { length $_ ? "\t$_" : '' } @line;
161
+
162
+          print "\n", join ("\n", @line), "\n";
163
+        }
164
+
165
+      defined ($in = <PIPE>)
166
+        or last;
167
+      $in ne "\n"
168
+        and die "$ME:$.: unexpected line:\n$in";
169
+    }
170
+
171
+  close PIPE
172
+    or die "$ME: error closing pipe from " . quoted_cmd (@cmd) . "\n";
173
+  # FIXME-someday: include $PROCESS_STATUS in the diagnostic
174
+}
175
+
176
+# Local Variables:
177
+# indent-tabs-mode: nil
178
+# eval: (add-hook 'write-file-hooks 'time-stamp)
179
+# time-stamp-start: "my $VERSION = '"
180
+# time-stamp-format: "%:y-%02m-%02d %02H:%02M"
181
+# time-stamp-time-zone: "UTC"
182
+# time-stamp-end: "'; # UTC"
183
+# End:

Loading…
Cancel
Save