# HG changeset patch # User Thomas Arendsen Hein # Date 2006-10-29 09:53:51 # Node ID 3b4e00cba57af13dc21d92931b929e5236c9aee5 # Parent 7f7425306925d1dd35a5dcf2d59dc133b4f8a521 Define and use nullrev (revision of nullid) instead of -1. diff --git a/hgext/hgk.py b/hgext/hgk.py --- a/hgext/hgk.py +++ b/hgext/hgk.py @@ -78,8 +78,8 @@ def catcommit(repo, n, prefix, changes=N if not changes: changes = repo.changelog.read(n) print "tree %s" % (hg.short(changes[0])) - if i1 != -1: print "parent %s" % (h1) - if i2 != -1: print "parent %s" % (h2) + if i1 != hg.nullrev: print "parent %s" % (h1) + if i2 != hg.nullrev: print "parent %s" % (h2) date_ar = changes[2] date = int(float(date_ar[0])) lines = changes[4].splitlines() @@ -241,10 +241,10 @@ def revtree(args, repo, full="tree", max date = changes[2][0] print "%s %s:%s" % (date, h, mask), mask = is_reachable(want_sha1, reachable, p1) - if i1 != -1 and mask > 0: + if i1 != hg.nullrev and mask > 0: print "%s:%s " % (h1, mask), mask = is_reachable(want_sha1, reachable, p2) - if i2 != -1 and mask > 0: + if i2 != hg.nullrev and mask > 0: print "%s:%s " % (h2, mask), print "" if maxnr and count >= maxnr: diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -1310,7 +1310,7 @@ class queue: for r in rev: p1, p2 = repo.changelog.parentrevs(r) n = repo.changelog.node(r) - if p2 != -1: + if p2 != revlog.nullrev: raise util.Abort(_('cannot import merge revision %d') % r) if lastparent and lastparent != r: raise util.Abort(_('revision %d is not the parent of %d') diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -116,7 +116,7 @@ def walkchangerevs(ui, repo, pats, chang last = filelog.count() - 1 else: last = filelog.rev(node) - for i, window in increasing_windows(last, -1): + for i, window in increasing_windows(last, nullrev): revs = [] for j in xrange(i - window, i + 1): n = filelog.node(j) @@ -157,7 +157,8 @@ def walkchangerevs(ui, repo, pats, chang # The slow path checks files modified in every changeset. def changerevgen(): - for i, window in increasing_windows(repo.changelog.count()-1, -1): + for i, window in increasing_windows(repo.changelog.count()-1, + nullrev): for j in xrange(i - window, i + 1): yield j, change(j)[3] @@ -169,7 +170,7 @@ def walkchangerevs(ui, repo, pats, chang class followfilter: def __init__(self, onlyfirst=False): - self.startrev = -1 + self.startrev = nullrev self.roots = [] self.onlyfirst = onlyfirst @@ -178,9 +179,10 @@ def walkchangerevs(ui, repo, pats, chang if self.onlyfirst: return repo.changelog.parentrevs(rev)[0:1] else: - return filter(lambda x: x != -1, repo.changelog.parentrevs(rev)) - - if self.startrev == -1: + return filter(lambda x: x != nullrev, + repo.changelog.parentrevs(rev)) + + if self.startrev == nullrev: self.startrev = rev return True @@ -322,7 +324,7 @@ class changeset_printer(object): parents = log.parentrevs(rev) if not self.ui.debugflag: - parents = [p for p in parents if p != -1] + parents = [p for p in parents if p != nullrev] if len(parents) == 1 and parents[0] == rev-1: parents = [] parents = [(p, hexfunc(log.node(p))) for p in parents] @@ -1872,7 +1874,7 @@ def log(ui, repo, *pats, **opts): if rev in rcache[fn]: return rcache[fn][rev] mr = repo.manifest.rev(man) - if repo.manifest.parentrevs(mr) != (mr - 1, -1): + if repo.manifest.parentrevs(mr) != (mr - 1, nullrev): return ncache[fn].get(repo.manifest.find(man, fn)[0]) if not dcache or dcache[0] != man: dcache[:] = [man, repo.manifest.readdelta(man)] @@ -1888,7 +1890,8 @@ def log(ui, repo, *pats, **opts): elif st == 'add': du.bump(rev) changenode = repo.changelog.node(rev) - parents = [p for p in repo.changelog.parentrevs(rev) if p != -1] + parents = [p for p in repo.changelog.parentrevs(rev) + if p != nullrev] if opts['no_merges'] and len(parents) == 2: continue if opts['only_merges'] and len(parents) != 2: @@ -1922,7 +1925,7 @@ def log(ui, repo, *pats, **opts): if parents: prev = parents[0] else: - prev = -1 + prev = nullrev prev = repo.changelog.node(prev) patch.diff(repo, prev, changenode, match=matchfn, fp=du) du.write("\n\n") diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -39,7 +39,7 @@ class changectx(object): return self._rev == other._rev def __nonzero__(self): - return self._rev != -1 + return self._rev != nullrev def __getattr__(self, name): if name == '_changeset': @@ -257,7 +257,7 @@ class filectx(object): if r: pl[0] = (r[0], getlog(r[0]).rev(r[1])) - return [ getctx(p, n) for p, n in pl if n != -1 ] + return [getctx(p, n) for p, n in pl if n != nullrev] # use linkrev to find the first changeset where self appeared if self.rev() != self._filelog.linkrev(self._filenode): diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -332,10 +332,10 @@ class localrepository(repo.repository): node, label = l.rstrip().split(" ", 1) partial[label] = bin(node) else: # invalidate the cache - last, lrev = nullid, -1 + last, lrev = nullid, nullrev f.close() except IOError: - last, lrev = nullid, -1 + last, lrev = nullid, nullrev return partial, last, lrev def _writebranchcache(self, branches, tip, tiprev): diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -34,7 +34,7 @@ def filemerge(repo, fw, fo, wctx, mctx): fca = fcm.ancestor(fco) if not fca: - fca = repo.filectx(fw, fileid=-1) + fca = repo.filectx(fw, fileid=nullrev) a = repo.wjoin(fw) b = temp("base", fca) c = temp("other", fco) diff --git a/mercurial/node.py b/mercurial/node.py --- a/mercurial/node.py +++ b/mercurial/node.py @@ -10,6 +10,7 @@ of the GNU General Public License, incor from demandload import demandload demandload(globals(), "binascii") +nullrev = -1 nullid = "\0" * 20 def hex(node): diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -102,7 +102,7 @@ class lazyparser(object): self.datasize = size self.l = size/self.s self.index = [None] * self.l - self.map = {nullid: -1} + self.map = {nullid: nullrev} self.allmap = 0 self.all = 0 self.mapfind_count = 0 @@ -387,14 +387,14 @@ class revlog(object): e[0] = self.offset_type(0, type) self.index[0] = e else: - self.nodemap = { nullid: -1} + self.nodemap = {nullid: nullrev} self.index = [] def parseindex(self, fp, st): s = struct.calcsize(self.indexformat) self.index = [] - self.nodemap = {nullid: -1} + self.nodemap = {nullid: nullrev} inline = self.inlinedata() n = 0 leftover = None @@ -474,7 +474,7 @@ class revlog(object): except KeyError: raise RevlogError(_('%s: no node %s') % (self.indexfile, hex(node))) def linkrev(self, node): - return (node == nullid) and -1 or self.index[self.rev(node)][-4] + return (node == nullid) and nullrev or self.index[self.rev(node)][-4] def parents(self, node): if node == nullid: return (nullid, nullid) r = self.rev(node) @@ -483,15 +483,15 @@ class revlog(object): return d return (self.node(d[0]), self.node(d[1])) def parentrevs(self, rev): - if rev == -1: - return (-1, -1) + if rev == nullrev: + return (nullrev, nullrev) d = self.index[rev][-3:-1] if self.version == REVLOGV0: return (self.rev(d[0]), self.rev(d[1])) return d def start(self, rev): if rev < 0: - return -1 + return nullrev if self.version != REVLOGV0: return self.ngoffset(self.index[rev][0]) return self.index[rev][0] @@ -581,8 +581,8 @@ class revlog(object): lowestrev = min([self.rev(n) for n in roots]) else: roots = [nullid] # Everybody's a descendent of nullid - lowestrev = -1 - if (lowestrev == -1) and (heads is None): + lowestrev = nullrev + if (lowestrev == nullrev) and (heads is None): # We want _all_ the nodes! return ([self.node(r) for r in xrange(0, self.count())], [nullid], list(self.heads())) @@ -634,7 +634,7 @@ class revlog(object): # roots that are not ancestors. # If one of the roots was nullid, everything is included anyway. - if lowestrev > -1: + if lowestrev > nullrev: # But, since we weren't, let's recompute the lowest rev to not # include roots that aren't ancestors. @@ -649,7 +649,7 @@ class revlog(object): else: # We are descending from nullid, and don't need to care about # any other roots. - lowestrev = -1 + lowestrev = nullrev roots = [nullid] # Transform our roots list into a 'set' (i.e. a dictionary where the # values don't matter. @@ -665,7 +665,7 @@ class revlog(object): for r in xrange(max(lowestrev, 0), highestrev + 1): n = self.node(r) isdescendent = False - if lowestrev == -1: # Everybody is a descendent of nullid + if lowestrev == nullrev: # Everybody is a descendent of nullid isdescendent = True elif n in descendents: # n is already a descendent @@ -1056,7 +1056,7 @@ class revlog(object): """calculate the least common ancestor of nodes a and b""" def parents(rev): - return [p for p in self.parentrevs(rev) if p != -1] + return [p for p in self.parentrevs(rev) if p != nullrev] c = ancestor.ancestor(self.rev(a), self.rev(b), parents) if c is None: @@ -1113,7 +1113,7 @@ class revlog(object): t = r - 1 node = None - base = prev = -1 + base = prev = nullrev start = end = textlen = 0 if r: end = self.end(t)