# HG changeset patch # User Matt Mackall # Date 2009-06-15 07:45:38 # Node ID 859f841937d08b16bce2d41e2382b101ec999867 # Parent 8b35b08724eb267353012675a104e36e028e5c1e subrepo: introduce basic state parsing diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -857,6 +857,14 @@ def debugstate(ui, repo, nodates=None): for f in repo.dirstate.copies(): ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) +def debugsub(ui, repo, rev=None): + if rev == '': + rev = None + for k,v in sorted(repo[rev].substate.items()): + ui.write('path %s\n' % k) + ui.write(' source %s\n' % v[0]) + ui.write(' revision %s\n' % v[1]) + def debugdata(ui, file_, rev): """dump the contents of a data file revision""" r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i") @@ -3228,6 +3236,10 @@ table = { (debugstate, [('', 'nodates', None, _('do not display the saved mtime'))], _('[OPTION]...')), + "debugsub": + (debugsub, + [('r', 'rev', '', _('revision to check'))], + _('[-r REV] [REV]')), "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')), "^diff": (diff, diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -7,7 +7,7 @@ from node import nullid, nullrev, short, hex from i18n import _ -import ancestor, bdiff, error, util +import ancestor, bdiff, error, util, subrepo import os, errno propertycache = util.propertycache @@ -73,6 +73,10 @@ class changectx(object): p = p[:-1] return [changectx(self._repo, x) for x in p] + @propertycache + def substate(self): + return subrepo.state(self) + def __contains__(self, key): return key in self._manifest diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py new file mode 100644 --- /dev/null +++ b/mercurial/subrepo.py @@ -0,0 +1,35 @@ +# subrepo.py - sub-repository handling for Mercurial +# +# Copyright 2006, 2007 Matt Mackall +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2, incorporated herein by reference. + +import config, util, errno + +def state(ctx): + p = config.config() + def read(f, sections=None, remap=None): + if f in ctx: + try: + p.parse(f, ctx[f].data(), sections, remap) + except IOError, err: + if err.errno != errno.ENOENT: + raise + read('.hgsub') + + rev = {} + if '.hgsubstate' in ctx: + try: + for l in ctx['.hgsubstate'].data().splitlines(): + revision, path = l.split() + rev[path] = revision + except IOError, err: + if err.errno != errno.ENOENT: + raise + + state = {} + for path, src in p[''].items(): + state[path] = (src, rev.get(path, '')) + + return state diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out --- a/tests/test-debugcomplete.out +++ b/tests/test-debugcomplete.out @@ -73,6 +73,7 @@ debugrebuildstate debugrename debugsetparents debugstate +debugsub debugwalk % Do not show the alias of a debug command if there are other candidates @@ -199,6 +200,7 @@ debugrebuildstate: rev debugrename: rev debugsetparents: debugstate: nodates +debugsub: rev debugwalk: include, exclude grep: print0, all, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude heads: rev, active, closed, style, template