[PATCH] commit: can now take a similarity option with --addremove (issue1503)
Miloš Hadžić
milos.hadzic at gmail.com
Sat Mar 19 18:40:07 UTC 2011
# HG changeset patch
# User Miloš Hadžić <milos.hadzic at gmail.com>
# Date 1300559674 -3600
# Node ID d8f4bd324762fa36cf24fa456ae00be2f6a56eff
# Parent eaee75036725f1869ff272deb353505b696a5cdd
commit: can now take a similarity option with --addremove (issue1503)
This is a simple patch that adds the ability to set the similarity option of
--addremove while doing a commit. If the addremove option is not set but
similarity is, the function aborts. For example:
$ hg commit --similarity 50
$ abort: similarity must be used with --addremove
I haven't included any tests. I'm not sure if they are needed for this patch.
Perhaps a test for setting similarity without addremove would be needed?
diff -r eaee75036725 -r d8f4bd324762 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Sat Mar 19 01:34:49 2011 -0500
+++ b/mercurial/cmdutil.py Sat Mar 19 19:34:34 2011 +0100
@@ -1343,6 +1343,19 @@
# extract addremove carefully -- this function can be called from a command
# that doesn't support addremove
+ sim = opts.get('similarity')
+ if sim:
+ if opts.get('addremove'):
+ try:
+ sim = float(sim or 0)
+ except ValueError:
+ raise util.Abort(_("similarity must be a number"))
+ if sim < 0 or sim > 100:
+ raise util.Abort(_("similarity must be between 0 and 100"))
+ addremove(repo, pats, opts, similarity=sim / 100.0)
+ else:
+ raise util.Abort(_("similarity must be used with --addremove"))
+
if opts.get('addremove'):
addremove(repo, pats, opts)
diff -r eaee75036725 -r d8f4bd324762 mercurial/commands.py
--- a/mercurial/commands.py Sat Mar 19 01:34:49 2011 -0500
+++ b/mercurial/commands.py Sat Mar 19 19:34:34 2011 +0100
@@ -4387,7 +4387,7 @@
_('mark new/missing files as added/removed before committing')),
('', 'close-branch', None,
_('mark a branch as closed, hiding it from the branch list')),
- ] + walkopts + commitopts + commitopts2,
+ ] + walkopts + commitopts + commitopts2 + similarityopts,
_('[OPTION]... [FILE]...')),
"copy|cp":
(copy,
More information about the Mercurial-devel
mailing list