Merge branch 'bk/maint-cvsexportcommit'
authorJunio C Hamano <gitster@pobox.com>
Thu, 1 Nov 2007 22:39:59 +0000 (15:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Nov 2007 22:39:59 +0000 (15:39 -0700)
* bk/maint-cvsexportcommit:
cvsexportcommit: fix for commits that do not have parents

1  2 
git-cvsexportcommit.perl
diff --combined git-cvsexportcommit.perl
index f284c88a46b5cc7d6e75b78346829ce03e60b060,b2c9f98e86557dfe9649381fb9b24c1631cf004a..26844af4390b8b0902ad853f40e4d9f60b75fd23
@@@ -30,6 -30,11 +30,6 @@@ if ($opt_d) 
        @cvs = ('cvs');
  }
  
 -# setup a tempdir
 -our ($tmpdir, $tmpdirname) = tempdir('git-cvsapplycommit-XXXXXX',
 -                                   TMPDIR => 1,
 -                                   CLEANUP => 1);
 -
  # resolve target commit
  my $commit;
  $commit = pop @ARGV;
@@@ -82,6 -87,7 +82,7 @@@ foreach my $line (@commit) 
      }
  }
  
+ 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";
      }
  }
  
@@@ -116,7 -124,11 +119,11 @@@ if ($opt_a) 
  }
  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
  
@@@ -129,7 -141,7 +136,7 @@@ my $context = $opt_p ? '' : '-C1'
  print "Checking if patch will apply\n";
  
  my @stat;
 -open APPLY, "GIT_DIR= git-apply $context --binary --summary --numstat<.cvsexportcommit.diff|" || die "cannot patch";
 +open APPLY, "GIT_DIR= git-apply $context --summary --numstat<.cvsexportcommit.diff|" || die "cannot patch";
  @stat=<APPLY>;
  close APPLY || die "Cannot patch";
  my (@bfiles,@files,@afiles,@dfiles);
@@@ -215,7 -227,7 +222,7 @@@ if ($dirty) 
  }
  
  print "Applying\n";
 -`GIT_DIR= git-apply $context --binary --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch";
 +`GIT_DIR= git-apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch";
  
  print "Patch applied successfully. Adding new files and directories to CVS\n";
  my $dirtypatch = 0;