Mercurial > public > mercurial-scm > hg
comparison hgext/git/index.py @ 44951:83e41b73d115
git: add debug logging when there's a mismatch in the cached heads list
The dag rebuild can be expensive, so let's try and avoid bugs where it
transparently rebuilds all the time for no reason. This would have
prevented the issue fixed in D8622.
Differential Revision: https://phab.mercurial-scm.org/D8625
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 09 Jun 2020 17:13:26 -0400 |
parents | fb2936c5f6dc |
children | 59fa3890d40a |
comparison
equal
deleted
inserted
replaced
44950:f9734b2d59cc | 44951:83e41b73d115 |
---|---|
214 (p1node, p1fnode, p2node, p2fnode, commit.id.hex, path, filenode), | 214 (p1node, p1fnode, p2node, p2fnode, commit.id.hex, path, filenode), |
215 ) | 215 ) |
216 db.commit() | 216 db.commit() |
217 | 217 |
218 | 218 |
219 def _index_repo(gitrepo, db, progress_factory=lambda *args, **kwargs: None): | 219 def _index_repo( |
220 gitrepo, | |
221 db, | |
222 logfn=lambda x: None, | |
223 progress_factory=lambda *args, **kwargs: None, | |
224 ): | |
220 # Identify all references so we can tell the walker to visit all of them. | 225 # Identify all references so we can tell the walker to visit all of them. |
221 all_refs = gitrepo.listall_references() | 226 all_refs = gitrepo.listall_references() |
222 possible_heads = set() | 227 possible_heads = set() |
223 prog = progress_factory(b'refs') | 228 prog = progress_factory(b'refs') |
224 for pos, ref in enumerate(all_refs): | 229 for pos, ref in enumerate(all_refs): |
251 } | 256 } |
252 walker = None | 257 walker = None |
253 cur_cache_heads = {h.hex for h in possible_heads} | 258 cur_cache_heads = {h.hex for h in possible_heads} |
254 if cur_cache_heads == cache_heads: | 259 if cur_cache_heads == cache_heads: |
255 return | 260 return |
261 logfn(b'heads mismatch, rebuilding dagcache\n') | |
256 for start in possible_heads: | 262 for start in possible_heads: |
257 if walker is None: | 263 if walker is None: |
258 walker = gitrepo.walk(start, _OUR_ORDER) | 264 walker = gitrepo.walk(start, _OUR_ORDER) |
259 else: | 265 else: |
260 walker.push(start) | 266 walker.push(start) |
337 db.commit() | 343 db.commit() |
338 if prog is not None: | 344 if prog is not None: |
339 prog.complete() | 345 prog.complete() |
340 | 346 |
341 | 347 |
342 def get_index(gitrepo, progress_factory=lambda *args, **kwargs: None): | 348 def get_index( |
349 gitrepo, logfn=lambda x: None, progress_factory=lambda *args, **kwargs: None | |
350 ): | |
343 cachepath = os.path.join( | 351 cachepath = os.path.join( |
344 pycompat.fsencode(gitrepo.path), b'..', b'.hg', b'cache' | 352 pycompat.fsencode(gitrepo.path), b'..', b'.hg', b'cache' |
345 ) | 353 ) |
346 if not os.path.exists(cachepath): | 354 if not os.path.exists(cachepath): |
347 os.makedirs(cachepath) | 355 os.makedirs(cachepath) |
348 dbpath = os.path.join(cachepath, b'git-commits.sqlite') | 356 dbpath = os.path.join(cachepath, b'git-commits.sqlite') |
349 db = _createdb(dbpath) | 357 db = _createdb(dbpath) |
350 # TODO check against gitrepo heads before doing a full index | 358 # TODO check against gitrepo heads before doing a full index |
351 # TODO thread a ui.progress call into this layer | 359 # TODO thread a ui.progress call into this layer |
352 _index_repo(gitrepo, db, progress_factory) | 360 _index_repo(gitrepo, db, logfn, progress_factory) |
353 return db | 361 return db |