Patchwork [hglib] client: update method parses only the line with known format

login
register
mail settings
Submitter Alexander Plavin
Date April 23, 2013, 5:20 p.m.
Message ID <e10a24363cdaef6a6cc9.1366737636@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1473/
State Superseded
Headers show

Comments

Alexander Plavin - April 23, 2013, 5:20 p.m.
# HG changeset patch
# User Alexander Plavin <me@aplavin.ru>
# Date 1366737561 -14400
# Node ID e10a24363cdaef6a6cc937d9f388d02d273416b8
# Parent  181d1a4115cf7f9ab23f4db2647d3974803aa6db
client: update method parses only the line with known format

Before this there was incorrect behaviour of update when output of 'hg update'
had multiple lines, e.g. with largefiles enabled
Alexander Plavin - April 23, 2013, 5:23 p.m.
However, don't know how to add test for it as hglib doesn't support
largefiles extension (and, if I get it right, any extension).


2013/4/23 Alexander Plavin <me@aplavin.ru>

> # HG changeset patch
> # User Alexander Plavin <me@aplavin.ru>
> # Date 1366737561 -14400
> # Node ID e10a24363cdaef6a6cc937d9f388d02d273416b8
> # Parent  181d1a4115cf7f9ab23f4db2647d3974803aa6db
> client: update method parses only the line with known format
>
> Before this there was incorrect behaviour of update when output of 'hg
> update'
> had multiple lines, e.g. with largefiles enabled
>
> diff -r 181d1a4115cf -r e10a24363cda hglib/client.py
> --- a/hglib/client.py   Tue Apr 02 01:11:47 2013 -0500
> +++ b/hglib/client.py   Tue Apr 23 21:19:21 2013 +0400
> @@ -1508,6 +1508,12 @@
>          # filter out 'merging ...' lines
>          out = util.skiplines(out, 'merging ')
>
> +        for line in out.split('\n'):
> +            # get only the line with known format, which contains 4
> counters
> +            if re.match('^\d+ [\w ]+(, \d+ [\w ]+){3}$', line):
> +                out = line
> +                break
> +
>          counters = out.rstrip().split(', ')
>          return tuple(int(s.split(' ', 1)[0]) for s in counters)
>
>
Idan Kamara - April 23, 2013, 6:38 p.m.
On Tue, Apr 23, 2013 at 8:20 PM, Alexander Plavin <me@aplavin.ru> wrote:

> # HG changeset patch
> # User Alexander Plavin <me@aplavin.ru>
> # Date 1366737561 -14400
> # Node ID e10a24363cdaef6a6cc937d9f388d02d273416b8
> # Parent  181d1a4115cf7f9ab23f4db2647d3974803aa6db
> client: update method parses only the line with known format
>
> Before this there was incorrect behaviour of update when output of 'hg
> update'
> had multiple lines, e.g. with largefiles enabled
>
> diff -r 181d1a4115cf -r e10a24363cda hglib/client.py
> --- a/hglib/client.py   Tue Apr 02 01:11:47 2013 -0500
> +++ b/hglib/client.py   Tue Apr 23 21:19:21 2013 +0400
> @@ -1508,6 +1508,12 @@
>          # filter out 'merging ...' lines
>          out = util.skiplines(out, 'merging ')
>

^ This is no longer necessary then.


> +        for line in out.split('\n'):
> +            # get only the line with known format, which contains 4
> counters
> +            if re.match('^\d+ [\w ]+(, \d+ [\w ]+){3}$', line):
> +                out = line
> +                break
> +
>

If we're bothering with a regex, might as well extract the counters with
groups instead of the trick below?


>          counters = out.rstrip().split(', ')
>          return tuple(int(s.split(' ', 1)[0]) for s in counters)
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff -r 181d1a4115cf -r e10a24363cda hglib/client.py
--- a/hglib/client.py	Tue Apr 02 01:11:47 2013 -0500
+++ b/hglib/client.py	Tue Apr 23 21:19:21 2013 +0400
@@ -1508,6 +1508,12 @@ 
         # filter out 'merging ...' lines
         out = util.skiplines(out, 'merging ')
 
+        for line in out.split('\n'):
+            # get only the line with known format, which contains 4 counters
+            if re.match('^\d+ [\w ]+(, \d+ [\w ]+){3}$', line):
+                out = line
+                break
+
         counters = out.rstrip().split(', ')
         return tuple(int(s.split(' ', 1)[0]) for s in counters)