[PATCH 2 of 2] copy shared command options to prevent duplicates (issue2772)

Martin Geisler mg at aragost.com
Fri May 27 03:23:37 CDT 2011


Idan Kamara <idankk86 at gmail.com> writes:

> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1306428989 -10800
> # Node ID c0b716bb34d346c3c76589e3537430934898d0bd
> # Parent  838230858bfba5abfa76e9ed3b57ef0681cba1a2
> copy shared command options to prevent duplicates (issue2772)
>
> +# list all extensions in hgext/ and write them to hgrc
> +exts = [os.path.splitext(f)[0] for f in os.listdir(os.environ["TESTDIR"] + "/../hgext/")
> +        if os.path.splitext(f)[1] == '.py' and f not in ignore]

Mercurial already knows how to find the extension -- see 'hg help
extensions'. This is done with code in mercurial.extensions, I think you
can just call the disabled function there.

> +map(lambda x: hgrc.write(x + '=\n'), exts)
> +hgrc.close()

Though I like map, filter, etc, I really dislike using them with
side-effects like this. A normal for loop is much better:

  for e in exts:
      hgrc.write("%s =\n" % e)
  hgrc.close()

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/


More information about the Mercurial-devel mailing list