changeset 3578:3b4e00cba57a

Define and use nullrev (revision of nullid) instead of -1.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sun, 29 Oct 2006 10:53:51 +0100
parents 7f7425306925
children 0ed2732aa393
files hgext/hgk.py hgext/mq.py mercurial/commands.py mercurial/context.py mercurial/localrepo.py mercurial/merge.py mercurial/node.py mercurial/revlog.py
diffstat 8 files changed, 38 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/hgk.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/hgext/hgk.py	Sun Oct 29 10:53:51 2006 +0100
@@ -78,8 +78,8 @@
     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 @@
                 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:
--- a/hgext/mq.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/hgext/mq.py	Sun Oct 29 10:53:51 2006 +0100
@@ -1310,7 +1310,7 @@
             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')
--- a/mercurial/commands.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/mercurial/commands.py	Sun Oct 29 10:53:51 2006 +0100
@@ -116,7 +116,7 @@
                 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 @@
 
         # 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 @@
 
     class followfilter:
         def __init__(self, onlyfirst=False):
-            self.startrev = -1
+            self.startrev = nullrev
             self.roots = []
             self.onlyfirst = onlyfirst
 
@@ -178,9 +179,10 @@
                 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 @@
 
         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 @@
         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 @@
         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 @@
                 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")
--- a/mercurial/context.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/mercurial/context.py	Sun Oct 29 10:53:51 2006 +0100
@@ -39,7 +39,7 @@
         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 @@
                 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):
--- a/mercurial/localrepo.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/mercurial/localrepo.py	Sun Oct 29 10:53:51 2006 +0100
@@ -332,10 +332,10 @@
                     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):
--- a/mercurial/merge.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/mercurial/merge.py	Sun Oct 29 10:53:51 2006 +0100
@@ -34,7 +34,7 @@
 
     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)
--- a/mercurial/node.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/mercurial/node.py	Sun Oct 29 10:53:51 2006 +0100
@@ -10,6 +10,7 @@
 from demandload import demandload
 demandload(globals(), "binascii")
 
+nullrev = -1
 nullid = "\0" * 20
 
 def hex(node):
--- a/mercurial/revlog.py	Sat Oct 28 23:37:59 2006 -0300
+++ b/mercurial/revlog.py	Sun Oct 29 10:53:51 2006 +0100
@@ -102,7 +102,7 @@
         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 @@
                 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 @@
         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 @@
             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 @@
             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 @@
             # 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 @@
             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 @@
         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 @@
         """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 @@
         t = r - 1
         node = None
 
-        base = prev = -1
+        base = prev = nullrev
         start = end = textlen = 0
         if r:
             end = self.end(t)