annotate onsub.py @ 68:eb91fd5d49b3

minimally changed to get Cython Queue example working, Cython version
author Henry S Thompson <ht@inf.ed.ac.uk>
date Fri, 17 Jan 2025 15:43:56 +0000
parents c8bf62a6eb21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 # onsub.py - execute commands recursively on subrepositories
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 #
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 # Copyright 2010, 2011 aragost Trifork
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 #
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 # the GNU General Public License version 2 or any later version.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 import os
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 from mercurial.i18n import _
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 from mercurial import extensions, subrepo, util, registrar
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12 """execute a command in each subrepository"""
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14 cmdtable = {}
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 command = registrar.command(cmdtable)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 @command(b'onsub',
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 [(b'b', b'breadth-first', None,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 _(b'use breadth-first traversal')),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 (b'p', b'post-order', None,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 _(b'use post-order depth-first traversal')),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 (b'', b'root-repo', None,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23 _(b'include root repository in traversal')),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 (b'', b'max-depth', -1,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 _(b'limit recursion to N levels (negative for no limit)'), b'N'),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 (b'', b'ignore-errors', None,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 _(b'continue execution despite errors')),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
28 (b't', b'type', b'',
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
29 _(b'the type of repo to filter'), b'TYPE'),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
30 (b'0', b'print0', None,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
31 _(b'end subrepository names with NUL, for use with xargs'))],
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 _(b'[-b] [-0] [-t TYPE] [--ignore-errors] CMD [POST-CMD]'),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
33 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
34 helpbasic=True
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
35 )
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
36 def onsub(ui, repo, *args, **opts):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
37 """execute a command in each subrepository
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
38
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
39 Executes CMD with the current working directory set to the root of
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
40 each subrepository. By default, execution stops if CMD returns a
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
41 non-zero exit code. Use --ignore-errors to override this.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
42
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
43 If a POST-CMD is specified, this will be executed after all
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
44 subrepositories below the current subrepository has been visited.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
45 This corresponds to a post-order traversal of the tree.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
46
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 It is an error to specify a POST-CMD together with the
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 --breadth-first flag.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
49
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50 Use --verbose/-v to print the command being run and the subrepo
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
51 name for each run of CMD in a subrepo. Alternately, use
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
52 --print0/-0 to print just the subrepo name followed by a NUL
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
53 character instead of a newline. This can be useful in combination
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
54 with :hg:`status --print0`.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
55
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
56 The command has access to the following environment variables:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
57
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
58 ``HG_REPO``:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
59 Absolute path to the top-level repository in which the onsub
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
60 command was executed.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
61
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
62 ``HG_SUBPATH``:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
63 Relative path to the current subrepository from the top-level
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
64 repository.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
65
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
66 ``HG_SUBURL``:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
67 URL for the current subrepository as specified in the
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
68 containing repository's ``.hgsub`` file.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
69
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
70 ``HG_SUBSTATE``:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
71 State of the current subrepository as specified in the
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
72 containing repository's ``.hgsubstate`` file.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
73
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
74 ``HG_SUBTYPE``:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
75 The type of the current subrepository (hg, git or svn).
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
76 """
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
77
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
78 # function level "constants" - these won't be modified by the nested functions
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
79 print0 = opts.get('print0')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
80 if opts.get('ignore_errors'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
81 onerr = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
82 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
83 onerr = util.Abort
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
84 maxdepth = opts.get('max_depth')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
85 precmd = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
86 postcmd = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
87 includeroot = opts.get('root_repo')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
88 repotypefilter = opts.get('type')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
89
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
90 def execCmd(sub, cmd, kind):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
91 """if sub == None, cmd is executed inside repo; else, inside sub.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
92 If cmd == None, do nothing. If cmd == '', do only the print0 (if needed).
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
93 Else, do either print0 or the debugging message, then execute the command.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
94 kind is the type of the (sub)repo.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
95 """
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
96 if sub == None:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
97 envargdict = dict(HG_SUBPATH='.',
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
98 HG_SUBURL='.',
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
99 HG_SUBSTATE=repo['.'].hex(),
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
100 HG_REPO=repo.root,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
101 HG_SUBTYPE=kind)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
102 relpath = '.'
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
103 cmdwd = repo.root
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
104 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
105 # subrepo.relpath was renamed to subrepo.subrelpath in
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
106 # 18b5b6392fcf.
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
107 if hasattr(subrepo, 'relpath'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
108 relpath = subrepo.relpath(sub)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
109 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
110 relpath = subrepo.subrelpath(sub)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
111 envargdict = dict(HG_SUBPATH=relpath,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
112 HG_SUBURL=sub._path,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
113 HG_SUBSTATE=sub._state[1],
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
114 HG_REPO=repo.root,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
115 HG_SUBTYPE=kind)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
116 cmdwd = os.path.join(repo.root, relpath)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
117 if cmd != None and (repotypefilter == '' or repotypefilter == kind):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
118 if print0:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
119 ui.write(relpath, "\0")
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
120 if cmd != '':
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
121 if not print0: ui.write(_("executing '%s' in %s\n") % (cmd, relpath))
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
122 util.system(cmd, environ=envargdict, cwd=cmdwd, onerr=onerr,
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
123 errprefix=_('terminated onsub in %s') % relpath)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
124
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
125 def bfs():
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
126 """execute precmd in repo.root and in each subrepository, breadth-first"""
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
127 if includeroot:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
128 execCmd(None, precmd, 'hg')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
129 ctx = repo['.']
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
130 work = [(1, ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
131 while work:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
132 (depth, sub, kind) = work.pop(0)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
133 if depth > maxdepth >= 0:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
134 continue
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
135 execCmd(sub, precmd, kind)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
136 if kind == 'hg':
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
137 rev = sub._state[1]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
138 ctx = sub._repo[rev]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
139 w = [(depth + 1, ctx.sub(subpath), ctx.substate[subpath][2])
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
140 for subpath in sorted(ctx.substate)]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
141 work.extend(w)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
142
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
143 def dfs():
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
144 """execute pre-/postcmd in repo.root and in each subrepository, depth-first"""
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
145
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
146 def dfs_rek(depth, sub, kind):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
147 if depth > maxdepth >= 0:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
148 return
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
149 execCmd(sub, precmd, kind)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
150 if kind == 'hg':
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
151 rev = sub._state[1]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
152 ctx = sub._repo[rev]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
153 for subpath in sorted(ctx.substate):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
154 dfs_rek(depth+1, ctx.sub(subpath), ctx.substate[subpath][2])
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
155 execCmd(sub, postcmd, kind)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
156
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
157 ctx = repo['.']
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
158 work = [(ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
159 if includeroot:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
160 execCmd(None, precmd, 'hg')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
161 for (sub, kind) in work:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
162 dfs_rek(1, sub, kind)
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
163 if includeroot:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
164 execCmd(None, postcmd, 'hg')
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
165
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
166 ### start of main function part ###
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
167 if len(args) == 2:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
168 precmd = args[0]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
169 postcmd = args[1]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
170 if opts.get('breadth_first') or opts.get('post_order'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
171 raise util.Abort(_("onsub: '-b' and '-p' imply the use of only one command"))
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
172 elif len(args) == 1:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
173 if opts.get('post_order'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
174 precmd = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
175 postcmd = args[0]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
176 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
177 precmd = args[0]
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
178 postcmd = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
179 elif len(args) == 0:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
180 # cmd == '' means only do print0
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
181 if opts.get('post_order'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
182 precmd = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
183 postcmd = ''
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
184 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
185 precmd = ''
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
186 postcmd = None
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
187 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
188 raise util.Abort(_("onsub: at most 2 command arguments required"))
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
189 if opts.get('post_order') and opts.get('breadth_first'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
190 raise util.Abort(_("onsub: '-b' and '-p' are mutually exclusive"))
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
191
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
192 if opts.get('breadth_first'):
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
193 bfs()
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
194 else:
c8bf62a6eb21 from ???
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
195 dfs()