From: Junio C Hamano Date: Sun, 25 May 2008 20:37:20 +0000 (-0700) Subject: Merge branch 'js/cvsexportcommit' X-Git-Tag: v1.5.6-rc0~11 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6c99f18660f62f90b83f0592c81ab6a4092d6d13?hp=-c Merge branch 'js/cvsexportcommit' * js/cvsexportcommit: cvsexportcommit: introduce -W for shared working trees (between Git and CVS) cvsexportcommit: chomp only removes trailing whitespace Conflicts: git-cvsexportcommit.perl --- 6c99f18660f62f90b83f0592c81ab6a4092d6d13 diff --combined Documentation/git-cvsexportcommit.txt index 363c36d694,b78c9f36f3..f75afaaadc --- a/Documentation/git-cvsexportcommit.txt +++ b/Documentation/git-cvsexportcommit.txt @@@ -8,7 -8,7 +8,7 @@@ git-cvsexportcommit - Export a single c SYNOPSIS -------- - 'git-cvsexportcommit' [-h] [-u] [-v] [-c] [-P] [-p] [-a] [-d cvsroot] [-w cvsworkdir] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID + 'git-cvsexportcommit' [-h] [-u] [-v] [-c] [-P] [-p] [-a] [-d cvsroot] [-w cvsworkdir] [-W] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID DESCRIPTION @@@ -65,17 -65,16 +65,22 @@@ OPTION -w:: Specify the location of the CVS checkout to use for the export. This option does not require GIT_DIR to be set before execution if the - current directory is within a git repository. + current directory is within a git repository. The default is the + value of 'cvsexportcommit.cvsdir'. + -W:: + Tell cvsexportcommit that the current working directory is not only + a Git checkout, but also the CVS checkout. Therefore, Git will + reset the working directory to the parent commit before proceeding. + -v:: Verbose. +CONFIGURATION +------------- +cvsexportcommit.cvsdir:: + The default location of the CVS checkout to use for the export. + EXAMPLES -------- diff --combined git-cvsexportcommit.perl index c93bd9c9b5,eaa3218e79..c6c70e9eba --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@@ -6,21 -6,16 +6,21 @@@ use File::Temp qw(tempdir) use Data::Dumper; use File::Basename qw(basename dirname); use File::Spec; +use Git; - our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w); + 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); - getopts('uhPpvcfam:d:w:'); + getopts('uhPpvcfam:d:w:W'); $opt_h && usage(); die "Need at least one commit identifier!" unless @ARGV; +# Get git-config settings +my $repo = Git->repository(); +$opt_w = $repo->config('cvsexportcommit.cvsdir') unless defined $opt_w; + - if ($opt_w) { + 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 @@@ -30,7 -25,9 +30,9 @@@ } # Make sure GIT_DIR is absolute $ENV{GIT_DIR} = File::Spec->rel2abs($ENV{GIT_DIR}); + } + if ($opt_w) { if (! -d $opt_w."/CVS" ) { die "$opt_w is not a CVS checkout"; } @@@ -121,6 -118,15 +123,15 @@@ if ($parent) } } + my $go_back_to = 0; + + if ($opt_W) { + $opt_v && print "Resetting to $parent\n"; + $go_back_to = `git symbolic-ref HEAD 2> /dev/null || + git rev-parse HEAD` || die "Could not determine current branch"; + system("git checkout -q $parent^0") && die "Could not check out $parent^0"; + } + $opt_v && print "Applying to CVS commit $commit from parent $parent\n"; # grab the commit message @@@ -215,7 -221,8 +226,8 @@@ if (@canstatusfiles) my $basename = basename($name); $basename = "no file " . $basename if (exists($added{$basename})); - chomp($basename); + $basename =~ s/^\s+//; + $basename =~ s/\s+$//; if (!exists($fullname{$basename})) { $fullname{$basename} = $name; @@@ -264,7 -271,11 +276,11 @@@ if ($dirty) } print "Applying\n"; - `GIT_DIR= git-apply $context --summary --numstat --apply <.cvsexportcommit.diff` || die "cannot patch"; + 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"; + } print "Patch applied successfully. Adding new files and directories to CVS\n"; my $dirtypatch = 0; @@@ -317,7 -328,9 +333,9 @@@ if ($dirtypatch) print "using a patch program. After applying the patch and resolving the\n"; print "problems you may commit using:"; print "\n cd \"$opt_w\"" if $opt_w; - print "\n $cmd\n\n"; + print "\n $cmd\n"; + print "\n git checkout $go_back_to\n" if $go_back_to; + print "\n"; exit(1); } @@@ -337,6 -350,14 +355,14 @@@ if ($opt_c) # clean up 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}$/)) { + system("git symbolic-ref HEAD $go_back_to") && + die "cannot move back to $go_back_to"; + } + } + # CVS version 1.11.x and 1.12.x sleeps the wrong way to ensure the timestamp # used by CVS and the one set by subsequence file modifications are different. # If they are not different CVS will not detect changes.