[PATCH 2 of 2 STABLE RFC] Add test to demonstrate a problem with revlog post-unbundle (issue2137)

Greg Ward greg-hg at gerg.ca
Tue Apr 13 17:32:35 CDT 2010


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1271197895 14400
# Branch stable
# Node ID 26c803a769af786dd1a833fe4bdb45f2fee17b6f
# Parent  fcd774f7d93d55fc74c04a4f8cb9c7ef7722af1c
Add test to demonstrate a problem with revlog post-unbundle (issue2137).

This does NOT fix the bug: it just adds a failing test.  I'm posting
it for feedback and discussion.

diff --git a/tests/issue2137.py b/tests/issue2137.py
new file mode 100755
--- /dev/null
+++ b/tests/issue2137.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+# attempt to reproduce hg issue 2137 (revlog not properly updated after
+# unbundle, causing repo.lookup() to fail spuriously)
+
+import sys
+from mercurial import ui as hgui, hg, commands, node as hgnode, error, revlog
+
+(path, bundle) = sys.argv[1:3]
+
+revlog._prereadsize = 128
+ui = hgui.ui()
+ui.setconfig('ui', 'verbose', 'true')
+#ui.setconfig('ui', 'debug', 'true')
+ui.write('opening %s\n' % path)
+repo = hg.repository(ui, path)
+
+ui.write('initial sanity check\n')
+assert len(repo) == len(repo.changelog.index) - 1 == repo.changelog.nodemap.p.l
+tip = repo.changelog.tip()
+assert repo.lookup(hgnode.short(tip)) == tip
+
+# apply the bundle
+ui.write('applying bundle\n')
+commands.unbundle(ui, repo, bundle, update=False)
+
+# demonstrate the bug: first, expose the low-level problem (changelog's
+# nodemap has two different idea's of the changelog's length)
+ui.write('testing for the bug (1: changelog length)\n')
+cl = repo.changelog
+if cl.nodemap.p.l == len(repo):
+    print "PASS: cl.nodemap.p.l == len(repo) == %d" % len(repo)
+else:
+    print "FAIL: len(repo) == %d, cl.nodemap.p.l == %d" \
+          % (len(repo), cl.nodemap.p.l)
+
+# and demonstrate it again the high-level way: looking up the abbreviated
+# changeset ID of a changeset that is known to be in the changelog fails
+ui.write('testing for the bug (2: repo.lookup())\n')
+tip1 = cl.tip()
+try:
+    tip2 = repo.lookup(hgnode.short(tip1))
+    assert tip1 == tip2
+    print "PASS: looked up tip two ways and got consistent results"
+except error.RepoLookupError:
+    print "FAIL: failed to lookup abbreviated changeset ID of tip"
diff --git a/tests/test-issue2137 b/tests/test-issue2137
new file mode 100755
--- /dev/null
+++ b/tests/test-issue2137
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+echo "% setup"
+hg init repo1
+
+# need to do this in Python in order to monkeypatch revlog._maxinline
+cat > prep.py <<EOF
+import os
+from mercurial import ui, hg, revlog
+
+revlog._maxinline = 128
+os.chdir('repo1')
+ui = ui.ui()
+repo = hg.repository(ui, '.')
+
+open('a', 'a').write('a\n')
+repo.add(['a'])
+repo.commit(text='add a with a long commit message to make the changelog a bit bigger',
+            user='test test test test test test test test test test test',
+            date=(0, 0))
+
+open('b', 'a').write('b\n')
+repo.add(['b'])
+repo.commit(text='add b and ramble on a bit here too for the same reason',
+            user='test test test test test test test test test test test',
+            date=(0, 0))
+EOF
+#echo $PYTHON prep.py
+$PYTHON prep.py
+#hg -R repo1 log -v
+
+# changelog must be split into *.d and *.i, and *.i must be > 128 bytes
+ls -1 repo1/.hg/store/00changelog.*
+
+echo ""
+echo "% clone and bundle"
+hg -q clone repo1 repo2
+cd repo2
+echo a >> a
+hg commit -m'modify a'
+cd ../repo1
+hg -q incoming --bundle incoming.bundle ../repo2
+
+echo ""
+echo "% demonstrate the bug"
+#echo $PYTHON $TESTDIR/issue2137.py . incoming.bundle
+$PYTHON $TESTDIR/issue2137.py . incoming.bundle


More information about the Mercurial-devel mailing list