cvsexportcommit: fix for commits that do not have parents
authorBrad King <brad.king@kitware.com>
Wed, 31 Oct 2007 20:55:13 +0000 (16:55 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Nov 2007 06:51:13 +0000 (23:51 -0700)
Previously commits without parents would fail to export with a
message indicating that the commits had more than one parent.
Instead we should use the --root option for git-diff-tree in
place of a parent.

Signed-off-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-cvsexportcommit.perl
index 7b19a33ad1cceaf61793be4e16e4b144d415a975..b2c9f98e86557dfe9649381fb9b24c1631cf004a 100755 (executable)
@@ -87,6 +87,7 @@
     }
 }
 
+my $noparent = "0000000000000000000000000000000000000000";
 if ($parent) {
     my $found;
     # double check that it's a valid parent
 } else { # we don't have a parent from the cmdline...
     if (@parents == 1) { # it's safe to get it from the commit
        $parent = $parents[0];
-    } else { # or perhaps not!
-       die "This commit has more than one parent -- please name the parent you want to use explicitly";
+    } elsif (@parents == 0) { # there is no parent
+        $parent = $noparent;
+    } else { # cannot choose automatically from multiple parents
+        die "This commit has more than one parent -- please name the parent you want to use explicitly";
     }
 }
 
 }
 close MSG;
 
-`git-diff-tree --binary -p $parent $commit >.cvsexportcommit.diff`;# || die "Cannot diff";
+if ($parent eq $noparent) {
+    `git-diff-tree --binary -p --root $commit >.cvsexportcommit.diff`;# || die "Cannot diff";
+} else {
+    `git-diff-tree --binary -p $parent $commit >.cvsexportcommit.diff`;# || die "Cannot diff";
+}
 
 ## apply non-binary changes