Mercurial > hg-onsub
annotate onsub.py @ 17:5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Updated test.
Added a test for mixed subrepo cases.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 27 Mar 2012 16:53:23 -0700 |
parents | 44feac64ecfe |
children | d920e3425db5 |
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') |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
66 |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
67 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
|
68 """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
|
69 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
|
70 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
|
71 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
|
72 """ |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
73 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
|
74 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
|
75 HG_SUBURL='.', |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
76 HG_SUBSTATE=repo['.'].hex(), |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
77 HG_REPO=repo.root, |
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
78 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
|
79 relpath = '.' |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
80 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
|
81 else: |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
82 # 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
|
83 # 18b5b6392fcf. |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
84 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
|
85 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
|
86 else: |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 HG_SUBSTATE=sub._state[1], |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
91 HG_REPO=repo.root, |
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
92 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
|
93 cmdwd = os.path.join(repo.root, relpath) |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
94 if cmd != None: |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
95 if print0: |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
96 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
|
97 if cmd != '': |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
102 def bfs(): |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
103 """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
|
104 if includeroot: |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
105 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
|
106 ctx = repo['.'] |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
107 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
|
108 while work: |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
109 (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
|
110 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
|
111 continue |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
112 execCmd(sub, precmd, kind) |
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
113 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
|
114 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
|
115 ctx = sub._repo[rev] |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
120 def dfs(): |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
121 """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
|
122 |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
123 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
|
124 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
|
125 return |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
126 execCmd(sub, precmd, kind) |
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
134 ctx = repo['.'] |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
135 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
|
136 if includeroot: |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
137 execCmd(None, precmd, 'hg') |
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
138 for (sub, kind) in work: |
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
139 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
|
140 if includeroot: |
17
5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
141 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
|
142 |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
143 ### start of main function part ### |
12
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
144 if len(args) == 2: |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
145 precmd = args[0] |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
146 postcmd = args[1] |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
147 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
|
148 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
|
149 elif len(args) == 1: |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
150 if opts.get('post_order'): |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
151 precmd = None |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
152 postcmd = args[0] |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
153 else: |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
154 precmd = args[0] |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
155 postcmd = None |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
156 elif len(args) == 0: |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
157 # cmd == '' means only do print0 |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
158 if opts.get('post_order'): |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
159 precmd = None |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
160 postcmd = '' |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
161 else: |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
162 precmd = '' |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
163 postcmd = None |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
164 else: |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
165 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
|
166 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
|
167 raise util.Abort(_("onsub: '-b' and '-p' are mutually exclusive")) |
0 | 168 |
16
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
169 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
|
170 bfs() |
12
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
171 else: |
16
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
172 dfs() |
44feac64ecfe
refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents:
14
diff
changeset
|
173 |
0 | 174 cmdtable = { |
175 "onsub": | |
176 (onsub, | |
177 [('b', 'breadth-first', None, | |
178 _('use breadth-first traversal')), | |
12
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
179 ('p', 'post-order', None, |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
180 _('use post-order depth-first traversal')), |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
181 ('', 'root-repo', None, |
90b54c4fe4fe
onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents:
8
diff
changeset
|
182 _('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
|
183 ('', 'max-depth', -1, |
ecc4fd16555d
Add --max-depth option to limit depth of recursion.
Greg Ward <greg@gerg.ca>
parents:
7
diff
changeset
|
184 _('limit recursion to N levels (negative for no limit)'), 'N'), |
3 | 185 ('', 'ignore-errors', None, |
186 _('continue execution despite errors')), | |
0 | 187 ('0', 'print0', None, |
188 _('end subrepository names with NUL, for use with xargs'))], | |
14 | 189 _('[-b] [-0] [--ignore-errors] CMD [POST-CMD]')) |
0 | 190 } |