[PATCH] log: follow filenames correctly through renames (issue2383)
Mads Kiilerich
mads at kiilerich.com
Fri Sep 17 21:42:51 CDT 2010
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1284777504 -7200
# Branch stable
# Node ID b6bc56c4e76ac22dfa7b1545aac2106385c07252
# Parent ed639917c825ca88ea738bbf940ac5d123bee806
log: follow filenames correctly through renames (issue2383)
Changeset f786fc4b8764 "fixed" issue647 but should have been like this:
Changeset printers show method now makes it possible to specify a custom
matcher. That is now used for the log command to follow renames of named files.
This patch is an early preview. Comments will be appreciated.
TODO:
Exactly when should we follow renames? Is fnmatch.files() the right test and
and should the new matcher inherit more than the filenames?
Add test
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -709,6 +709,8 @@
self.ui.write(self.footer)
def show(self, ctx, copies=None, matchfn=None, **props):
+ """Show changeset ctx.
+ matchfn is used for patch/diffstat if specified."""
if self.buffered:
self.ui.pushbuffer()
self._show(ctx, copies, matchfn, props)
@@ -799,9 +801,10 @@
self.showpatch(changenode, matchfn)
def showpatch(self, node, matchfn):
- if not matchfn:
- matchfn = self.patch
- if matchfn:
+ """Optionally show patch/stat, using matchfn if specified."""
+ if self.patch:
+ if not matchfn:
+ matchfn = self.patch
stat = self.diffopts.get('stat')
diff = self.diffopts.get('patch')
diffopts = patch.diffopts(self.ui, self.diffopts)
@@ -934,8 +937,8 @@
except SyntaxError, inst:
raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
-def show_changeset(ui, repo, opts, buffered=False):
- """show one changeset using template or regular display.
+def show_changeset(ui, repo, opts, buffered=False, matchfn=False):
+ """create changeset printer using template or regular display.
Display format will be the first non-empty hit of:
1. option 'template'
@@ -948,7 +951,7 @@
# options
patch = False
if opts.get('patch') or opts.get('stat'):
- patch = matchall(repo)
+ patch = matchfn or matchall(repo)
tmpl = opts.get('template')
style = None
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2498,7 +2498,7 @@
branches = opts.get('branch', []) + opts.get('only_branch', [])
opts['branch'] = [repo.lookupbranch(b) for b in branches]
- displayer = cmdutil.show_changeset(ui, repo, opts, True)
+ displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
def prep(ctx, fns):
rev = ctx.rev()
parents = [p for p in repo.changelog.parentrevs(rev)
@@ -2532,7 +2532,7 @@
copies.append((fn, rename[0]))
revmatchfn = None
- if opts.get('patch') or opts.get('stat'):
+ if matchfn.files():
revmatchfn = cmdutil.match(repo, fns, default='path')
displayer.show(ctx, copies=copies, matchfn=revmatchfn)
More information about the Mercurial-devel
mailing list