Mercurial > hg-onsub
diff 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 |
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,