Mercurial > hg-onsub
comparison onsub.py @ 8:ecc4fd16555d
Add --max-depth option to limit depth of recursion.
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Sun, 24 Apr 2011 11:09:36 -0400 |
parents | a2ad7553ba79 |
children | 90b54c4fe4fe |
comparison
equal
deleted
inserted
replaced
7:a2ad7553ba79 | 8:ecc4fd16555d |
---|---|
41 ``HG_SUBSTATE``: | 41 ``HG_SUBSTATE``: |
42 State of the current subrepository as specified in the | 42 State of the current subrepository as specified in the |
43 containing repository's ``.hgsubstate`` file. | 43 containing repository's ``.hgsubstate`` file. |
44 """ | 44 """ |
45 cmd = ' '.join(args) | 45 cmd = ' '.join(args) |
46 foreach(ui, repo, cmd, not opts.get('breadth_first'), opts.get('print0'), | 46 foreach(ui, repo, cmd, |
47 not opts.get('breadth_first'), | |
48 opts.get('max_depth'), | |
49 opts.get('print0'), | |
47 opts.get('ignore_errors')) | 50 opts.get('ignore_errors')) |
48 | 51 |
49 def foreach(ui, repo, cmd, depthfirst, print0, ignoreerrors): | 52 def foreach(ui, repo, cmd, depthfirst, maxdepth, print0, ignoreerrors): |
50 """execute cmd in repo.root and in each subrepository""" | 53 """execute cmd in repo.root and in each subrepository""" |
51 ctx = repo['.'] | 54 ctx = repo['.'] |
52 work = [ctx.sub(subpath) for subpath in sorted(ctx.substate)] | 55 work = [(1, ctx.sub(subpath)) for subpath in sorted(ctx.substate)] |
53 if depthfirst: | 56 if depthfirst: |
54 work.reverse() | 57 work.reverse() |
55 | 58 |
56 while work: | 59 while work: |
57 if depthfirst: | 60 if depthfirst: |
58 sub = work.pop() | 61 (depth, sub) = work.pop() |
59 else: | 62 else: |
60 sub = work.pop(0) | 63 (depth, sub) = work.pop(0) |
64 if depth > maxdepth >= 0: | |
65 continue | |
61 | 66 |
62 # subrepo.relpath was renamed to subrepo.subrelpath in | 67 # subrepo.relpath was renamed to subrepo.subrelpath in |
63 # 18b5b6392fcf. | 68 # 18b5b6392fcf. |
64 if hasattr(subrepo, 'relpath'): | 69 if hasattr(subrepo, 'relpath'): |
65 relpath = subrepo.relpath(sub) | 70 relpath = subrepo.relpath(sub) |
83 errprefix=_('terminated onsub in %s') % relpath) | 88 errprefix=_('terminated onsub in %s') % relpath) |
84 | 89 |
85 if isinstance(sub, subrepo.hgsubrepo): | 90 if isinstance(sub, subrepo.hgsubrepo): |
86 rev = sub._state[1] | 91 rev = sub._state[1] |
87 ctx = sub._repo[rev] | 92 ctx = sub._repo[rev] |
88 w = [ctx.sub(subpath) for subpath in sorted(ctx.substate)] | 93 w = [(depth + 1, ctx.sub(subpath)) |
94 for subpath in sorted(ctx.substate)] | |
89 if depthfirst: | 95 if depthfirst: |
90 w.reverse() | 96 w.reverse() |
91 work.extend(w) | 97 work.extend(w) |
92 | 98 |
93 cmdtable = { | 99 cmdtable = { |
94 "onsub": | 100 "onsub": |
95 (onsub, | 101 (onsub, |
96 [('b', 'breadth-first', None, | 102 [('b', 'breadth-first', None, |
97 _('use breadth-first traversal')), | 103 _('use breadth-first traversal')), |
104 ('', 'max-depth', -1, | |
105 _('limit recursion to N levels (negative for no limit)'), 'N'), | |
98 ('', 'ignore-errors', None, | 106 ('', 'ignore-errors', None, |
99 _('continue execution despite errors')), | 107 _('continue execution despite errors')), |
100 ('0', 'print0', None, | 108 ('0', 'print0', None, |
101 _('end subrepository names with NUL, for use with xargs'))], | 109 _('end subrepository names with NUL, for use with xargs'))], |
102 _('[-b] [-0] [--ignore-errors] CMD')) | 110 _('[-b] [-0] [--ignore-errors] CMD')) |