From c5eb4247a5629b8baa18d4adbde1f0ab72d1a540 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sun, 24 Oct 2010 11:50:25 +0100 Subject: [PATCH] Improve commit messages for git imports Improve the quality of the commit messages produced by git import by adding an explicit author (obtained from the $module-author file), and by including a list of all of the upstream changes that are being imported. Change-Id: I73516865144eb6ecd631822d1103a9b18d01b049 Reviewed-on: http://gerrit.openafs.org/3099 Reviewed-by: Jeffrey Altman Tested-by: BuildBot Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/external/heimdal-author | 1 + src/external/heimdal-last | 1 + src/external/import-external-git.pl | 47 +++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/external/heimdal-author create mode 100644 src/external/heimdal-last diff --git a/src/external/heimdal-author b/src/external/heimdal-author new file mode 100644 index 0000000..3a9f432 --- /dev/null +++ b/src/external/heimdal-author @@ -0,0 +1 @@ +Heimdal Developers diff --git a/src/external/heimdal-last b/src/external/heimdal-last new file mode 100644 index 0000000..cbe734d --- /dev/null +++ b/src/external/heimdal-last @@ -0,0 +1 @@ +bf1f62b0a8cf72d32875656a7365f1e14d535dc5 diff --git a/src/external/import-external-git.pl b/src/external/import-external-git.pl index 5a279d3..2f2ca78 100755 --- a/src/external/import-external-git.pl +++ b/src/external/import-external-git.pl @@ -57,6 +57,24 @@ while (<$fh>) { } undef $fh; +# Read in our last-sha1 file +my $last; + +$fh = IO::File->new("$externalDir/$module-last"); +if ($fh) { + $last = $fh->getline; + chomp $last; +} +undef $fh; + +my $author; +$fh = IO::File->new("$externalDir/$module-author"); +if ($fh) { + $author = $fh->getline; + chomp $author; +} +undef $fh; + # Create the external directory, if it doesn't exist. mkdir "$externalDir/$module" if (! -d "$externalDir/$module"); @@ -82,6 +100,14 @@ my $commitDesc = `git describe $commitish`; chomp $commitSha1; chomp $commitDesc; +# If we know what our last import was, then get a list of all of the changes +# since that import +my $changes; +if ($last) { + my $filelist = join(' ', sort keys(%mapping)); + $changes = `git shortlog $last..$commitish $filelist`; +} + # Populate our temporary directory with the originals of everything that was # listed in the mapping file system("git archive --format=tar --prefix=source/ $commitish". @@ -141,15 +167,26 @@ eval { } if (system("git status") == 0) { - my $fh=IO::File->new("$tempdir/commit-msg", "w") + my $fh=IO::File->new("$externalDir/$module-last", "w"); + $fh->print($commitSha1."\n"); + undef $fh; + system("git add $externalDir/$module-last") == 0 + or die "Git add of last file failed with $!\n"; + + $fh=IO::File->new("$tempdir/commit-msg", "w") or die "Unable to write commit message\n"; $fh->print("Import of code from $module\n"); $fh->print("\n"); - $fh->print("This commit updates the code imported from the external\n"); - $fh->print("$module git repository to their revision\n$commitSha1\n"); - $fh->print("which is described as $commitDesc\n"); + $fh->print("This commit updates the code imported from $module to\n"); + $fh->print("$commitSha1 ($commitDesc)\n"); + if ($changes) { + $fh->print("\n"); + $fh->print("Upstream changes are:\n\n"); + $fh->print($changes); + } undef $fh; - system("git commit -F $tempdir/commit-msg") == 0 + $author="--author '$author'" if ($author); + system("git commit -F $tempdir/commit-msg $author") == 0 or die "Commit failed : $!\n"; } }; -- 1.9.4