Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/branchmap.py @ 18118:e70ff1e599f4
branchmap: extract read logic from repo
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Wed, 19 Dec 2012 14:46:57 +0100 |
parents | 526e7ec5c96e |
children | 88990d3e3d75 |
comparison
equal
deleted
inserted
replaced
18117:526e7ec5c96e | 18118:e70ff1e599f4 |
---|---|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4 # | 4 # |
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from node import hex | 8 from node import bin, hex, nullid, nullrev |
9 import encoding | 9 import encoding |
10 | |
11 def read(repo): | |
12 partial = {} | |
13 try: | |
14 f = repo.opener("cache/branchheads") | |
15 lines = f.read().split('\n') | |
16 f.close() | |
17 except (IOError, OSError): | |
18 return {}, nullid, nullrev | |
19 | |
20 try: | |
21 last, lrev = lines.pop(0).split(" ", 1) | |
22 last, lrev = bin(last), int(lrev) | |
23 if lrev >= len(repo) or repo[lrev].node() != last: | |
24 # invalidate the cache | |
25 raise ValueError('invalidating branch cache (tip differs)') | |
26 for l in lines: | |
27 if not l: | |
28 continue | |
29 node, label = l.split(" ", 1) | |
30 label = encoding.tolocal(label.strip()) | |
31 if not node in repo: | |
32 raise ValueError('invalidating branch cache because node '+ | |
33 '%s does not exist' % node) | |
34 partial.setdefault(label, []).append(bin(node)) | |
35 except KeyboardInterrupt: | |
36 raise | |
37 except Exception, inst: | |
38 if repo.ui.debugflag: | |
39 repo.ui.warn(str(inst), '\n') | |
40 partial, last, lrev = {}, nullid, nullrev | |
41 return partial, last, lrev | |
10 | 42 |
11 def write(repo, branches, tip, tiprev): | 43 def write(repo, branches, tip, tiprev): |
12 try: | 44 try: |
13 f = repo.opener("cache/branchheads", "w", atomictemp=True) | 45 f = repo.opener("cache/branchheads", "w", atomictemp=True) |
14 f.write("%s %s\n" % (hex(tip), tiprev)) | 46 f.write("%s %s\n" % (hex(tip), tiprev)) |