Mercurial > hg-onsub
comparison 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 |
comparison
equal
deleted
inserted
replaced
21:003eee5497e0 | 22:f21f26513968 |
---|---|
5 # This software may be used and distributed according to the terms of | 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. | 6 # the GNU General Public License version 2 or any later version. |
7 | 7 |
8 import os | 8 import os |
9 from mercurial.i18n import _ | 9 from mercurial.i18n import _ |
10 from mercurial import extensions, subrepo, util, cmdutil | 10 from mercurial import extensions, subrepo, util, registrar |
11 | 11 |
12 cmdtable = {} | 12 cmdtable = {} |
13 command = cmdutil.command(cmdtable) | 13 command = registrar.command(cmdtable) |
14 | 14 |
15 """execute a command in each subrepository""" | 15 """execute a command in each subrepository""" |
16 | 16 |
17 @command("onsub", | 17 @command("onsub", |
18 [('b', 'breadth-first', None, | 18 [('b', 'breadth-first', None, |
84 includeroot = opts.get('root_repo') | 84 includeroot = opts.get('root_repo') |
85 repotypefilter = opts.get('type') | 85 repotypefilter = opts.get('type') |
86 | 86 |
87 def execCmd(sub, cmd, kind): | 87 def execCmd(sub, cmd, kind): |
88 """if sub == None, cmd is executed inside repo; else, inside sub. | 88 """if sub == None, cmd is executed inside repo; else, inside sub. |
89 If cmd == None, do nothing. If cmd == '', do only the print0 (if needed). | 89 If cmd == None, do nothing. If cmd == '', do only the print0 (if needed). |
90 Else, do either print0 or the debugging message, then execute the command. | 90 Else, do either print0 or the debugging message, then execute the command. |
91 kind is the type of the (sub)repo. | 91 kind is the type of the (sub)repo. |
92 """ | 92 """ |
93 if sub == None: | 93 if sub == None: |
94 envargdict = dict(HG_SUBPATH='.', | 94 envargdict = dict(HG_SUBPATH='.', |
126 raise onerr(errmsg) | 126 raise onerr(errmsg) |
127 | 127 |
128 def bfs(): | 128 def bfs(): |
129 """execute precmd in repo.root and in each subrepository, breadth-first""" | 129 """execute precmd in repo.root and in each subrepository, breadth-first""" |
130 if includeroot: | 130 if includeroot: |
131 execCmd(None, precmd, 'hg') | 131 execCmd(None, precmd, 'hg') |
132 ctx = repo['.'] | 132 ctx = repo['.'] |
133 work = [(1, ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] | 133 work = [(1, ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] |
134 while work: | 134 while work: |
135 (depth, sub, kind) = work.pop(0) | 135 (depth, sub, kind) = work.pop(0) |
136 if depth > maxdepth >= 0: | 136 if depth > maxdepth >= 0: |
137 continue | 137 continue |
138 execCmd(sub, precmd, kind) | 138 execCmd(sub, precmd, kind) |
139 if kind == 'hg': | 139 if kind == 'hg': |
140 rev = sub._state[1] | 140 rev = sub._state[1] |
141 ctx = sub._repo[rev] | 141 ctx = sub._repo[rev] |
142 w = [(depth + 1, ctx.sub(subpath), ctx.substate[subpath][2]) | 142 w = [(depth + 1, ctx.sub(subpath), ctx.substate[subpath][2]) |
143 for subpath in sorted(ctx.substate)] | 143 for subpath in sorted(ctx.substate)] |
144 work.extend(w) | 144 work.extend(w) |
145 | 145 |
146 def dfs(): | 146 def dfs(): |
147 """execute pre-/postcmd in repo.root and in each subrepository, depth-first""" | 147 """execute pre-/postcmd in repo.root and in each subrepository, depth-first""" |
148 | 148 |
149 def dfs_rek(depth, sub, kind): | 149 def dfs_rek(depth, sub, kind): |
150 if depth > maxdepth >= 0: | 150 if depth > maxdepth >= 0: |
151 return | 151 return |
152 execCmd(sub, precmd, kind) | 152 execCmd(sub, precmd, kind) |
153 if kind == 'hg': | 153 if kind == 'hg': |
154 rev = sub._state[1] | 154 rev = sub._state[1] |
155 ctx = sub._repo[rev] | 155 ctx = sub._repo[rev] |
156 for subpath in sorted(ctx.substate): | 156 for subpath in sorted(ctx.substate): |
157 dfs_rek(depth+1, ctx.sub(subpath), ctx.substate[subpath][2]) | 157 dfs_rek(depth+1, ctx.sub(subpath), ctx.substate[subpath][2]) |
158 execCmd(sub, postcmd, kind) | 158 execCmd(sub, postcmd, kind) |
159 | 159 |
160 ctx = repo['.'] | 160 ctx = repo['.'] |
161 work = [(ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] | 161 work = [(ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] |
162 if includeroot: | 162 if includeroot: |
163 execCmd(None, precmd, 'hg') | 163 execCmd(None, precmd, 'hg') |
164 for (sub, kind) in work: | 164 for (sub, kind) in work: |
165 dfs_rek(1, sub, kind) | 165 dfs_rek(1, sub, kind) |
166 if includeroot: | 166 if includeroot: |
167 execCmd(None, postcmd, 'hg') | 167 execCmd(None, postcmd, 'hg') |
168 | 168 |
169 ### start of main function part ### | 169 ### start of main function part ### |
170 if len(args) == 2: | 170 if len(args) == 2: |
171 precmd = args[0] | 171 precmd = args[0] |
172 postcmd = args[1] | 172 postcmd = args[1] |
173 if opts.get('breadth_first') or opts.get('post_order'): | 173 if opts.get('breadth_first') or opts.get('post_order'): |