Mercurial > hg
annotate mercurial/repoview.py @ 43198:c16fe77e340a
pathcopies: give up any optimization based on `introrev`
Between 8a0136f69027 and d98fb3f42f33, we sped up the search for the
introduction revision during path copies. However, further checking show that
finding the introduction revision is still expensive and that we are better off
without it. So we simply drop it and only rely on the linkrev optimisation.
I ran `perfpathcopies` on 6989 pair of revision in the pypy
repository (`hg perfhelper-pathcopies`. The result is massively in favor of
dropping this condition. The result of the copy tracing are unchanged.
Attempt to use a smaller changes preserving linkrev usage were unsuccessful, it
can return wrong result. The following changesets broke test-mv-cp-st-diff.t
- if not f.isintroducedafter(limit):
+ if limit >= 0 and f.linkrev() < limit:
return None
Here are various numbers (before this changeset/after this changesets)
source destination before after saved-time ratio
worth cases e66f24650daf 695dfb0f493b 1.062843 1.246369 -0.183526 1.172675
c979853a3b6a 8d60fe293e79 1.036985 1.196414 -0.159429 1.153743
22349fa2fc33 fbb1c9fd86c0 0.879926 1.038682 -0.158756 1.180420
682b98f3e672 a4878080a536 0.909952 1.063801 -0.153849 1.169074
5adabc9b9848 920958a93997 0.993622 1.147452 -0.153830 1.154817
worse 1% dbfbfcf077e9 aea8f2fd3593 1.016595 1.082999 -0.066404 1.065320
worse 5% c95f1ced15f2 7d29d5e39734 0.453694 0.471156 -0.017462 1.038488
worse 10% 3e144ed1d5b7 2aef0e942480 0.035140 0.037535 -0.002395 1.068156
worse 25% 321fc60db035 801748ba582a 0.009267 0.009325 -0.000058 1.006259
median 2088ce763fc2 e6991321d78b 0.000665 0.000651 0.000014 0.978947
best 25% 915631a97de6 385b31354be6 0.040743 0.040363 0.000380 0.990673
best 10% ad495c36a765 19c10384d3e7 0.431658 0.411490 0.020168 0.953278
best 5% d13ae7d283ae 813c99f810ac 1.141404 1.075346 0.066058 0.942126
best 1% 81593cb4a496 99ae11866969 1.833297 0.063823 1.769474 0.034813
best cases c3b14617fbd7 743a0fcaa4eb 1101.811740 2.735970 1099.075770 0.002483
c3b14617fbd7 9ba6ab77fd29 1116.753953 2.800729 1113.953224 0.002508
058b99d6e81f 57e249b7a3ea 1246.128485 3.042762 1243.085723 0.002442
9a8c361aab49 0354a250d371 1253.111894 3.085796 1250.026098 0.002463
442dbbc53c68 3ec1002a818c 1261.786294 3.138607 1258.647687 0.002487
As one can see, the average case is not really impacted. However, the worth case
we get after this changeset are much better than the one we had before it. We
have 30 pairs where improvements are above 10 minutes.
This reflect in the combined time for all pairs
before: 26256s
after: 1300s (-95%)
If we remove these pathological 30 cases, we still see a significant improvements:
before: 1631s
after: 1245s (-24%)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 10 Oct 2019 03:49:33 +0200 |
parents | 1f339b503a40 |
children | 4353942be294 |
rev | line source |
---|---|
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 # repoview.py - Filtered view of a localrepo object |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 # |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 # Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 # Logilab SA <contact@logilab.fr> |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 # |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
7 # GNU General Public License version 2 or any later version. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
8 |
25972
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
9 from __future__ import absolute_import |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
10 |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
11 import copy |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
12 import weakref |
25972
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
13 |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
14 from .node import nullrev |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
15 from .pycompat import ( |
43090
1f339b503a40
py3: manually import pycompat.delattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
16 delattr, |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
17 getattr, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
18 setattr, |
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43087
diff
changeset
|
19 ) |
25972
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
20 from . import ( |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
21 obsolete, |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
22 phases, |
35249
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
23 pycompat, |
25972
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
24 tags as tagsmod, |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
25 util, |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
26 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
27 from .utils import repoviewutil |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
28 |
18242
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
29 |
18293
1f35d6737ed8
repoview: extract hideable revision computation in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18274
diff
changeset
|
30 def hideablerevs(repo): |
28780
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
31 """Revision candidates to be hidden |
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
32 |
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
33 This is a standalone function to allow extensions to wrap it. |
18293
1f35d6737ed8
repoview: extract hideable revision computation in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18274
diff
changeset
|
34 |
28780
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
35 Because we use the set of immutable changesets as a fallback subset in |
42138
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42126
diff
changeset
|
36 branchmap (see mercurial.utils.repoviewutils.subsettable), you cannot set |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42126
diff
changeset
|
37 "public" changesets as "hideable". Doing so would break multiple code |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42126
diff
changeset
|
38 assertions and lead to crashes.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
39 obsoletes = obsolete.getrevs(repo, b'obsolete') |
39297
06c976acc581
phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents:
38851
diff
changeset
|
40 internals = repo._phasecache.getrevset(repo, phases.localhiddenphases) |
06c976acc581
phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents:
38851
diff
changeset
|
41 internals = frozenset(internals) |
06c976acc581
phases: add an internal phases
Boris Feld <boris.feld@octobus.net>
parents:
38851
diff
changeset
|
42 return obsoletes | internals |
18293
1f35d6737ed8
repoview: extract hideable revision computation in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18274
diff
changeset
|
43 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
44 |
32586
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
45 def pinnedrevs(repo): |
32585
bceb398e6d72
hidden: drop obsolete comment about cacheability
Martin von Zweigbergk <martinvonz@google.com>
parents:
32480
diff
changeset
|
46 """revisions blocking hidden changesets from being filtered |
32480
43ae9e6eaaba
hidden: drop outdated comment about "dynamic" performance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32479
diff
changeset
|
47 """ |
32426
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
48 |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
49 cl = repo.changelog |
32586
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
50 pinned = set() |
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
51 pinned.update([par.rev() for par in repo[None].parents()]) |
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
52 pinned.update([cl.rev(bm) for bm in repo._bookmarks.values()]) |
32426
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
53 |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
54 tags = {} |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
55 tagsmod.readlocaltags(repo.ui, repo, tags, {}) |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
56 if tags: |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
57 rev, nodemap = cl.rev, cl.nodemap |
32586
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
58 pinned.update(rev(t[0]) for t in tags.values() if t[0] in nodemap) |
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
59 return pinned |
32426
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
60 |
32477
20c1c2fb8106
hidden: simplify the computation of consistency blocker
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32476
diff
changeset
|
61 |
32588
d964959cbf66
hidden: remove unnecessary 'domain' parameter from _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32587
diff
changeset
|
62 def _revealancestors(pfunc, hidden, revs): |
d964959cbf66
hidden: remove unnecessary 'domain' parameter from _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32587
diff
changeset
|
63 """reveals contiguous chains of hidden ancestors of 'revs' by removing them |
d964959cbf66
hidden: remove unnecessary 'domain' parameter from _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32587
diff
changeset
|
64 from 'hidden' |
32475
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
65 |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
66 - pfunc(r): a funtion returning parent of 'r', |
32587
b9b41d8f4522
hidden: change _domainancestors() to _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32586
diff
changeset
|
67 - hidden: the (preliminary) hidden revisions, to be updated |
32475
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
68 - revs: iterable of revnum, |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
69 |
32591
2af0b9a02bf9
hidden: make _revealancestors() reveal ancestors exclusively
Martin von Zweigbergk <martinvonz@google.com>
parents:
32590
diff
changeset
|
70 (Ancestors are revealed exclusively, i.e. the elements in 'revs' are |
2af0b9a02bf9
hidden: make _revealancestors() reveal ancestors exclusively
Martin von Zweigbergk <martinvonz@google.com>
parents:
32590
diff
changeset
|
71 *not* revealed) |
32475
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
72 """ |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
73 stack = list(revs) |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
74 while stack: |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
75 for p in pfunc(stack.pop()): |
32588
d964959cbf66
hidden: remove unnecessary 'domain' parameter from _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32587
diff
changeset
|
76 if p != nullrev and p in hidden: |
32587
b9b41d8f4522
hidden: change _domainancestors() to _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32586
diff
changeset
|
77 hidden.remove(p) |
32475
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
78 stack.append(p) |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
79 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
80 |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
81 def computehidden(repo, visibilityexceptions=None): |
18242
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
82 """compute the set of hidden revision to filter |
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
83 |
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
84 During most operation hidden should be filtered.""" |
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
85 assert not repo.changelog.filteredrevs |
22151
c0c369aec643
repoview: cache hidden changesets
David Soria Parra <davidsp@fb.com>
parents:
22150
diff
changeset
|
86 |
32479
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
87 hidden = hideablerevs(repo) |
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
88 if hidden: |
32592
c37ca35b8450
hidden: subtract pinned revs from hidden earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
32591
diff
changeset
|
89 hidden = set(hidden - pinnedrevs(repo)) |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
90 if visibilityexceptions: |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
91 hidden -= visibilityexceptions |
32479
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
92 pfunc = repo.changelog.parentrevs |
38157
02f992ac26e9
phases: define an official tuple of mutable phases
Boris Feld <boris.feld@octobus.net>
parents:
38156
diff
changeset
|
93 mutable = repo._phasecache.getrevset(repo, phases.mutablephases) |
32479
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
94 |
32593
e4d0b2efb8b5
hidden: remove unnecessary guard condition
Martin von Zweigbergk <martinvonz@google.com>
parents:
32592
diff
changeset
|
95 visible = mutable - hidden |
e4d0b2efb8b5
hidden: remove unnecessary guard condition
Martin von Zweigbergk <martinvonz@google.com>
parents:
32592
diff
changeset
|
96 _revealancestors(pfunc, hidden, visible) |
32479
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
97 return frozenset(hidden) |
18242
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
98 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
99 |
42126
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
100 def computesecret(repo, visibilityexceptions=None): |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
101 """compute the set of revision that can never be exposed through hgweb |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
102 |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
103 Changeset in the secret phase (or above) should stay unaccessible.""" |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
104 assert not repo.changelog.filteredrevs |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
105 secrets = repo._phasecache.getrevset(repo, phases.remotehiddenphases) |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
106 return frozenset(secrets) |
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
107 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
108 |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
109 def computeunserved(repo, visibilityexceptions=None): |
18102
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
110 """compute the set of revision that should be filtered when used a server |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
111 |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
112 Secret and hidden changeset should not pretend to be here.""" |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
113 assert not repo.changelog.filteredrevs |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
114 # fast path in simple case to avoid impact of non optimised code |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 hiddens = filterrevs(repo, b'visible') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
116 secrets = filterrevs(repo, b'served.hidden') |
42125
bc15e37ecc16
repoview: fix conditional around unserved changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39297
diff
changeset
|
117 if secrets: |
42126
ef0e3cc684b3
repoview: introduce a filter for serving hidden changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42125
diff
changeset
|
118 return frozenset(hiddens | secrets) |
18273
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
119 else: |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
120 return hiddens |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
121 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
122 |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
123 def computemutable(repo, visibilityexceptions=None): |
18245
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
124 assert not repo.changelog.filteredrevs |
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
125 # fast check to avoid revset call on huge repo |
25149
3f0744eeaeaf
cleanup: use __builtins__.any instead of util.any
Augie Fackler <augie@google.com>
parents:
25086
diff
changeset
|
126 if any(repo._phasecache.phaseroots[1:]): |
18274
254b708fd37d
performance: speedup computation of mutable revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18273
diff
changeset
|
127 getphase = repo._phasecache.phase |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
128 maymutable = filterrevs(repo, b'base') |
18274
254b708fd37d
performance: speedup computation of mutable revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18273
diff
changeset
|
129 return frozenset(r for r in maymutable if getphase(repo, r)) |
18245
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
130 return frozenset() |
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
131 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
132 |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
133 def computeimpactable(repo, visibilityexceptions=None): |
18246
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
134 """Everything impactable by mutable revision |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
135 |
18462
593eb3786165
documentation: update to new filter names
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18445
diff
changeset
|
136 The immutable filter still have some chance to get invalidated. This will |
18246
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
137 happen when: |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
138 |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
139 - you garbage collect hidden changeset, |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
140 - public phase is moved backward, |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
141 - something is changed in the filtering (this could be fixed) |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
142 |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
143 This filter out any mutable changeset and any public changeset that may be |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
144 impacted by something happening to a mutable revision. |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
145 |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
146 This is achieved by filtered everything with a revision number egal or |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
147 higher than the first mutable changeset is filtered.""" |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
148 assert not repo.changelog.filteredrevs |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
149 cl = repo.changelog |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
150 firstmutable = len(cl) |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
151 for roots in repo._phasecache.phaseroots[1:]: |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
152 if roots: |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
153 firstmutable = min(firstmutable, min(cl.rev(r) for r in roots)) |
18443
64848f7fb764
repoview: protect `base` computation from weird phase root
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18382
diff
changeset
|
154 # protect from nullrev root |
64848f7fb764
repoview: protect `base` computation from weird phase root
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18382
diff
changeset
|
155 firstmutable = max(0, firstmutable) |
38783
e7aa113b14f7
global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38158
diff
changeset
|
156 return frozenset(pycompat.xrange(firstmutable, len(cl))) |
18246
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
157 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
158 |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
159 # function to compute filtered set |
20196
59198508b0bd
filter: add a comment so that people do not forget to update subsettable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20032
diff
changeset
|
160 # |
20549
2025315cfb0c
comments: fix minor spelling issues found with spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20405
diff
changeset
|
161 # When adding a new filter you MUST update the table at: |
42138
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42126
diff
changeset
|
162 # mercurial.utils.repoviewutil.subsettable |
20196
59198508b0bd
filter: add a comment so that people do not forget to update subsettable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20032
diff
changeset
|
163 # Otherwise your filter will have to recompute all its branches cache |
59198508b0bd
filter: add a comment so that people do not forget to update subsettable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20032
diff
changeset
|
164 # from scratch (very slow). |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
165 filtertable = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 b'visible': computehidden, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 b'visible-hidden': computehidden, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
168 b'served.hidden': computesecret, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
169 b'served': computeunserved, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
170 b'immutable': computemutable, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
171 b'base': computeimpactable, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
172 } |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
173 |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
174 _basefiltername = list(filtertable) |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
175 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
176 |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
177 def extrafilter(ui): |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
178 """initialize extra filter and return its id |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
179 |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
180 If extra filtering is configured, we make sure the associated filtered view |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
181 are declared and return the associated id. |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
182 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
183 frevs = ui.config(b'experimental', b'extra-filter-revs') |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
184 if frevs is None: |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
185 return None |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
186 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
187 fid = pycompat.sysbytes(util.DIGESTS[b'sha1'](frevs).hexdigest())[:12] |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
188 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
189 combine = lambda fname: fname + b'%' + fid |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
190 |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
191 subsettable = repoviewutil.subsettable |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
192 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
193 if combine(b'base') not in filtertable: |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
194 for name in _basefiltername: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
195 |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
196 def extrafilteredrevs(repo, *args, **kwargs): |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
197 baserevs = filtertable[name](repo, *args, **kwargs) |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
198 extrarevs = frozenset(repo.revs(frevs)) |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
199 return baserevs | extrarevs |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
200 |
42231
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
201 filtertable[combine(name)] = extrafilteredrevs |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
202 if name in subsettable: |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
203 subsettable[combine(name)] = combine(subsettable[name]) |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
204 return fid |
d345627d104b
repoview: introduce a `experimental.extra-filter-revs` config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42138
diff
changeset
|
205 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
206 |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
207 def filterrevs(repo, filtername, visibilityexceptions=None): |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
208 """returns set of filtered revision for this filter name |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
209 |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
210 visibilityexceptions is a set of revs which must are exceptions for |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
211 hidden-state and must be visible. They are dynamic and hence we should not |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
212 cache it's result""" |
18101
a464deecc9dd
clfilter: add a cache on repo for set of revision to filter for a given set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18100
diff
changeset
|
213 if filtername not in repo.filteredrevcache: |
a464deecc9dd
clfilter: add a cache on repo for set of revision to filter for a given set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18100
diff
changeset
|
214 func = filtertable[filtername] |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
215 if visibilityexceptions: |
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
216 return func(repo.unfiltered, visibilityexceptions) |
18101
a464deecc9dd
clfilter: add a cache on repo for set of revision to filter for a given set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18100
diff
changeset
|
217 repo.filteredrevcache[filtername] = func(repo.unfiltered()) |
a464deecc9dd
clfilter: add a cache on repo for set of revision to filter for a given set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18100
diff
changeset
|
218 return repo.filteredrevcache[filtername] |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
219 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
220 |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
221 class repoview(object): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
222 """Provide a read/write view of a repo through a filtered changelog |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
223 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
224 This object is used to access a filtered version of a repository without |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
225 altering the original repository object itself. We can not alter the |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
226 original object for two main reasons: |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
227 - It prevents the use of a repo with multiple filters at the same time. In |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
228 particular when multiple threads are involved. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
229 - It makes scope of the filtering harder to control. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
230 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
231 This object behaves very closely to the original repository. All attribute |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
232 operations are done on the original repository: |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
233 - An access to `repoview.someattr` actually returns `repo.someattr`, |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
234 - A write to `repoview.someattr` actually sets value of `repo.someattr`, |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
235 - A deletion of `repoview.someattr` actually drops `someattr` |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
236 from `repo.__dict__`. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
237 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
238 The only exception is the `changelog` property. It is overridden to return |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
239 a (surface) copy of `repo.changelog` with some revisions filtered. The |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
240 `filtername` attribute of the view control the revisions that need to be |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
241 filtered. (the fact the changelog is copied is an implementation detail). |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
242 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
243 Unlike attributes, this object intercepts all method calls. This means that |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
244 all methods are run on the `repoview` object with the filtered `changelog` |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
245 property. For this purpose the simple `repoview` class must be mixed with |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
246 the actual class of the repository. This ensures that the resulting |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
247 `repoview` object have the very same methods than the repo object. This |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
248 leads to the property below. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
249 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
250 repoview.method() --> repo.__class__.method(repoview) |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
251 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
252 The inheritance has to be done dynamically because `repo` can be of any |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18495
diff
changeset
|
253 subclasses of `localrepo`. Eg: `bundlerepo` or `statichttprepo`. |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
254 """ |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
255 |
35492
3ad582b2895c
repoview: add visibilityexceptions as an optional argument to repo.filtered()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
256 def __init__(self, repo, filtername, visibilityexceptions=None): |
31221
2faf233b88e4
repoview: convert attribute names to unicodes on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31049
diff
changeset
|
257 object.__setattr__(self, r'_unfilteredrepo', repo) |
2faf233b88e4
repoview: convert attribute names to unicodes on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31049
diff
changeset
|
258 object.__setattr__(self, r'filtername', filtername) |
2faf233b88e4
repoview: convert attribute names to unicodes on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31049
diff
changeset
|
259 object.__setattr__(self, r'_clcachekey', None) |
2faf233b88e4
repoview: convert attribute names to unicodes on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31049
diff
changeset
|
260 object.__setattr__(self, r'_clcache', None) |
35492
3ad582b2895c
repoview: add visibilityexceptions as an optional argument to repo.filtered()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
261 # revs which are exceptions and must not be hidden |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
262 object.__setattr__(self, r'_visibilityexceptions', visibilityexceptions) |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
263 |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18495
diff
changeset
|
264 # not a propertycache on purpose we shall implement a proper cache later |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
265 @property |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
266 def changelog(self): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
267 """return a filtered version of the changeset |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
268 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
269 this changelog must not be used for writing""" |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
270 # some cache may be implemented later |
18445
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
271 unfi = self._unfilteredrepo |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
272 unfichangelog = unfi.changelog |
27258
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
273 # bypass call to changelog.method |
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
274 unfiindex = unfichangelog.index |
38851
781b2720d2ac
index: don't include nullid in len()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38783
diff
changeset
|
275 unfilen = len(unfiindex) |
27258
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
276 unfinode = unfiindex[unfilen - 1][7] |
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
277 |
35493
3c9c05a38d78
repoview: add visibilityexception argument to filterrevs() and related fns
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35492
diff
changeset
|
278 revs = filterrevs(unfi, self.filtername, self._visibilityexceptions) |
18445
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
279 cl = self._clcache |
27258
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
280 newkey = (unfilen, unfinode, hash(revs), unfichangelog._delayed) |
28265
332926212ef8
repoview: discard filtered changelog if index isn't shared with unfiltered
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27917
diff
changeset
|
281 # if cl.index is not unfiindex, unfi.changelog would be |
332926212ef8
repoview: discard filtered changelog if index isn't shared with unfiltered
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27917
diff
changeset
|
282 # recreated, and our clcache refers to garbage object |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
283 if cl is not None and ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
284 cl.index is not unfiindex or newkey != self._clcachekey |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
285 ): |
27258
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
286 cl = None |
18445
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
287 # could have been made None by the previous if |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
288 if cl is None: |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
289 cl = copy.copy(unfichangelog) |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
290 cl.filteredrevs = revs |
31358
4015dfc899bb
repoview: specify setattr values as native strings
Augie Fackler <augie@google.com>
parents:
31221
diff
changeset
|
291 object.__setattr__(self, r'_clcache', cl) |
4015dfc899bb
repoview: specify setattr values as native strings
Augie Fackler <augie@google.com>
parents:
31221
diff
changeset
|
292 object.__setattr__(self, r'_clcachekey', newkey) |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
293 return cl |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
294 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
295 def unfiltered(self): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
296 """Return an unfiltered version of a repo""" |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
297 return self._unfilteredrepo |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
298 |
35492
3ad582b2895c
repoview: add visibilityexceptions as an optional argument to repo.filtered()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
299 def filtered(self, name, visibilityexceptions=None): |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
300 """Return a filtered version of a repository""" |
35492
3ad582b2895c
repoview: add visibilityexceptions as an optional argument to repo.filtered()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
301 if name == self.filtername and not visibilityexceptions: |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
302 return self |
35492
3ad582b2895c
repoview: add visibilityexceptions as an optional argument to repo.filtered()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35249
diff
changeset
|
303 return self.unfiltered().filtered(name, visibilityexceptions) |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
304 |
35249
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
305 def __repr__(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
306 return r'<%s:%s %r>' % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
307 self.__class__.__name__, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
308 pycompat.sysstr(self.filtername), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
309 self.unfiltered(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
310 ) |
35249
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
311 |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
312 # everything access are forwarded to the proxied repo |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
313 def __getattr__(self, attr): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
314 return getattr(self._unfilteredrepo, attr) |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
315 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
316 def __setattr__(self, attr, value): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
317 return setattr(self._unfilteredrepo, attr, value) |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
318 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
319 def __delattr__(self, attr): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
320 return delattr(self._unfilteredrepo, attr) |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
321 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
322 |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
323 # Python <3.4 easily leaks types via __mro__. See |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
324 # https://bugs.python.org/issue17950. We cache dynamically created types |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
325 # so they won't be leaked on every invocation of repo.filtered(). |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
326 _filteredrepotypes = weakref.WeakKeyDictionary() |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
327 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
328 |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
329 def newtype(base): |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
330 """Create a new type with the repoview mixin and the given base class""" |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
331 if base not in _filteredrepotypes: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
332 |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
333 class filteredrepo(repoview, base): |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
334 pass |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42231
diff
changeset
|
335 |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
336 _filteredrepotypes[base] = filteredrepo |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
337 return _filteredrepotypes[base] |