]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote-bzr: fix for disappeared revisions
authorFelipe Contreras <felipe.contreras@gmail.com>
Tue, 7 May 2013 23:39:35 +0000 (18:39 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 May 2013 05:38:40 +0000 (22:38 -0700)
It's possible that the previous tip goes away, we should not assume it's
always present. Fortunately we are only using it to calculate the
progress to display to the user, so only that needs to be fixed.

Also, add a test that triggers this issue.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/remote-helpers/git-remote-bzr
contrib/remote-helpers/test-bzr.sh

index 0ef30f8d558da0fc2061f98c5670dc515c4dc12b..3e452af1dc1e3a2c6f67d10c1cea403709564671 100755 (executable)
@@ -282,9 +282,13 @@ def export_branch(repo, name):
 
     branch.lock_read()
     revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
-    tip_revno = branch.revision_id_to_revno(tip)
-    last_revno, _ = branch.last_revision_info()
-    total = last_revno - tip_revno
+    try:
+        tip_revno = branch.revision_id_to_revno(tip)
+        last_revno, _ = branch.last_revision_info()
+        total = last_revno - tip_revno
+    except bzrlib.errors.NoSuchRevision:
+        tip_revno = 0
+        total = 0
 
     for revid, _, seq, _ in revs:
 
@@ -353,7 +357,10 @@ def export_branch(repo, name):
 
         progress = (revno - tip_revno)
         if (progress % 100 == 0):
-            print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
+            if total:
+                print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
+            else:
+                print "progress revision %d '%s' (%d)" % (revno, name, progress)
 
     branch.unlock()
 
index cec55f132e53b588223fab137075cd30ba7753e9..d9c32f4864745320b6594d614849035db0c95606 100755 (executable)
@@ -300,4 +300,42 @@ test_expect_success 'proper bzr repo' '
   test_cmp ../expected actual
 '
 
+test_expect_success 'strip' '
+  # Do not imitate this style; always chdir inside a subshell instead
+  mkdir -p tmp && cd tmp &&
+  test_when_finished "cd .. && rm -rf tmp" &&
+
+  (
+  bzr init bzrrepo &&
+  cd bzrrepo &&
+
+  echo one >> content &&
+  bzr add content &&
+  bzr commit -m one &&
+
+  echo two >> content &&
+  bzr commit -m two
+  ) &&
+
+  git clone "bzr::$PWD/bzrrepo" gitrepo &&
+
+  (
+  cd bzrrepo &&
+  bzr uncommit --force &&
+
+  echo three >> content &&
+  bzr commit -m three &&
+
+  echo four >> content &&
+  bzr commit -m four &&
+  bzr log --line | sed -e "s/^[0-9]\+: //" > ../expected
+  ) &&
+
+  (cd gitrepo &&
+  git fetch &&
+  git log --format="%an %ad %s" --date=short origin/master > ../actual) &&
+
+  test_cmp expected actual
+'
+
 test_done