[PATCH 1 of 3] tip: -S/--subrepos for hg tip to recurse on subrepositories
Erik Zielke
ez at aragost.com
Tue Oct 19 14:11:06 UTC 2010
# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1285578511 -7200
# Node ID 5945827cd267fd156f818e4f4778bdc569e77a8a
# Parent 62c8f7691bc3bb8c907831d40da1e22c0769d8da
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 template.
diff -r 62c8f7691bc3 -r 5945827cd267 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Sun Oct 10 09:50:25 2010 -0500
+++ b/mercurial/cmdutil.py Mon Sep 27 11:08:31 2010 +0200
@@ -731,7 +731,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
@@ -741,6 +741,7 @@
self.hunk = {}
self.lastheader = None
self.footer = None
+ self.subpath = subpath
def flush(self, rev):
if rev in self.header:
@@ -785,6 +786,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')
@@ -886,7 +890,7 @@
class changeset_templater(changeset_printer):
'''format changeset information.'''
- def __init__(self, ui, repo, patch, diffopts, mapfile, buffered):
+ def __init__(self, ui, repo, patch, diffopts, mapfile, buffered, subpath=None):
changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered)
formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
defaulttempl = {
@@ -897,6 +901,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 = {}
@@ -940,6 +945,7 @@
props['repo'] = self.repo
props['revcache'] = {'copies': copies}
props['cache'] = self.cache
+ props['subrepopath'] = self.subpath
# find correct templates for current mode
@@ -985,7 +991,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:
@@ -1017,7 +1023,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:
@@ -1029,7 +1035,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 62c8f7691bc3 -r 5945827cd267 mercurial/commands.py
--- a/mercurial/commands.py Sun Oct 10 09:50:25 2010 -0500
+++ b/mercurial/commands.py Mon Sep 27 11:08:31 2010 +0200
@@ -3744,9 +3744,7 @@
Returns 0 on success.
"""
- displayer = cmdutil.show_changeset(ui, repo, opts)
- displayer.show(repo[len(repo) - 1])
- displayer.close()
+ hg.tip(ui, repo, None, **opts)
def unbundle(ui, repo, fname1, *fnames, **opts):
"""apply one or more changegroup files
@@ -4455,7 +4453,7 @@
(tip,
[('p', 'patch', None, _('show patch')),
('g', 'git', None, _('use git extended diff format')),
- ] + templateopts,
+ ] + templateopts + subrepoopts,
_('[-p] [-g]')),
"unbundle":
(unbundle,
diff -r 62c8f7691bc3 -r 5945827cd267 mercurial/hg.py
--- a/mercurial/hg.py Sun Oct 10 09:50:25 2010 -0500
+++ b/mercurial/hg.py Mon Sep 27 11:08:31 2010 +0200
@@ -518,6 +518,17 @@
recurse()
return 0 # exit code is zero since we found outgoing changes
+def tip(ui, repo, subpath, **opts):
+ displayer = cmdutil.show_changeset(ui, repo, opts, subpath=subpath)
+ displayer.show(repo[len(repo) - 1])
+ displayer.close()
+
+ 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 62c8f7691bc3 -r 5945827cd267 mercurial/subrepo.py
--- a/mercurial/subrepo.py Sun Oct 10 09:50:25 2010 -0500
+++ b/mercurial/subrepo.py Mon Sep 27 11:08:31 2010 +0200
@@ -292,6 +292,9 @@
def fileflags(self, name):
"""return file flags"""
return ''
+
+ def tip(self, ui, source, **opts):
+ raise NotImplementedError
def archive(self, archiver, prefix):
for name in self.files():
@@ -336,6 +339,11 @@
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)
+ hg.tip(ui, self._repo, path, **opts)
+
def status(self, rev2, **opts):
try:
rev1 = self._state[1]
diff -r 62c8f7691bc3 -r 5945827cd267 mercurial/templatekw.py
--- a/mercurial/templatekw.py Sun Oct 10 09:50:25 2010 -0500
+++ 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 62c8f7691bc3 -r 5945827cd267 tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t Sun Oct 10 09:50:25 2010 -0500
+++ 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 62c8f7691bc3 -r 5945827cd267 tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t Sun Oct 10 09:50:25 2010 -0500
+++ 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