Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Benes <mbenes@suse.cz>2015-04-01 13:39:26 +0200
committerMiroslav Benes <mbenes@suse.cz>2015-04-01 13:41:50 +0200
commit212a7ae1831a636a0b3fc0a52d65d35066ba1c57 (patch)
treec750287c0fa48ed52d152db67ff2b13d26218d58
parentbc88dd7eb10290d6196fc58d1a8b8e4860675be8 (diff)
Automatically generate .changes file from git log
Also add comments to tar-up.sh script to distinguish between sections. Signed-off-by: Miroslav Benes <mbenes@suse.cz>
-rw-r--r--rpm/kgraft-patch.changes30
-rwxr-xr-xscripts/gitlog2changes.pl151
-rwxr-xr-xscripts/tar-up.sh10
3 files changed, 160 insertions, 31 deletions
diff --git a/rpm/kgraft-patch.changes b/rpm/kgraft-patch.changes
deleted file mode 100644
index c438ebe..0000000
--- a/rpm/kgraft-patch.changes
+++ /dev/null
@@ -1,30 +0,0 @@
--------------------------------------------------------------------
-Tue Mar 24 11:14:47 UTC 2015 - mmarek@suse.cz
-
-- Add the git commit and branch to the package description (bnc#920633)
-
--------------------------------------------------------------------
-Wed Nov 26 09:08:31 UTC 2014 - mbenes@suse.com
-
-- Set .immediate flags for the initial patch
-
--------------------------------------------------------------------
-Tue Nov 25 15:25:31 UTC 2014 - mbenes@suse.com
-
-- Add .replace_all set as true even to the initial patch
-
--------------------------------------------------------------------
-Mon Nov 24 14:02:20 UTC 2014 - mmarek@suse.cz
-
-- Drop the hardcoded kernel release string.
-
--------------------------------------------------------------------
-Wed Nov 12 03:10:13 UTC 2014 - mmarek@suse.com
-
-- Mark the module as supported (bnc#904970)
-
--------------------------------------------------------------------
-Mon Nov 3 13:37:39 UTC 2014 - mbenes@suse.com
-
-- Package with initial kGraft patch (uname)
-
diff --git a/scripts/gitlog2changes.pl b/scripts/gitlog2changes.pl
new file mode 100755
index 0000000..718c2d9
--- /dev/null
+++ b/scripts/gitlog2changes.pl
@@ -0,0 +1,151 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use POSIX qw(strftime setlocale LC_ALL);
+
+$ENV{'TZ'} = "CET";
+setlocale(LC_ALL, "C");
+
+{
+my ($last_ts, $last_email, $last_commit, $last_message) = (0, "");
+sub print_commit {
+ my ($commit, $email, $ts, @message) = @_;
+
+ return unless $commit;
+ # display series by the same author and with the same author date
+ # as a single changelog entry (see scripts/log2)
+ if ($last_ts != $ts || $last_email ne $email) {
+ if ($last_commit) {
+ print "- commit " . substr($last_commit, 0, 7) . "\n\n";
+ }
+ return unless @message;
+ print "-" x 67 . "\n";
+ print strftime("%a %b %e %H:%M:%S %Z %Y - $email\n\n",
+ localtime($ts));
+ $last_commit = $commit;
+ $last_message = "";
+ }
+ $last_ts = $ts;
+ $last_email = $email;
+ my $first = 1;
+ for my $line (@message) {
+ if ($line !~ /^[- ] /) {
+ if ($first) {
+ $line = "- $line";
+ } else {
+ $line = " $line";
+ }
+ }
+ $first = 0;
+ }
+ my $msg = join("\n", @message);
+ if ($msg eq $last_message) {
+ # avoid printing cherry-picked commits twice
+ # FIXME: Handle the case where a whole patch series is
+ # cherry-picked one by one. At the same time, we do not want
+ # to filter commits, that have the same changelog within a
+ # series, but are different. See for example
+ # git grep 'e1000e: update driver version number' SLE11-SP3
+ # and many others
+ return;
+ }
+ $last_message = $msg;
+ print $msg, "\n";
+}
+}
+
+sub parse_gitlog {
+ my $fh = shift;
+
+ my @res;
+ my $cur = { message => [] };
+ my @states = qw(commit tree parent author committer blank message);
+ my $st = 0;
+ while (my $line = <$fh>) {
+ next if $line =~ /^#/;
+ chomp($line);
+ my $expect = $states[$st];
+ if ($expect eq "blank") {
+ if ($line ne "") {
+ die "Malformed git rev-parse output ($cur->{commit}): expected blank line, got \"$line\"\n";
+ }
+ $st++;
+ next;
+ }
+ if ($expect eq "message") {
+ if ($line eq "") {
+ push(@res, $cur);
+ $cur = { message => [] };
+ $st = 0;
+ next;
+ }
+ if ($line !~ s/^ {4}//) {
+ die "Malformed git rev-parse output ($cur->{commit}): expected log message, got \"$line\"\n";
+ }
+ next unless $line;
+ # delete Signed-off-by: et al
+ next if $line =~ /^[A-Z][-a-zA-Z]+-by: /;
+ push(@{$cur->{message}}, $line) if $line;
+ next;
+ }
+ # parsing commit headers
+ next if $expect eq "commit" && $line eq "";
+ (my $got = $line) =~ s/ .*//;
+ # Root commit has no "parent" header. Multiple "parent" headers are
+ # not possible, since we use --no-merges
+ if ($expect eq "parent" && $got eq "author") {
+ $expect = $states[++$st];
+ }
+ if ($got ne $expect) {
+ $cur->{commit} ||= "commit unknown";
+ die "Malformed git rev-parse output ($cur->{commit}): expected \"$expect\", got \"$got\"\n";
+ }
+ if ($got eq "commit") {
+ ($cur->{commit} = $line) =~ s/^commit //;
+ } elsif ($got eq "author") {
+ ($cur->{email} = $line) =~ s/.*<(.+)>.*/$1/;
+ ($cur->{ts} = $line) =~ s/.*> (\d+) [-+]\d{4}$/$1/;
+ if (!$cur->{email} || !$cur->{ts}) {
+ die "Malformed author header ($cur->{commit}): $line\n";
+ }
+ }
+ $st++;
+ }
+ return @res;
+}
+
+my @fixups;
+if ($ARGV[0] eq "--fixups") {
+ shift(@ARGV);
+ my $fixups_file = shift(@ARGV);
+ open(my $fh, '<', $fixups_file) or die "$fixups_file: $!\n";
+ @fixups = parse_gitlog($fh);
+ close($fh);
+}
+
+open(my $pipe, '-|', "git", "rev-list", "--no-merges", "--pretty=raw", @ARGV)
+ or die "Error running git rev-list: $!\n";
+my @commits = parse_gitlog($pipe);
+close($pipe) or die "Error running git rev-list: $!\n";
+
+# apply any fixups
+my %commits_h = map { $_->{commit} => $_ } @commits;
+for my $fix (@fixups) {
+ my $orig = $commits_h{$fix->{commit}};
+ if (!$fix->{message}) {
+ # delete the original commit
+ $orig->{commit} = undef;
+ } else {
+ $orig->{email} = $fix->{email};
+ $orig->{ts} = $fix->{ts};
+ $orig->{message} = $fix->{message};
+ }
+}
+
+for my $c (sort { $b->{ts} - $a->{ts} } @commits) {
+ print_commit($c->{commit}, $c->{email}, $c->{ts}, @{$c->{message}});
+}
+# print "- commit 1234567" for the last commit
+print_commit($commits[$#commits]->{commit}, "", 0);
diff --git a/scripts/tar-up.sh b/scripts/tar-up.sh
index 9a5bded..3880893 100755
--- a/scripts/tar-up.sh
+++ b/scripts/tar-up.sh
@@ -1,5 +1,6 @@
#!/bin/bash
+# options
until [ "$#" = "0" ] ; do
case "$1" in
--dir=*)
@@ -28,6 +29,7 @@ EOF
esac
done
+# builddir
[ -z "$build_dir" ] && build_dir=kgraft-mod-source
if [ -z "$build_dir" ]; then
echo "Please define the build directory with the --dir option" >&2
@@ -37,6 +39,7 @@ fi
rm -f "$build_dir"/*
mkdir -p "$build_dir"
+# archives
# eventual TODO: make it more general
archives="uname_patch"
for archive in $archives; do
@@ -44,14 +47,15 @@ for archive in $archives; do
tar cfj $build_dir/$archive.tar.bz2 $archive
done
+# install to builddir
source $(dirname $0)/release-version.sh
install -m 644 kgr_patch_main.c $build_dir
install -m 644 Makefile $build_dir
install -m 644 rpm/kgraft-patch.spec $build_dir/kgraft-patch-"$RELEASE".spec
-install -m 644 rpm/kgraft-patch.changes $build_dir/kgraft-patch-"$RELEASE".changes
install -m 644 rpm/config.sh $build_dir/config.sh
+# timestamp
tsfile=source-timestamp
ts=$(git show --pretty=format:%ct HEAD | head -n 1)
date "+%Y-%m-%d %H:%M:%S %z" -d "1970-01-01 00:00 UTC $ts seconds" >$build_dir/$tsfile
@@ -68,3 +72,7 @@ sed -i \
d
}" \
$build_dir/kgraft-patch-"$RELEASE".spec
+
+# changelog
+changelog=$build_dir/kgraft-patch-"$RELEASE".changes
+scripts/gitlog2changes.pl HEAD -- > "$changelog"