30 |
30 |
31 eh = exthelper.exthelper() |
31 eh = exthelper.exthelper() |
32 |
32 |
33 def simpledepth(repo, rev): |
33 def simpledepth(repo, rev): |
34 """simple but obviously right implementation of depth""" |
34 """simple but obviously right implementation of depth""" |
35 return len(repo.revs('::%d', rev)) |
35 return len(repo.revs(b'::%d', rev)) |
36 |
36 |
37 @eh.command( |
37 @eh.command( |
38 b'debugdepth', |
38 b'debugdepth', |
39 [ |
39 [ |
40 (b'r', b'rev', [], b'revs to print depth for'), |
40 (b'r', b'rev', [], b'revs to print depth for'), |
44 def debugdepth(ui, repo, **opts): |
44 def debugdepth(ui, repo, **opts): |
45 """display depth of REVS |
45 """display depth of REVS |
46 """ |
46 """ |
47 revs = scmutil.revrange(repo, opts['rev']) |
47 revs = scmutil.revrange(repo, opts['rev']) |
48 method = opts['method'] |
48 method = opts['method'] |
49 if method in ('cached', 'compare'): |
49 if method in (b'cached', b'compare'): |
50 cache = repo.depthcache |
50 cache = repo.depthcache |
51 cache.save(repo) |
51 cache.save(repo) |
52 for r in revs: |
52 for r in revs: |
53 ctx = repo[r] |
53 ctx = repo[r] |
54 if method == 'simple': |
54 if method == b'simple': |
55 depth = simpledepth(repo, r) |
55 depth = simpledepth(repo, r) |
56 elif method == 'cached': |
56 elif method == b'cached': |
57 depth = cache.get(r) |
57 depth = cache.get(r) |
58 elif method == 'compare': |
58 elif method == b'compare': |
59 simple = simpledepth(repo, r) |
59 simple = simpledepth(repo, r) |
60 cached = cache.get(r) |
60 cached = cache.get(r) |
61 if simple != cached: |
61 if simple != cached: |
62 raise error.Abort('depth differ for revision %s: %d != %d' |
62 raise error.Abort(b'depth differ for revision %s: %d != %d' |
63 % (ctx, simple, cached)) |
63 % (ctx, simple, cached)) |
64 depth = simple |
64 depth = simple |
65 else: |
65 else: |
66 raise error.Abort('unknown method "%s"' % method) |
66 raise error.Abort(b'unknown method "%s"' % method) |
67 ui.write('%s %d\n' % (ctx, depth)) |
67 ui.write(b'%s %d\n' % (ctx, depth)) |
68 |
68 |
69 @eh.reposetup |
69 @eh.reposetup |
70 def setupcache(ui, repo): |
70 def setupcache(ui, repo): |
71 |
71 |
72 class depthcacherepo(repo.__class__): |
72 class depthcacherepo(repo.__class__): |
92 |
92 |
93 repo.__class__ = depthcacherepo |
93 repo.__class__ = depthcacherepo |
94 |
94 |
95 class depthcache(genericcaches.changelogsourcebase): |
95 class depthcache(genericcaches.changelogsourcebase): |
96 |
96 |
97 _filepath = 'evoext-depthcache-00' |
97 _filepath = b'evoext-depthcache-00' |
98 _cachename = 'evo-ext-depthcache' |
98 _cachename = b'evo-ext-depthcache' |
99 |
99 |
100 def __init__(self): |
100 def __init__(self): |
101 super(depthcache, self).__init__() |
101 super(depthcache, self).__init__() |
102 self._data = array.array(r'l') |
102 self._data = array.array(r'l') |
103 |
103 |
104 def get(self, rev): |
104 def get(self, rev): |
105 if len(self._data) <= rev: |
105 if len(self._data) <= rev: |
106 raise error.ProgrammingError('depthcache must be warmed before use') |
106 raise error.ProgrammingError(b'depthcache must be warmed before use') |
107 return self._data[rev] |
107 return self._data[rev] |
108 |
108 |
109 def _updatefrom(self, repo, data): |
109 def _updatefrom(self, repo, data): |
110 """compute the rev of one revision, assert previous revision has an hot cache |
110 """compute the rev of one revision, assert previous revision has an hot cache |
111 """ |
111 """ |
112 cl = repo.unfiltered().changelog |
112 cl = repo.unfiltered().changelog |
113 total = len(data) |
113 total = len(data) |
114 |
114 |
115 def progress(pos, rev=None): |
115 def progress(pos, rev=None): |
116 revstr = '' if rev is None else ('rev %d' % rev) |
116 revstr = b'' if rev is None else (b'rev %d' % rev) |
117 compat.progress(repo.ui, 'updating depth cache', |
117 compat.progress(repo.ui, b'updating depth cache', |
118 pos, revstr, unit='revision', total=total) |
118 pos, revstr, unit=b'revision', total=total) |
119 progress(0) |
119 progress(0) |
120 for idx, rev in enumerate(data, 1): |
120 for idx, rev in enumerate(data, 1): |
121 assert rev == len(self._data), (rev, len(self._data)) |
121 assert rev == len(self._data), (rev, len(self._data)) |
122 self._data.append(self._depth(cl, rev)) |
122 self._data.append(self._depth(cl, rev)) |
123 if not (idx % 10000): # progress as a too high performance impact |
123 if not (idx % 10000): # progress as a too high performance impact |
197 """ |
197 """ |
198 if self._cachekey is None or self._cachekey == self._ondiskkey: |
198 if self._cachekey is None or self._cachekey == self._ondiskkey: |
199 return |
199 return |
200 |
200 |
201 try: |
201 try: |
202 cachefile = repo.cachevfs(self._filepath, 'w', atomictemp=True) |
202 cachefile = repo.cachevfs(self._filepath, b'w', atomictemp=True) |
203 headerdata = self._serializecachekey() |
203 headerdata = self._serializecachekey() |
204 cachefile.write(headerdata) |
204 cachefile.write(headerdata) |
205 cachefile.write(compat.arraytobytes(self._data)) |
205 cachefile.write(compat.arraytobytes(self._data)) |
206 cachefile.close() |
206 cachefile.close() |
207 self._ondiskkey = self._cachekey |
207 self._ondiskkey = self._cachekey |
208 except (IOError, OSError) as exc: |
208 except (IOError, OSError) as exc: |
209 repo.ui.log('depthcache', 'could not write update %s\n' % exc) |
209 repo.ui.log(b'depthcache', b'could not write update %s\n' % exc) |
210 repo.ui.debug('depthcache: could not write update %s\n' % exc) |
210 repo.ui.debug(b'depthcache: could not write update %s\n' % exc) |