Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/branchmap.py @ 39152:2a4bfbb52111
branchmap: load branchmap as an iterable
This avoids reading all the file into memory if the cache turns out to be
invalid.
Differential Revision: https://phab.mercurial-scm.org/D4281
author | Martijn Pieters <mj@octobus.net> |
---|---|
date | Mon, 13 Aug 2018 21:22:14 +0100 |
parents | f0b6fbea00cf |
children | b892df0766e1 |
comparison
equal
deleted
inserted
replaced
39151:222aba766015 | 39152:2a4bfbb52111 |
---|---|
38 return filename | 38 return filename |
39 | 39 |
40 def read(repo): | 40 def read(repo): |
41 try: | 41 try: |
42 f = repo.cachevfs(_filename(repo)) | 42 f = repo.cachevfs(_filename(repo)) |
43 lines = f.read().split('\n') | 43 cachekey = next(f).split(" ", 2) |
44 f.close() | |
45 except (IOError, OSError): | |
46 return None | |
47 | |
48 try: | |
49 cachekey = lines.pop(0).split(" ", 2) | |
50 last, lrev = cachekey[:2] | 44 last, lrev = cachekey[:2] |
51 last, lrev = bin(last), int(lrev) | 45 last, lrev = bin(last), int(lrev) |
52 filteredhash = None | 46 filteredhash = None |
53 if len(cachekey) > 2: | 47 if len(cachekey) > 2: |
54 filteredhash = bin(cachekey[2]) | 48 filteredhash = bin(cachekey[2]) |
56 filteredhash=filteredhash) | 50 filteredhash=filteredhash) |
57 if not partial.validfor(repo): | 51 if not partial.validfor(repo): |
58 # invalidate the cache | 52 # invalidate the cache |
59 raise ValueError(r'tip differs') | 53 raise ValueError(r'tip differs') |
60 cl = repo.changelog | 54 cl = repo.changelog |
61 for l in lines: | 55 for l in f: |
62 if not l: | 56 if not l: |
63 continue | 57 continue |
64 node, state, label = l.split(" ", 2) | 58 node, state, label = l.split(" ", 2) |
65 if state not in 'oc': | 59 if state not in 'oc': |
66 raise ValueError(r'invalid branch state') | 60 raise ValueError(r'invalid branch state') |
70 raise ValueError( | 64 raise ValueError( |
71 r'node %s does not exist' % pycompat.sysstr(hex(node))) | 65 r'node %s does not exist' % pycompat.sysstr(hex(node))) |
72 partial.setdefault(label, []).append(node) | 66 partial.setdefault(label, []).append(node) |
73 if state == 'c': | 67 if state == 'c': |
74 partial._closednodes.add(node) | 68 partial._closednodes.add(node) |
69 | |
70 except (IOError, OSError): | |
71 return None | |
72 | |
75 except Exception as inst: | 73 except Exception as inst: |
76 if repo.ui.debugflag: | 74 if repo.ui.debugflag: |
77 msg = 'invalid branchheads cache' | 75 msg = 'invalid branchheads cache' |
78 if repo.filtername is not None: | 76 if repo.filtername is not None: |
79 msg += ' (%s)' % repo.filtername | 77 msg += ' (%s)' % repo.filtername |