# HG changeset patch # User Martin Geisler # Date 2010-09-07 14:23:55 # Node ID c0a8f9dea0f60cbef918e684b7623a2df5d2196e # Parent 7bccd04292a23f4d23e636aa6ef7d3a30a1329b9 subrepos: handle modified but uncommitted .hgsub diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -682,10 +682,17 @@ def diffordiffstat(ui, repo, diffopts, n if listsubrepos: ctx1 = repo[node1] - for subpath in ctx1.substate: - sub = ctx1.sub(subpath) + ctx2 = repo[node2] + # Create a (subpath, ctx) mapping where we prefer subpaths + # from ctx1. The subpaths from ctx2 are important when the + # .hgsub file has been modified (in ctx2) but not yet + # committed (in ctx1). + subpaths = dict.fromkeys(ctx2.substate, ctx2) + subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) + for subpath, ctx in subpaths.iteritems(): + sub = ctx.sub(subpath) if node2 is not None: - node2 = bin(repo[node2].substate[subpath][1]) + node2 = bin(ctx2.substate[subpath][1]) submatch = matchmod.narrowmatcher(subpath, match) sub.diff(diffopts, node2, submatch, changes=changes, stat=stat, fp=fp, prefix=prefix) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1161,8 +1161,14 @@ class localrepository(repo.repository): r = modified, added, removed, deleted, unknown, ignored, clean if listsubrepos: - for subpath in ctx1.substate: - sub = ctx1.sub(subpath) + # Create a (subpath, ctx) mapping where we prefer subpaths + # from ctx1. The subpaths from ctx2 are important when the + # .hgsub file has been modified (in ctx2) but not yet + # committed (in ctx1). + subpaths = dict.fromkeys(ctx2.substate, ctx2) + subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) + for subpath, ctx in subpaths.iteritems(): + sub = ctx.sub(subpath) if working: rev2 = None else: diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t --- a/tests/test-subrepo-recursion.t +++ b/tests/test-subrepo-recursion.t @@ -28,6 +28,36 @@ Create test repository: $ echo 'foo = foo' > .hgsub $ hg add .hgsub +Test recursive status without committing anything: + + $ hg status + A .hgsub + A foo/.hgsub + A foo/bar/z.txt + A foo/y.txt + A x.txt + +Test recursive diff without committing anything: + + $ hg diff foo + diff -r 000000000000 foo/.hgsub + --- /dev/null + +++ b/foo/.hgsub + @@ -0,0 +1,1 @@ + +bar = bar + diff -r 000000000000 foo/y.txt + --- /dev/null + +++ b/foo/y.txt + @@ -0,0 +1,1 @@ + +y1 + diff -r 000000000000 foo/bar/z.txt + --- /dev/null + +++ b/foo/bar/z.txt + @@ -0,0 +1,1 @@ + +z1 + +Commits: + $ hg commit -m 0-0-0 committing subrepository foo committing subrepository foo/bar