[PATCH] tip: -S/--subrepos for hg tip to recurse on subrepositories

Erik Zielke ez at aragost.com
Thu Sep 30 09:08:30 CDT 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1285578511 -7200
# Node ID 71891e2de2cc1f74cd166757e1a2ff52024505da
# Parent  234e9a63173db6eb117b952cccbc4ccc9fc297ab
tip: -S/--subrepos for hg tip to recurse on subrepositories

Option for tip to recurse on subrepositories.

Shows
  subrepo:  name of subrepo
before a sub repository changeset

And added {subrepo} as a keyword for templates to show subrepo name
with a templatex

diff -r 234e9a63173d -r 71891e2de2cc mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Thu Sep 30 12:46:46 2010 +0200
+++ b/mercurial/cmdutil.py	Mon Sep 27 11:08:31 2010 +0200
@@ -736,7 +736,7 @@
 class changeset_printer(object):
     '''show changeset information when templating not requested.'''
 
-    def __init__(self, ui, repo, patch, diffopts, buffered):
+    def __init__(self, ui, repo, patch, diffopts, buffered, subpath=None):
         self.ui = ui
         self.repo = repo
         self.buffered = buffered
@@ -746,6 +746,7 @@
         self.hunk = {}
         self.lastheader = None
         self.footer = None
+        self.subpath = subpath
 
     def flush(self, rev):
         if rev in self.header:
@@ -790,6 +791,9 @@
         parents = [(p, hexfunc(log.node(p)))
                    for p in self._meaningful_parentrevs(log, rev)]
 
+        if self.subpath:
+            self.ui.write(_("subrepo:     %s\n") % self.subpath)
+
         self.ui.write(_("changeset:   %d:%s\n") % (rev, hexfunc(changenode)),
                       label='log.changeset')
 
@@ -891,8 +895,10 @@
 class changeset_templater(changeset_printer):
     '''format changeset information.'''
 
-    def __init__(self, ui, repo, patch, diffopts, mapfile, buffered):
-        changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered)
+    def __init__(self, ui, repo, patch, diffopts,
+                 mapfile, buffered, subpath=None):
+        changeset_printer.__init__(self, ui, repo, patch,
+                                   diffopts, buffered, subpath)
         formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
         defaulttempl = {
             'parent': '{rev}:{node|formatnode} ',
@@ -902,6 +908,7 @@
             }
         # filecopy is preserved for compatibility reasons
         defaulttempl['filecopy'] = defaulttempl['file_copy']
+        self.subpath = subpath
         self.t = templater.templater(mapfile, {'formatnode': formatnode},
                                      cache=defaulttempl)
         self.cache = {}
@@ -945,6 +952,7 @@
         props['repo'] = self.repo
         props['revcache'] = {'copies': copies}
         props['cache'] = self.cache
+        props['subrepopath'] = self.subpath
 
         # find correct templates for current mode
 
@@ -990,7 +998,7 @@
         except SyntaxError, inst:
             raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
 
-def show_changeset(ui, repo, opts, buffered=False):
+def show_changeset(ui, repo, opts, buffered=False, subpath=None):
     """show one changeset using template or regular display.
 
     Display format will be the first non-empty hit of:
@@ -1022,7 +1030,7 @@
             style = util.expandpath(ui.config('ui', 'style', ''))
 
     if not (tmpl or style):
-        return changeset_printer(ui, repo, patch, opts, buffered)
+        return changeset_printer(ui, repo, patch, opts, buffered, subpath)
 
     mapfile = None
     if style and not tmpl:
@@ -1034,7 +1042,7 @@
                 mapfile = mapname
 
     try:
-        t = changeset_templater(ui, repo, patch, opts, mapfile, buffered)
+        t = changeset_templater(ui, repo, patch, opts, mapfile, buffered, subpath)
     except SyntaxError, inst:
         raise util.Abort(inst.args[0])
     if tmpl:
diff -r 234e9a63173d -r 71891e2de2cc mercurial/commands.py
--- a/mercurial/commands.py	Thu Sep 30 12:46:46 2010 +0200
+++ b/mercurial/commands.py	Mon Sep 27 11:08:31 2010 +0200
@@ -3719,6 +3719,8 @@
     displayer.show(repo[len(repo) - 1])
     displayer.close()
 
+    hg.tip(ui, repo, **opts)
+
 def unbundle(ui, repo, fname1, *fnames, **opts):
     """apply one or more changegroup files
 
@@ -4417,7 +4419,7 @@
         (tip,
          [('p', 'patch', None, _('show patch')),
           ('g', 'git', None, _('use git extended diff format')),
-         ] + templateopts,
+         ] + templateopts + subrepoopts ,
          _('[-p] [-g]')),
     "unbundle":
         (unbundle,
diff -r 234e9a63173d -r 71891e2de2cc mercurial/hg.py
--- a/mercurial/hg.py	Thu Sep 30 12:46:46 2010 +0200
+++ b/mercurial/hg.py	Mon Sep 27 11:08:31 2010 +0200
@@ -522,6 +522,13 @@
     recurse()
     return 0 # exit code is zero since we found outgoing changes
 
+def tip(ui, repo, **opts):
+    if opts.get('subrepos'):
+        ctx = repo[None]
+        for subpath in sorted(ctx.substate):
+            sub = ctx.sub(subpath)
+            sub.tip(ui, **opts)
+
 def revert(repo, node, choose):
     """revert changes to revision in node without updating dirstate"""
     return mergemod.update(repo, node, False, True, choose)[3] > 0
diff -r 234e9a63173d -r 71891e2de2cc mercurial/subrepo.py
--- a/mercurial/subrepo.py	Thu Sep 30 12:46:46 2010 +0200
+++ b/mercurial/subrepo.py	Mon Sep 27 11:08:31 2010 +0200
@@ -282,6 +282,9 @@
         """return file flags"""
         return ''
 
+    def tip(self, ui, source, **opts):
+        raise NotImplementedError
+
     def archive(self, archiver, prefix):
         for name in self.files():
             flags = self.fileflags(name)
@@ -324,6 +327,14 @@
         return cmdutil.add(ui, self._repo, match, dryrun, True,
                            os.path.join(prefix, self._path))
 
+    def tip(self, ui, **opts):
+        repo = self._repo
+        path = relpath(self)
+        displayer = cmdutil.show_changeset(ui, repo, opts, subpath=path)
+        displayer.show(repo[len(repo) - 1])
+        displayer.close()
+        hg.tip(ui, repo, **opts)
+
     def status(self, rev2, **opts):
         try:
             rev1 = self._state[1]
diff -r 234e9a63173d -r 71891e2de2cc mercurial/templatekw.py
--- a/mercurial/templatekw.py	Thu Sep 30 12:46:46 2010 +0200
+++ b/mercurial/templatekw.py	Mon Sep 27 11:08:31 2010 +0200
@@ -236,6 +236,9 @@
 def showrev(repo, ctx, templ, **args):
     return ctx.rev()
 
+def showsubrepo(**args):
+    return args['subrepopath']
+
 def showtags(**args):
     return showlist('tag', args['ctx'].tags(), **args)
 
@@ -267,5 +270,6 @@
     'node': shownode,
     'rev': showrev,
     'tags': showtags,
+    'subrepo': showsubrepo,
 }
 
diff -r 234e9a63173d -r 71891e2de2cc tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t	Thu Sep 30 12:46:46 2010 +0200
+++ b/tests/test-debugcomplete.t	Mon Sep 27 11:08:31 2010 +0200
@@ -243,7 +243,7 @@
   showconfig: untrusted
   tag: force, local, rev, remove, edit, message, date, user
   tags: 
-  tip: patch, git, style, template
+  tip: patch, git, style, template, subrepos
   unbundle: update
   verify: 
   version: 
diff -r 234e9a63173d -r 71891e2de2cc tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t	Thu Sep 30 12:46:46 2010 +0200
+++ b/tests/test-subrepo-recursion.t	Mon Sep 27 11:08:31 2010 +0200
@@ -341,6 +341,37 @@
   abort: cannot combine --bundle and --subrepos
   [255]
 
+Test recursive tip
+  $ hg tip -S
+  changeset:   2:1326fa26d0c0
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2-3-2
+  
+  subrepo:     foo
+  changeset:   3:65903cebad86
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2-3-2
+  
+  subrepo:     foo/bar
+  changeset:   2:31ecbdafd357
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2-3-2
+  
+Test recursive tip using template
+  $ hg tip -S --template '{subrepo}\n{rev}:{node|short} {desc}\n'
+  
+  2:1326fa26d0c0 2-3-2
+  foo
+  3:65903cebad86 2-3-2
+  foo/bar
+  2:31ecbdafd357 2-3-2
+
 Test missing subrepo:
 
   $ rm -r foo


More information about the Mercurial-devel mailing list