annotate onsub.py @ 22:f21f26513968 default tip

Update for Mercurial 4.8.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 03 Nov 2018 23:38:48 -0700
parents 003eee5497e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
11fd0da50daa Copyright and license header
Martin Geisler <mg@aragost.com>
parents: 4
diff changeset
1 # onsub.py - execute commands recursively on subrepositories
11fd0da50daa Copyright and license header
Martin Geisler <mg@aragost.com>
parents: 4
diff changeset
2 #
11fd0da50daa Copyright and license header
Martin Geisler <mg@aragost.com>
parents: 4
diff changeset
3 # Copyright 2010, 2011 aragost Trifork
11fd0da50daa Copyright and license header
Martin Geisler <mg@aragost.com>
parents: 4
diff changeset
4 #
11fd0da50daa Copyright and license header
Martin Geisler <mg@aragost.com>
parents: 4
diff changeset
5 # This software may be used and distributed according to the terms of
11fd0da50daa Copyright and license header
Martin Geisler <mg@aragost.com>
parents: 4
diff changeset
6 # the GNU General Public License version 2 or any later version.
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
7
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
8 import os
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
9 from mercurial.i18n import _
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
10 from mercurial import extensions, subrepo, util, registrar
20
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
11
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
12 cmdtable = {}
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
13 command = registrar.command(cmdtable)
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
14
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
15 """execute a command in each subrepository"""
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
16
20
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
17 @command("onsub",
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
18 [('b', 'breadth-first', None,
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
19 _('use breadth-first traversal')),
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
20 ('p', 'post-order', None,
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
21 _('use post-order depth-first traversal')),
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
22 ('', 'root-repo', None,
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
23 _('include root repository in traversal')),
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
24 ('', 'max-depth', -1,
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
25 _('limit recursion to N levels (negative for no limit)'), 'N'),
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
26 ('', 'ignore-errors', None,
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
27 _('continue execution despite errors')),
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
28 ('t', 'type', '',
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
29 _('the type of repo to filter'), 'TYPE'),
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
30 ('0', 'print0', None,
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
31 _('end subrepository names with NUL, for use with xargs'))],
132e522fda32 compatibility with mercurial 3.8
viktor.kuzmin
parents: 18
diff changeset
32 _('[-b] [-0] [-t TYPE] [--ignore-errors] CMD [POST-CMD]'))
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
33 def onsub(ui, repo, *args, **opts):
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
34 """execute a command in each subrepository
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
35
7
a2ad7553ba79 Improve help text (in particular, clarify meaning of --print0).
Greg Ward <greg@gerg.ca>
parents: 6
diff changeset
36 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
37 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
38 non-zero exit code. Use --ignore-errors to override this.
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
39
14
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
40 If a POST-CMD is specified, this will be executed after all
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
41 subrepositories below the current subrepository has been visited.
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
42 This corresponds to a post-order traversal of the tree.
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
43
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
44 It is an error to specify a POST-CMD together with the
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
45 --breadth-first flag.
34aa014b5989 Add help for POST-CMD
Martin Geisler <mg@aragost.com>
parents: 12
diff changeset
46
7
a2ad7553ba79 Improve help text (in particular, clarify meaning of --print0).
Greg Ward <greg@gerg.ca>
parents: 6
diff changeset
47 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
48 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
49 --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
50 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
51 with :hg:`status --print0`.
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
52
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
53 The command has access to the following environment variables:
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
54
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
55 ``HG_REPO``:
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
56 Absolute path to the top-level repository in which the onsub
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
57 command was executed.
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
58
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
59 ``HG_SUBPATH``:
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
60 Relative path to the current subrepository from the top-level
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
61 repository.
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
62
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
63 ``HG_SUBURL``:
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
64 URL for the current subrepository as specified in the
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
65 containing repository's ``.hgsub`` file.
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
66
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
67 ``HG_SUBSTATE``:
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
68 State of the current subrepository as specified in the
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
69 containing repository's ``.hgsubstate`` file.
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
70
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
71 ``HG_SUBTYPE``:
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
72 The type of the current subrepository (hg, git or svn).
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
73 """
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
74
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
75 # 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
76 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
77 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
78 onerr = None
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
79 else:
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
80 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
81 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
82 precmd = None
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
83 postcmd = None
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
84 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
85 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
86
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
87 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
88 """if sub == None, cmd is executed inside repo; else, inside sub.
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
89 If cmd == None, do nothing. If cmd == '', do only the print0 (if needed).
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
90 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
91 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
92 """
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
93 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
94 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
95 HG_SUBURL='.',
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
96 HG_SUBSTATE=repo['.'].hex(),
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
97 HG_REPO=repo.root,
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
98 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
99 relpath = '.'
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
100 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
101 else:
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
102 # 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
103 # 18b5b6392fcf.
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
104 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
105 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
106 else:
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
107 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
108 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
109 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
110 HG_SUBSTATE=sub._state[1],
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
111 HG_REPO=repo.root,
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
112 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
113 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
114 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
115 if print0:
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
116 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
117 if cmd != '':
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
118 if not print0: ui.note(_("executing '%s' in %s\n") % (cmd, relpath))
21
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
119 rc = util.system(cmd, environ=envargdict, cwd=cmdwd)
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
120 if rc:
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
121 errprefix=_('terminated onsub in %s') % relpath
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
122 errmsg = '%s: %s' % (errprefix, errmsg)
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
123 try:
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
124 onerr.warn(errmsg + '\n')
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
125 except AttributeError:
003eee5497e0 * Hotfixed onsub for use with mercurial 4.1+
Matthias Muenzner <matthias.muenzner@jkaref.com>
parents: 20
diff changeset
126 raise onerr(errmsg)
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
127
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
128 def bfs():
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
129 """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
130 if includeroot:
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
131 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
132 ctx = repo['.']
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
133 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
134 while work:
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
135 (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
136 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
137 continue
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
138 execCmd(sub, precmd, kind)
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
139 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
140 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
141 ctx = sub._repo[rev]
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
142 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
143 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
144 work.extend(w)
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
145
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
146 def dfs():
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
147 """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
148
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
149 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
150 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
151 return
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
152 execCmd(sub, precmd, kind)
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
153 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
154 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
155 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
156 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
157 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
158 execCmd(sub, postcmd, kind)
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
159
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
160 ctx = repo['.']
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
161 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
162 if includeroot:
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
163 execCmd(None, precmd, 'hg')
17
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
164 for (sub, kind) in work:
5ea3f7533ec5 Exposed new environment variable with the subrepo type.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
165 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
166 if includeroot:
22
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
167 execCmd(None, postcmd, 'hg')
f21f26513968 Update for Mercurial 4.8.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
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 ### start of main function part ###
12
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
170 if len(args) == 2:
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
171 precmd = args[0]
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
172 postcmd = args[1]
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
173 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
174 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
175 elif len(args) == 1:
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
176 if opts.get('post_order'):
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
177 precmd = None
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
178 postcmd = args[0]
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
179 else:
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
180 precmd = args[0]
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
181 postcmd = None
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
182 elif len(args) == 0:
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
183 # cmd == '' means only do print0
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
184 if opts.get('post_order'):
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
185 precmd = None
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
186 postcmd = ''
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
187 else:
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
188 precmd = ''
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
189 postcmd = None
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
190 else:
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
191 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
192 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
193 raise util.Abort(_("onsub: '-b' and '-p' are mutually exclusive"))
0
e49f3bbfec4d Initial version.
Martin Geisler <mg@aragost.com>
parents:
diff changeset
194
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
195 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
196 bfs()
12
90b54c4fe4fe onsub extension: pre and post order
jakob krainz <jakob@hawo-net.de>
parents: 8
diff changeset
197 else:
16
44feac64ecfe refactoring: disentangled breadth-first and depth-first search; made functions nested
jakob krainz <jakob@hawo-net.de>
parents: 14
diff changeset
198 dfs()