Skip to content

Commit 435f39a

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b892dc commit 435f39a

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

contrib/remote-helpers/git-remote-bzr

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,13 @@ def export_branch(repo, name):
282282

283283
branch.lock_read()
284284
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
288292

289293
for revid, _, seq, _ in revs:
290294

@@ -353,7 +357,10 @@ def export_branch(repo, name):
353357

354358
progress = (revno - tip_revno)
355359
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)
357364

358365
branch.unlock()
359366

contrib/remote-helpers/test-bzr.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,42 @@ test_expect_success 'proper bzr repo' '
300300
test_cmp ../expected actual
301301
'
302302

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+
303341
test_done

0 commit comments

Comments
 (0)