Mercurial > hg-onsub
diff onsub.py @ 17:5ea3f7533ec5
Exposed new environment variable with the subrepo type.
Updated test.
Added a test for mixed subrepo cases.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 27 Mar 2012 16:53:23 -0700 |
parents | 44feac64ecfe |
children | d920e3425db5 |
line wrap: on
line diff
--- a/onsub.py Tue Mar 06 19:59:36 2012 +0100 +++ b/onsub.py Tue Mar 27 16:53:23 2012 -0700 @@ -48,6 +48,9 @@ ``HG_SUBSTATE``: State of the current subrepository as specified in the containing repository's ``.hgsubstate`` file. + + ``HG_SUBTYPE``: + The type of the current subrepository (hg, git or svn). """ # function level "constants" - these won't be modified by the nested functions @@ -61,16 +64,18 @@ postcmd = None includeroot = opts.get('root_repo') - def execCmd(sub, cmd): + def execCmd(sub, cmd, kind): """if sub == None, cmd is executed inside repo; else, inside sub. If cmd == None, do nothing. If cmd == '', do only the print0 (if needed). Else, do either print0 or the debugging message, then execute the command. + kind is the type of the (sub)repo. """ if sub == None: envargdict = dict(HG_SUBPATH='.', HG_SUBURL='.', HG_SUBSTATE=repo['.'].hex(), - HG_REPO=repo.root) + HG_REPO=repo.root, + HG_SUBTYPE=kind) relpath = '.' cmdwd = repo.root else: @@ -83,7 +88,8 @@ envargdict = dict(HG_SUBPATH=relpath, HG_SUBURL=sub._path, HG_SUBSTATE=sub._state[1], - HG_REPO=repo.root) + HG_REPO=repo.root, + HG_SUBTYPE=kind) cmdwd = os.path.join(repo.root, relpath) if cmd != None: if print0: @@ -96,43 +102,43 @@ def bfs(): """execute precmd in repo.root and in each subrepository, breadth-first""" if includeroot: - execCmd(None, precmd) + execCmd(None, precmd, 'hg') ctx = repo['.'] - work = [(1, ctx.sub(subpath)) for subpath in sorted(ctx.substate)] + work = [(1, ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] while work: - (depth, sub) = work.pop(0) + (depth, sub, kind) = work.pop(0) if depth > maxdepth >= 0: continue - execCmd(sub, precmd) - if isinstance(sub, subrepo.hgsubrepo): + execCmd(sub, precmd, kind) + if kind == 'hg': rev = sub._state[1] ctx = sub._repo[rev] - w = [(depth + 1, ctx.sub(subpath)) + w = [(depth + 1, ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] work.extend(w) def dfs(): """execute pre-/postcmd in repo.root and in each subrepository, depth-first""" - def dfs_rek(depth, sub): + def dfs_rek(depth, sub, kind): if depth > maxdepth >= 0: return - execCmd(sub, precmd) - if isinstance(sub, subrepo.hgsubrepo): + execCmd(sub, precmd, kind) + if kind == 'hg': rev = sub._state[1] ctx = sub._repo[rev] for subpath in sorted(ctx.substate): - dfs_rek(depth+1, ctx.sub(subpath)) - execCmd(sub, postcmd) + dfs_rek(depth+1, ctx.sub(subpath), ctx.substate[subpath][2]) + execCmd(sub, postcmd, kind) ctx = repo['.'] - work = [ctx.sub(subpath) for subpath in sorted(ctx.substate)] + work = [(ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)] if includeroot: - execCmd(None, precmd) - for sub in work: - dfs_rek(1, sub) + execCmd(None, precmd, 'hg') + for (sub, kind) in work: + dfs_rek(1, sub, kind) if includeroot: - execCmd(None, postcmd) + execCmd(None, postcmd, 'hg') ### start of main function part ### if len(args) == 2: