Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 469:e205194ca7ef
Various node id lookup tweaks
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Various node id lookup tweaks
- - lookup of nullid with lazymap fixed
- - do the Pythonic thing with negative rev numbers (-1 == tip)
- - bound ranges on rev numbers
- - catch exceptions more correctly
- - restrict node id matching to beginning of string on
manifest hash: 15918cb74f41ac4bbf8bf02bc3bb599f24f0b5b8
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCvQzDywK+sNU5EO8RAnKfAJ4vzXnrGmRwOlPqNQFxxrUKchzAzQCcDkbi
g3T3KiiVUckrWpziGq67YUE=
=vrSU
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Fri, 24 Jun 2005 23:50:27 -0800 |
parents | c9d134165392 |
children | 0a338d506268 934279f3ca53 |
comparison
equal
deleted
inserted
replaced
468:157675add351 | 469:e205194ca7ef |
---|---|
96 self.p.load(pos) | 96 self.p.load(pos) |
97 def __contains__(self, key): | 97 def __contains__(self, key): |
98 self.p.load() | 98 self.p.load() |
99 return key in self.p.map | 99 return key in self.p.map |
100 def __iter__(self): | 100 def __iter__(self): |
101 yield nullid | |
101 for i in xrange(self.p.l): | 102 for i in xrange(self.p.l): |
102 try: | 103 try: |
103 yield self.p.index[i][6] | 104 yield self.p.index[i][6] |
104 except: | 105 except: |
105 self.p.load(i) | 106 self.p.load(i) |
190 return c | 191 return c |
191 | 192 |
192 def lookup(self, id): | 193 def lookup(self, id): |
193 try: | 194 try: |
194 rev = int(id) | 195 rev = int(id) |
195 if str(rev) != id: raise "mismatch" | 196 if str(rev) != id: raise ValueError |
197 if rev < 0: rev = self.count() + rev | |
198 if rev < 0 or rev >= self.count: raise ValueError | |
196 return self.node(rev) | 199 return self.node(rev) |
197 except: | 200 except (ValueError, OverflowError): |
198 c = [] | 201 c = [] |
199 for n in self.nodemap: | 202 for n in self.nodemap: |
200 if id in hex(n): | 203 if hex(n).startswith(id): |
201 c.append(n) | 204 c.append(n) |
202 if len(c) > 1: raise KeyError("Ambiguous identifier") | 205 if len(c) > 1: raise KeyError("Ambiguous identifier") |
203 if len(c) < 1: raise KeyError("No match found") | 206 if len(c) < 1: raise KeyError("No match found") |
204 return c[0] | 207 return c[0] |
205 | 208 |