Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/branchmap.py @ 51302:9d3721552b6c
pytype: import typing directly
First we no longer needs the pycompat layer, second having the types imported in
all case will allow to use them more directly in type annotation, something
important to upgrade the old "type comment" to proper type annotation.
A lot a stupid assert are needed to keep pyflakes happy. We should be able to
remove most of them once the type comment have been upgraded.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 20 Dec 2023 12:51:20 +0100 |
parents | 227124098e14 |
children | f15cb5111a1e |
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 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46796
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
18116
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 |
25918
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
8 |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
9 import struct |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
10 |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
11 from .node import ( |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
12 bin, |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
13 hex, |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
14 nullrev, |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
15 ) |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
16 |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
17 from typing import ( |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
18 Any, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
19 Callable, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
20 Dict, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
21 Iterable, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
22 List, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
23 Optional, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
24 Set, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
25 TYPE_CHECKING, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
26 Tuple, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
27 Union, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
28 ) |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
29 |
25918
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
30 from . import ( |
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
31 encoding, |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26460
diff
changeset
|
32 error, |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
33 obsolete, |
25918
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
34 scmutil, |
30995
22fbca1d11ed
mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents:
29758
diff
changeset
|
35 util, |
25918
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
36 ) |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
37 |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36968
diff
changeset
|
38 from .utils import ( |
42138
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42134
diff
changeset
|
39 repoviewutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36968
diff
changeset
|
40 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36968
diff
changeset
|
41 ) |
25918
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
42 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
43 # keeps pyflakes happy |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
44 assert [ |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
45 Any, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
46 Callable, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
47 Dict, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
48 Iterable, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
49 List, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
50 Optional, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
51 Set, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
52 Tuple, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
53 Union, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
54 ] |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
55 |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
56 if TYPE_CHECKING: |
46796 | 57 from . import localrepo |
43680
9c1eccdd7ed8
branchmap: annotate constructor type for branchcache
Augie Fackler <augie@google.com>
parents:
43678
diff
changeset
|
58 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49308
diff
changeset
|
59 assert [localrepo] |
43680
9c1eccdd7ed8
branchmap: annotate constructor type for branchcache
Augie Fackler <augie@google.com>
parents:
43678
diff
changeset
|
60 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
61 subsettable = repoviewutil.subsettable |
42138
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42134
diff
changeset
|
62 |
25918
47f36e050c2e
branchmap: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
63 calcsize = struct.calcsize |
31379
906be86990c4
rbc: use struct unpack_from and pack_into instead of unpack and pack
Mads Kiilerich <madski@unity3d.com>
parents:
31369
diff
changeset
|
64 pack_into = struct.pack_into |
906be86990c4
rbc: use struct unpack_from and pack_into instead of unpack and pack
Mads Kiilerich <madski@unity3d.com>
parents:
31369
diff
changeset
|
65 unpack_from = struct.unpack_from |
18117
526e7ec5c96e
branchmap: extract write logic from localrepo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18116
diff
changeset
|
66 |
18118
e70ff1e599f4
branchmap: extract read logic from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18117
diff
changeset
|
67 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49026
diff
changeset
|
68 class BranchMapCache: |
41729
a87ca1d7e61d
branchmap: improve doc about BranchMapCache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41689
diff
changeset
|
69 """mapping of filtered views of repo with their branchcache""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
70 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
71 def __init__(self): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
72 self._per_filter = {} |
41581
c795c462b1d6
branchmap: add some clarifications and clean up flow
Martijn Pieters <mj@octobus.net>
parents:
41580
diff
changeset
|
73 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
74 def __getitem__(self, repo): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
75 self.updatecache(repo) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
76 return self._per_filter[repo.filtername] |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
77 |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
78 def updatecache(self, repo): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
79 """Update the cache for the given filtered view on a repository""" |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
80 # This can trigger updates for the caches for subsets of the filtered |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
81 # view, e.g. when there is no cache for this filtered view or the cache |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
82 # is stale. |
18121
f8a13f061a8a
branchmap: extract updatebranchcache from repo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18120
diff
changeset
|
83 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
84 cl = repo.changelog |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
85 filtername = repo.filtername |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
86 bcache = self._per_filter.get(filtername) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
87 if bcache is None or not bcache.validfor(repo): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
88 # cache object missing or cache object stale? Read from disk |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
89 bcache = branchcache.fromfile(repo) |
41581
c795c462b1d6
branchmap: add some clarifications and clean up flow
Martijn Pieters <mj@octobus.net>
parents:
41580
diff
changeset
|
90 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
91 revs = [] |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
92 if bcache is None: |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
93 # no (fresh) cache available anymore, perhaps we can re-use |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
94 # the cache for a subset, then extend that to add info on missing |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
95 # revisions. |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
96 subsetname = subsettable.get(filtername) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
97 if subsetname is not None: |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
98 subset = repo.filtered(subsetname) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
99 bcache = self[subset].copy() |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
100 extrarevs = subset.changelog.filteredrevs - cl.filteredrevs |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
101 revs.extend(r for r in extrarevs if r <= bcache.tiprev) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
102 else: |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
103 # nothing to fall back on, start empty. |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46444
diff
changeset
|
104 bcache = branchcache(repo) |
24373
59cc09240afb
revbranchcache: move out of branchmap onto localrepo
Durham Goode <durham@fb.com>
parents:
24163
diff
changeset
|
105 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
106 revs.extend(cl.revs(start=bcache.tiprev + 1)) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
107 if revs: |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
108 bcache.update(repo, revs) |
18124
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
109 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
110 assert bcache.validfor(repo), filtername |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
111 self._per_filter[repo.filtername] = bcache |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
112 |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
113 def replace(self, repo, remotebranchmap): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
114 """Replace the branchmap cache for a repo with a branch mapping. |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
115 |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
116 This is likely only called during clone with a branch map from a |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
117 remote. |
26460
79ef867538ea
branchmap: move branch cache code out of streamclone.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25918
diff
changeset
|
118 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
119 """ |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
120 cl = repo.changelog |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
121 clrev = cl.rev |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
122 clbranchinfo = cl.branchinfo |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
123 rbheads = [] |
43728
5cdc3c1292f6
branchmap: make "closed" a set from beginning instead of converting from list
Martin von Zweigbergk <martinvonz@google.com>
parents:
43680
diff
changeset
|
124 closed = set() |
49026
2cce2fa5bcf7
py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
125 for bheads in remotebranchmap.values(): |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
126 rbheads += bheads |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
127 for h in bheads: |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
128 r = clrev(h) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
129 b, c = clbranchinfo(r) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
130 if c: |
43728
5cdc3c1292f6
branchmap: make "closed" a set from beginning instead of converting from list
Martin von Zweigbergk <martinvonz@google.com>
parents:
43680
diff
changeset
|
131 closed.add(h) |
26460
79ef867538ea
branchmap: move branch cache code out of streamclone.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25918
diff
changeset
|
132 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
133 if rbheads: |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
134 rtiprev = max((int(clrev(node)) for node in rbheads)) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
135 cache = branchcache( |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46444
diff
changeset
|
136 repo, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
137 remotebranchmap, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
138 repo[rtiprev].node(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
139 rtiprev, |
43728
5cdc3c1292f6
branchmap: make "closed" a set from beginning instead of converting from list
Martin von Zweigbergk <martinvonz@google.com>
parents:
43680
diff
changeset
|
140 closednodes=closed, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
141 ) |
26460
79ef867538ea
branchmap: move branch cache code out of streamclone.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25918
diff
changeset
|
142 |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
143 # Try to stick it as low as possible |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
144 # filter above served are unlikely to be fetch from a clone |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
145 for candidate in (b'base', b'immutable', b'served'): |
41626
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
146 rview = repo.filtered(candidate) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
147 if cache.validfor(rview): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
148 self._per_filter[candidate] = cache |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
149 cache.write(rview) |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
150 return |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
151 |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
152 def clear(self): |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
153 self._per_filter.clear() |
328ca3b9e545
branchmap: encapsulate cache updating in the map itself
Martijn Pieters <mj@octobus.net>
parents:
41581
diff
changeset
|
154 |
48363
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
155 def write_delayed(self, repo): |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
156 unfi = repo.unfiltered() |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
157 for filtername, cache in self._per_filter.items(): |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
158 if cache._delayed: |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
159 repo = unfi.filtered(filtername) |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
160 cache.write(repo) |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
161 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
162 |
42120
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
163 def _unknownnode(node): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
164 """raises ValueError when branchcache found a node which does not exists""" |
49308
227124098e14
py3: use `x.hex()` instead of `pycompat.sysstr(node.hex(x))`
Manuel Jacob <me@manueljacob.de>
parents:
49233
diff
changeset
|
165 raise ValueError('node %s does not exist' % node.hex()) |
26460
79ef867538ea
branchmap: move branch cache code out of streamclone.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25918
diff
changeset
|
166 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
167 |
42602
c7d236b55a3e
py3: fix formatting of branchmap log messages with repo.filtername=None
Martin von Zweigbergk <martinvonz@google.com>
parents:
42247
diff
changeset
|
168 def _branchcachedesc(repo): |
c7d236b55a3e
py3: fix formatting of branchmap log messages with repo.filtername=None
Martin von Zweigbergk <martinvonz@google.com>
parents:
42247
diff
changeset
|
169 if repo.filtername is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
170 return b'branch cache (%s)' % repo.filtername |
42602
c7d236b55a3e
py3: fix formatting of branchmap log messages with repo.filtername=None
Martin von Zweigbergk <martinvonz@google.com>
parents:
42247
diff
changeset
|
171 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
172 return b'branch cache' |
42602
c7d236b55a3e
py3: fix formatting of branchmap log messages with repo.filtername=None
Martin von Zweigbergk <martinvonz@google.com>
parents:
42247
diff
changeset
|
173 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
174 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49026
diff
changeset
|
175 class branchcache: |
20181
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
176 """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
|
177 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
178 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
|
179 branch heads of a repo. |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
180 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
181 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
|
182 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
183 <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
|
184 <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
|
185 <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
|
186 ... |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
187 |
b9515fb9e72a
branchmap: add documentation on the branchcache on-disk format
Brodie Rao <brodie@sf.io>
parents:
20032
diff
changeset
|
188 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
|
189 branch cache is for a filtered repo view, an optional third hash is |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
190 included that hashes the hashes of all filtered and obsolete revisions. |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
191 |
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 """ |
41688
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
196 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
197 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
198 self, |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46444
diff
changeset
|
199 repo, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
200 entries=(), |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
201 tipnode=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
202 tiprev=nullrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
203 filteredhash=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
204 closednodes=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
205 hasnode=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
206 ): |
46796 | 207 # type: (localrepo.localrepository, Union[Dict[bytes, List[bytes]], Iterable[Tuple[bytes, List[bytes]]]], bytes, int, Optional[bytes], Optional[Set[bytes]], Optional[Callable[[bytes], bool]]) -> None |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
208 """hasnode is a function which can be used to verify whether changelog |
42007
b5511845f9d5
branchcache: have a hasnode function to validate nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42006
diff
changeset
|
209 has a given node or not. If it's not provided, we assume that every node |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
210 we have exists in changelog""" |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46444
diff
changeset
|
211 self._repo = repo |
48363
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
212 self._delayed = False |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
213 if tipnode is None: |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
214 self.tipnode = repo.nullid |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
215 else: |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
216 self.tipnode = tipnode |
41688
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
217 self.tiprev = tiprev |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
218 self.filteredhash = filteredhash |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
219 # closednodes is a set of nodes that close their branch. If the branch |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
220 # cache has been updated, it may contain nodes that are no longer |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
221 # heads. |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
222 if closednodes is None: |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
223 self._closednodes = set() |
bfc49f1df615
branchmap: move __init__ up in branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41626
diff
changeset
|
224 else: |
43680
9c1eccdd7ed8
branchmap: annotate constructor type for branchcache
Augie Fackler <augie@google.com>
parents:
43678
diff
changeset
|
225 self._closednodes = closednodes |
42005
b137a6793c51
branchcache: make entries a private attribute
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42004
diff
changeset
|
226 self._entries = dict(entries) |
42006
111de135fc76
branchcache: add attributes to track which nodes are verified
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42005
diff
changeset
|
227 # whether closed nodes are verified or not |
111de135fc76
branchcache: add attributes to track which nodes are verified
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42005
diff
changeset
|
228 self._closedverified = False |
111de135fc76
branchcache: add attributes to track which nodes are verified
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42005
diff
changeset
|
229 # branches for which nodes are verified |
111de135fc76
branchcache: add attributes to track which nodes are verified
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42005
diff
changeset
|
230 self._verifiedbranches = set() |
42007
b5511845f9d5
branchcache: have a hasnode function to validate nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42006
diff
changeset
|
231 self._hasnode = hasnode |
b5511845f9d5
branchcache: have a hasnode function to validate nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42006
diff
changeset
|
232 if self._hasnode is None: |
b5511845f9d5
branchcache: have a hasnode function to validate nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42006
diff
changeset
|
233 self._hasnode = lambda x: True |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
234 |
42120
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
235 def _verifyclosed(self): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
236 """verify the closed nodes we have""" |
42120
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
237 if self._closedverified: |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
238 return |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
239 for node in self._closednodes: |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
240 if not self._hasnode(node): |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
241 _unknownnode(node) |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
242 |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
243 self._closedverified = True |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
244 |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
245 def _verifybranch(self, branch): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
246 """verify head nodes for the given branch.""" |
42120
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
247 if branch not in self._entries or branch in self._verifiedbranches: |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
248 return |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
249 for n in self._entries[branch]: |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
250 if not self._hasnode(n): |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
251 _unknownnode(n) |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
252 |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
253 self._verifiedbranches.add(branch) |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
254 |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
255 def _verifyall(self): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
256 """verifies nodes of all the branches""" |
42133
75e8e16ca107
branchcache: only iterate over branches which needs to be verified
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42132
diff
changeset
|
257 needverification = set(self._entries.keys()) - self._verifiedbranches |
75e8e16ca107
branchcache: only iterate over branches which needs to be verified
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42132
diff
changeset
|
258 for b in needverification: |
42120
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
259 self._verifybranch(b) |
2f8147521e59
branchcache: add functions to validate changelog nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42113
diff
changeset
|
260 |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
261 def __iter__(self): |
42005
b137a6793c51
branchcache: make entries a private attribute
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42004
diff
changeset
|
262 return iter(self._entries) |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
263 |
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
264 def __setitem__(self, key, value): |
42005
b137a6793c51
branchcache: make entries a private attribute
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42004
diff
changeset
|
265 self._entries[key] = value |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
266 |
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
267 def __getitem__(self, key): |
42121
6578654916ae
branchcache: lazily validate nodes from the branchmap
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42120
diff
changeset
|
268 self._verifybranch(key) |
42005
b137a6793c51
branchcache: make entries a private attribute
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42004
diff
changeset
|
269 return self._entries[key] |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
270 |
42113
f0def07fa82f
branchmap: implement __contains__()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42112
diff
changeset
|
271 def __contains__(self, key): |
42121
6578654916ae
branchcache: lazily validate nodes from the branchmap
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42120
diff
changeset
|
272 self._verifybranch(key) |
42113
f0def07fa82f
branchmap: implement __contains__()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42112
diff
changeset
|
273 return key in self._entries |
f0def07fa82f
branchmap: implement __contains__()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42112
diff
changeset
|
274 |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
275 def iteritems(self): |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
276 for k, v in self._entries.items(): |
42134
f0203c3406e7
branchcache: lazily validate nodes in iteritems()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42133
diff
changeset
|
277 self._verifybranch(k) |
f0203c3406e7
branchcache: lazily validate nodes in iteritems()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42133
diff
changeset
|
278 yield k, v |
42001
624d6683c705
branchmap: remove the dict interface from the branchcache class (API)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41844
diff
changeset
|
279 |
42603
3018749a71bb
py3: source-transform only call-sites of iteritems(), not definitions
Martin von Zweigbergk <martinvonz@google.com>
parents:
42602
diff
changeset
|
280 items = iteritems |
3018749a71bb
py3: source-transform only call-sites of iteritems(), not definitions
Martin von Zweigbergk <martinvonz@google.com>
parents:
42602
diff
changeset
|
281 |
42004
0bd730fbcc2b
branchcache: introduce hasbranch()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42003
diff
changeset
|
282 def hasbranch(self, label): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
283 """checks whether a branch of this name exists or not""" |
42121
6578654916ae
branchcache: lazily validate nodes from the branchmap
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42120
diff
changeset
|
284 self._verifybranch(label) |
42005
b137a6793c51
branchcache: make entries a private attribute
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42004
diff
changeset
|
285 return label in self._entries |
42004
0bd730fbcc2b
branchcache: introduce hasbranch()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42003
diff
changeset
|
286 |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
287 @classmethod |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
288 def fromfile(cls, repo): |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
289 f = None |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
290 try: |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
291 f = repo.cachevfs(cls._filename(repo)) |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
292 lineiter = iter(f) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
293 cachekey = next(lineiter).rstrip(b'\n').split(b" ", 2) |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
294 last, lrev = cachekey[:2] |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
295 last, lrev = bin(last), int(lrev) |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
296 filteredhash = None |
42007
b5511845f9d5
branchcache: have a hasnode function to validate nodes
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42006
diff
changeset
|
297 hasnode = repo.changelog.hasnode |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
298 if len(cachekey) > 2: |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
299 filteredhash = bin(cachekey[2]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
300 bcache = cls( |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46444
diff
changeset
|
301 repo, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
302 tipnode=last, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
303 tiprev=lrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
304 filteredhash=filteredhash, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
305 hasnode=hasnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
306 ) |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
307 if not bcache.validfor(repo): |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
308 # invalidate the cache |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43547
diff
changeset
|
309 raise ValueError('tip differs') |
41813
8ad46ac6728e
branchmap: prevent reading the file twice through different iterators
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41802
diff
changeset
|
310 bcache.load(repo, lineiter) |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
311 except (IOError, OSError): |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
312 return None |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
313 |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
314 except Exception as inst: |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
315 if repo.ui.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
316 msg = b'invalid %s: %s\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
317 repo.ui.debug( |
43547
1a47fe4bc154
branchmap: pytype is confused about bytestr
Augie Fackler <augie@google.com>
parents:
43106
diff
changeset
|
318 msg |
1a47fe4bc154
branchmap: pytype is confused about bytestr
Augie Fackler <augie@google.com>
parents:
43106
diff
changeset
|
319 % ( |
1a47fe4bc154
branchmap: pytype is confused about bytestr
Augie Fackler <augie@google.com>
parents:
43106
diff
changeset
|
320 _branchcachedesc(repo), |
46392
799973a44c82
branchmap: force Exception to bytes before logging
Matt Harbison <matt_harbison@yahoo.com>
parents:
46254
diff
changeset
|
321 stringutil.forcebytestr(inst), |
43547
1a47fe4bc154
branchmap: pytype is confused about bytestr
Augie Fackler <augie@google.com>
parents:
43106
diff
changeset
|
322 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
323 ) |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
324 bcache = None |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
325 |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
326 finally: |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
327 if f: |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
328 f.close() |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
329 |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
330 return bcache |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
331 |
41813
8ad46ac6728e
branchmap: prevent reading the file twice through different iterators
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41802
diff
changeset
|
332 def load(self, repo, lineiter): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
333 """fully loads the branchcache by reading from the file using the line |
41813
8ad46ac6728e
branchmap: prevent reading the file twice through different iterators
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41802
diff
changeset
|
334 iterator passed""" |
41802
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
335 for line in lineiter: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
336 line = line.rstrip(b'\n') |
41802
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
337 if not line: |
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
338 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
339 node, state, label = line.split(b" ", 2) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
340 if state not in b'oc': |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43547
diff
changeset
|
341 raise ValueError('invalid branch state') |
41802
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
342 label = encoding.tolocal(label.strip()) |
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
343 node = bin(node) |
42005
b137a6793c51
branchcache: make entries a private attribute
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42004
diff
changeset
|
344 self._entries.setdefault(label, []).append(node) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
345 if state == b'c': |
41802
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
346 self._closednodes.add(node) |
68bbcc70e274
branchcache: move loading of branch names and nodes into it's own function
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41768
diff
changeset
|
347 |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
348 @staticmethod |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
349 def _filename(repo): |
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
350 """name of a branchcache file for a given repo or repoview""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
351 filename = b"branch2" |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
352 if repo.filtername: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
353 filename = b'%s-%s' % (filename, repo.filtername) |
41579
bf7fb97aecf1
branchmap: make branchcache responsible for reading
Martijn Pieters <mj@octobus.net>
parents:
41418
diff
changeset
|
354 return filename |
18124
79db6d40bced
branchmap: store branchcache in a dedicated object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18121
diff
changeset
|
355 |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
356 def validfor(self, repo): |
48733
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
357 """check that cache contents are valid for (a subset of) this repo |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
358 |
48733
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
359 - False when the order of changesets changed or if we detect a strip. |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
360 - True when cache is up-to-date for the current repo or its subset.""" |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
361 try: |
48733
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
362 node = repo.changelog.node(self.tiprev) |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
363 except IndexError: |
48733
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
364 # changesets were stripped and now we don't even have enough to |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
365 # find tiprev |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
366 return False |
48733
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
367 if self.tipnode != node: |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
368 # tiprev doesn't correspond to tipnode: repo was stripped, or this |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
369 # repo has a different order of changesets |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
370 return False |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
371 tiphash = scmutil.filteredhash(repo, self.tiprev, needobsolete=True) |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
372 # hashes don't match if this repo view has a different set of filtered |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
373 # revisions (e.g. due to phase changes) or obsolete revisions (e.g. |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
374 # history was rewritten) |
02e9ad08999b
branchmap: split a long condition in branchcache.validfor(), add comments
Anton Shestakov <av6@dwimlabs.net>
parents:
48732
diff
changeset
|
375 return self.filteredhash == tiphash |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
376 |
20186
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
377 def _branchtip(self, heads): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
378 """Return tuple with last open head in heads and false, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
379 otherwise return last closed head and true.""" |
20186
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
380 tip = heads[-1] |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
381 closed = True |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
382 for h in reversed(heads): |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
383 if h not in self._closednodes: |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
384 tip = h |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
385 closed = False |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
386 break |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
387 return tip, closed |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
388 |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
389 def branchtip(self, branch): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
390 """Return the tipmost open head on branch head, otherwise return the |
20245
4edd179fefb8
help: branch names primarily denote the tipmost unclosed branch head
Mads Kiilerich <madski@unity3d.com>
parents:
20190
diff
changeset
|
391 tipmost closed head on branch. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44470
diff
changeset
|
392 Raise KeyError for unknown branch.""" |
20186
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
393 return self._branchtip(self[branch])[0] |
f5b461a4bc55
branchmap: introduce branchtip() method
Brodie Rao <brodie@sf.io>
parents:
20185
diff
changeset
|
394 |
34091
abf91c4f9608
branches: correctly show inactive multiheaded branches
the31k <the31k@thethirty.one>
parents:
33661
diff
changeset
|
395 def iteropen(self, nodes): |
abf91c4f9608
branches: correctly show inactive multiheaded branches
the31k <the31k@thethirty.one>
parents:
33661
diff
changeset
|
396 return (n for n in nodes if n not in self._closednodes) |
abf91c4f9608
branches: correctly show inactive multiheaded branches
the31k <the31k@thethirty.one>
parents:
33661
diff
changeset
|
397 |
20188
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
398 def branchheads(self, branch, closed=False): |
42121
6578654916ae
branchcache: lazily validate nodes from the branchmap
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42120
diff
changeset
|
399 self._verifybranch(branch) |
42112
29c22496dd97
branchmap: prevent using __getitem__() in branchheads()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42111
diff
changeset
|
400 heads = self._entries[branch] |
20188
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
401 if not closed: |
34091
abf91c4f9608
branches: correctly show inactive multiheaded branches
the31k <the31k@thethirty.one>
parents:
33661
diff
changeset
|
402 heads = list(self.iteropen(heads)) |
20188
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
403 return heads |
3a3727829607
branchmap: introduce branchheads() method
Brodie Rao <brodie@sf.io>
parents:
20186
diff
changeset
|
404 |
20190
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
405 def iterbranches(self): |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
406 for bn, heads in self.items(): |
20190
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
407 yield (bn, heads) + self._branchtip(heads) |
d5d25e541637
branchmap: introduce iterbranches() method
Brodie Rao <brodie@sf.io>
parents:
20188
diff
changeset
|
408 |
42002
662ffdde5adf
branchcache: rename itervalues() to iterheads()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42001
diff
changeset
|
409 def iterheads(self): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
410 """returns all the heads""" |
42121
6578654916ae
branchcache: lazily validate nodes from the branchmap
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42120
diff
changeset
|
411 self._verifyall() |
49026
2cce2fa5bcf7
py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
412 return self._entries.values() |
42002
662ffdde5adf
branchcache: rename itervalues() to iterheads()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42001
diff
changeset
|
413 |
18232
dd0b636b0b65
branchmap: add a copy method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18218
diff
changeset
|
414 def copy(self): |
dd0b636b0b65
branchmap: add a copy method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18218
diff
changeset
|
415 """return an deep copy of the branchcache object""" |
42111
f0fa0fc4900a
branchmap: dynamically resolve type of branchcache class
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42007
diff
changeset
|
416 return type(self)( |
46793
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46444
diff
changeset
|
417 self._repo, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
418 self._entries, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
419 self.tipnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
420 self.tiprev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
421 self.filteredhash, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
422 self._closednodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
423 ) |
18132
db25bf1dc828
branchmap: move validity logic in the object itself
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18131
diff
changeset
|
424 |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
425 def write(self, repo): |
48363
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
426 tr = repo.currenttransaction() |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
427 if not getattr(tr, 'finalized', True): |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
428 # Avoid premature writing. |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
429 # |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
430 # (The cache warming setup by localrepo will update the file later.) |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
431 self._delayed = True |
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
432 return |
18128
f0d56efaa35a
branchmap: make write a method on the branchmap object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18127
diff
changeset
|
433 try: |
49233
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
434 filename = self._filename(repo) |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
435 with repo.cachevfs(filename, b"w", atomictemp=True) as f: |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
436 cachekey = [hex(self.tipnode), b'%d' % self.tiprev] |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
437 if self.filteredhash is not None: |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
438 cachekey.append(hex(self.filteredhash)) |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
439 f.write(b" ".join(cachekey) + b'\n') |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
440 nodecount = 0 |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
441 for label, nodes in sorted(self._entries.items()): |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
442 label = encoding.fromlocal(label) |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
443 for node in nodes: |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
444 nodecount += 1 |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
445 if node in self._closednodes: |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
446 state = b'c' |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
447 else: |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
448 state = b'o' |
f923bdd7477d
branchmap: use a context manager when writing the branchmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49037
diff
changeset
|
449 f.write(b"%s %s %s\n" % (hex(node), state, label)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
450 repo.ui.log( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
451 b'branchcache', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
452 b'wrote %s with %d labels and %d nodes\n', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
453 _branchcachedesc(repo), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
454 len(self._entries), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
455 nodecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
456 ) |
48363
8e5effbf52d0
branchmap: stop writing cache for uncommitted data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47142
diff
changeset
|
457 self._delayed = False |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26460
diff
changeset
|
458 except (IOError, OSError, error.Abort) as inst: |
34371
d0db41af73c0
branchmap: remove superfluous pass statements
Augie Fackler <augie@google.com>
parents:
34091
diff
changeset
|
459 # Abort may be raised by read only opener, so log and continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
460 repo.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
461 b"couldn't write branch cache: %s\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
462 % stringutil.forcebytestr(inst) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
463 ) |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
464 |
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
|
465 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
|
466 """Given a branchhead cache, self, that may have extra nodes or be |
20263
ea4996754d91
branchmap: simplify update code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20262
diff
changeset
|
467 missing heads, and a generator of nodes that are strictly a superset of |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
468 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
|
469 """ |
30995
22fbca1d11ed
mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents:
29758
diff
changeset
|
470 starttime = util.timer() |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
471 cl = repo.changelog |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
472 # collect new branch entries |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
473 newbranches = {} |
24373
59cc09240afb
revbranchcache: move out of branchmap onto localrepo
Durham Goode <durham@fb.com>
parents:
24163
diff
changeset
|
474 getbranchinfo = repo.revbranchcache().branchinfo |
18307
0eed2546118a
branchmap: Save changectx creation during update
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18305
diff
changeset
|
475 for r in revgen: |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
476 branch, closesbranch = getbranchinfo(r) |
20262
cf450ee3f8f7
branchmap: stop useless rev -> node -> rev round trip
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20261
diff
changeset
|
477 newbranches.setdefault(branch, []).append(r) |
20185
7d4219512823
branchmap: cache open/closed branch head information
Brodie Rao <brodie@sf.io>
parents:
20181
diff
changeset
|
478 if closesbranch: |
20262
cf450ee3f8f7
branchmap: stop useless rev -> node -> rev round trip
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20261
diff
changeset
|
479 self._closednodes.add(cl.node(r)) |
22357
9c3c3dc14a65
branchmap: pre-filter topological heads before ancestors based filtering
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22356
diff
changeset
|
480 |
42247
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
481 # new tip revision which we found after iterating items from new |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
482 # branches |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
483 ntiprev = self.tiprev |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
484 |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
485 # Delay fetching the topological heads until they are needed. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
486 # A repository without non-continous branches can skip this part. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
487 topoheads = None |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
488 |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
489 # If a changeset is visible, its parents must be visible too, so |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
490 # use the faster unfiltered parent accessor. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
491 parentrevs = repo.unfiltered().changelog.parentrevs |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
492 |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
493 # Faster than using ctx.obsolete() |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
494 obsrevs = obsolete.getrevs(repo, b'obsolete') |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
495 |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
496 for branch, newheadrevs in newbranches.items(): |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
497 # For every branch, compute the new branchheads. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
498 # A branchhead is a revision such that no descendant is on |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
499 # the same branch. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
500 # |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
501 # The branchheads are computed iteratively in revision order. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
502 # This ensures topological order, i.e. parents are processed |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
503 # before their children. Ancestors are inclusive here, i.e. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
504 # any revision is an ancestor of itself. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
505 # |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
506 # Core observations: |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
507 # - The current revision is always a branchhead for the |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
508 # repository up to that point. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
509 # - It is the first revision of the branch if and only if |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
510 # there was no branchhead before. In that case, it is the |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
511 # only branchhead as there are no possible ancestors on |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
512 # the same branch. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
513 # - If a parent is on the same branch, a branchhead can |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
514 # only be an ancestor of that parent, if it is parent |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
515 # itself. Otherwise it would have been removed as ancestor |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
516 # of that parent before. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
517 # - Therefore, if all parents are on the same branch, they |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
518 # can just be removed from the branchhead set. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
519 # - If one parent is on the same branch and the other is not |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
520 # and there was exactly one branchhead known, the existing |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
521 # branchhead can only be an ancestor if it is the parent. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
522 # Otherwise it would have been removed as ancestor of |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
523 # the parent before. The other parent therefore can't have |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
524 # a branchhead as ancestor. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
525 # - In all other cases, the parents on different branches |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
526 # could have a branchhead as ancestor. Those parents are |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
527 # kept in the "uncertain" set. If all branchheads are also |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
528 # topological heads, they can't have descendants and further |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
529 # checks can be skipped. Otherwise, the ancestors of the |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
530 # "uncertain" set are removed from branchheads. |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
531 # This computation is heavy and avoided if at all possible. |
48732
8b393f40a5e6
branchmap: don't add branch entries if there are no heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48701
diff
changeset
|
532 bheads = self._entries.get(branch, []) |
44470
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44349
diff
changeset
|
533 bheadset = {cl.rev(node) for node in bheads} |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
534 uncertain = set() |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
535 for newrev in sorted(newheadrevs): |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
536 if newrev in obsrevs: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
537 # We ignore obsolete changesets as they shouldn't be |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
538 # considered heads. |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
539 continue |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
540 |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
541 if not bheadset: |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
542 bheadset.add(newrev) |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
543 continue |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
544 |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
545 parents = [p for p in parentrevs(newrev) if p != nullrev] |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
546 samebranch = set() |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
547 otherbranch = set() |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
548 obsparents = set() |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
549 for p in parents: |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
550 if p in obsrevs: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
551 # We ignored this obsolete changeset earlier, but now |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
552 # that it has non-ignored children, we need to make |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
553 # sure their ancestors are not considered heads. To |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
554 # achieve that, we will simply treat this obsolete |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
555 # changeset as a parent from other branch. |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
556 obsparents.add(p) |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
557 elif p in bheadset or getbranchinfo(p)[0] == branch: |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
558 samebranch.add(p) |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
559 else: |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
560 otherbranch.add(p) |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
561 if not (len(bheadset) == len(samebranch) == 1): |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
562 uncertain.update(otherbranch) |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
563 uncertain.update(obsparents) |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
564 bheadset.difference_update(samebranch) |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
565 bheadset.add(newrev) |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
566 |
22357
9c3c3dc14a65
branchmap: pre-filter topological heads before ancestors based filtering
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22356
diff
changeset
|
567 if uncertain: |
46254
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
568 if topoheads is None: |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
569 topoheads = set(cl.headrevs()) |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
570 if bheadset - topoheads: |
c4b792fa109e
branchmap: avoid ancestor computations in absence of non-continous branches
Joerg Sonnenberger <joerg@bec.de>
parents:
45957
diff
changeset
|
571 floorrev = min(bheadset) |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
572 if floorrev <= max(uncertain): |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
573 ancestors = set(cl.ancestors(uncertain, floorrev)) |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
574 bheadset -= ancestors |
48732
8b393f40a5e6
branchmap: don't add branch entries if there are no heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48701
diff
changeset
|
575 if bheadset: |
8b393f40a5e6
branchmap: don't add branch entries if there are no heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48701
diff
changeset
|
576 self[branch] = [cl.node(rev) for rev in sorted(bheadset)] |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
577 tiprev = max(newheadrevs) |
42247
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
578 if tiprev > ntiprev: |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
579 ntiprev = tiprev |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
580 |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
581 if ntiprev > self.tiprev: |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
582 self.tiprev = ntiprev |
9893d7aa7420
branchcache: store the maximum tip in a variable inside for loop
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42228
diff
changeset
|
583 self.tipnode = cl.node(ntiprev) |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
584 |
19838
23386881abeb
branchmap: remove the droppednodes logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19837
diff
changeset
|
585 if not self.validfor(repo): |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
586 # old cache key is now invalid for the repo, but we've just updated |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
587 # the cache and we assume it's valid, so let's make the cache key |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
588 # valid as well by recomputing it from the cached data |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
589 self.tipnode = repo.nullid |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
590 self.tiprev = nullrev |
42002
662ffdde5adf
branchcache: rename itervalues() to iterheads()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42001
diff
changeset
|
591 for heads in self.iterheads(): |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
592 if not heads: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
593 # all revisions on a branch are obsolete |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
594 continue |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
595 # note: tiprev is not necessarily the tip revision of repo, |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
596 # because the tip could be obsolete (i.e. not a head) |
18131
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
597 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
|
598 if tiprev > self.tiprev: |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
599 self.tipnode = cl.node(tiprev) |
f0eeb9b3444a
branchmap: make update a method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18130
diff
changeset
|
600 self.tiprev = tiprev |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
601 self.filteredhash = scmutil.filteredhash( |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
602 repo, self.tiprev, needobsolete=True |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48363
diff
changeset
|
603 ) |
21031
05cfcecb3aef
branchmap: log events related to branch cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20264
diff
changeset
|
604 |
30995
22fbca1d11ed
mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents:
29758
diff
changeset
|
605 duration = util.timer() - starttime |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
606 repo.ui.log( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
607 b'branchcache', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
608 b'updated %s in %.4f seconds\n', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
609 _branchcachedesc(repo), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
610 duration, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
611 ) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
612 |
41580
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
613 self.write(repo) |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
614 |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
615 |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
616 class remotebranchcache(branchcache): |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
617 """Branchmap info for a remote connection, should not write locally""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
618 |
41580
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
619 def write(self, repo): |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
620 pass |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
621 |
eb7ce452e0fb
branchmap: updating triggers a write
Martijn Pieters <mj@octobus.net>
parents:
41579
diff
changeset
|
622 |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
623 # Revision branch info cache |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
624 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
625 _rbcversion = b'-v1' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
626 _rbcnames = b'rbc-names' + _rbcversion |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
627 _rbcrevs = b'rbc-revs' + _rbcversion |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
628 # [4 byte hash prefix][4 byte branch name number with sign bit indicating open] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
629 _rbcrecfmt = b'>4sI' |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
630 _rbcrecsize = calcsize(_rbcrecfmt) |
46434
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
631 _rbcmininc = 64 * _rbcrecsize |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
632 _rbcnodelen = 4 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
633 _rbcbranchidxmask = 0x7FFFFFFF |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
634 _rbccloseflag = 0x80000000 |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
635 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
636 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49026
diff
changeset
|
637 class revbranchcache: |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
638 """Persistent cache, mapping from revision number to branch name and close. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
639 This is a low level cache, independent of filtering. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
640 |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
641 Branch names are stored in rbc-names in internal encoding separated by 0. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
642 rbc-names is append-only, and each branch name is only stored once and will |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
643 thus have a unique index. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
644 |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
645 The branch info for each revision is stored in rbc-revs as constant size |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
646 records. The whole file is read into memory, but it is only 'parsed' on |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
647 demand. The file is usually append-only but will be truncated if repo |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
648 modification is detected. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
649 The record for each revision contains the first 4 bytes of the |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
650 corresponding node hash, and the record is only used if it still matches. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
651 Even a completely trashed rbc-revs fill thus still give the right result |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
652 while converging towards full recovery ... assuming no incorrectly matching |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
653 node hashes. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
654 The record also contains 4 bytes where 31 bits contains the index of the |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
655 branch and the last bit indicate that it is a branch close commit. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
656 The usage pattern for rbc-revs is thus somewhat similar to 00changelog.i |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
657 and will grow with it but be 1/8th of its size. |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
658 """ |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
659 |
24159
5b4ed033390b
revisionbranchcache: fall back to slow path if starting readonly (issue4531)
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
660 def __init__(self, repo, readonly=True): |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
661 assert repo.filtername is None |
24374
77fd1fb538cd
revbranchcache: store repo on the object
Durham Goode <durham@fb.com>
parents:
24373
diff
changeset
|
662 self._repo = repo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
663 self._names = [] # branch names in local encoding with static index |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
30995
diff
changeset
|
664 self._rbcrevs = bytearray() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
665 self._rbcsnameslen = 0 # length of names read at _rbcsnameslen |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
666 try: |
33535
755e6532e81d
cachevfs: migration the revbranchcache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33534
diff
changeset
|
667 bndata = repo.cachevfs.read(_rbcnames) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
668 self._rbcsnameslen = len(bndata) # for verification before writing |
31380
7dd2f51f38ac
rbc: empty (and invalid) rbc-names file should give an empty name list
Mads Kiilerich <mads@kiilerich.com>
parents:
31379
diff
changeset
|
669 if bndata: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
670 self._names = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
671 encoding.tolocal(bn) for bn in bndata.split(b'\0') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
672 ] |
29423
d2c6f3a948fa
branchmap: remove unused exception variable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28558
diff
changeset
|
673 except (IOError, OSError): |
24159
5b4ed033390b
revisionbranchcache: fall back to slow path if starting readonly (issue4531)
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
674 if readonly: |
5b4ed033390b
revisionbranchcache: fall back to slow path if starting readonly (issue4531)
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
675 # don't try to use cache - fall back to the slow path |
5b4ed033390b
revisionbranchcache: fall back to slow path if starting readonly (issue4531)
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
676 self.branchinfo = self._branchinfo |
5b4ed033390b
revisionbranchcache: fall back to slow path if starting readonly (issue4531)
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
677 |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
678 if self._names: |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
679 try: |
33535
755e6532e81d
cachevfs: migration the revbranchcache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33534
diff
changeset
|
680 data = repo.cachevfs.read(_rbcrevs) |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
30995
diff
changeset
|
681 self._rbcrevs[:] = data |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25266
diff
changeset
|
682 except (IOError, OSError) as inst: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
683 repo.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
684 b"couldn't read revision branch cache: %s\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
685 % stringutil.forcebytestr(inst) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
686 ) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
687 # remember number of good records on disk |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
688 self._rbcrevslen = min( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
689 len(self._rbcrevs) // _rbcrecsize, len(repo.changelog) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
690 ) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
691 if self._rbcrevslen == 0: |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
692 self._names = [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
693 self._rbcnamescount = len(self._names) # number of names read at |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
694 # _rbcsnameslen |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
695 |
28558
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
696 def _clear(self): |
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
697 self._rbcsnameslen = 0 |
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
698 del self._names[:] |
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
699 self._rbcnamescount = 0 |
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
700 self._rbcrevslen = len(self._repo.changelog) |
31355
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
30995
diff
changeset
|
701 self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
702 util.clearcachedproperty(self, b'_namesreverse') |
40749
50a64c321c1e
branchmap: build the revbranchcache._namesreverse() only when required
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40494
diff
changeset
|
703 |
50a64c321c1e
branchmap: build the revbranchcache._namesreverse() only when required
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40494
diff
changeset
|
704 @util.propertycache |
50a64c321c1e
branchmap: build the revbranchcache._namesreverse() only when required
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40494
diff
changeset
|
705 def _namesreverse(self): |
44470
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44349
diff
changeset
|
706 return {b: r for r, b in enumerate(self._names)} |
28558
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
707 |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
708 def branchinfo(self, rev): |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
709 """Return branch name and close flag for rev, using and updating |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
710 persistent cache.""" |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
711 changelog = self._repo.changelog |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
712 rbcrevidx = rev * _rbcrecsize |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
713 |
25266
38117278f295
revbranchcache: return uncached branchinfo for nullrev (issue4683)
Yuya Nishihara <yuya@tcha.org>
parents:
24728
diff
changeset
|
714 # avoid negative index, changelog.read(nullrev) is fast without cache |
38117278f295
revbranchcache: return uncached branchinfo for nullrev (issue4683)
Yuya Nishihara <yuya@tcha.org>
parents:
24728
diff
changeset
|
715 if rev == nullrev: |
38117278f295
revbranchcache: return uncached branchinfo for nullrev (issue4683)
Yuya Nishihara <yuya@tcha.org>
parents:
24728
diff
changeset
|
716 return changelog.branchinfo(rev) |
38117278f295
revbranchcache: return uncached branchinfo for nullrev (issue4683)
Yuya Nishihara <yuya@tcha.org>
parents:
24728
diff
changeset
|
717 |
29604
db0095c83344
rbc: fix invalid rbc-revs entries caused by missing cache growth
Mads Kiilerich <madski@unity3d.com>
parents:
29423
diff
changeset
|
718 # if requested rev isn't allocated, grow and cache the rev info |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
719 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
720 return self._branchinfo(rev) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
721 |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
722 # fast path: extract data from cache, use it if node is matching |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
723 reponode = changelog.node(rev)[:_rbcnodelen] |
33661
1814ca418b30
branchmap: revert c34532365b38 for Python 2.7 compatibility
Mike Hommey <mh@glandium.org>
parents:
33535
diff
changeset
|
724 cachenode, branchidx = unpack_from( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
725 _rbcrecfmt, util.buffer(self._rbcrevs), rbcrevidx |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
726 ) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
727 close = bool(branchidx & _rbccloseflag) |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
728 if close: |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
729 branchidx &= _rbcbranchidxmask |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
730 if cachenode == b'\0\0\0\0': |
24376
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
731 pass |
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
732 elif cachenode == reponode: |
29615
a2a380e2750f
rbc: fix superfluous rebuilding from scratch - don't abuse self._rbcnamescount
Mads Kiilerich <madski@unity3d.com>
parents:
29604
diff
changeset
|
733 try: |
28558
bcd106d456c4
cache: rebuild branch cache from scratch when inconsistencies are detected
Mads Kiilerich <madski@unity3d.com>
parents:
28557
diff
changeset
|
734 return self._names[branchidx], close |
29615
a2a380e2750f
rbc: fix superfluous rebuilding from scratch - don't abuse self._rbcnamescount
Mads Kiilerich <madski@unity3d.com>
parents:
29604
diff
changeset
|
735 except IndexError: |
a2a380e2750f
rbc: fix superfluous rebuilding from scratch - don't abuse self._rbcnamescount
Mads Kiilerich <madski@unity3d.com>
parents:
29604
diff
changeset
|
736 # recover from invalid reference to unknown branch |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
737 self._repo.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
738 b"referenced branch names not found" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
739 b" - rebuilding revision branch cache from scratch\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
740 ) |
29615
a2a380e2750f
rbc: fix superfluous rebuilding from scratch - don't abuse self._rbcnamescount
Mads Kiilerich <madski@unity3d.com>
parents:
29604
diff
changeset
|
741 self._clear() |
24376
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
742 else: |
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
743 # rev/node map has changed, invalidate the cache from here up |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
744 self._repo.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
745 b"history modification detected - truncating " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
746 b"revision branch cache to revision %d\n" % rev |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
747 ) |
24376
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
748 truncate = rbcrevidx + _rbcrecsize |
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
749 del self._rbcrevs[truncate:] |
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
750 self._rbcrevslen = min(self._rbcrevslen, truncate) |
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
751 |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
752 # fall back to slow path and make sure it will be written to disk |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
753 return self._branchinfo(rev) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
754 |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
755 def _branchinfo(self, rev): |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
756 """Retrieve branch info from changelog and update _rbcrevs""" |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
757 changelog = self._repo.changelog |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
758 b, close = changelog.branchinfo(rev) |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
759 if b in self._namesreverse: |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
760 branchidx = self._namesreverse[b] |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
761 else: |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
762 branchidx = len(self._names) |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
763 self._names.append(b) |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
764 self._namesreverse[b] = branchidx |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
765 reponode = changelog.node(rev) |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
766 if close: |
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
767 branchidx |= _rbccloseflag |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
768 self._setcachedata(rev, reponode, branchidx) |
24375
fe255b2525d5
revbranchcache: move entry writing to a separate function
Durham Goode <durham@fb.com>
parents:
24374
diff
changeset
|
769 return b, close |
fe255b2525d5
revbranchcache: move entry writing to a separate function
Durham Goode <durham@fb.com>
parents:
24374
diff
changeset
|
770 |
46444
3e91d9978bec
branchmap: update rev-branch-cache incrementally
Joerg Sonnenberger <joerg@bec.de>
parents:
46434
diff
changeset
|
771 def setdata(self, rev, changelogrevision): |
36968
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
772 """add new data information to the cache""" |
46444
3e91d9978bec
branchmap: update rev-branch-cache incrementally
Joerg Sonnenberger <joerg@bec.de>
parents:
46434
diff
changeset
|
773 branch, close = changelogrevision.branchinfo |
3e91d9978bec
branchmap: update rev-branch-cache incrementally
Joerg Sonnenberger <joerg@bec.de>
parents:
46434
diff
changeset
|
774 |
36968
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
775 if branch in self._namesreverse: |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
776 branchidx = self._namesreverse[branch] |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
777 else: |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
778 branchidx = len(self._names) |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
779 self._names.append(branch) |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
780 self._namesreverse[branch] = branchidx |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
781 if close: |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
782 branchidx |= _rbccloseflag |
46444
3e91d9978bec
branchmap: update rev-branch-cache incrementally
Joerg Sonnenberger <joerg@bec.de>
parents:
46434
diff
changeset
|
783 self._setcachedata(rev, self._repo.changelog.node(rev), branchidx) |
36968
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
784 # If no cache data were readable (non exists, bad permission, etc) |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
785 # the cache was bypassing itself by setting: |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
786 # |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
787 # self.branchinfo = self._branchinfo |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
788 # |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
789 # Since we now have data in the cache, we need to drop this bypassing. |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43547
diff
changeset
|
790 if 'branchinfo' in vars(self): |
36968
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
791 del self.branchinfo |
95f4f1bfb650
revbranchcache: add a public function to update the data
Boris Feld <boris.feld@octobus.net>
parents:
36504
diff
changeset
|
792 |
40494
5e5c8f2a1eb5
branchmap: do not specify changelog as an argument
Yuya Nishihara <yuya@tcha.org>
parents:
40375
diff
changeset
|
793 def _setcachedata(self, rev, node, branchidx): |
24375
fe255b2525d5
revbranchcache: move entry writing to a separate function
Durham Goode <durham@fb.com>
parents:
24374
diff
changeset
|
794 """Writes the node's branch data to the in-memory cache data.""" |
31463
a5bad127128d
branchmap: handle nullrev in setcachedata
Durham Goode <durham@fb.com>
parents:
31390
diff
changeset
|
795 if rev == nullrev: |
a5bad127128d
branchmap: handle nullrev in setcachedata
Durham Goode <durham@fb.com>
parents:
31390
diff
changeset
|
796 return |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
797 rbcrevidx = rev * _rbcrecsize |
46434
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
798 requiredsize = rbcrevidx + _rbcrecsize |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
799 rbccur = len(self._rbcrevs) |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
800 if rbccur < requiredsize: |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
801 # bytearray doesn't allocate extra space at least in Python 3.7. |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
802 # When multiple changesets are added in a row, precise resize would |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
803 # result in quadratic complexity. Overallocate to compensate by |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
804 # use the classic doubling technique for dynamic arrays instead. |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
805 # If there was a gap in the map before, less space will be reserved. |
1726a53a8494
reverse-branch-cache: switch to doubling allocating scheme
Joerg Sonnenberger <joerg@bec.de>
parents:
46254
diff
changeset
|
806 self._rbcrevs.extend(b'\0' * max(_rbcmininc, requiredsize)) |
31379
906be86990c4
rbc: use struct unpack_from and pack_into instead of unpack and pack
Mads Kiilerich <madski@unity3d.com>
parents:
31369
diff
changeset
|
807 pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx) |
24376
203a078da052
revbranchcache: populate cache incrementally
Durham Goode <durham@fb.com>
parents:
24375
diff
changeset
|
808 self._rbcrevslen = min(self._rbcrevslen, rev) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
809 |
24377
656f93ce66d5
revbranchcache: move cache writing to the transaction finalizer
Durham Goode <durham@fb.com>
parents:
24376
diff
changeset
|
810 tr = self._repo.currenttransaction() |
656f93ce66d5
revbranchcache: move cache writing to the transaction finalizer
Durham Goode <durham@fb.com>
parents:
24376
diff
changeset
|
811 if tr: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
812 tr.addfinalize(b'write-revbranchcache', self.write) |
24377
656f93ce66d5
revbranchcache: move cache writing to the transaction finalizer
Durham Goode <durham@fb.com>
parents:
24376
diff
changeset
|
813 |
656f93ce66d5
revbranchcache: move cache writing to the transaction finalizer
Durham Goode <durham@fb.com>
parents:
24376
diff
changeset
|
814 def write(self, tr=None): |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
815 """Save branch cache if it is dirty.""" |
24374
77fd1fb538cd
revbranchcache: store repo on the object
Durham Goode <durham@fb.com>
parents:
24373
diff
changeset
|
816 repo = self._repo |
29756
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
817 wlock = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
818 step = b'' |
29756
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
819 try: |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
820 # write the new names |
29755
9f3c49ee4486
branchmap: preparatory indent of indent the branch rev writing code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29615
diff
changeset
|
821 if self._rbcnamescount < len(self._names): |
29756
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
822 wlock = repo.wlock(wait=False) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
823 step = b' names' |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
824 self._writenames(repo) |
23785
cb99bacb9b4e
branchcache: introduce revbranchcache for caching of revision branch names
Mads Kiilerich <madski@unity3d.com>
parents:
22357
diff
changeset
|
825 |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
826 # write the new revs |
29755
9f3c49ee4486
branchmap: preparatory indent of indent the branch rev writing code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29615
diff
changeset
|
827 start = self._rbcrevslen * _rbcrecsize |
9f3c49ee4486
branchmap: preparatory indent of indent the branch rev writing code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29615
diff
changeset
|
828 if start != len(self._rbcrevs): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
829 step = b'' |
29756
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
830 if wlock is None: |
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
831 wlock = repo.wlock(wait=False) |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
832 self._writerevs(repo, start) |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
833 |
29757
3b184adfb5be
branchmap: simplify error handlind when writing rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29756
diff
changeset
|
834 except (IOError, OSError, error.Abort, error.LockError) as inst: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
835 repo.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
836 b"couldn't write revision branch cache%s: %s\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
837 % (step, stringutil.forcebytestr(inst)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
838 ) |
29756
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
839 finally: |
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
840 if wlock is not None: |
0d588332ad2c
branchmap: acquires lock before writting the rev branch cache
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29755
diff
changeset
|
841 wlock.release() |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
842 |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
843 def _writenames(self, repo): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
844 """write the new branch names to revbranchcache""" |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
845 if self._rbcnamescount != 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
846 f = repo.cachevfs.open(_rbcnames, b'ab') |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
847 if f.tell() == self._rbcsnameslen: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
848 f.write(b'\0') |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
849 else: |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
850 f.close() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
851 repo.ui.debug(b"%s changed - rewriting it\n" % _rbcnames) |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
852 self._rbcnamescount = 0 |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
853 self._rbcrevslen = 0 |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
854 if self._rbcnamescount == 0: |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
855 # before rewriting names, make sure references are removed |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
856 repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
857 f = repo.cachevfs.open(_rbcnames, b'wb') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
858 f.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
859 b'\0'.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
860 encoding.fromlocal(b) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
861 for b in self._names[self._rbcnamescount :] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
862 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42603
diff
changeset
|
863 ) |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
864 self._rbcsnameslen = f.tell() |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
865 f.close() |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
866 self._rbcnamescount = len(self._names) |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
867 |
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
868 def _writerevs(self, repo, start): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46819
diff
changeset
|
869 """write the new revs to revbranchcache""" |
42223
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
870 revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
871 with repo.cachevfs.open(_rbcrevs, b'ab') as f: |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
872 if f.tell() != start: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
873 repo.ui.debug( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
874 b"truncating cache/%s to %d\n" % (_rbcrevs, start) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
875 ) |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
876 f.seek(start) |
42223
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
877 if f.tell() != start: |
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
878 start = 0 |
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
879 f.seek(start) |
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
880 f.truncate() |
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
881 end = revs * _rbcrecsize |
ececa45c80d8
revbranchcache: use context manager in _writerevs() to write to file
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42222
diff
changeset
|
882 f.write(self._rbcrevs[start:end]) |
42222
09fd338522fa
revbranchcache: factor logic to write names and revs in separate functions
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42138
diff
changeset
|
883 self._rbcrevslen = revs |