diff mercurial/testing/storage.py @ 40003:0e8836be9541

storageutil: implement file identifier resolution method (BC) revlog.lookup() has a number of advanced features, including partial node matching. These advanced features aren't needed for file id lookup because file identifiers are almost always from internal sources. (An exception to this is hgweb, which appears to have some code paths that attempt to resolve a user-supplied string to a node.) This commit implements a new function for resolving file identifiers to nodes. It behaves like revlog.lookup() but without the advanced features. Tests reveal behavior changes: * Partial hex nodes are no longer resolved to nodes. * "-1" now returns nullid instead of raising LookupError. * "0" on an empty store now raises LookupError instead of returning nullid. I'm not sure why "-1" wasn't recognized before. But it seems reasonable to accept it as a value since integer -1 resolves to nullid. These changes all seem reasonable to me. And with the exception of partial hex node matching, we may want to consider changing revlog.lookup() as well. Differential Revision: https://phab.mercurial-scm.org/D4797
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 11:03:17 -0700
parents 215fd73cfe52
children ad8389ecd3f5
line wrap: on
line diff
--- a/mercurial/testing/storage.py	Fri Sep 28 11:00:20 2018 -0700
+++ b/mercurial/testing/storage.py	Fri Sep 28 11:03:17 2018 -0700
@@ -85,21 +85,19 @@
         self.assertEqual(f.lookup(nullid), nullid)
         self.assertEqual(f.lookup(nullrev), nullid)
         self.assertEqual(f.lookup(hex(nullid)), nullid)
-
-        # String converted to integer doesn't work for nullrev.
-        with self.assertRaises(error.LookupError):
-            f.lookup(b'%d' % nullrev)
+        self.assertEqual(f.lookup(b'%d' % nullrev), nullid)
 
         with self.assertRaises(error.LookupError):
             f.lookup(b'badvalue')
 
-        self.assertEqual(f.lookup(hex(nullid)[0:12]), nullid)
+        with self.assertRaises(error.LookupError):
+            f.lookup(hex(nullid)[0:12])
 
         with self.assertRaises(error.LookupError):
             f.lookup(b'-2')
 
-        # TODO this is wonky.
-        self.assertEqual(f.lookup(b'0'), nullid)
+        with self.assertRaises(error.LookupError):
+            f.lookup(b'0')
 
         with self.assertRaises(error.LookupError):
             f.lookup(b'1')
@@ -197,7 +195,9 @@
         self.assertEqual(f.lookup(-1), nullid)
         self.assertEqual(f.lookup(b'0'), node)
         self.assertEqual(f.lookup(hex(node)), node)
-        self.assertEqual(f.lookup(hex(node)[0:12]), node)
+
+        with self.assertRaises(error.LookupError):
+            f.lookup(hex(node)[0:12])
 
         with self.assertRaises(IndexError):
             f.lookup(-2)