changeset 14323:a79fea6b3e77

debugindex etc.: add --changelog and --manifest options These open the changelog and manifest, respectively, directly so you don't need to specify the path. The options have been added to debugindex, debugdata and debugrevlog. The patch also fixes some minor usage-related bugs.
author Sune Foldager <cryo@cyanite.org>
date Sat, 14 May 2011 00:30:32 +0200
parents a90131b85fd8
children d3a49a52f117
files mercurial/cmdutil.py mercurial/commands.py tests/test-clone-r.t tests/test-debugcomplete.t tests/test-excessive-merge.t tests/test-filebranch.t tests/test-strip-cross.t
diffstat 7 files changed, 66 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Fri May 13 14:58:24 2011 -0500
+++ b/mercurial/cmdutil.py	Sat May 14 00:30:32 2011 +0200
@@ -8,7 +8,7 @@
 from node import hex, nullid, nullrev, short
 from i18n import _
 import os, sys, errno, re, tempfile
-import util, scmutil, templater, patch, error, templatekw
+import util, scmutil, templater, patch, error, templatekw, revlog
 import match as matchmod
 import subrepo
 
@@ -170,6 +170,41 @@
                               pathname),
                 mode)
 
+def openrevlog(repo, cmd, file_, opts):
+    """opens the changelog, manifest, a filelog or a given revlog"""
+    cl = opts['changelog']
+    mf = opts['manifest']
+    msg = None
+    if cl and mf:
+        msg = _('cannot specify --changelog and --manifest 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 '
+                    'without a repository')
+    if msg:
+        raise util.Abort(msg)
+
+    r = None
+    if repo:
+        if cl:
+            r = repo.changelog
+        elif mf:
+            r = repo.manifest
+        elif file_:
+            filelog = repo.file(file_)
+            if len(filelog):
+                r = filelog
+    if not r:
+        if not file_:
+            raise error.CommandError(cmd, _('invalid arguments'))
+        if not os.path.isfile(file_):
+            raise util.Abort(_("revlog '%s' not found") % file_)
+        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
+                          file_[:-2] + ".i")
+    return r
+
 def copy(ui, repo, pats, opts, rename=False):
     # called with the repo lock held
     #
--- a/mercurial/commands.py	Fri May 13 14:58:24 2011 -0500
+++ b/mercurial/commands.py	Sat May 14 00:30:32 2011 +0200
@@ -1502,17 +1502,17 @@
         ui.write(line)
         ui.write("\n")
 
-@command('debugdata', [], _('FILE REV'))
-def debugdata(ui, repo, file_, rev):
+@command('debugdata',
+    [('c', 'changelog', False, _('open changelog')),
+     ('m', 'manifest', False, _('open manifest'))],
+    _('-c|-m|FILE REV'))
+def debugdata(ui, repo, file_, rev = None, **opts):
     """dump the contents of a data file revision"""
-    r = None
-    if repo:
-        filelog = repo.file(file_)
-        if len(filelog):
-            r = filelog
-    if not r:
-        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
-                          file_[:-2] + ".i")
+    if opts.get('changelog') or opts.get('manifest'):
+        file_, rev = None, file_
+    elif rev is None:
+        raise error.CommandError('debugdata', _('invalid arguments'))
+    r = cmdutil.openrevlog(repo, 'debugdata', file_, opts)
     try:
         ui.write(r.revision(r.lookup(rev)))
     except KeyError:
@@ -1645,23 +1645,17 @@
         raise util.Abort(_("no ignore patterns found"))
 
 @command('debugindex',
-    [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
-    _('FILE'))
-def debugindex(ui, repo, file_, **opts):
+    [('c', 'changelog', False, _('open changelog')),
+     ('m', 'manifest', False, _('open manifest')),
+     ('f', 'format', 0, _('revlog format'), _('FORMAT'))],
+    _('[-f FORMAT] -c|-m|FILE'))
+def debugindex(ui, repo, file_ = None, **opts):
     """dump the contents of an index file"""
-    r = None
-    if repo:
-        filelog = repo.file(file_)
-        if len(filelog):
-            r = filelog
-
+    r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
     format = opts.get('format', 0)
     if format not in (0, 1):
         raise util.Abort(_("unknown format %d") % format)
 
-    if not r:
-        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
-
     generaldelta = r.version & revlog.REVLOGGENERALDELTA
     if generaldelta:
         basehdr = ' delta'
@@ -1855,17 +1849,13 @@
         else:
             ui.write(_("%s not renamed\n") % rel)
 
-@command('debugrevlog', [], _('FILE'))
-def debugrevlog(ui, repo, file_):
+@command('debugrevlog',
+    [('c', 'changelog', False, _('open changelog')),
+     ('m', 'manifest', False, _('open manifest'))],
+     _('-c|-m|FILE'))
+def debugrevlog(ui, repo, file_ = None, **opts):
     """show data and statistics about a revlog"""
-    r = None
-    if repo:
-        filelog = repo.file(file_)
-        if len(filelog):
-            r = filelog
-    if not r:
-        r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
-
+    r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
     v = r.version
     format = v & 0xFFFF
     flags = []
@@ -5019,4 +5009,4 @@
           " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
           " debugknown debuggetbundle debugbundle")
 optionalrepo = ("identify paths serve showconfig debugancestor debugdag"
-                " debugdata debugindex debugindexdot")
+                " debugdata debugindex debugindexdot debugrevlog")
--- a/tests/test-clone-r.t	Fri May 13 14:58:24 2011 -0500
+++ b/tests/test-clone-r.t	Sat May 14 00:30:32 2011 +0200
@@ -56,7 +56,7 @@
      rev    offset  length   base linkrev nodeid       p1           p2
        0         0       8      0       6 12ab3bcc5ea4 000000000000 000000000000
 
-  $ hg debugindex .hg/store/00manifest.i
+  $ hg debugindex --manifest
      rev    offset  length   base linkrev nodeid       p1           p2
        0         0      48      0       0 43eadb1d2d06 000000000000 000000000000
        1        48      48      1       1 8b89697eba2c 43eadb1d2d06 000000000000
--- a/tests/test-debugcomplete.t	Fri May 13 14:58:24 2011 -0500
+++ b/tests/test-debugcomplete.t	Sat May 14 00:30:32 2011 +0200
@@ -219,20 +219,20 @@
   debugcommands: 
   debugcomplete: options
   debugdag: tags, branches, dots, spaces
-  debugdata: 
+  debugdata: changelog, manifest
   debugdate: extended
   debugdiscovery: old, nonheads, ssh, remotecmd, insecure
   debugfsinfo: 
   debuggetbundle: head, common, type
   debugignore: 
-  debugindex: format
+  debugindex: changelog, manifest, format
   debugindexdot: 
   debuginstall: 
   debugknown: 
   debugpushkey: 
   debugrebuildstate: rev
   debugrename: rev
-  debugrevlog: 
+  debugrevlog: changelog, manifest
   debugrevspec: 
   debugsetparents: 
   debugstate: nodates, datesort
--- a/tests/test-excessive-merge.t	Fri May 13 14:58:24 2011 -0500
+++ b/tests/test-excessive-merge.t	Sat May 14 00:30:32 2011 +0200
@@ -63,7 +63,7 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     test
   
-  $ hg debugindex .hg/store/00changelog.i
+  $ hg debugindex --changelog
      rev    offset  length   base linkrev nodeid       p1           p2
        0         0      60      0       0 5e0375449e74 000000000000 000000000000
        1        60      62      1       1 96155394af80 5e0375449e74 000000000000
--- a/tests/test-filebranch.t	Fri May 13 14:58:24 2011 -0500
+++ b/tests/test-filebranch.t	Sat May 14 00:30:32 2011 +0200
@@ -75,7 +75,7 @@
 
 main: we should have a merge here:
 
-  $ hg debugindex .hg/store/00changelog.i
+  $ hg debugindex --changelog
      rev    offset  length   base linkrev nodeid       p1           p2
        0         0      73      0       0 cdca01651b96 000000000000 000000000000
        1        73      68      1       1 f6718a9cb7f3 cdca01651b96 000000000000
--- a/tests/test-strip-cross.t	Fri May 13 14:58:24 2011 -0500
+++ b/tests/test-strip-cross.t	Sat May 14 00:30:32 2011 +0200
@@ -33,7 +33,7 @@
   $ cd ..
   $ hg clone -q -U -r -1 -r -2 -r -3 -r -4 -r -6 orig crossed
   $ cd crossed
-  $ hg debugindex .hg/store/00manifest.i
+  $ hg debugindex --manifest
      rev    offset  length   base linkrev nodeid       p1           p2
        0         0     112      0       0 6f105cbb914d 000000000000 000000000000
        1       112      56      1       3 1b55917b3699 000000000000 000000000000