[PATCH 1 of 5] record: extract ishunk to a function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri May 22 16:50:46 CDT 2015



On 05/21/2015 06:17 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon at fb.com>
> # Date 1432243682 25200
> #      Thu May 21 14:28:02 2015 -0700
> # Node ID 6a07454641dd43d5b7ba727769df984f1647b4e9
> # Parent  451df92cec4912aefac57a4cf82e9268192c867b
> record: extract ishunk to a function
>
> We extract this code as we want to reuse it in revert -i.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -17,6 +17,10 @@
>   import crecord as crecordmod
>   import lock as lockmod
>
> +def ishunk(x):
> +    hunkclasses = (crecordmod.uihunk, patch.recordhunk)
> +    return isinstance(x, hunkclasses)

note: I'm sad every time I look at this isinstance code. I'm not sure 
what the other type are an why we can't just ducktype them.

There is also a suspicious AttributeError catching somewhere in the code.

What kind of object are in this 'chunks' variable if not hunk?


> +
>   def parsealiases(cmd):
>       return cmd.lstrip("^").split("|")
>
> @@ -59,8 +63,6 @@
>   def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
>               filterfn, *pats, **opts):
>       import merge as mergemod
> -    hunkclasses = (crecordmod.uihunk, patch.recordhunk)
> -    ishunk = lambda x: isinstance(x, hunkclasses)
>
>       if not ui.interactive():
>           raise util.Abort(_('running non-interactively, use %s instead') %
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list