Patchwork [hglib] commit: allow rev and node to be anywhere in the output

login
register
mail settings
Submitter Idan Kamara
Date Jan. 1, 2016, 12:57 a.m.
Message ID <2725547a5f92d61a6724.1451609824@idank-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/12455/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

Idan Kamara - Jan. 1, 2016, 12:57 a.m.
# HG changeset patch
# User Idan Kamara <idankk86@gmail.com>
# Date 1451609631 28800
#      Thu Dec 31 16:53:51 2015 -0800
# Node ID 2725547a5f92d61a672420569f7237b81b582fab
# Parent  ffca01835a7c4b84c494f33af485c9118de7d3d8
commit: allow rev and node to be anywhere in the output

a01d3d32b53a in hg changed the output of commit --debug so the committed
changeset isn't necessarily the last line.
Yuya Nishihara - Jan. 1, 2016, 10:05 a.m.
On Thu, 31 Dec 2015 16:57:04 -0800, Idan Kamara wrote:
> # HG changeset patch
> # User Idan Kamara <idankk86@gmail.com>
> # Date 1451609631 28800
> #      Thu Dec 31 16:53:51 2015 -0800
> # Node ID 2725547a5f92d61a672420569f7237b81b582fab
> # Parent  ffca01835a7c4b84c494f33af485c9118de7d3d8
> commit: allow rev and node to be anywhere in the output
> 
> a01d3d32b53a in hg changed the output of commit --debug so the committed
> changeset isn't necessarily the last line.

Looks good to me. A few nits follow.

> diff --git a/hglib/client.py b/hglib/client.py
> --- a/hglib/client.py
> +++ b/hglib/client.py
> @@ -568,8 +568,12 @@
>                            close_branch=closebranch, d=date, u=user, l=logfile,
>                            I=include, X=exclude, amend=amend)
>          out = self.rawcommand(args)
> -        rev, node = out.splitlines()[-1].rsplit(b(':'))
> -        return int(rev.split()[-1]), node
> +        m = re.search(b(r'^committed changeset (\d+):([0-9a-f]+)'), out,
> +                      re.MULTILINE)
> +        if not m:
> +            raise ValueError('revision and node not found in hg output: %r' % out)

 - this line exceeds 80 columns
 - I guess "out" is too long to be embedded in ValueError
Matt Mackall - Jan. 16, 2016, 6:02 p.m.
On Thu, 2015-12-31 at 16:57 -0800, Idan Kamara wrote:
> # HG changeset patch
> # User Idan Kamara <idankk86@gmail.com>
> # Date 1451609631 28800
> #      Thu Dec 31 16:53:51 2015 -0800
> # Node ID 2725547a5f92d61a672420569f7237b81b582fab
> # Parent  ffca01835a7c4b84c494f33af485c9118de7d3d8
> commit: allow rev and node to be anywhere in the output

Queued for hglib, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -568,8 +568,12 @@ 
                           close_branch=closebranch, d=date, u=user, l=logfile,
                           I=include, X=exclude, amend=amend)
         out = self.rawcommand(args)
-        rev, node = out.splitlines()[-1].rsplit(b(':'))
-        return int(rev.split()[-1]), node
+        m = re.search(b(r'^committed changeset (\d+):([0-9a-f]+)'), out,
+                      re.MULTILINE)
+        if not m:
+            raise ValueError('revision and node not found in hg output: %r' % out)
+        rev, node = m.groups()
+        return int(rev), node
 
     def config(self, names=[], untrusted=False, showsource=False):
         """Return a list of (section, key, value) config settings from all