[PATCH] commit: can now take a similarity option with --addremove (issue1503)

Matt Mackall mpm at selenic.com
Sat Mar 19 14:02:22 CDT 2011


On Sat, 2011-03-19 at 19:40 +0100, Miloš Hadžić wrote:
> # 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)

I noticed you've added yourself to our not-yet-official GSoC effort:

http://mercurial.selenic.com/wiki/SummerOfCode/2011

..so I guessed this patch was probably aimed at fulfilling our GSoC
'submit a patch' requirement. But then I remembered you got in a patch
already two days ago!

I'm not sure if this is a feature we actually want - there's not a lot
of demand for it so it's mostly feature creep.

> 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)

It'd probably be better to not duplicate this code and have the error
checking done in addremove itself. Then the logic here can be reduced
to:

if opts.get('addremove'):
   addremove(..., opts.get('similarity'))
elif opts.get('similarity'):
   abort(...)

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list