[PATCH 2 of 8] cmdalias & wrapcommand: remove is-comparisons with non-singletons

Martin Geisler mg at lazybytes.net
Tue Nov 16 16:54:04 CST 2010


Dan Villiom Podlaski Christiansen <danchr at gmail.com> writes:

> # HG changeset patch
> # User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
> # Date 1289939758 -3600
> # Branch stable
> # Node ID b5093e797e19679cc8e7b01a7fd41feba94c6c27
> # Parent  26ddc30bd301eadc5278e2161ebdae91a1a28025
> cmdalias & wrapcommand: remove is-comparisons with non-singletons.
>
> Regular equality comparisons are used instead. In the case of command
> table entries, this will compare the values rather than object
> identity. This should be safe, if ever so slightly slower.

I don't think it's a matter of being safe -- it's a matter of comparing
objects and there the 'is' operator is just fine. It is only when
comparing an object with a literal that we can get into trouble.

The code below is not interested in knowing if the entry returned by
cmdutil.findcmd is an unrelated object that is equal in value to e, it
wants to know if entry 'is' e. So I would not change this.

> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -200,7 +200,7 @@ class cmdalias(object):
>          try:
>              aliases, entry = cmdutil.findcmd(self.name, cmdtable)
>              for alias, e in cmdtable.iteritems():
> -                if e is entry:
> +                if e == entry:
>                      self.cmd = alias
>                      break
>              self.shadows = True
> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -120,7 +120,7 @@ def wrapcommand(table, command, wrapper)
>      assert hasattr(wrapper, '__call__')
>      aliases, entry = cmdutil.findcmd(command, table)
>      for alias, e in table.iteritems():
> -        if e is entry:
> +        if e == entry:
>              key = alias
>              break
>  
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

-- 
Martin Geisler

Mercurial links: http://mercurial.ch/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20101116/9184b7b9/attachment.pgp>


More information about the Mercurial-devel mailing list