Mercurial > hg-onsub
changeset 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 |
files | onsub.py test-onsub-mixed.t test-onsub.t |
diffstat | 3 files changed, 84 insertions(+), 19 deletions(-) [+] |
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:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-onsub-mixed.t Tue Mar 27 16:53:23 2012 -0700 @@ -0,0 +1,56 @@ +Load extension: + + $ echo "[extensions]" >> $HGRCPATH + $ echo "onsub = $TESTDIR/onsub.py" >> $HGRCPATH + +Create some nicely nested subrepositories with mixed types: + + $ hg init + $ for d in a b; do hg init $d; echo "$d = $d" >> .hgsub; done + $ git init -q git-i + $ cd git-i + $ git config core.autocrlf false + $ echo something > something + $ git add something + $ git commit -q -m init + $ cd .. + $ echo "git-i = [git]$git-i" >> .hgsub + $ hg add .hgsub + + $ cd a + + $ git init -q git-j + $ cd git-j + $ git config core.autocrlf false + $ echo something > something + $ git add something + $ git commit -q -m init + $ cd .. + $ echo "git-j = [git]git-j" >> .hgsub + $ hg add .hgsub + + $ cd .. + + $ hg commit -m init -S + committing subrepository a + committing subrepository a/git-j + committing subrepository b + committing subrepository git-i + +Test the subrepo type + + $ hg onsub 'echo $HG_SUBPATH = $HG_SUBTYPE' + a = hg + a/git-j = git + b = hg + git-i = git + +Test the subrepo type including the root repository + + $ hg onsub 'echo $HG_SUBPATH = $HG_SUBTYPE' --root-repo + . = hg + a = hg + a/git-j = git + b = hg + git-i = git +
--- a/test-onsub.t Tue Mar 06 19:59:36 2012 +0100 +++ b/test-onsub.t Tue Mar 27 16:53:23 2012 -0700 @@ -44,6 +44,9 @@ 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). + options: -b --breadth-first use breadth-first traversal