Mercurial > hg
annotate mercurial/repoview.py @ 35443:a8478b808f17
check-code: remove unused variable 'winglobmsg'
Follows up 5feb782c7a95.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 14 Dec 2017 22:26:46 +0900 |
parents | d4ad9d695a9e |
children | 3ad582b2895c |
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 |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
15 from . import ( |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
16 obsolete, |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
17 phases, |
35249
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
18 pycompat, |
25972
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
19 tags as tagsmod, |
f279191124f3
repoview: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25149
diff
changeset
|
20 ) |
18242
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
21 |
18293
1f35d6737ed8
repoview: extract hideable revision computation in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18274
diff
changeset
|
22 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
|
23 """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
|
24 |
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
25 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
|
26 |
28780
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
27 Because we use the set of immutable changesets as a fallback subset in |
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
28 branchmap (see mercurial.branchmap.subsettable), you cannot set "public" |
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
29 changesets as "hideable". Doing so would break multiple code assertions and |
faff8c2b5ee3
hideablerevs: expand docstring to warn about possible traps
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
28265
diff
changeset
|
30 lead to crashes.""" |
18293
1f35d6737ed8
repoview: extract hideable revision computation in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18274
diff
changeset
|
31 return obsolete.getrevs(repo, 'obsolete') |
1f35d6737ed8
repoview: extract hideable revision computation in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18274
diff
changeset
|
32 |
32586
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
33 def pinnedrevs(repo): |
32585
bceb398e6d72
hidden: drop obsolete comment about cacheability
Martin von Zweigbergk <martinvonz@google.com>
parents:
32480
diff
changeset
|
34 """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
|
35 """ |
32426
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
36 |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
37 cl = repo.changelog |
32586
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
38 pinned = set() |
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
39 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
|
40 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
|
41 |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
42 tags = {} |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
43 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
|
44 if tags: |
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
45 rev, nodemap = cl.rev, cl.nodemap |
32586
47e4c6bb39f1
hidden: rename "revealedrevs" to "pinnedrevs" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
32585
diff
changeset
|
46 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
|
47 return pinned |
32426
06aa645e2372
repoview: move '_getdynamicblock' next to 'hideablerevs'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31444
diff
changeset
|
48 |
32477
20c1c2fb8106
hidden: simplify the computation of consistency blocker
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32476
diff
changeset
|
49 |
32588
d964959cbf66
hidden: remove unnecessary 'domain' parameter from _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32587
diff
changeset
|
50 def _revealancestors(pfunc, hidden, revs): |
d964959cbf66
hidden: remove unnecessary 'domain' parameter from _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32587
diff
changeset
|
51 """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
|
52 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
|
53 |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
54 - 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
|
55 - 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
|
56 - 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
|
57 |
32591
2af0b9a02bf9
hidden: make _revealancestors() reveal ancestors exclusively
Martin von Zweigbergk <martinvonz@google.com>
parents:
32590
diff
changeset
|
58 (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
|
59 *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
|
60 """ |
1d70ec85ae00
hidden: add a function returning ancestors of revs within a domain
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32427
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 if p != nullrev and p in hidden: |
32587
b9b41d8f4522
hidden: change _domainancestors() to _revealancestors()
Martin von Zweigbergk <martinvonz@google.com>
parents:
32586
diff
changeset
|
65 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
|
66 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
|
67 |
18242
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
68 def computehidden(repo): |
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
69 """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
|
70 |
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
71 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
|
72 assert not repo.changelog.filteredrevs |
22151
c0c369aec643
repoview: cache hidden changesets
David Soria Parra <davidsp@fb.com>
parents:
22150
diff
changeset
|
73 |
32479
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
74 hidden = hideablerevs(repo) |
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
75 if hidden: |
32592
c37ca35b8450
hidden: subtract pinned revs from hidden earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
32591
diff
changeset
|
76 hidden = set(hidden - pinnedrevs(repo)) |
32479
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
77 pfunc = repo.changelog.parentrevs |
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
78 mutablephases = (phases.draft, phases.secret) |
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
79 mutable = repo._phasecache.getrevset(repo, mutablephases) |
4c5bc7cbd989
hidden: unify the static and dynamic blocker logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32478
diff
changeset
|
80 |
32593
e4d0b2efb8b5
hidden: remove unnecessary guard condition
Martin von Zweigbergk <martinvonz@google.com>
parents:
32592
diff
changeset
|
81 visible = mutable - hidden |
e4d0b2efb8b5
hidden: remove unnecessary guard condition
Martin von Zweigbergk <martinvonz@google.com>
parents:
32592
diff
changeset
|
82 _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
|
83 return frozenset(hidden) |
18242
e4687edec014
clfilter: introduces a hidden filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18233
diff
changeset
|
84 |
18102
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
85 def computeunserved(repo): |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
86 """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
|
87 |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
88 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
|
89 assert not repo.changelog.filteredrevs |
3c7b67b76190
clfilter: introduce a "unserver" filtering mode
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18101
diff
changeset
|
90 # fast path in simple case to avoid impact of non optimised code |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
91 hiddens = filterrevs(repo, 'visible') |
18273
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
92 if phases.hassecret(repo): |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
93 cl = repo.changelog |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
94 secret = phases.secret |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
95 getphase = repo._phasecache.phase |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
96 first = min(cl.rev(n) for n in repo._phasecache.phaseroots[secret]) |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
97 revs = cl.revs(start=first) |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
98 secrets = set(r for r in revs if getphase(repo, r) >= secret) |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
99 return frozenset(hiddens | secrets) |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
100 else: |
a2d54f68e13c
performance: speedup computation of unserved revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18272
diff
changeset
|
101 return hiddens |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
102 |
18245
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
103 def computemutable(repo): |
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
104 assert not repo.changelog.filteredrevs |
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
105 # 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
|
106 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
|
107 getphase = repo._phasecache.phase |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
108 maymutable = filterrevs(repo, 'base') |
18274
254b708fd37d
performance: speedup computation of mutable revisions
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18273
diff
changeset
|
109 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
|
110 return frozenset() |
aff706b3a21c
clfilter: add mutable filtering
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18242
diff
changeset
|
111 |
18246
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
112 def computeimpactable(repo): |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
113 """Everything impactable by mutable revision |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
114 |
18462
593eb3786165
documentation: update to new filter names
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18445
diff
changeset
|
115 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
|
116 happen when: |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
117 |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
118 - you garbage collect hidden changeset, |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
119 - public phase is moved backward, |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
120 - 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
|
121 |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
122 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
|
123 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
|
124 |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
125 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
|
126 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
|
127 assert not repo.changelog.filteredrevs |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
128 cl = repo.changelog |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
129 firstmutable = len(cl) |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
130 for roots in repo._phasecache.phaseroots[1:]: |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
131 if roots: |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
132 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
|
133 # 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
|
134 firstmutable = max(0, firstmutable) |
18246
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
135 return frozenset(xrange(firstmutable, len(cl))) |
58ca19edc043
clfilter: add impactable filter
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18245
diff
changeset
|
136 |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
137 # 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
|
138 # |
20549
2025315cfb0c
comments: fix minor spelling issues found with spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20405
diff
changeset
|
139 # When adding a new filter you MUST update the table at: |
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
|
140 # mercurial.branchmap.subsettable |
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
|
141 # 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
|
142 # from scratch (very slow). |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
143 filtertable = {'visible': computehidden, |
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
144 'served': computeunserved, |
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
145 'immutable': computemutable, |
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
146 'base': computeimpactable} |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
147 |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18293
diff
changeset
|
148 def filterrevs(repo, filtername): |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
149 """returns set of filtered revision for this filter name""" |
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
|
150 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
|
151 func = filtertable[filtername] |
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
|
152 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
|
153 return repo.filteredrevcache[filtername] |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
154 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
155 class repoview(object): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
156 """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
|
157 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 - 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
|
162 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
|
163 - 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
|
164 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
165 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
|
166 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
|
167 - 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
|
168 - 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
|
169 - 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
|
170 from `repo.__dict__`. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
171 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
172 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
|
173 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
|
174 `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
|
175 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
|
176 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 `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
|
182 leads to the property below. |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
183 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
184 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
|
185 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
186 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
|
187 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
|
188 """ |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
189 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
190 def __init__(self, repo, filtername): |
31221
2faf233b88e4
repoview: convert attribute names to unicodes on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31049
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 object.__setattr__(self, r'_clcache', None) |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
195 |
18644
3e92772d5383
spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents:
18495
diff
changeset
|
196 # 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
|
197 @property |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
198 def changelog(self): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
199 """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
|
200 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
201 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
|
202 # some cache may be implemented later |
18445
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
203 unfi = self._unfilteredrepo |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
204 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
|
205 # 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
|
206 unfiindex = unfichangelog.index |
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
207 unfilen = len(unfiindex) - 1 |
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
208 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
|
209 |
18445
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
210 revs = filterrevs(unfi, self.filtername) |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
211 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
|
212 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
|
213 # 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
|
214 # recreated, and our clcache refers to garbage object |
332926212ef8
repoview: discard filtered changelog if index isn't shared with unfiltered
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27917
diff
changeset
|
215 if (cl is not None and |
332926212ef8
repoview: discard filtered changelog if index isn't shared with unfiltered
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27917
diff
changeset
|
216 (cl.index is not unfiindex or newkey != self._clcachekey)): |
27258
beda2c9dbbff
repoview: bypass changelog method to computed cache key
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
27257
diff
changeset
|
217 cl = None |
18445
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
218 # 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
|
219 if cl is None: |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
220 cl = copy.copy(unfichangelog) |
4d92e2d75cff
repoview: cache filtered changelog
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18443
diff
changeset
|
221 cl.filteredrevs = revs |
31358
4015dfc899bb
repoview: specify setattr values as native strings
Augie Fackler <augie@google.com>
parents:
31221
diff
changeset
|
222 object.__setattr__(self, r'_clcache', cl) |
4015dfc899bb
repoview: specify setattr values as native strings
Augie Fackler <augie@google.com>
parents:
31221
diff
changeset
|
223 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
|
224 return cl |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
225 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
226 def unfiltered(self): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
227 """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
|
228 return self._unfilteredrepo |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
229 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
230 def filtered(self, name): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
231 """Return a filtered version of a repository""" |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
232 if name == self.filtername: |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
233 return self |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
234 return self.unfiltered().filtered(name) |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
235 |
35249
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
236 def __repr__(self): |
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
237 return r'<%s:%s %r>' % (self.__class__.__name__, |
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
238 pycompat.sysstr(self.filtername), |
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
239 self.unfiltered()) |
d4ad9d695a9e
repoview: include filter name in repr for debugging
Yuya Nishihara <yuya@tcha.org>
parents:
35248
diff
changeset
|
240 |
18100
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
241 # 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
|
242 def __getattr__(self, attr): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
243 return getattr(self._unfilteredrepo, attr) |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
244 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
245 def __setattr__(self, attr, value): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
246 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
|
247 |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
248 def __delattr__(self, attr): |
3a6ddacb7198
clfilter: add actual repo filtering mechanism
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
249 return delattr(self._unfilteredrepo, attr) |
35248
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
250 |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
251 # 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
|
252 # 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
|
253 # 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
|
254 _filteredrepotypes = weakref.WeakKeyDictionary() |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
255 |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
256 def newtype(base): |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
257 """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
|
258 if base not in _filteredrepotypes: |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
259 class filteredrepo(repoview, base): |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
260 pass |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
261 _filteredrepotypes[base] = filteredrepo |
c752fbe228fb
repoview: extract a factory function of proxy class
Yuya Nishihara <yuya@tcha.org>
parents:
34649
diff
changeset
|
262 return _filteredrepotypes[base] |