Improve commit messages for git imports
authorSimon Wilkinson <sxw@your-file-system.com>
Sun, 24 Oct 2010 10:50:25 +0000 (11:50 +0100)
committerDerrick Brashear <shadow@dementia.org>
Wed, 27 Oct 2010 19:26:17 +0000 (12:26 -0700)
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 <jaltman@openafs.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/external/heimdal-author [new file with mode: 0644]
src/external/heimdal-last [new file with mode: 0644]
src/external/import-external-git.pl

diff --git a/src/external/heimdal-author b/src/external/heimdal-author
new file mode 100644 (file)
index 0000000..3a9f432
--- /dev/null
@@ -0,0 +1 @@
+Heimdal Developers <heimdal-discuss@sics.se>
diff --git a/src/external/heimdal-last b/src/external/heimdal-last
new file mode 100644 (file)
index 0000000..cbe734d
--- /dev/null
@@ -0,0 +1 @@
+bf1f62b0a8cf72d32875656a7365f1e14d535dc5
index 5a279d3..2f2ca78 100755 (executable)
@@ -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";
   }
 };