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