Mercurial > hg
annotate mercurial/branchmap.py @ 20202:a6014018ec28
util: remove unused realpath (issue4063)
util.realpath was in use for only 5 days from dbdb777502dc
until it was backed out in c519cd8f0169 because it caused
issue3077 and issue3071.
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Sun, 29 Dec 2013 13:54:04 +0000 |
parents | d5d25e541637 |
children | 4edd179fefb8 |
rev | line source |
---|---|
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 |
20032
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
10 import util |
18117
526e7ec5c96e
branchmap: extract write logic from localrepo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18116
diff
changeset
|
11 |
18185
5a047276764e
branchmap: move the cache file name into a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18184
diff
changeset
|
12 def _filename(repo): |
18187
4df8716d32f1
branchmap: use a different file name for filtered view of repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18185
diff
changeset
|
13 """name of a branchcache file for a given repo or repoview""" |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
14 filename = "cache/branch2" |
18187
4df8716d32f1
branchmap: use a different file name for filtered view of repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18185
diff
changeset
|
15 if repo.filtername: |
4df8716d32f1
branchmap: use a different file name for filtered view of repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18185
diff
changeset
|
16 filename = '%s-%s' % (filename, repo.filtername) |
4df8716d32f1
branchmap: use a different file name for filtered view of repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18185
diff
changeset
|
17 return filename |
18185
5a047276764e
branchmap: move the cache file name into a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18184
diff
changeset
|
18 |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
19 def read(repo): |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
20 try: |
18185
5a047276764e
branchmap: move the cache file name into a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18184
diff
changeset
|
21 f = repo.opener(_filename(repo)) |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
22 lines = f.read().split('\n') |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
23 f.close() |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
24 except (IOError, OSError): |
18212
493778b5fe9f
branchmap: read return None in case of failure
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18189
diff
changeset
|
25 return None |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
26 |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
27 try: |
18184
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
28 cachekey = lines.pop(0).split(" ", 2) |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
29 last, lrev = cachekey[:2] |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
30 last, lrev = bin(last), int(lrev) |
18184
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
31 filteredhash = None |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
32 if len(cachekey) > 2: |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
33 filteredhash = bin(cachekey[2]) |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
34 partial = branchcache(tipnode=last, tiprev=lrev, |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
35 filteredhash=filteredhash) |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
36 if not partial.validfor(repo): |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
37 # invalidate the cache |
18166
3a2e810dd3d8
branchmap: improve invalid cache message when reading
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18132
diff
changeset
|
38 raise ValueError('tip differs') |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
39 for l in lines: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
40 if not l: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
41 continue |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
42 node, state, label = l.split(" ", 2) |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
43 if state not in 'oc': |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
44 raise ValueError('invalid branch state') |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
45 label = encoding.tolocal(label.strip()) |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
46 if not node in repo: |
18166
3a2e810dd3d8
branchmap: improve invalid cache message when reading
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18132
diff
changeset
|
47 raise ValueError('node %s does not exist' % node) |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
48 node = bin(node) |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
49 partial.setdefault(label, []).append(node) |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
50 if state == 'c': |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
51 partial._closednodes.add(node) |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
52 except KeyboardInterrupt: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
53 raise |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
54 except Exception, inst: |
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
55 if repo.ui.debugflag: |
18188
46ed5226503a
branchmap: report filtername when read fails
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18187
diff
changeset
|
56 msg = 'invalid branchheads cache' |
46ed5226503a
branchmap: report filtername when read fails
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18187
diff
changeset
|
57 if repo.filtername is not None: |
46ed5226503a
branchmap: report filtername when read fails
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18187
diff
changeset
|
58 msg += ' (%s)' % repo.filtername |
46ed5226503a
branchmap: report filtername when read fails
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18187
diff
changeset
|
59 msg += ': %s\n' |
46ed5226503a
branchmap: report filtername when read fails
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18187
diff
changeset
|
60 repo.ui.warn(msg % inst) |
18212
493778b5fe9f
branchmap: read return None in case of failure
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18189
diff
changeset
|
61 partial = None |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
62 return partial |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
63 |
18130
1b05ffce47bd
branchmap: make update responsible to update the cache key
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18129
diff
changeset
|
64 |
18120
88990d3e3d75
branchmap: extract _updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18118
diff
changeset
|
65 |
20032
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
66 ### Nearest subset relation |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
67 # Nearest subset of filter X is a filter Y so that: |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
68 # * Y is included in X, |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
69 # * X - Y is as small as possible. |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
70 # This create and ordering used for branchmap purpose. |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
71 # the ordering may be partial |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
72 subsettable = {None: 'visible', |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
73 'visible': 'served', |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
74 'served': 'immutable', |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
75 'immutable': 'base'} |
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
76 |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
77 def updatecache(repo): |
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
78 cl = repo.changelog |
18189
b9026ba002f6
branchmap: enable caching for filtered version too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18188
diff
changeset
|
79 filtername = repo.filtername |
b9026ba002f6
branchmap: enable caching for filtered version too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18188
diff
changeset
|
80 partial = repo._branchcaches.get(filtername) |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
81 |
18234
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
82 revs = [] |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
83 if partial is None or not partial.validfor(repo): |
18126
090ada0acddb
branchmap: add the tiprev (cache key) on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18125
diff
changeset
|
84 partial = read(repo) |
18212
493778b5fe9f
branchmap: read return None in case of failure
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18189
diff
changeset
|
85 if partial is None: |
20032
175c6fd8cacc
subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents:
19839
diff
changeset
|
86 subsetname = subsettable.get(filtername) |
18234
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
87 if subsetname is None: |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
88 partial = branchcache() |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
89 else: |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
90 subset = repo.filtered(subsetname) |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
91 partial = subset.branchmap().copy() |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
92 extrarevs = subset.changelog.filteredrevs - cl.filteredrevs |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
93 revs.extend(r for r in extrarevs if r <= partial.tiprev) |
a55b06885cda
branchmap: allow to use cache of subset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18232
diff
changeset
|
94 revs.extend(cl.revs(start=partial.tiprev + 1)) |
18218
d5655e742457
branchmap: drop `_cacheabletip` usage in `updatecache`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18214
diff
changeset
|
95 if revs: |
18305
2502a15e033d
branchmap: pass revision insteads of changectx to the update function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18234
diff
changeset
|
96 partial.update(repo, revs) |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
97 partial.write(repo) |
18451
d6b3b36f1db2
branchmap: display filtername when `updatebranch` fails to do its jobs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18357
diff
changeset
|
98 assert partial.validfor(repo), filtername |
18189
b9026ba002f6
branchmap: enable caching for filtered version too
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18188
diff
changeset
|
99 repo._branchcaches[repo.filtername] = partial |
18124
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
100 |
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
101 class branchcache(dict): |
20181
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
102 """A dict like object that hold branches heads cache. |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
103 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
104 This cache is used to avoid costly computations to determine all the |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
105 branch heads of a repo. |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
106 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
107 The cache is serialized on disk in the following format: |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
108 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
109 <tip hex node> <tip rev number> [optional filtered repo hex hash] |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
110 <branch head hex node> <open/closed state> <branch name> |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
111 <branch head hex node> <open/closed state> <branch name> |
20181
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
112 ... |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
113 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
114 The first line is used to check if the cache is still valid. If the |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
115 branch cache is for a filtered repo view, an optional third hash is |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
116 included that hashes the hashes of all filtered revisions. |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
117 |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
118 The open/closed state is represented by a single letter 'o' or 'c'. |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
119 This field can be used to avoid changelog reads when determining if a |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
120 branch head closes a branch or not. |
20181
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
121 """ |
18124
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
122 |
18168
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
123 def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev, |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
124 filteredhash=None, closednodes=None): |
18125
ad194a8ab5c1
branchmap: add the tipnode (cache key) on the branchcache object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18124
diff
changeset
|
125 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
|
126 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
|
127 self.tiprev = tiprev |
18168
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
128 self.filteredhash = filteredhash |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
129 # closednodes is a set of nodes that close their branch. If the branch |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
130 # cache has been updated, it may contain nodes that are no longer |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
131 # heads. |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
132 if closednodes is None: |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
133 self._closednodes = set() |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
134 else: |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
135 self._closednodes = closednodes |
18168
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
136 |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
137 def _hashfiltered(self, repo): |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
138 """build hash of revision filtered in the current cache |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
139 |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18451
diff
changeset
|
140 Tracking tipnode and tiprev is not enough to ensure validity of the |
18168
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
141 cache as they do not help to distinct cache that ignored various |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
142 revision bellow tiprev. |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
143 |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
144 To detect such difference, we build a cache of all ignored revisions. |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
145 """ |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
146 cl = repo.changelog |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
147 if not cl.filteredrevs: |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
148 return None |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
149 key = None |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
150 revs = sorted(r for r in cl.filteredrevs if r <= self.tiprev) |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
151 if revs: |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
152 s = util.sha1() |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
153 for rev in revs: |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
154 s.update('%s;' % rev) |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
155 key = s.digest() |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
156 return key |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
157 |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
158 def validfor(self, repo): |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18451
diff
changeset
|
159 """Is the cache content valid regarding a repo |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
160 |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18451
diff
changeset
|
161 - False when cached tipnode is unknown or if we detect a strip. |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
162 - True when cache is up to date or a subset of current repo.""" |
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
163 try: |
18168
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
164 return ((self.tipnode == repo.changelog.node(self.tiprev)) |
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
165 and (self.filteredhash == self._hashfiltered(repo))) |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
166 except IndexError: |
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
167 return False |
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
168 |
20186
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
169 def _branchtip(self, heads): |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
170 tip = heads[-1] |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
171 closed = True |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
172 for h in reversed(heads): |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
173 if h not in self._closednodes: |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
174 tip = h |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
175 closed = False |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
176 break |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
177 return tip, closed |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
178 |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
179 def branchtip(self, branch): |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
180 return self._branchtip(self[branch])[0] |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
181 |
20188
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
182 def branchheads(self, branch, closed=False): |
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
183 heads = self[branch] |
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
184 if not closed: |
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
185 heads = [h for h in heads if h not in self._closednodes] |
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
186 return heads |
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
187 |
20190
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
188 def iterbranches(self): |
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
189 for bn, heads in self.iteritems(): |
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
190 yield (bn, heads) + self._branchtip(heads) |
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
191 |
18232
dd0b636b0b65
branchmap: add a copy method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18218
diff
changeset
|
192 def copy(self): |
dd0b636b0b65
branchmap: add a copy method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18218
diff
changeset
|
193 """return an deep copy of the branchcache object""" |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
194 return branchcache(self, self.tipnode, self.tiprev, self.filteredhash, |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
195 self._closednodes) |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
196 |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
197 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
|
198 try: |
18185
5a047276764e
branchmap: move the cache file name into a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18184
diff
changeset
|
199 f = repo.opener(_filename(repo), "w", atomictemp=True) |
18184
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
200 cachekey = [hex(self.tipnode), str(self.tiprev)] |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
201 if self.filteredhash is not None: |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
202 cachekey.append(hex(self.filteredhash)) |
8d48af68e2ae
branchmap: read and write key part related to filtered revision
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18168
diff
changeset
|
203 f.write(" ".join(cachekey) + '\n') |
18357
a4ab37ca887b
localrepo: store branchheads sorted
Mads Kiilerich <mads@kiilerich.com>
parents:
18307
diff
changeset
|
204 for label, nodes in sorted(self.iteritems()): |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
205 for node in nodes: |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
206 if node in self._closednodes: |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
207 state = 'c' |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
208 else: |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
209 state = 'o' |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
210 f.write("%s %s %s\n" % (hex(node), state, |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
211 encoding.fromlocal(label))) |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
212 f.close() |
18214
cd4c75200206
branchmap: ignore Abort error while writing cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18212
diff
changeset
|
213 except (IOError, OSError, util.Abort): |
cd4c75200206
branchmap: ignore Abort error while writing cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18212
diff
changeset
|
214 # Abort may be raise by read only opener |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
215 pass |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
216 |
18305
2502a15e033d
branchmap: pass revision insteads of changectx to the update function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18234
diff
changeset
|
217 def update(self, repo, revgen): |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
218 """Given a branchhead cache, self, that may have extra nodes or be |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
219 missing heads, and a generator of nodes that are at least a superset of |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
220 heads missing, this function updates self to be correct. |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
221 """ |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
222 cl = repo.changelog |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
223 # collect new branch entries |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
224 newbranches = {} |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
225 getbranchinfo = cl.branchinfo |
18307
0eed2546118a
branchmap: Save changectx creation during update
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18305
diff
changeset
|
226 for r in revgen: |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
227 branch, closesbranch = getbranchinfo(r) |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
228 node = cl.node(r) |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
229 newbranches.setdefault(branch, []).append(node) |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
230 if closesbranch: |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
231 self._closednodes.add(node) |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
232 # if older branchheads are reachable from new ones, they aren't |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
233 # really branchheads. Note checking parents is insufficient: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
234 # 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
235 for branch, newnodes in newbranches.iteritems(): |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
236 bheads = self.setdefault(branch, []) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
237 # Remove candidate heads that no longer are in the repo (e.g., as |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
238 # the result of a strip that just happened). Avoid using 'node in |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
239 # self' here because that dives down into branchcache code somewhat |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
240 # recursively. |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
241 bheadrevs = [cl.rev(node) for node in bheads |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
242 if cl.hasnode(node)] |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
243 newheadrevs = [cl.rev(node) for node in newnodes |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
244 if cl.hasnode(node)] |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
245 ctxisnew = bheadrevs and min(newheadrevs) > max(bheadrevs) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
246 # Remove duplicates - nodes that are in newheadrevs and are already |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
247 # in bheadrevs. This can happen if you strip a node whose parent |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
248 # was already a head (because they're on different branches). |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
249 bheadrevs = sorted(set(bheadrevs).union(newheadrevs)) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
250 |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
251 # Starting from tip means fewer passes over reachable. If we know |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
252 # the new candidates are not ancestors of existing heads, we don't |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
253 # have to examine ancestors of existing heads |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
254 if ctxisnew: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
255 iterrevs = sorted(newheadrevs) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
256 else: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
257 iterrevs = list(bheadrevs) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
258 |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
259 # This loop prunes out two kinds of heads - heads that are |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
260 # superseded by a head in newheadrevs, and newheadrevs that are not |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
261 # heads because an existing head is their descendant. |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
262 while iterrevs: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
263 latest = iterrevs.pop() |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
264 if latest not in bheadrevs: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
265 continue |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
266 ancestors = set(cl.ancestors([latest], |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
267 bheadrevs[0])) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
268 if ancestors: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
269 bheadrevs = [b for b in bheadrevs if b not in ancestors] |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
270 self[branch] = [cl.node(rev) for rev in bheadrevs] |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
271 tiprev = max(bheadrevs) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
272 if tiprev > self.tiprev: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
273 self.tipnode = cl.node(tiprev) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
274 self.tiprev = tiprev |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
275 |
19838
23386881abeb
branchmap: remove the droppednodes logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19837
diff
changeset
|
276 if not self.validfor(repo): |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
277 # cache key are not valid anymore |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
278 self.tipnode = nullid |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
279 self.tiprev = nullrev |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
280 for heads in self.values(): |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
281 tiprev = max(cl.rev(node) for node in heads) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
282 if tiprev > self.tiprev: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
283 self.tipnode = cl.node(tiprev) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
284 self.tiprev = tiprev |
18168
c351759ab0a0
branchmap: takes filtered revision in account for cache calculation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18167
diff
changeset
|
285 self.filteredhash = self._hashfiltered(repo) |