subrepo: introduce basic state parsing
authorMatt Mackall <mpm@selenic.com>
Mon, 15 Jun 2009 02:45:38 -0500
changeset 8812 859f841937d0
parent 8811 8b35b08724eb
child 8813 db3c1ab0e632
subrepo: introduce basic state parsing
mercurial/commands.py
mercurial/context.py
mercurial/subrepo.py
tests/test-debugcomplete.out
--- a/mercurial/commands.py	Mon Jun 15 00:03:27 2009 +0200
+++ b/mercurial/commands.py	Mon Jun 15 02:45:38 2009 -0500
@@ -857,6 +857,14 @@
     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 @@
         (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,
--- a/mercurial/context.py	Mon Jun 15 00:03:27 2009 +0200
+++ b/mercurial/context.py	Mon Jun 15 02:45:38 2009 -0500
@@ -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 @@
             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
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/subrepo.py	Mon Jun 15 02:45:38 2009 -0500
@@ -0,0 +1,35 @@
+# subrepo.py - sub-repository handling for Mercurial
+#
+# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
+#
+# 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
--- a/tests/test-debugcomplete.out	Mon Jun 15 00:03:27 2009 +0200
+++ b/tests/test-debugcomplete.out	Mon Jun 15 02:45:38 2009 -0500
@@ -73,6 +73,7 @@
 debugrename
 debugsetparents
 debugstate
+debugsub
 debugwalk
 
 % Do not show the alias of a debug command if there are other candidates
@@ -199,6 +200,7 @@
 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