##// END OF EJS Templates
add __len__ and __iter__ methods to repo and revlog
Matt Mackall -
r6750:fb42030d default
parent child Browse files
Show More
@@ -12,7 +12,7 b' for f in sys.argv[1:]:'
12 binopen = lambda fn: open(fn, 'rb')
12 binopen = lambda fn: open(fn, 'rb')
13 r = revlog.revlog(binopen, f)
13 r = revlog.revlog(binopen, f)
14 print "file:", f
14 print "file:", f
15 for i in xrange(r.count()):
15 for i in r:
16 n = r.node(i)
16 n = r.node(i)
17 p = r.parents(n)
17 p = r.parents(n)
18 d = r.revision(n)
18 d = r.revision(n)
@@ -118,7 +118,5 b' def hook(ui, repo, hooktype, node=None, '
118 ui.debug(_('acl: changes have source "%s" - skipping\n') % source)
118 ui.debug(_('acl: changes have source "%s" - skipping\n') % source)
119 return
119 return
120
120
121 start = repo.changelog.rev(bin(node))
121 for rev in xrange(repo[node].rev(), len(repo)):
122 end = repo.changelog.count()
123 for rev in xrange(start, end):
124 c.check(repo.changelog.node(rev))
122 c.check(repo.changelog.node(rev))
@@ -91,7 +91,7 b' def gather_stats(ui, repo, amap, revs=No'
91 cl = repo.changelog
91 cl = repo.changelog
92
92
93 if not revs:
93 if not revs:
94 revs = range(0, cl.count())
94 revs = range(len(cl))
95
95
96 nr_revs = len(revs)
96 nr_revs = len(revs)
97 cur_rev = 0
97 cur_rev = 0
@@ -89,7 +89,7 b' def filelog_grapher(repo, path, start_re'
89 assert start_rev >= stop_rev
89 assert start_rev >= stop_rev
90 curr_rev = start_rev
90 curr_rev = start_rev
91 revs = []
91 revs = []
92 filerev = repo.file(path).count() - 1
92 filerev = len(repo.file(path)) - 1
93 while filerev >= 0:
93 while filerev >= 0:
94 fctx = repo.filectx(path, fileid=filerev)
94 fctx = repo.filectx(path, fileid=filerev)
95
95
@@ -198,7 +198,7 b' def get_revs(repo, rev_opt):'
198 revs = revrange(repo, rev_opt)
198 revs = revrange(repo, rev_opt)
199 return (max(revs), min(revs))
199 return (max(revs), min(revs))
200 else:
200 else:
201 return (repo.changelog.count() - 1, 0)
201 return (len(repo) - 1, 0)
202
202
203 def graphlog(ui, repo, path=None, **opts):
203 def graphlog(ui, repo, path=None, **opts):
204 """show revision history alongside an ASCII revision graph
204 """show revision history alongside an ASCII revision graph
@@ -175,7 +175,7 b' def catfile(ui, repo, type=None, r=None,'
175 # you can specify a commit to stop at by starting the sha1 with ^
175 # you can specify a commit to stop at by starting the sha1 with ^
176 def revtree(ui, args, repo, full="tree", maxnr=0, parents=False):
176 def revtree(ui, args, repo, full="tree", maxnr=0, parents=False):
177 def chlogwalk():
177 def chlogwalk():
178 count = repo.changelog.count()
178 count = len(repo)
179 i = count
179 i = count
180 l = [0] * 100
180 l = [0] * 100
181 chunk = 100
181 chunk = 100
@@ -178,6 +178,7 b' class kwtemplater(object):'
178 notify = self.ui.debug
178 notify = self.ui.debug
179 else: # kwexpand/kwshrink
179 else: # kwexpand/kwshrink
180 ctx = self.repo['.']
180 ctx = self.repo['.']
181 mf = ctx.manifest()
181 notify = self.ui.note
182 notify = self.ui.note
182 candidates = [f for f in files if self.iskwfile(f, ctx.flags)]
183 candidates = [f for f in files if self.iskwfile(f, ctx.flags)]
183 if candidates:
184 if candidates:
@@ -2319,7 +2319,7 b' def reposetup(ui, repo):'
2319 # we might as well use it, but we won't save it.
2319 # we might as well use it, but we won't save it.
2320
2320
2321 # update the cache up to the tip
2321 # update the cache up to the tip
2322 self._updatebranchcache(partial, start, cl.count())
2322 self._updatebranchcache(partial, start, len(cl))
2323
2323
2324 return partial
2324 return partial
2325
2325
@@ -269,11 +269,11 b' def hook(ui, repo, hooktype, node=None, '
269 node = bin(node)
269 node = bin(node)
270 ui.pushbuffer()
270 ui.pushbuffer()
271 if hooktype == 'changegroup':
271 if hooktype == 'changegroup':
272 start = repo.changelog.rev(node)
272 start = repo[node].rev()
273 end = repo.changelog.count()
273 end = len(repo)
274 count = end - start
274 count = end - start
275 for rev in xrange(start, end):
275 for rev in xrange(start, end):
276 n.node(repo.changelog.node(rev))
276 n.node(repo[node].rev())
277 n.diff(node, repo.changelog.tip())
277 n.diff(node, repo.changelog.tip())
278 else:
278 else:
279 count = 1
279 count = 1
@@ -98,7 +98,7 b' def macencode(s, cmd):'
98
98
99 def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
99 def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
100 halt = False
100 halt = False
101 for rev in xrange(repo.changelog.rev(bin(node)), repo.changelog.count()):
101 for rev in xrange(repo[node].rev(), len(repo)):
102 c = repo[rev]
102 c = repo[rev]
103 for f in c.files():
103 for f in c.files():
104 if f not in c:
104 if f not in c:
@@ -34,7 +34,7 b' class bundlerevlog(revlog.revlog):'
34 for chunk in changegroup.chunkiter(bundlefile):
34 for chunk in changegroup.chunkiter(bundlefile):
35 pos = bundlefile.tell()
35 pos = bundlefile.tell()
36 yield chunk, pos - len(chunk)
36 yield chunk, pos - len(chunk)
37 n = self.count()
37 n = len(self)
38 prev = None
38 prev = None
39 for chunk, start in chunkpositer():
39 for chunk, start in chunkpositer():
40 size = len(chunk)
40 size = len(chunk)
@@ -82,7 +82,7 b' class changelog(revlog):'
82 "delay visibility of index updates to other readers"
82 "delay visibility of index updates to other readers"
83 self._realopener = self.opener
83 self._realopener = self.opener
84 self.opener = self._delayopener
84 self.opener = self._delayopener
85 self._delaycount = self.count()
85 self._delaycount = len(self)
86 self._delaybuf = []
86 self._delaybuf = []
87 self._delayname = None
87 self._delayname = None
88
88
@@ -108,7 +108,7 b' class changelog(revlog):'
108 # if we're doing an initial clone, divert to another file
108 # if we're doing an initial clone, divert to another file
109 if self._delaycount == 0:
109 if self._delaycount == 0:
110 self._delayname = fp.name
110 self._delayname = fp.name
111 if not self.count():
111 if not len(self):
112 # make sure to truncate the file
112 # make sure to truncate the file
113 mode = mode.replace('a', 'w')
113 mode = mode.replace('a', 'w')
114 return self._realopener(name + ".a", mode)
114 return self._realopener(name + ".a", mode)
@@ -192,4 +192,4 b' class changelog(revlog):'
192 list.sort()
192 list.sort()
193 l = [hex(manifest), user, parseddate] + list + ["", desc]
193 l = [hex(manifest), user, parseddate] + list + ["", desc]
194 text = "\n".join(l)
194 text = "\n".join(l)
195 return self.addrevision(text, transaction, self.count(), p1, p2)
195 return self.addrevision(text, transaction, len(self), p1, p2)
@@ -126,7 +126,7 b' def revpair(repo, revs):'
126 if revrangesep in revs[0]:
126 if revrangesep in revs[0]:
127 start, end = revs[0].split(revrangesep, 1)
127 start, end = revs[0].split(revrangesep, 1)
128 start = revfix(repo, start, 0)
128 start = revfix(repo, start, 0)
129 end = revfix(repo, end, repo.changelog.count() - 1)
129 end = revfix(repo, end, len(repo) - 1)
130 else:
130 else:
131 start = revfix(repo, revs[0], None)
131 start = revfix(repo, revs[0], None)
132 elif len(revs) == 2:
132 elif len(revs) == 2:
@@ -151,7 +151,7 b' def revrange(repo, revs):'
151 if revrangesep in spec:
151 if revrangesep in spec:
152 start, end = spec.split(revrangesep, 1)
152 start, end = spec.split(revrangesep, 1)
153 start = revfix(repo, start, 0)
153 start = revfix(repo, start, 0)
154 end = revfix(repo, end, repo.changelog.count() - 1)
154 end = revfix(repo, end, len(repo) - 1)
155 step = start > end and -1 or 1
155 step = start > end and -1 or 1
156 for rev in xrange(start, end+step, step):
156 for rev in xrange(start, end+step, step):
157 if rev in seen:
157 if rev in seen:
@@ -988,7 +988,7 b' def walkchangerevs(ui, repo, pats, chang'
988 m = match(repo, pats, opts)
988 m = match(repo, pats, opts)
989 follow = opts.get('follow') or opts.get('follow_first')
989 follow = opts.get('follow') or opts.get('follow_first')
990
990
991 if repo.changelog.count() == 0:
991 if not len(repo):
992 return [], m
992 return [], m
993
993
994 if follow:
994 if follow:
@@ -1007,9 +1007,9 b' def walkchangerevs(ui, repo, pats, chang'
1007 if not slowpath:
1007 if not slowpath:
1008 # Only files, no patterns. Check the history of each file.
1008 # Only files, no patterns. Check the history of each file.
1009 def filerevgen(filelog, node):
1009 def filerevgen(filelog, node):
1010 cl_count = repo.changelog.count()
1010 cl_count = len(repo)
1011 if node is None:
1011 if node is None:
1012 last = filelog.count() - 1
1012 last = len(filelog) - 1
1013 else:
1013 else:
1014 last = filelog.rev(node)
1014 last = filelog.rev(node)
1015 for i, window in increasing_windows(last, nullrev):
1015 for i, window in increasing_windows(last, nullrev):
@@ -1032,7 +1032,7 b' def walkchangerevs(ui, repo, pats, chang'
1032 minrev, maxrev = min(revs), max(revs)
1032 minrev, maxrev = min(revs), max(revs)
1033 for file_, node in iterfiles():
1033 for file_, node in iterfiles():
1034 filelog = repo.file(file_)
1034 filelog = repo.file(file_)
1035 if filelog.count() == 0:
1035 if not len(filelog):
1036 if node is None:
1036 if node is None:
1037 # A zero count may be a directory or deleted file, so
1037 # A zero count may be a directory or deleted file, so
1038 # try to find matching entries on the slow path.
1038 # try to find matching entries on the slow path.
@@ -1058,8 +1058,7 b' def walkchangerevs(ui, repo, pats, chang'
1058
1058
1059 # The slow path checks files modified in every changeset.
1059 # The slow path checks files modified in every changeset.
1060 def changerevgen():
1060 def changerevgen():
1061 for i, window in increasing_windows(repo.changelog.count()-1,
1061 for i, window in increasing_windows(len(repo) - 1, nullrev):
1062 nullrev):
1063 for j in xrange(i - window, i + 1):
1062 for j in xrange(i - window, i + 1):
1064 yield j, change(j)[3]
1063 yield j, change(j)[3]
1065
1064
@@ -773,7 +773,7 b' def debugindex(ui, file_):'
773 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
773 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
774 ui.write(" rev offset length base linkrev" +
774 ui.write(" rev offset length base linkrev" +
775 " nodeid p1 p2\n")
775 " nodeid p1 p2\n")
776 for i in xrange(r.count()):
776 for i in r:
777 node = r.node(i)
777 node = r.node(i)
778 try:
778 try:
779 pp = r.parents(node)
779 pp = r.parents(node)
@@ -787,7 +787,7 b' def debugindexdot(ui, file_):'
787 """dump an index DAG as a .dot file"""
787 """dump an index DAG as a .dot file"""
788 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
788 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
789 ui.write("digraph G {\n")
789 ui.write("digraph G {\n")
790 for i in xrange(r.count()):
790 for i in r:
791 node = r.node(i)
791 node = r.node(i)
792 pp = r.parents(node)
792 pp = r.parents(node)
793 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
793 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
@@ -1762,7 +1762,7 b' def log(ui, repo, *pats, **opts):'
1762 if opts['copies'] and opts['rev']:
1762 if opts['copies'] and opts['rev']:
1763 endrev = max(cmdutil.revrange(repo, opts['rev'])) + 1
1763 endrev = max(cmdutil.revrange(repo, opts['rev'])) + 1
1764 else:
1764 else:
1765 endrev = repo.changelog.count()
1765 endrev = len(repo)
1766 rcache = {}
1766 rcache = {}
1767 ncache = {}
1767 ncache = {}
1768 def getrenamed(fn, rev):
1768 def getrenamed(fn, rev):
@@ -1774,7 +1774,7 b' def log(ui, repo, *pats, **opts):'
1774 rcache[fn] = {}
1774 rcache[fn] = {}
1775 ncache[fn] = {}
1775 ncache[fn] = {}
1776 fl = repo.file(fn)
1776 fl = repo.file(fn)
1777 for i in xrange(fl.count()):
1777 for i in fl:
1778 node = fl.node(i)
1778 node = fl.node(i)
1779 lr = fl.linkrev(node)
1779 lr = fl.linkrev(node)
1780 renamed = fl.renamed(node)
1780 renamed = fl.renamed(node)
@@ -2794,7 +2794,7 b' def tip(ui, repo, **opts):'
2794 that repository becomes the current tip. The "tip" tag is special
2794 that repository becomes the current tip. The "tip" tag is special
2795 and cannot be renamed or assigned to a different changeset.
2795 and cannot be renamed or assigned to a different changeset.
2796 """
2796 """
2797 cmdutil.show_changeset(ui, repo, opts).show(nullrev+repo.changelog.count())
2797 cmdutil.show_changeset(ui, repo, opts).show(len(repo) - 1)
2798
2798
2799 def unbundle(ui, repo, fname1, *fnames, **opts):
2799 def unbundle(ui, repo, fname1, *fnames, **opts):
2800 """apply one or more changegroup files
2800 """apply one or more changegroup files
@@ -67,7 +67,7 b' def _findlimit(repo, a, b):'
67 # - quit when interesting revs is zero
67 # - quit when interesting revs is zero
68
68
69 cl = repo.changelog
69 cl = repo.changelog
70 working = cl.count() # pseudo rev for the working directory
70 working = len(cl) # pseudo rev for the working directory
71 if a is None:
71 if a is None:
72 a = working
72 a = working
73 if b is None:
73 if b is None:
@@ -384,7 +384,7 b' class dirstate(object):'
384 def rebuild(self, parent, files):
384 def rebuild(self, parent, files):
385 self.clear()
385 self.clear()
386 for f in files:
386 for f in files:
387 if 'x' in files.flag(f):
387 if 'x' in files.flags(f):
388 self._map[f] = ('n', 0777, -1, 0, 0)
388 self._map[f] = ('n', 0777, -1, 0, 0)
389 else:
389 else:
390 self._map[f] = ('n', 0666, -1, 0, 0)
390 self._map[f] = ('n', 0666, -1, 0, 0)
@@ -20,12 +20,12 b' def bisect(changelog, state):'
20 badrev = min([changelog.rev(n) for n in bad])
20 badrev = min([changelog.rev(n) for n in bad])
21 goodrevs = [changelog.rev(n) for n in good]
21 goodrevs = [changelog.rev(n) for n in good]
22 # build ancestors array
22 # build ancestors array
23 ancestors = [[]] * (changelog.count() + 1) # an extra for [-1]
23 ancestors = [[]] * (len(changelog) + 1) # an extra for [-1]
24
24
25 # clear good revs from array
25 # clear good revs from array
26 for node in goodrevs:
26 for node in goodrevs:
27 ancestors[node] = None
27 ancestors[node] = None
28 for rev in xrange(changelog.count(), -1, -1):
28 for rev in xrange(len(changelog), -1, -1):
29 if ancestors[rev] is None:
29 if ancestors[rev] is None:
30 for prev in clparents(rev):
30 for prev in clparents(rev):
31 ancestors[prev] = None
31 ancestors[prev] = None
@@ -110,7 +110,7 b' def _search(web, tmpl, query):'
110 qw = query.lower().split()
110 qw = query.lower().split()
111
111
112 def revgen():
112 def revgen():
113 for i in xrange(cl.count() - 1, 0, -100):
113 for i in xrange(len(cl) - 1, 0, -100):
114 l = []
114 l = []
115 for j in xrange(max(0, i - 100), i + 1):
115 for j in xrange(max(0, i - 100), i + 1):
116 ctx = web.repo[j]
116 ctx = web.repo[j]
@@ -168,7 +168,7 b' def changelog(web, req, tmpl, shortlog ='
168 if 'rev' in req.form:
168 if 'rev' in req.form:
169 hi = req.form['rev'][0]
169 hi = req.form['rev'][0]
170 else:
170 else:
171 hi = web.repo.changelog.count() - 1
171 hi = len(web.repo) - 1
172 try:
172 try:
173 ctx = web.repo[hi]
173 ctx = web.repo[hi]
174 except RepoError:
174 except RepoError:
@@ -205,7 +205,7 b' def changelog(web, req, tmpl, shortlog ='
205
205
206 maxchanges = shortlog and web.maxshortchanges or web.maxchanges
206 maxchanges = shortlog and web.maxshortchanges or web.maxchanges
207 cl = web.repo.changelog
207 cl = web.repo.changelog
208 count = cl.count()
208 count = len(cl)
209 pos = ctx.rev()
209 pos = ctx.rev()
210 start = max(0, pos - maxchanges + 1)
210 start = max(0, pos - maxchanges + 1)
211 end = min(count, start + maxchanges)
211 end = min(count, start + maxchanges)
@@ -409,7 +409,7 b' def summary(web, req, tmpl):'
409 yield l
409 yield l
410
410
411 cl = web.repo.changelog
411 cl = web.repo.changelog
412 count = cl.count()
412 count = len(cl)
413 start = max(0, count - web.maxchanges)
413 start = max(0, count - web.maxchanges)
414 end = min(count, start + web.maxchanges)
414 end = min(count, start + web.maxchanges)
415
415
@@ -498,7 +498,7 b' def filelog(web, req, tmpl):'
498 fctx = webutil.filectx(web.repo, req)
498 fctx = webutil.filectx(web.repo, req)
499 f = fctx.path()
499 f = fctx.path()
500 fl = fctx.filelog()
500 fl = fctx.filelog()
501 count = fl.count()
501 count = len(fl)
502 pagelen = web.maxshortchanges
502 pagelen = web.maxshortchanges
503 pos = fctx.filerev()
503 pos = fctx.filerev()
504 start = max(0, pos - pagelen + 1)
504 start = max(0, pos - pagelen + 1)
@@ -579,7 +579,7 b' def graph(web, req, tmpl):'
579 rev = webutil.changectx(web.repo, req).rev()
579 rev = webutil.changectx(web.repo, req).rev()
580 bg_height = 39
580 bg_height = 39
581
581
582 max_rev = web.repo.changelog.count() - 1
582 max_rev = len(web.repo) - 1
583 revcount = min(max_rev, int(req.form.get('revcount', [25])[0]))
583 revcount = min(max_rev, int(req.form.get('revcount', [25])[0]))
584 revnode = web.repo.changelog.node(rev)
584 revnode = web.repo.changelog.node(rev)
585 revnode_hex = hex(revnode)
585 revnode_hex = hex(revnode)
@@ -588,7 +588,7 b' def graph(web, req, tmpl):'
588 lessrev = max(0, rev - revcount / 2)
588 lessrev = max(0, rev - revcount / 2)
589
589
590 maxchanges = web.maxshortchanges or web.maxchanges
590 maxchanges = web.maxshortchanges or web.maxchanges
591 count = web.repo.changelog.count()
591 count = len(web.repo)
592 changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx)
592 changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx)
593
593
594 tree = list(graphmod.graph(web.repo, rev, rev - revcount))
594 tree = list(graphmod.graph(web.repo, rev, rev - revcount))
@@ -112,12 +112,11 b' def cleanpath(repo, path):'
112 return util.canonpath(repo.root, '', path)
112 return util.canonpath(repo.root, '', path)
113
113
114 def changectx(repo, req):
114 def changectx(repo, req):
115 changeid = "tip"
115 if 'node' in req.form:
116 if 'node' in req.form:
116 changeid = req.form['node'][0]
117 changeid = req.form['node'][0]
117 elif 'manifest' in req.form:
118 elif 'manifest' in req.form:
118 changeid = req.form['manifest'][0]
119 changeid = req.form['manifest'][0]
119 else:
120 changeid = repo.changelog.count() - 1
121
120
122 try:
121 try:
123 ctx = repo[changeid]
122 ctx = repo[changeid]
@@ -122,6 +122,16 b' class localrepository(repo.repository):'
122 return context.workingctx(self)
122 return context.workingctx(self)
123 return context.changectx(self, changeid)
123 return context.changectx(self, changeid)
124
124
125 def __nonzero__(self):
126 return True
127
128 def __len__(self):
129 return len(self.changelog)
130
131 def __iter__(self):
132 for i in xrange(len(self)):
133 yield i
134
125 def url(self):
135 def url(self):
126 return 'file:' + self.root
136 return 'file:' + self.root
127
137
@@ -368,7 +378,7 b' class localrepository(repo.repository):'
368 return self.nodetagscache.get(node, [])
378 return self.nodetagscache.get(node, [])
369
379
370 def _branchtags(self, partial, lrev):
380 def _branchtags(self, partial, lrev):
371 tiprev = self.changelog.count() - 1
381 tiprev = len(self) - 1
372 if lrev != tiprev:
382 if lrev != tiprev:
373 self._updatebranchcache(partial, lrev+1, tiprev+1)
383 self._updatebranchcache(partial, lrev+1, tiprev+1)
374 self._writebranchcache(partial, self.changelog.tip(), tiprev)
384 self._writebranchcache(partial, self.changelog.tip(), tiprev)
@@ -413,8 +423,7 b' class localrepository(repo.repository):'
413 try:
423 try:
414 last, lrev = lines.pop(0).split(" ", 1)
424 last, lrev = lines.pop(0).split(" ", 1)
415 last, lrev = bin(last), int(lrev)
425 last, lrev = bin(last), int(lrev)
416 if not (lrev < self.changelog.count() and
426 if lrev >= len(self) or self[lrev].node() != last:
417 self.changelog.node(lrev) == last): # sanity check
418 # invalidate the cache
427 # invalidate the cache
419 raise ValueError('invalidating branch cache (tip differs)')
428 raise ValueError('invalidating branch cache (tip differs)')
420 for l in lines:
429 for l in lines:
@@ -834,7 +843,7 b' class localrepository(repo.repository):'
834 # check in files
843 # check in files
835 new = {}
844 new = {}
836 changed = []
845 changed = []
837 linkrev = self.changelog.count()
846 linkrev = len(self)
838 commit.sort()
847 commit.sort()
839 for f in commit:
848 for f in commit:
840 self.ui.note(f + "\n")
849 self.ui.note(f + "\n")
@@ -1638,7 +1647,7 b' class localrepository(repo.repository):'
1638 # Nor do we know which filenodes are missing.
1647 # Nor do we know which filenodes are missing.
1639 msng_filenode_set = {}
1648 msng_filenode_set = {}
1640
1649
1641 junk = mnfst.index[mnfst.count() - 1] # Get around a bug in lazyindex
1650 junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex
1642 junk = None
1651 junk = None
1643
1652
1644 # A changeset always belongs to itself, so the changenode lookup
1653 # A changeset always belongs to itself, so the changenode lookup
@@ -1838,7 +1847,7 b' class localrepository(repo.repository):'
1838 # Go through all our files in order sorted by name.
1847 # Go through all our files in order sorted by name.
1839 for fname in changedfiles:
1848 for fname in changedfiles:
1840 filerevlog = self.file(fname)
1849 filerevlog = self.file(fname)
1841 if filerevlog.count() == 0:
1850 if not len(filerevlog):
1842 raise util.Abort(_("empty or missing revlog for %s") % fname)
1851 raise util.Abort(_("empty or missing revlog for %s") % fname)
1843 # Toss out the filenodes that the recipient isn't really
1852 # Toss out the filenodes that the recipient isn't really
1844 # missing.
1853 # missing.
@@ -1889,10 +1898,10 b' class localrepository(repo.repository):'
1889 def identity(x):
1898 def identity(x):
1890 return x
1899 return x
1891
1900
1892 def gennodelst(revlog):
1901 def gennodelst(log):
1893 for r in xrange(0, revlog.count()):
1902 for r in log:
1894 n = revlog.node(r)
1903 n = log.node(r)
1895 if revlog.linkrev(n) in revset:
1904 if log.linkrev(n) in revset:
1896 yield n
1905 yield n
1897
1906
1898 def changed_file_collector(changedfileset):
1907 def changed_file_collector(changedfileset):
@@ -1924,7 +1933,7 b' class localrepository(repo.repository):'
1924
1933
1925 for fname in changedfiles:
1934 for fname in changedfiles:
1926 filerevlog = self.file(fname)
1935 filerevlog = self.file(fname)
1927 if filerevlog.count() == 0:
1936 if not len(filerevlog):
1928 raise util.Abort(_("empty or missing revlog for %s") % fname)
1937 raise util.Abort(_("empty or missing revlog for %s") % fname)
1929 nodeiter = gennodelst(filerevlog)
1938 nodeiter = gennodelst(filerevlog)
1930 nodeiter = list(nodeiter)
1939 nodeiter = list(nodeiter)
@@ -1953,7 +1962,7 b' class localrepository(repo.repository):'
1953 """
1962 """
1954 def csmap(x):
1963 def csmap(x):
1955 self.ui.debug(_("add changeset %s\n") % short(x))
1964 self.ui.debug(_("add changeset %s\n") % short(x))
1956 return cl.count()
1965 return len(cl)
1957
1966
1958 def revmap(x):
1967 def revmap(x):
1959 return cl.rev(x)
1968 return cl.rev(x)
@@ -1976,11 +1985,11 b' class localrepository(repo.repository):'
1976 trp = weakref.proxy(tr)
1985 trp = weakref.proxy(tr)
1977 # pull off the changeset group
1986 # pull off the changeset group
1978 self.ui.status(_("adding changesets\n"))
1987 self.ui.status(_("adding changesets\n"))
1979 cor = cl.count() - 1
1988 cor = len(cl) - 1
1980 chunkiter = changegroup.chunkiter(source)
1989 chunkiter = changegroup.chunkiter(source)
1981 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1990 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1982 raise util.Abort(_("received changelog group is empty"))
1991 raise util.Abort(_("received changelog group is empty"))
1983 cnr = cl.count() - 1
1992 cnr = len(cl) - 1
1984 changesets = cnr - cor
1993 changesets = cnr - cor
1985
1994
1986 # pull off the manifest group
1995 # pull off the manifest group
@@ -2000,11 +2009,11 b' class localrepository(repo.repository):'
2000 break
2009 break
2001 self.ui.debug(_("adding %s revisions\n") % f)
2010 self.ui.debug(_("adding %s revisions\n") % f)
2002 fl = self.file(f)
2011 fl = self.file(f)
2003 o = fl.count()
2012 o = len(fl)
2004 chunkiter = changegroup.chunkiter(source)
2013 chunkiter = changegroup.chunkiter(source)
2005 if fl.addgroup(chunkiter, revmap, trp) is None:
2014 if fl.addgroup(chunkiter, revmap, trp) is None:
2006 raise util.Abort(_("received file revlog group is empty"))
2015 raise util.Abort(_("received file revlog group is empty"))
2007 revisions += fl.count() - o
2016 revisions += len(fl) - o
2008 files += 1
2017 files += 1
2009
2018
2010 # make changelog see real files again
2019 # make changelog see real files again
@@ -23,7 +23,7 b' def _collectfiles(repo, striprev):'
23 """find out the filelogs affected by the strip"""
23 """find out the filelogs affected by the strip"""
24 files = {}
24 files = {}
25
25
26 for x in xrange(striprev, repo.changelog.count()):
26 for x in xrange(striprev, len(repo)):
27 for name in repo[x].files():
27 for name in repo[x].files():
28 if name in files:
28 if name in files:
29 continue
29 continue
@@ -37,7 +37,7 b' def _collectextranodes(repo, files, link'
37 """return the nodes that have to be saved before the strip"""
37 """return the nodes that have to be saved before the strip"""
38 def collectone(revlog):
38 def collectone(revlog):
39 extra = []
39 extra = []
40 startrev = count = revlog.count()
40 startrev = count = len(revlog)
41 # find the truncation point of the revlog
41 # find the truncation point of the revlog
42 for i in xrange(0, count):
42 for i in xrange(0, count):
43 node = revlog.node(i)
43 node = revlog.node(i)
@@ -84,7 +84,7 b' def strip(ui, repo, node, backup="all"):'
84 tostrip = {striprev: 1}
84 tostrip = {striprev: 1}
85 saveheads = {}
85 saveheads = {}
86 savebases = []
86 savebases = []
87 for r in xrange(striprev + 1, cl.count()):
87 for r in xrange(striprev + 1, len(cl)):
88 parents = cl.parentrevs(r)
88 parents = cl.parentrevs(r)
89 if parents[0] in tostrip or parents[1] in tostrip:
89 if parents[0] in tostrip or parents[1] in tostrip:
90 # r is a descendant of striprev
90 # r is a descendant of striprev
@@ -515,9 +515,11 b' class revlog(object):'
515
515
516 def tip(self):
516 def tip(self):
517 return self.node(len(self.index) - 2)
517 return self.node(len(self.index) - 2)
518 def count(self):
518 def __len__(self):
519 return len(self.index) - 1
519 return len(self.index) - 1
520
520 def __iter__(self):
521 for i in xrange(len(self)):
522 yield i
521 def rev(self, node):
523 def rev(self, node):
522 try:
524 try:
523 return self.nodemap[node]
525 return self.nodemap[node]
@@ -620,12 +622,11 b' class revlog(object):'
620 lowestrev = nullrev
622 lowestrev = nullrev
621 if (lowestrev == nullrev) and (heads is None):
623 if (lowestrev == nullrev) and (heads is None):
622 # We want _all_ the nodes!
624 # We want _all_ the nodes!
623 return ([self.node(r) for r in xrange(0, self.count())],
625 return ([self.node(r) for r in self], [nullid], list(self.heads()))
624 [nullid], list(self.heads()))
625 if heads is None:
626 if heads is None:
626 # All nodes are ancestors, so the latest ancestor is the last
627 # All nodes are ancestors, so the latest ancestor is the last
627 # node.
628 # node.
628 highestrev = self.count() - 1
629 highestrev = len(self) - 1
629 # Set ancestors to None to signal that every node is an ancestor.
630 # Set ancestors to None to signal that every node is an ancestor.
630 ancestors = None
631 ancestors = None
631 # Set heads to an empty dictionary for later discovery of heads
632 # Set heads to an empty dictionary for later discovery of heads
@@ -754,15 +755,15 b' class revlog(object):'
754 as if they had no children
755 as if they had no children
755 """
756 """
756 if start is None and stop is None:
757 if start is None and stop is None:
757 count = self.count()
758 count = len(self)
758 if not count:
759 if not count:
759 return [nullid]
760 return [nullid]
760 ishead = [1] * (count + 1)
761 ishead = [1] * (count + 1)
761 index = self.index
762 index = self.index
762 for r in xrange(count):
763 for r in self:
763 e = index[r]
764 e = index[r]
764 ishead[e[5]] = ishead[e[6]] = 0
765 ishead[e[5]] = ishead[e[6]] = 0
765 return [self.node(r) for r in xrange(count) if ishead[r]]
766 return [self.node(r) for r in self if ishead[r]]
766
767
767 if start is None:
768 if start is None:
768 start = nullid
769 start = nullid
@@ -774,7 +775,7 b' class revlog(object):'
774 heads = {startrev: 1}
775 heads = {startrev: 1}
775
776
776 parentrevs = self.parentrevs
777 parentrevs = self.parentrevs
777 for r in xrange(startrev + 1, self.count()):
778 for r in xrange(startrev + 1, len(self)):
778 for p in parentrevs(r):
779 for p in parentrevs(r):
779 if p in reachable:
780 if p in reachable:
780 if r not in stoprevs:
781 if r not in stoprevs:
@@ -789,7 +790,7 b' class revlog(object):'
789 """find the children of a given node"""
790 """find the children of a given node"""
790 c = []
791 c = []
791 p = self.rev(node)
792 p = self.rev(node)
792 for r in range(p + 1, self.count()):
793 for r in range(p + 1, len(self)):
793 prevs = [pr for pr in self.parentrevs(r) if pr != nullrev]
794 prevs = [pr for pr in self.parentrevs(r) if pr != nullrev]
794 if prevs:
795 if prevs:
795 for pr in prevs:
796 for pr in prevs:
@@ -818,8 +819,8 b' class revlog(object):'
818 if str(rev) != id:
819 if str(rev) != id:
819 raise ValueError
820 raise ValueError
820 if rev < 0:
821 if rev < 0:
821 rev = self.count() + rev
822 rev = len(self) + rev
822 if rev < 0 or rev >= self.count():
823 if rev < 0 or rev >= len(self):
823 raise ValueError
824 raise ValueError
824 return self.node(rev)
825 return self.node(rev)
825 except (ValueError, OverflowError):
826 except (ValueError, OverflowError):
@@ -982,7 +983,7 b' class revlog(object):'
982 df = self.opener(self.datafile, 'w')
983 df = self.opener(self.datafile, 'w')
983 try:
984 try:
984 calc = self._io.size
985 calc = self._io.size
985 for r in xrange(self.count()):
986 for r in self:
986 start = self.start(r) + (r + 1) * calc
987 start = self.start(r) + (r + 1) * calc
987 length = self.length(r)
988 length = self.length(r)
988 fp.seek(start)
989 fp.seek(start)
@@ -995,7 +996,7 b' class revlog(object):'
995 fp = self.opener(self.indexfile, 'w', atomictemp=True)
996 fp = self.opener(self.indexfile, 'w', atomictemp=True)
996 self.version &= ~(REVLOGNGINLINEDATA)
997 self.version &= ~(REVLOGNGINLINEDATA)
997 self._inline = False
998 self._inline = False
998 for i in xrange(self.count()):
999 for i in self:
999 e = self._io.packentry(self.index[i], self.node, self.version, i)
1000 e = self._io.packentry(self.index[i], self.node, self.version, i)
1000 fp.write(e)
1001 fp.write(e)
1001
1002
@@ -1031,7 +1032,7 b' class revlog(object):'
1031 if node in self.nodemap:
1032 if node in self.nodemap:
1032 return node
1033 return node
1033
1034
1034 curr = self.count()
1035 curr = len(self)
1035 prev = curr - 1
1036 prev = curr - 1
1036 base = self.base(prev)
1037 base = self.base(prev)
1037 offset = self.end(prev)
1038 offset = self.end(prev)
@@ -1146,7 +1147,7 b' class revlog(object):'
1146 """
1147 """
1147
1148
1148 #track the base of the current delta log
1149 #track the base of the current delta log
1149 r = self.count()
1150 r = len(self)
1150 t = r - 1
1151 t = r - 1
1151 node = None
1152 node = None
1152
1153
@@ -1265,13 +1266,13 b' class revlog(object):'
1265 trust that the caller has saved the revisions that shouldn't be
1266 trust that the caller has saved the revisions that shouldn't be
1266 removed and that it'll readd them after this truncation.
1267 removed and that it'll readd them after this truncation.
1267 """
1268 """
1268 if self.count() == 0:
1269 if len(self) == 0:
1269 return
1270 return
1270
1271
1271 if isinstance(self.index, lazyindex):
1272 if isinstance(self.index, lazyindex):
1272 self._loadindexmap()
1273 self._loadindexmap()
1273
1274
1274 for rev in xrange(0, self.count()):
1275 for rev in self:
1275 if self.index[rev][4] >= minlink:
1276 if self.index[rev][4] >= minlink:
1276 break
1277 break
1277 else:
1278 else:
@@ -1292,15 +1293,15 b' class revlog(object):'
1292 # then reset internal state in memory to forget those revisions
1293 # then reset internal state in memory to forget those revisions
1293 self._cache = None
1294 self._cache = None
1294 self._chunkcache = None
1295 self._chunkcache = None
1295 for x in xrange(rev, self.count()):
1296 for x in xrange(rev, len(self)):
1296 del self.nodemap[self.node(x)]
1297 del self.nodemap[self.node(x)]
1297
1298
1298 del self.index[rev:-1]
1299 del self.index[rev:-1]
1299
1300
1300 def checksize(self):
1301 def checksize(self):
1301 expected = 0
1302 expected = 0
1302 if self.count():
1303 if len(self):
1303 expected = max(0, self.end(self.count() - 1))
1304 expected = max(0, self.end(len(self) - 1))
1304
1305
1305 try:
1306 try:
1306 f = self.opener(self.datafile)
1307 f = self.opener(self.datafile)
@@ -1321,10 +1322,10 b' class revlog(object):'
1321 di = actual - (i * s)
1322 di = actual - (i * s)
1322 if self._inline:
1323 if self._inline:
1323 databytes = 0
1324 databytes = 0
1324 for r in xrange(self.count()):
1325 for r in self:
1325 databytes += max(0, self.length(r))
1326 databytes += max(0, self.length(r))
1326 dd = 0
1327 dd = 0
1327 di = actual - self.count() * s - databytes
1328 di = actual - len(self) * s - databytes
1328 except IOError, inst:
1329 except IOError, inst:
1329 if inst.errno != errno.ENOENT:
1330 if inst.errno != errno.ENOENT:
1330 raise
1331 raise
@@ -65,13 +65,13 b' def _verify(repo):'
65 havecl = havemf = 1
65 havecl = havemf = 1
66 seen = {}
66 seen = {}
67 repo.ui.status(_("checking changesets\n"))
67 repo.ui.status(_("checking changesets\n"))
68 if repo.changelog.count() == 0 and repo.manifest.count() > 1:
68 if not len(repo) and len(repo.manifest):
69 havecl = 0
69 havecl = 0
70 err(0, _("empty or missing 00changelog.i"))
70 err(0, _("empty or missing 00changelog.i"))
71 else:
71 else:
72 checksize(repo.changelog, "changelog")
72 checksize(repo.changelog, "changelog")
73
73
74 for i in xrange(repo.changelog.count()):
74 for i in repo:
75 changesets += 1
75 changesets += 1
76 n = repo.changelog.node(i)
76 n = repo.changelog.node(i)
77 l = repo.changelog.linkrev(n)
77 l = repo.changelog.linkrev(n)
@@ -101,18 +101,18 b' def _verify(repo):'
101
101
102 seen = {}
102 seen = {}
103 repo.ui.status(_("checking manifests\n"))
103 repo.ui.status(_("checking manifests\n"))
104 if repo.changelog.count() > 0 and repo.manifest.count() == 0:
104 if len(repo) and not len(repo.manifest):
105 havemf = 0
105 havemf = 0
106 err(0, _("empty or missing 00manifest.i"))
106 err(0, _("empty or missing 00manifest.i"))
107 else:
107 else:
108 checkversion(repo.manifest, "manifest")
108 checkversion(repo.manifest, "manifest")
109 checksize(repo.manifest, "manifest")
109 checksize(repo.manifest, "manifest")
110
110
111 for i in xrange(repo.manifest.count()):
111 for i in repo.manifest:
112 n = repo.manifest.node(i)
112 n = repo.manifest.node(i)
113 l = repo.manifest.linkrev(n)
113 l = repo.manifest.linkrev(n)
114
114
115 if l < 0 or (havecl and l >= repo.changelog.count()):
115 if l < 0 or (havecl and l >= len(repo)):
116 err(None, _("bad link (%d) at manifest revision %d") % (l, i))
116 err(None, _("bad link (%d) at manifest revision %d") % (l, i))
117
117
118 if n in neededmanifests:
118 if n in neededmanifests:
@@ -182,19 +182,19 b' def _verify(repo):'
182 checkversion(fl, f)
182 checkversion(fl, f)
183 checksize(fl, f)
183 checksize(fl, f)
184
184
185 if fl.count() == 0:
185 if not len(fl):
186 err(filelinkrevs[f][0], _("empty or missing revlog"), f)
186 err(filelinkrevs[f][0], _("empty or missing revlog"), f)
187 continue
187 continue
188
188
189 seen = {}
189 seen = {}
190 nodes = {nullid: 1}
190 nodes = {nullid: 1}
191 for i in xrange(fl.count()):
191 for i in fl:
192 revisions += 1
192 revisions += 1
193 n = fl.node(i)
193 n = fl.node(i)
194 flr = fl.linkrev(n)
194 flr = fl.linkrev(n)
195
195
196 if flr < 0 or (havecl and flr not in filelinkrevs.get(f, [])):
196 if flr < 0 or (havecl and flr not in filelinkrevs.get(f, [])):
197 if flr < 0 or flr >= repo.changelog.count():
197 if flr < 0 or flr >= len(repo):
198 err(None, _("rev %d point to nonexistent changeset %d")
198 err(None, _("rev %d point to nonexistent changeset %d")
199 % (i, flr), f)
199 % (i, flr), f)
200 else:
200 else:
@@ -245,7 +245,7 b' def _verify(repo):'
245 rp = fl.renamed(n)
245 rp = fl.renamed(n)
246 if rp:
246 if rp:
247 fl2 = repo.file(rp[0])
247 fl2 = repo.file(rp[0])
248 if fl2.count() == 0:
248 if not len(fl2):
249 err(flr, _("empty or missing copy source revlog %s:%s")
249 err(flr, _("empty or missing copy source revlog %s:%s")
250 % (rp[0], short(rp[1])), f)
250 % (rp[0], short(rp[1])), f)
251 elif rp[1] == nullid:
251 elif rp[1] == nullid:
@@ -44,8 +44,8 b' def opener(*args):'
44 return wrapper
44 return wrapper
45
45
46 cl = changelog.changelog(opener('.hg/store'))
46 cl = changelog.changelog(opener('.hg/store'))
47 print cl.count(), 'revisions:'
47 print len(cl), 'revisions:'
48 for r in xrange(cl.count()):
48 for r in cl:
49 print short(cl.node(r))
49 print short(cl.node(r))
50 EOF
50 EOF
51
51
General Comments 0
You need to be logged in to leave comments. Login now