[PATCH 1 of 2 STABLE V3] util: add "shellsplit()" to centralize the logic to split command line

Mads Kiilerich mads at kiilerich.com
Fri Dec 5 08:54:19 CST 2014


On 12/05/2014 01:14 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1417781174 -32400
> #      Fri Dec 05 21:06:14 2014 +0900
> # Branch stable
> # Node ID 73b764f8fdf2c33ad56795ef2513d9687bd14734
> # Parent  57d35d3c1cf170513cc150c5021f5e3e0d7cdafb
> util: add "shellsplit()" to centralize the logic to split command line

It is not clear to me: What can this function do that shlex.split cannot?

Is it also relevant when on posix systems or could it (or most of the 
implementation) live in windows.py?

/Mads

> This is the preparation for fixing issue4463.
>
> This patch uses StringIO object to know exactly where the first shell
> delimiter character is placed in the case of "all=False", because
> "shlex.next()" returns the de-quoted string and this makes eliminating
> it from original string difficult in some complicated cases.
>
> For example, "shlex.next()" for '"foo"/"foo" bar baz' returns 'foo/foo'.
>
> On the other hand, "StringIO.tell()" allows us to know exactly what
> characters are not yet read in by shlex.
>
> This patch uses StringIO object also in the case of "all=True" but
> this doesn't have any problematic impact, because the shlex
> constructor itself creates StringIO object internally, if string
> object is passed as the parse target.
>
> Another patch series for "default" branch will replace existing
> "shlex.split()" invocations by "util.shellsplit()" (and add new
> "check-code.py" rule to prevent from using "shlex.split()").
>



More information about the Mercurial-devel mailing list