summaryrefslogtreecommitdiff
path: root/git-cvsexportcommit.perl
diff options
context:
space:
mode:
Diffstat (limited to 'git-cvsexportcommit.perl')
-rwxr-xr-xgit-cvsexportcommit.perl26
1 files changed, 15 insertions, 11 deletions
diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl
index fc00d5946a..289d4bc684 100755
--- a/git-cvsexportcommit.perl
+++ b/git-cvsexportcommit.perl
@@ -22,11 +22,15 @@ die "Need at least one commit identifier!" unless @ARGV;
my $repo = Git->repository();
$opt_w = $repo->config('cvsexportcommit.cvsdir') unless defined $opt_w;
+my $tmpdir = File::Temp::tempdir(CLEANUP => 1);
+my $hash_algo = $repo->config('extensions.objectformat') || 'sha1';
+my $hexsz = $hash_algo eq 'sha256' ? 64 : 40;
+
if ($opt_w || $opt_W) {
# Remember where GIT_DIR is before changing to CVS checkout
unless ($ENV{GIT_DIR}) {
# No GIT_DIR set. Figure it out for ourselves
- my $gd =`git-rev-parse --git-dir`;
+ my $gd =`git rev-parse --git-dir`;
chomp($gd);
$ENV{GIT_DIR} = $gd;
}
@@ -62,7 +66,7 @@ if ($opt_d) {
# resolve target commit
my $commit;
$commit = pop @ARGV;
-$commit = safe_pipe_capture('git-rev-parse', '--verify', "$commit^0");
+$commit = safe_pipe_capture('git', 'rev-parse', '--verify', "$commit^0");
chomp $commit;
if ($?) {
die "The commit reference $commit did not resolve!";
@@ -72,7 +76,7 @@ if ($?) {
my $parent;
if (@ARGV) {
$parent = pop @ARGV;
- $parent = safe_pipe_capture('git-rev-parse', '--verify', "$parent^0");
+ $parent = safe_pipe_capture('git', 'rev-parse', '--verify', "$parent^0");
chomp $parent;
if ($?) {
die "The parent reference did not resolve!";
@@ -80,7 +84,7 @@ if (@ARGV) {
}
# find parents from the commit itself
-my @commit = safe_pipe_capture('git-cat-file', 'commit', $commit);
+my @commit = safe_pipe_capture('git', 'cat-file', 'commit', $commit);
my @parents;
my $committer;
my $author;
@@ -96,7 +100,7 @@ foreach my $line (@commit) {
}
if ($stage eq 'headers') {
- if ($line =~ m/^parent (\w{40})$/) { # found a parent
+ if ($line =~ m/^parent ([0-9a-f]{$hexsz})$/) { # found a parent
push @parents, $1;
} elsif ($line =~ m/^author (.+) \d+ [-+]\d+$/) {
$author = $1;
@@ -111,7 +115,7 @@ foreach my $line (@commit) {
}
}
-my $noparent = "0000000000000000000000000000000000000000";
+my $noparent = "0" x $hexsz;
if ($parent) {
my $found;
# double check that it's a valid parent
@@ -158,9 +162,9 @@ if ($opt_a) {
close MSG;
if ($parent eq $noparent) {
- `git-diff-tree --binary -p --root $commit >.cvsexportcommit.diff`;# || die "Cannot diff";
+ `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";
+ `git diff-tree --binary -p $parent $commit >.cvsexportcommit.diff`;# || die "Cannot diff";
}
## apply non-binary changes
@@ -174,7 +178,7 @@ my $context = $opt_p ? '' : '-C1';
print "Checking if patch will apply\n";
my @stat;
-open APPLY, "GIT_DIR= git-apply $context --summary --numstat<.cvsexportcommit.diff|" || die "cannot patch";
+open APPLY, "GIT_INDEX_FILE=$tmpdir/index git apply $context --summary --numstat<.cvsexportcommit.diff|" || die "cannot patch";
@stat=<APPLY>;
close APPLY || die "Cannot patch";
my (@bfiles,@files,@afiles,@dfiles);
@@ -329,7 +333,7 @@ print "Applying\n";
if ($opt_W) {
system("git checkout -q $commit^0") && die "cannot patch";
} else {
- `GIT_DIR= git-apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch";
+ `GIT_INDEX_FILE=$tmpdir/index git apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch";
}
print "Patch applied successfully. Adding new files and directories to CVS\n";
@@ -407,7 +411,7 @@ unlink(".cvsexportcommit.diff");
if ($opt_W) {
system("git checkout $go_back_to") && die "cannot move back to $go_back_to";
- if (!($go_back_to =~ /^[0-9a-fA-F]{40}$/)) {
+ if (!($go_back_to =~ /^[0-9a-fA-F]{$hexsz}$/)) {
system("git symbolic-ref HEAD $go_back_to") &&
die "cannot move back to $go_back_to";
}