remote-bzr: fix for disappeared revisions
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>
Felipe Contreras committed
May 7, 2013 at 18:39 UTC
435f39a3e8f9dc1aab786347d4a92aee3ecef56a
2 files changed
+49
-4
contrib/remote-helpers/git-remote-bzr
+11
-4
@@ -282,9 +282,13 @@ def export_branch(repo, name):
282
283
branch.lock_read()
284
revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
285
- tip_revno = branch.revision_id_to_revno(tip)
286
- last_revno, _ = branch.last_revision_info()
287
- total = last_revno - tip_revno
285
+ try:
286
+ tip_revno = branch.revision_id_to_revno(tip)
287
+ last_revno, _ = branch.last_revision_info()
288
+ total = last_revno - tip_revno
289
+ except bzrlib.errors.NoSuchRevision:
290
+ tip_revno = 0
291
+ total = 0
292
293
for revid, _, seq, _ in revs:
294
@@ -353,7 +357,10 @@ def export_branch(repo, name):
357
358
progress = (revno - tip_revno)
359
if (progress % 100 == 0):
356
- print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
360
+ if total:
361
+ print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
362
+ else:
363
+ print "progress revision %d '%s' (%d)" % (revno, name, progress)
364
365
branch.unlock()
366
contrib/remote-helpers/test-bzr.sh
+38
@@ -300,4 +300,42 @@ test_expect_success 'proper bzr repo' '
300
test_cmp ../expected actual
301
'
302
303
+test_expect_success 'strip' '
304
+ # Do not imitate this style; always chdir inside a subshell instead
305
+ mkdir -p tmp && cd tmp &&
306
+ test_when_finished "cd .. && rm -rf tmp" &&
307
+
308
+ (
309
+ bzr init bzrrepo &&
310
+ cd bzrrepo &&
311
+
312
+ echo one >> content &&
313
+ bzr add content &&
314
+ bzr commit -m one &&
315
+
316
+ echo two >> content &&
317
+ bzr commit -m two
318
+ ) &&
319
+
320
+ git clone "bzr::$PWD/bzrrepo" gitrepo &&
321
+
322
+ (
323
+ cd bzrrepo &&
324
+ bzr uncommit --force &&
325
+
326
+ echo three >> content &&
327
+ bzr commit -m three &&
328
+
329
+ echo four >> content &&
330
+ bzr commit -m four &&
331
+ bzr log --line | sed -e "s/^[0-9]\+: //" > ../expected
332
+ ) &&
333
+
334
+ (cd gitrepo &&
335
+ git fetch &&
336
+ git log --format="%an %ad %s" --date=short origin/master > ../actual) &&
337
+
338
+ test_cmp expected actual
339
+'
340
+
341
test_done