From 57e0e3ebd6fac2bf5fe46fd946dae6129b07f474 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 23:30:43 +0100 Subject: cvsexportcommit: chomp only removes trailing whitespace In commit fef3a7cc(cvsexportcommit: be graceful when "cvs status" reorders the arguments), caution was taken to get the status even for files with leading or trailing whitespace. However, the author of that commit missed that chomp() removes only trailing newlines. With help of the mailing list, the author realized his mistake and provided this patch. The idea is that we do not want to rely on a certain layout of the output of "cvs status". Therefore we only call it with files that are unambiguous after stripping leading and trailing whitespace. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-cvsexportcommit.perl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git-cvsexportcommit.perl') diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl index b6036bd4d..317a89027 100755 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@ -210,7 +210,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; -- cgit v1.2.1 From d775734c40afed216160437c59a45c93bdf28689 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 15:29:49 +0100 Subject: cvsexportcommit: introduce -W for shared working trees (between Git and CVS) If you have a CVS checkout, it is easy to import the CVS history by calling "git cvsimport". However, interacting with the CVS repository using "git cvsexportcommit" was cumbersome, since that script assumes separate working directories for Git and CVS. Now, you can call cvsexportcommit with the -W option. This will automatically discover the GIT_DIR, and it will check out the parent commit before exporting the commit. The intended workflow is this: $ CVSROOT=$URL cvs co module $ cd module $ git cvsimport hack, hack, hack, making two commits, cleaning them up using rebase -i. $ git cvsexportcommit -W -c -p -u HEAD^ $ git cvsexportcommit -W -c -p -u HEAD Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-cvsexportcommit.perl | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'git-cvsexportcommit.perl') diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl index 317a89027..eaa3218e7 100755 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@ -7,15 +7,15 @@ use Data::Dumper; use File::Basename qw(basename dirname); use File::Spec; -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; -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 @@ -25,7 +25,9 @@ if ($opt_w) { } # 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"; } @@ -116,6 +118,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 @@ -260,7 +271,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; @@ -313,7 +328,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); } @@ -333,6 +350,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. -- cgit v1.2.1