annotate hgext/directaccess.py @ 1371:30d42079f4a2

directaccess: add some commands to the directaccess list Before this patch we had a limited list of commands in the directaccess list. This patch adds about 20 commands to that list: - all the read-only commands in core supporting a rev as an argument - 'outgoing': since people can use 'outgoing' to know what is going to be pushed, the output of hg outgoing should be consistent with to the output of hg push and must therefore disallow directaccess since hg push forbids it.
author Laurent Charignon <lcharignon@fb.com>
date Wed, 17 Jun 2015 10:30:07 -0700
parents c02cdb97ebfa
children 7023a01b9007
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
1 """ This extension provides direct access
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
2 It is the ability to refer and access hidden sha in commands provided that you
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
3 know their value.
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
4 For example hg log -r xxx where xxx is a commit has should work whether xxx is
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
5 hidden or not as we assume that the user knows what he is doing when referring
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
6 to xxx.
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
7 """
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
8 from mercurial import extensions
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
9 from mercurial import cmdutil
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
10 from mercurial import repoview
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
11 from mercurial import branchmap
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
12 from mercurial import revset
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
13 from mercurial import error
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
14 from mercurial import commands
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
15 from mercurial import hg
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
16 from mercurial.i18n import _
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
17
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
18 cmdtable = {}
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
19 command = cmdutil.command(cmdtable)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
20
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
21 # By default, all the commands have directaccess with warnings
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
22 # List of commands that have no directaccess and directaccess with no warning
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
23 directaccesslevel = [
1371
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
24 # Format:
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
25 # ('nowarning', 'evolve', 'prune'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
26 # means: no directaccess warning, for the command in evolve named prune
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
27 #
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
28 # ('error', None, 'serve'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
29 # means: no directaccess for the command in core named serve
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
30 #
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
31 # The list is ordered alphabetically by command names, starting with all
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
32 # the commands in core then all the commands in the extensions
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
33 #
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
34 # The general guideline is:
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
35 # - remove directaccess warnings for read only commands
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
36 # - no direct access for commands with consequences outside of the repo
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
37 # - leave directaccess warnings for all the other commands
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
38 #
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
39 ('nowarning', None, 'annotate'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
40 ('nowarning', None, 'archive'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
41 ('nowarning', None, 'bisect'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
42 ('nowarning', None, 'bookmarks'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
43 ('nowarning', None, 'bundle'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
44 ('nowarning', None, 'cat'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
45 ('nowarning', None, 'diff'),
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
46 ('nowarning', None, 'export'),
1371
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
47 ('nowarning', None, 'identify'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
48 ('nowarning', None, 'import'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
49 ('nowarning', None, 'incoming'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
50 ('nowarning', None, 'log'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
51 ('nowarning', None, 'manifest'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
52 ('error', None, 'outgoing'), # confusing if push errors and not outgoing
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
53 ('error', None, 'push'), # destructive
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
54 ('nowarning', None, 'revert'),
1368
c02cdb97ebfa directaccess: disable directaccess for push and serve
Laurent Charignon <lcharignon@fb.com>
parents: 1367
diff changeset
55 ('error', None, 'serve'),
1371
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
56 ('nowarning', None, 'tags'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
57 ('nowarning', None, 'unbundle'),
30d42079f4a2 directaccess: add some commands to the directaccess list
Laurent Charignon <lcharignon@fb.com>
parents: 1368
diff changeset
58 ('nowarning', None, 'update'),
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
59 ]
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
60
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
61 def reposetup(ui, repo):
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
62 repo._explicitaccess = set()
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
63
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
64 def _computehidden(repo):
1363
2eaa2943f9f3 directaccess: use cached filteredrevs
Laurent Charignon <lcharignon@fb.com>
parents: 1360
diff changeset
65 hidden = repoview.filterrevs(repo, 'visible')
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
66 cl = repo.changelog
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
67 dynamic = hidden & repo._explicitaccess
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
68 if dynamic:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
69 blocked = cl.ancestors(dynamic, inclusive=True)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
70 hidden = frozenset(r for r in hidden if r not in blocked)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
71 return hidden
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
72
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
73 def setupdirectaccess():
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
74 """ Add two new filtername that behave like visible to provide direct access
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
75 and direct access with warning. Wraps the commands to setup direct access """
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
76 repoview.filtertable.update({'visible-directaccess-nowarn': _computehidden})
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
77 repoview.filtertable.update({'visible-directaccess-warn': _computehidden})
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
78 branchmap.subsettable['visible-directaccess-nowarn'] = 'visible'
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
79 branchmap.subsettable['visible-directaccess-warn'] = 'visible'
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
80
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
81 for warn, ext, cmd in directaccesslevel:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
82 try:
1347
b00c2fe51ac8 directaccess: don't crash when evolve is not loaded
Laurent Charignon <lcharignon@fb.com>
parents: 1339
diff changeset
83 cmdtable = extensions.find(ext).cmdtable if ext else commands.table
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
84 wrapper = wrapwitherror if warn == 'error' else wrapwithoutwarning
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
85 extensions.wrapcommand(cmdtable, cmd, wrapper)
1347
b00c2fe51ac8 directaccess: don't crash when evolve is not loaded
Laurent Charignon <lcharignon@fb.com>
parents: 1339
diff changeset
86 except (error.UnknownCommand, KeyError):
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
87 pass
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
88
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
89 def wrapwitherror(orig, ui, repo, *args, **kwargs):
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
90 if repo and repo.filtername == 'visible-directaccess-warn':
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
91 repo = repo.filtered('visible')
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
92 return orig(ui, repo, *args, **kwargs)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
93
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
94 def wrapwithoutwarning(orig, ui, repo, *args, **kwargs):
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
95 if repo and repo.filtername == 'visible-directaccess-warn':
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
96 repo = repo.filtered("visible-directaccess-nowarn")
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
97 return orig(ui, repo, *args, **kwargs)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
98
1360
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
99 def uisetup(ui):
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
100 """ Change ordering of extensions to ensure that directaccess extsetup comes
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
101 after the one of the extensions in the loadsafter list """
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
102 loadsafter = ui.configlist('directaccess','loadsafter')
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
103 order = list(extensions._order)
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
104 directaccesidx = order.index('directaccess')
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
105
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
106 # The min idx for directaccess to load after all the extensions in loadafter
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
107 minidxdirectaccess = directaccesidx
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
108
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
109 for ext in loadsafter:
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
110 try:
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
111 minidxdirectaccess = max(minidxdirectaccess, order.index(ext))
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
112 except ValueError:
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
113 pass # extension not loaded
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
114
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
115 if minidxdirectaccess > directaccesidx:
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
116 order.insert(minidxdirectaccess + 1, 'directaccess')
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
117 order.remove('directaccess')
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
118 extensions._order = order
5c13945b32fc directaccess: add mechanism to load directaccess after some other extensions
Laurent Charignon <lcharignon@fb.com>
parents: 1347
diff changeset
119
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
120 def _repository(orig, *args, **kwargs):
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
121 """Make visible-directaccess-warn the default filter for new repos"""
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
122 repo = orig(*args, **kwargs)
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
123 return repo.filtered("visible-directaccess-warn")
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
124
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
125 def extsetup(ui):
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
126 extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
1367
0c134ca37567 directaccess: change rule from opt-in to opt-out
Laurent Charignon <lcharignon@fb.com>
parents: 1363
diff changeset
127 extensions.wrapfunction(hg, 'repository', _repository)
1339
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
128 setupdirectaccess()
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
129
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
130 def gethashsymbols(tree):
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
131 # Returns the list of symbols of the tree that look like hashes
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
132 # for example for the revset 3::abe3ff it will return ('abe3ff')
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
133 if not tree:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
134 return []
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
135
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
136 if len(tree) == 2 and tree[0] == "symbol":
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
137 try:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
138 int(tree[1])
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
139 return []
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
140 except ValueError as e:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
141 return [tree[1]]
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
142 elif len(tree) == 3:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
143 return gethashsymbols(tree[1]) + gethashsymbols(tree[2])
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
144 else:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
145 return []
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
146
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
147 def _posttreebuilthook(orig, tree, repo):
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
148 # This is use to enabled direct hash access
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
149 # We extract the symbols that look like hashes and add them to the
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
150 # explicitaccess set
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
151 orig(tree, repo)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
152 filternm = ""
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
153 if repo is not None:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
154 filternm = repo.filtername
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
155 if filternm is not None and filternm.startswith('visible-directaccess'):
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
156 prelength = len(repo._explicitaccess)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
157 accessbefore = set(repo._explicitaccess)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
158 repo.symbols = gethashsymbols(tree)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
159 cl = repo.unfiltered().changelog
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
160 for node in repo.symbols:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
161 try:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
162 node = cl._partialmatch(node)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
163 except error.LookupError:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
164 node = None
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
165 if node is not None:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
166 rev = cl.rev(node)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
167 if rev not in repo.changelog:
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
168 repo._explicitaccess.add(rev)
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
169 if prelength != len(repo._explicitaccess):
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
170 if repo.filtername != 'visible-directaccess-nowarn':
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
171 unhiddencommits = repo._explicitaccess - accessbefore
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
172 repo.ui.warn( _("Warning: accessing hidden changesets %s "
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
173 "for write operation\n") %
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
174 (",".join([str(repo.unfiltered()[l])
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
175 for l in unhiddencommits])))
0e2eb196923a inhibit: create direct access extension
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
176 repo.invalidatevolatilesets()