From 3ff903bfb9e34a02f681f1c95ef7aa3ce4d54d2a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 18 Feb 2006 03:49:38 -0800 Subject: [PATCH 1/3] archimport: remove files from the index before adding/updating This fixes a bug when importing where a directory gets removed/renamed but is immediately replaced by a file of the same name in the same changeset. This fix only applies to the accurate (default) strategy the moment. This patch should also fix the fast strategy if/when it is updated to handle the cases that would've triggered this bug. This bug was originally found in git-svn, but I remembered I did the same thing with archimport as well. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-archimport.perl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/git-archimport.perl b/git-archimport.perl index 841738d5c7..6792624d46 100755 --- a/git-archimport.perl +++ b/git-archimport.perl @@ -346,12 +346,10 @@ sub process_patchset_accurate { } # update the index with all the changes we got + system('git-diff-files --name-only -z | '. + 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n"; system('git-ls-files --others -z | '. 'git-update-index --add -z --stdin') == 0 or die "$! $?\n"; - system('git-ls-files --deleted -z | '. - 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n"; - system('git-ls-files -z | '. - 'git-update-index -z --stdin') == 0 or die "$! $?\n"; return 1; } @@ -416,22 +414,14 @@ sub process_patchset_fast { # imports don't give us good info # on added files. Shame on them if ($ps->{type} eq 'i' || $ps->{type} eq 't') { - system('git-ls-files --others -z | '. - 'git-update-index --add -z --stdin') == 0 or die "$! $?\n"; system('git-ls-files --deleted -z | '. 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n"; + system('git-ls-files --others -z | '. + 'git-update-index --add -z --stdin') == 0 or die "$! $?\n"; } # TODO: handle removed_directories and renamed_directories: - - if (my $add = $ps->{new_files}) { - while (@$add) { - my @slice = splice(@$add, 0, 100); - system('git-update-index','--add','--',@slice) == 0 or - die "Error in git-update-index --add: $! $?\n"; - } - } - + if (my $del = $ps->{removed_files}) { unlink @$del; while (@$del) { @@ -462,6 +452,14 @@ sub process_patchset_fast { } } + if (my $add = $ps->{new_files}) { + while (@$add) { + my @slice = splice(@$add, 0, 100); + system('git-update-index','--add','--',@slice) == 0 or + die "Error in git-update-index --add: $! $?\n"; + } + } + if (my $mod = $ps->{modified_files}) { while (@$mod) { my @slice = splice(@$mod, 0, 100); From 39ba7d54649b35c943b026b54bff40cfa0153f3e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 18 Feb 2006 21:44:20 +0100 Subject: [PATCH 2/3] Fix retries in git-cvsimport Fixed a couple of bugs in recovering from broken connections: The _line() method now returns undef correctly when the connection is broken instead of falling off the function and returning garbage. Retries are now reported to stderr and the eventual partially downloaded file is discarded instead of being appended to. The "Server gone away" test has been removed, because it was reachable only if the garbage return bug bit. Signed-off-by: Martin Mares Signed-off-by: Junio C Hamano --- git-cvsimport.perl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 00fc3bacda..24f9834342 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -361,6 +361,7 @@ sub _line { } } } + return undef; } sub file { my($self,$fn,$rev) = @_; @@ -372,19 +373,15 @@ sub file { $self->_file($fn,$rev) and $res = $self->_line($fh); if (!defined $res) { - # retry + print STDERR "Server has gone away while fetching $fn $rev, retrying...\n"; + truncate $fh, 0; $self->conn(); - $self->_file($fn,$rev) - or die "No file command send\n"; + $self->_file($fn,$rev) or die "No file command send"; $res = $self->_line($fh); - die "No input: $fn $rev\n" unless defined $res; + die "Retry failed" unless defined $res; } close ($fh); - if ($res eq '') { - die "Looks like the server has gone away while fetching $fn $rev -- exiting!"; - } - return ($name, $res); } From 9a0e6731c632c841cd2de9dec0b9091b2f10c6fd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 18 Feb 2006 23:42:03 -0800 Subject: [PATCH 3/3] Allow git-mv to accept ./ in paths. Signed-off-by: Junio C Hamano --- git-mv.perl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/git-mv.perl b/git-mv.perl index 83dc7e45cf..2ea852c918 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -75,6 +75,15 @@ while(scalar @srcArgs > 0) { $dst = shift @dstArgs; $bad = ""; + for ($src, $dst) { + # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" + s|^\./||; + s|/\./|/| while (m|/\./|); + s|//+|/|g; + # Also "a/b/../c" ==> "a/c" + 1 while (s,(^|/)[^/]+/\.\./,$1,); + } + if ($opt_v) { print "Checking rename of '$src' to '$dst'\n"; }