[PATCH] treemanifest: add --dir option to debug{revlog,data,index}

Martin von Zweigbergk martinvonz at google.com
Fri May 15 23:37:27 CDT 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1428907866 25200
#      Sun Apr 12 23:51:06 2015 -0700
# Node ID bcf1b1acab3ee716cfdb59e32a6e5ff189816bbe
# Parent  1ef96a3b8b89a896f2c9f3f977dbef8f45bb0e26
treemanifest: add --dir option to debug{revlog,data,index}

It should be possible to debug the submanifest revlogs without having
to know where they are stored (in .hg/store/meta/), so let's add a
--dir option for this purpose.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -450,14 +450,17 @@
     """opens the changelog, manifest, a filelog or a given revlog"""
     cl = opts['changelog']
     mf = opts['manifest']
+    dir = opts['dir']
     msg = None
     if cl and mf:
         msg = _('cannot specify --changelog and --manifest at the same time')
+    elif cl and dir:
+        msg = _('cannot specify --changelog and --dir at the same time')
     elif cl or mf:
         if file_:
             msg = _('cannot specify filename with --changelog or --manifest')
         elif not repo:
-            msg = _('cannot specify --changelog or --manifest '
+            msg = _('cannot specify --changelog or --manifest or --dir '
                     'without a repository')
     if msg:
         raise util.Abort(msg)
@@ -466,6 +469,13 @@
     if repo:
         if cl:
             r = repo.unfiltered().changelog
+        elif dir:
+            if 'treemanifest' not in repo.requirements:
+                raise util.Abort(_("--dir can only be used on repos with "
+                                   "treemanifest enabled"))
+            dirlog = repo.dirlog(file_)
+            if len(dirlog):
+                r = dirlog
         elif mf:
             r = repo.manifest
         elif file_:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2056,7 +2056,8 @@
 
 @command('debugdata',
     [('c', 'changelog', False, _('open changelog')),
-     ('m', 'manifest', False, _('open manifest'))],
+     ('m', 'manifest', False, _('open manifest')),
+     ('', 'dir', False, _('open directory manifest'))],
     _('-c|-m|FILE REV'))
 def debugdata(ui, repo, file_, rev=None, **opts):
     """dump the contents of a data file revision"""
@@ -2227,6 +2228,7 @@
 @command('debugindex',
     [('c', 'changelog', False, _('open changelog')),
      ('m', 'manifest', False, _('open manifest')),
+     ('', 'dir', False, _('open directory manifest')),
      ('f', 'format', 0, _('revlog format'), _('FORMAT'))],
     _('[-f FORMAT] -c|-m|FILE'),
     optionalrepo=True)
@@ -2729,6 +2731,7 @@
 @command('debugrevlog',
     [('c', 'changelog', False, _('open changelog')),
      ('m', 'manifest', False, _('open manifest')),
+     ('', 'dir', False, _('open directory manifest')),
      ('d', 'dump', False, _('dump index data'))],
     _('-c|-m|FILE'),
     optionalrepo=True)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -460,6 +460,9 @@
     def manifest(self):
         return manifest.manifest(self.svfs)
 
+    def dirlog(self, dir):
+        return manifest.manifest(self.svfs, dir)
+
     @repofilecache('dirstate')
     def dirstate(self):
         warned = [0]
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -815,6 +815,8 @@
         indexfile = "00manifest.i"
         if dir:
             assert self._treeondisk
+            if not dir.endswith('/'):
+                dir = dir + '/'
             indexfile = "meta/" + dir + "00manifest.i"
         revlog.revlog.__init__(self, opener, indexfile)
         self._dir = dir
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -234,7 +234,7 @@
   debugcommands: 
   debugcomplete: options
   debugdag: tags, branches, dots, spaces
-  debugdata: changelog, manifest
+  debugdata: changelog, manifest, dir
   debugdate: extended
   debugdirstate: nodates, datesort
   debugdiscovery: old, nonheads, ssh, remotecmd, insecure
@@ -242,7 +242,7 @@
   debugfsinfo: 
   debuggetbundle: head, common, type
   debugignore: 
-  debugindex: changelog, manifest, format
+  debugindex: changelog, manifest, dir, format
   debugindexdot: 
   debuginstall: 
   debugknown: 
@@ -255,7 +255,7 @@
   debugpvec: 
   debugrebuilddirstate: rev
   debugrename: rev
-  debugrevlog: changelog, manifest, dump
+  debugrevlog: changelog, manifest, dir, dump
   debugrevspec: optimize
   debugsetparents: 
   debugsub: rev
diff --git a/tests/test-treemanifest.t b/tests/test-treemanifest.t
--- a/tests/test-treemanifest.t
+++ b/tests/test-treemanifest.t
@@ -30,7 +30,7 @@
   b\x00362fef284ce2ca02aecc8de6d5e8a1c3af0556fe (esc)
   dir1\x008b3ffd73f901e83304c83d33132c8e774ceac44ed (esc)
   e\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
-  $ hg debugdata .hg/store/meta/dir1/00manifest.i 0
+  $ hg debugdata --dir dir1 0
   a\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
   b\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
 
@@ -60,9 +60,9 @@
   $ echo 3 > dir2/a
   $ hg add dir2
   adding dir2/a
-  $ hg debugindex .hg/store/meta/dir1/00manifest.i > before
+  $ hg debugindex --dir dir1 > before
   $ hg ci -qm 'add dir2'
-  $ hg debugindex .hg/store/meta/dir1/00manifest.i > after
+  $ hg debugindex --dir dir1 > after
   $ diff before after
   $ rm before after
 
@@ -71,9 +71,9 @@
   $ hg rm dir1/dir1
   removing dir1/dir1/a
   removing dir1/dir1/b
-  $ hg debugindex .hg/store/meta/dir1/dir1/00manifest.i > before
+  $ hg debugindex --dir dir1/dir1 > before
   $ hg ci -qm 'remove dir1/dir1'
-  $ hg debugindex .hg/store/meta/dir1/dir1/00manifest.i > after
+  $ hg debugindex --dir dir1/dir1 > after
   $ diff before after
   $ rm before after
 
@@ -113,7 +113,7 @@
   5
   $ cat dir1/b
   6
-  $ hg debugindex .hg/store/meta/dir1/00manifest.i
+  $ hg debugindex --dir dir1
      rev    offset  length   base linkrev nodeid       p1           p2
        0         0      54      0       1 8b3ffd73f901 000000000000 000000000000
        1        54      68      0       2 b66d046c644f 8b3ffd73f901 000000000000
@@ -131,14 +131,14 @@
   $ hg ci -m 'modify dir2/a'
   created new head
 
-  $ hg debugindex .hg/store/meta/dir2/00manifest.i > before
+  $ hg debugindex --dir dir2 > before
   $ hg merge 'desc("modify dir1/a")'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg revert -r 'desc("modify dir2/a")' .
   reverting dir1/a (glob)
   $ hg ci -m 'merge, keeping parent 1'
-  $ hg debugindex .hg/store/meta/dir2/00manifest.i > after
+  $ hg debugindex --dir dir2 > after
   $ diff before after
   $ rm before after
 
@@ -147,7 +147,7 @@
 
   $ hg co 'desc("modify dir2/a")'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ hg debugindex .hg/store/meta/dir1/00manifest.i > before
+  $ hg debugindex --dir dir1 > before
   $ hg merge 'desc("modify dir1/a")'
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
@@ -155,7 +155,7 @@
   reverting dir2/a (glob)
   $ hg ci -m 'merge, keeping parent 2'
   created new head
-  $ hg debugindex .hg/store/meta/dir1/00manifest.i > after
+  $ hg debugindex --dir dir1 > after
   $ diff before after
   $ rm before after
 


More information about the Mercurial-devel mailing list