7
use File::Basename qw(basename dirname);
8
use File::Spec;
9
10
-our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w);
10
+our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w, $opt_W);
11
12
-getopts('uhPpvcfam:d:w:');
12
+getopts('uhPpvcfam:d:w:W');
13
14
$opt_h && usage();
15
16
die "Need at least one commit identifier!" unless @ARGV;
17
18
-if ($opt_w) {
18
+if ($opt_w || $opt_W) {
19
# Remember where GIT_DIR is before changing to CVS checkout
20
unless ($ENV{GIT_DIR}) {
21
# No GIT_DIR set. Figure it out for ourselves
25
}
26
# Make sure GIT_DIR is absolute
27
$ENV{GIT_DIR} = File::Spec->rel2abs($ENV{GIT_DIR});
28
+}
29
30
+if ($opt_w) {
31
if (! -d $opt_w."/CVS" ) {
32
die "$opt_w is not a CVS checkout";
33
}
118
}
119
}
120
121
+my $go_back_to = 0;
122
+
123
+if ($opt_W) {
124
+ $opt_v && print "Resetting to $parent\n";
125
+ $go_back_to = `git symbolic-ref HEAD 2> /dev/null ||
126
+ git rev-parse HEAD` || die "Could not determine current branch";
127
+ system("git checkout -q $parent^0") && die "Could not check out $parent^0";
128
+}
129
+
130
$opt_v && print "Applying to CVS commit $commit from parent $parent\n";
131
132
# grab the commit message
271
}
272
273
print "Applying\n";
263
-`GIT_DIR= git-apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch";
274
+if ($opt_W) {
275
+ system("git checkout -q $commit^0") && die "cannot patch";
276
+} else {
277
+ `GIT_DIR= git-apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch";
278
+}
279
280
print "Patch applied successfully. Adding new files and directories to CVS\n";
281
my $dirtypatch = 0;
328
print "using a patch program. After applying the patch and resolving the\n";
329
print "problems you may commit using:";
330
print "\n cd \"$opt_w\"" if $opt_w;
316
- print "\n $cmd\n\n";
331
+ print "\n $cmd\n";
332
+ print "\n git checkout $go_back_to\n" if $go_back_to;
333
+ print "\n";
334
exit(1);
335
}
336
350
# clean up
351
unlink(".cvsexportcommit.diff");
352
353
+if ($opt_W) {
354
+ system("git checkout $go_back_to") && die "cannot move back to $go_back_to";
355
+ if (!($go_back_to =~ /^[0-9a-fA-F]{40}$/)) {
356
+ system("git symbolic-ref HEAD $go_back_to") &&
357
+ die "cannot move back to $go_back_to";
358
+ }
359
+}
360
+
361
# CVS version 1.11.x and 1.12.x sleeps the wrong way to ensure the timestamp
362
# used by CVS and the one set by subsequence file modifications are different.
363
# If they are not different CVS will not detect changes.