diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -10,7 +10,7 @@ from i18n import _ import os, sys, errno, re, glob, tempfile import util, templater, patch, error, encoding, templatekw import match as matchmod -import similar, revset +import similar, revset, subrepo revrangesep = ':' @@ -683,14 +683,7 @@ def diffordiffstat(ui, repo, diffopts, n if listsubrepos: ctx1 = repo[node1] 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) + for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): if node2 is not None: node2 = bin(ctx2.substate[subpath][1]) submatch = matchmod.narrowmatcher(subpath, match) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1161,14 +1161,7 @@ class localrepository(repo.repository): r = modified, added, removed, deleted, unknown, ignored, clean if listsubrepos: - # 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) + for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): if working: rev2 = None else: diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -184,6 +184,16 @@ def _abssource(repo, push=False): return repo.ui.config('paths', 'default-push', repo.root) return repo.ui.config('paths', 'default', repo.root) +def itersubrepos(ctx1, ctx2): + """find subrepos in ctx1 or ctx2""" + # 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 sorted(subpaths.iteritems()): + yield subpath, ctx.sub(subpath) + def subrepo(ctx, path): """return instance of the right subrepo class for subrepo in path""" # subrepo inherently violates our import layering rules