author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Thu, 20 Dec 2012 16:28:43 +0100 | |
changeset 18128 | f0d56efaa35a |
parent 18127 | dcd43ac7572d |
child 18129 | 3264d3ce53a0 |
permissions | -rw-r--r-- |
18116
bcee63733aad
branchmap: create a mercurial.branchmap module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 |
# branchmap.py - logic to computes, maintain and stores branchmap for local repo |
bcee63733aad
branchmap: create a mercurial.branchmap module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 |
# |
bcee63733aad
branchmap: create a mercurial.branchmap module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
bcee63733aad
branchmap: create a mercurial.branchmap module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 |
# |
bcee63733aad
branchmap: create a mercurial.branchmap module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
bcee63733aad
branchmap: create a mercurial.branchmap module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
18117
526e7ec5c96e
branchmap: extract write logic from localrepo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18116
diff
changeset
|
7 |
|
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
8 |
from node import bin, hex, nullid, nullrev |
18117
526e7ec5c96e
branchmap: extract write logic from localrepo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18116
diff
changeset
|
9 |
import encoding |
526e7ec5c96e
branchmap: extract write logic from localrepo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18116
diff
changeset
|
10 |
|
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
11 |
def read(repo): |
18124
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
12 |
partial = branchcache() |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
13 |
try: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
14 |
f = repo.opener("cache/branchheads") |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
15 |
lines = f.read().split('\n') |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
16 |
f.close() |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
17 |
except (IOError, OSError): |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
18 |
return branchcache() |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
19 |
|
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
20 |
try: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
21 |
last, lrev = lines.pop(0).split(" ", 1) |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
22 |
last, lrev = bin(last), int(lrev) |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
23 |
if lrev >= len(repo) or repo[lrev].node() != last: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
24 |
# invalidate the cache |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
25 |
raise ValueError('invalidating branch cache (tip differs)') |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
26 |
for l in lines: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
27 |
if not l: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
28 |
continue |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
29 |
node, label = l.split(" ", 1) |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
30 |
label = encoding.tolocal(label.strip()) |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
31 |
if not node in repo: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
32 |
raise ValueError('invalidating branch cache because node '+ |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
33 |
'%s does not exist' % node) |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
34 |
partial.setdefault(label, []).append(bin(node)) |
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
35 |
partial.tipnode = last |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
36 |
partial.tiprev = lrev |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
37 |
except KeyboardInterrupt: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
38 |
raise |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
39 |
except Exception, inst: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
40 |
if repo.ui.debugflag: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
41 |
repo.ui.warn(str(inst), '\n') |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
42 |
partial = branchcache() |
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
43 |
return partial |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
44 |
|
18120
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
45 |
def update(repo, partial, ctxgen): |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
46 |
"""Given a branchhead cache, partial, that may have extra nodes or be |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
47 |
missing heads, and a generator of nodes that are at least a superset of |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
48 |
heads missing, this function updates partial to be correct. |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
49 |
""" |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
50 |
# collect new branch entries |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
51 |
newbranches = {} |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
52 |
for c in ctxgen: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
53 |
newbranches.setdefault(c.branch(), []).append(c.node()) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
54 |
# if older branchheads are reachable from new ones, they aren't |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
55 |
# really branchheads. Note checking parents is insufficient: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
56 |
# 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
57 |
for branch, newnodes in newbranches.iteritems(): |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
58 |
bheads = partial.setdefault(branch, []) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
59 |
# Remove candidate heads that no longer are in the repo (e.g., as |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
60 |
# the result of a strip that just happened). Avoid using 'node in |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
61 |
# self' here because that dives down into branchcache code somewhat |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
62 |
# recursively. |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
63 |
bheadrevs = [repo.changelog.rev(node) for node in bheads |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
64 |
if repo.changelog.hasnode(node)] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
65 |
newheadrevs = [repo.changelog.rev(node) for node in newnodes |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
66 |
if repo.changelog.hasnode(node)] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
67 |
ctxisnew = bheadrevs and min(newheadrevs) > max(bheadrevs) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
68 |
# Remove duplicates - nodes that are in newheadrevs and are already |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
69 |
# in bheadrevs. This can happen if you strip a node whose parent |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
70 |
# was already a head (because they're on different branches). |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
71 |
bheadrevs = sorted(set(bheadrevs).union(newheadrevs)) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
72 |
|
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
73 |
# Starting from tip means fewer passes over reachable. If we know |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
74 |
# the new candidates are not ancestors of existing heads, we don't |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
75 |
# have to examine ancestors of existing heads |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
76 |
if ctxisnew: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
77 |
iterrevs = sorted(newheadrevs) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
78 |
else: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
79 |
iterrevs = list(bheadrevs) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
80 |
|
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
81 |
# This loop prunes out two kinds of heads - heads that are |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
82 |
# superseded by a head in newheadrevs, and newheadrevs that are not |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
83 |
# heads because an existing head is their descendant. |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
84 |
while iterrevs: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
85 |
latest = iterrevs.pop() |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
86 |
if latest not in bheadrevs: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
87 |
continue |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
88 |
ancestors = set(repo.changelog.ancestors([latest], |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
89 |
bheadrevs[0])) |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
90 |
if ancestors: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
91 |
bheadrevs = [b for b in bheadrevs if b not in ancestors] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
92 |
partial[branch] = [repo.changelog.node(rev) for rev in bheadrevs] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
93 |
|
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
94 |
# There may be branches that cease to exist when the last commit in the |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
95 |
# branch was stripped. This code filters them out. Note that the |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
96 |
# branch that ceased to exist may not be in newbranches because |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
97 |
# newbranches is the set of candidate heads, which when you strip the |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
98 |
# last commit in a branch will be the parent branch. |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
99 |
for branch in partial.keys(): |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
100 |
nodes = [head for head in partial[branch] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
101 |
if repo.changelog.hasnode(head)] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
102 |
if not nodes: |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
103 |
del partial[branch] |
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
104 |
|
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
105 |
def updatecache(repo): |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
106 |
repo = repo.unfiltered() # Until we get a smarter cache management |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
107 |
cl = repo.changelog |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
108 |
tip = cl.tip() |
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
109 |
partial = repo._branchcache |
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
110 |
if partial is not None and partial.tipnode == tip: |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
111 |
return |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
112 |
|
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
113 |
if partial is None or partial.tipnode not in cl.nodemap: |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
114 |
partial = read(repo) |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
115 |
|
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
116 |
catip = repo._cacheabletip() |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
117 |
# if partial.tiprev == catip: cache is already up to date |
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
118 |
# if partial.tiprev > catip: we have uncachable element in `partial` can't |
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
119 |
# write on disk |
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
120 |
if partial.tiprev < catip: |
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
121 |
ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip)) |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
122 |
update(repo, partial, ctxgen) |
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
123 |
partial.tipnode = cl.node(catip) |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
124 |
partial.tiprev = catip |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
125 |
partial.write(repo) |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
126 |
# If cacheable tip were lower than actual tip, we need to update the |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
127 |
# cache up to tip. This update (from cacheable to actual tip) is not |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
128 |
# written to disk since it's not cacheable. |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
129 |
tiprev = len(repo) - 1 |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
130 |
if partial.tiprev < tiprev: |
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
131 |
ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, tiprev)) |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
132 |
update(repo, partial, ctxgen) |
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
133 |
partial.tipnode = cl.node(tiprev) |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
134 |
partial.tiprev = tiprev |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
135 |
repo._branchcache = partial |
18124
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
136 |
|
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
137 |
class branchcache(dict): |
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
138 |
"""A dict like object that hold branches heads cache""" |
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
139 |
|
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
140 |
def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev): |
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
141 |
super(branchcache, self).__init__(entries) |
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
142 |
self.tipnode = tipnode |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
143 |
self.tiprev = tiprev |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
144 |
|
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
145 |
def write(self, repo): |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
146 |
try: |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
147 |
f = repo.opener("cache/branchheads", "w", atomictemp=True) |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
148 |
f.write("%s %s\n" % (hex(self.tipnode), self.tiprev)) |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
149 |
for label, nodes in self.iteritems(): |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
150 |
for node in nodes: |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
151 |
f.write("%s %s\n" % (hex(node), encoding.fromlocal(label))) |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
152 |
f.close() |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
153 |
except (IOError, OSError): |
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
154 |
pass |