Mercurial > hg-onsub
changeset 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 | ef52038b4459 |
files | onsub.py test-onsub.t |
diffstat | 2 files changed, 35 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/onsub.py Sun Apr 24 10:07:03 2011 -0400 +++ b/onsub.py Sun Apr 24 11:09:36 2011 -0400 @@ -43,21 +43,26 @@ containing repository's ``.hgsubstate`` file. """ cmd = ' '.join(args) - foreach(ui, repo, cmd, not opts.get('breadth_first'), opts.get('print0'), + foreach(ui, repo, cmd, + not opts.get('breadth_first'), + opts.get('max_depth'), + opts.get('print0'), opts.get('ignore_errors')) -def foreach(ui, repo, cmd, depthfirst, print0, ignoreerrors): +def foreach(ui, repo, cmd, depthfirst, maxdepth, print0, ignoreerrors): """execute cmd in repo.root and in each subrepository""" ctx = repo['.'] - work = [ctx.sub(subpath) for subpath in sorted(ctx.substate)] + work = [(1, ctx.sub(subpath)) for subpath in sorted(ctx.substate)] if depthfirst: work.reverse() while work: if depthfirst: - sub = work.pop() + (depth, sub) = work.pop() else: - sub = work.pop(0) + (depth, sub) = work.pop(0) + if depth > maxdepth >= 0: + continue # subrepo.relpath was renamed to subrepo.subrelpath in # 18b5b6392fcf. @@ -85,7 +90,8 @@ if isinstance(sub, subrepo.hgsubrepo): rev = sub._state[1] ctx = sub._repo[rev] - w = [ctx.sub(subpath) for subpath in sorted(ctx.substate)] + w = [(depth + 1, ctx.sub(subpath)) + for subpath in sorted(ctx.substate)] if depthfirst: w.reverse() work.extend(w) @@ -95,6 +101,8 @@ (onsub, [('b', 'breadth-first', None, _('use breadth-first traversal')), + ('', 'max-depth', -1, + _('limit recursion to N levels (negative for no limit)'), 'N'), ('', 'ignore-errors', None, _('continue execution despite errors')), ('0', 'print0', None,
--- a/test-onsub.t Sun Apr 24 10:07:03 2011 -0400 +++ b/test-onsub.t Sun Apr 24 11:09:36 2011 -0400 @@ -40,6 +40,8 @@ options: -b --breadth-first use breadth-first traversal + --max-depth N limit recursion to N levels (negative for no limit) + (default: -1) --ignore-errors continue execution despite errors -0 --print0 end subrepository names with NUL, for use with xargs @@ -105,6 +107,25 @@ a/y/s a/y/t +Limit depth of traversal: + $ hg onsub --max-depth 1 'echo $HG_SUBPATH' + a + b + $ hg onsub --max-depth 2 'echo $HG_SUBPATH' + a + a/x + a/y + b + b/u + b/v + $ hg onsub --max-depth 2 -b 'echo $HG_SUBPATH' + a + b + a/x + a/y + b/u + b/v + Test aborting: $ hg onsub -v 'test $HG_SUBPATH != "a/y/r"'