# [PATCH] git-svn: remove files from the index before adding/updating

3 messages from 2006-02-18 to 2006-02-18. Participants: Eric Wong.
Thread: https://gitlist.dev/t/3382

## Eric Wong, 2006-02-18 05:04

Subject: [PATCH] git-svn: remove files from the index before adding/updating
Message-ID: <11402390872301-git-send-email-normalperson@yhbt.net>
URL: https://gitlist.dev/e/11402390872301-git-send-email-normalperson%40yhbt.net

```
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
revision.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 contrib/git-svn/git-svn |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

c142c70866ab8ce1765e4b88506aa79b5c5c1427
diff --git a/contrib/git-svn/git-svn b/contrib/git-svn/git-svn
index 2caf057..71a8b3b 100755
--- a/contrib/git-svn/git-svn
+++ b/contrib/git-svn/git-svn
@@ -580,13 +580,12 @@ sub svn_info {
 sub sys { system(@_) == 0 or croak $? }
 
 sub git_addremove {
-	system(	"git-ls-files -z --others ".
+	system( "git-diff-files --name-only -z ".
+				" | git-update-index --remove -z --stdin; ".
+		"git-ls-files -z --others ".
 			"'--exclude-from=$GIT_DIR/$GIT_SVN/info/exclude'".
-				"| git-update-index --add -z --stdin; ".
-		"git-ls-files -z --deleted ".
-				"| git-update-index --remove -z --stdin; ".
-		"git-ls-files -z --modified".
-				"| git-update-index -z --stdin") == 0 or croak $?
+				" | git-update-index --add -z --stdin; "
+		) == 0 or croak $?
 }
 
 sub s_to_file {
-- 
1.2.0.g4d1a-dirty

```

## Eric Wong, 2006-02-18 11:49

Subject: [PATCH] archimport: remove files from the index before adding/updating
Message-ID: <20060218114628.GA24678@BL4ST>
URL: https://gitlist.dev/e/20060218114628.GA24678%40BL4ST
In-Reply-To: <11402390872301-git-send-email-normalperson@yhbt.net>

```
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 <normalperson@yhbt.net>

---

 git-archimport.perl |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)

011fe464212c52d46ad5b797eb1d8f86c1d77916
diff --git a/git-archimport.perl b/git-archimport.perl
index 841738d..6792624 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);
-- 
1.2.1.gffaf

```

## Eric Wong, 2006-02-18 12:36

Subject: Re: [PATCH] archimport: remove files from the index before adding/updating
Message-ID: <20060218123652.GB12296@hand.yhbt.net>
URL: https://gitlist.dev/e/20060218123652.GB12296%40hand.yhbt.net
In-Reply-To: <20060218114628.GA24678@BL4ST>

```
Oops, forgot to Cc Martin on this :>

-- 
Eric Wong

```
