[PATCH hglib] hglib: update grep to cope with behavior change in hg 5.2
Augie Fackler
raf at durin42.com
Mon Mar 23 15:54:48 UTC 2020
queued, thanks
> On Mar 21, 2020, at 23:53, Daehyeok Mun <daehyeok at gmail.com> wrote:
>
> # HG changeset patch
> # User Daehyeok Mun <daehyeok at gmail.com>
> # Date 1584845990 25200
> # Sat Mar 21 19:59:50 2020 -0700
> # Node ID 0bea9671f133da45a644f85749d4fc99248e18a3
> # Parent 868a903689fd40b9b3b33fad8a29df44763c0283
> hglib: update grep to cope with behavior change in hg 5.2.
>
> Since version 5.2, revision filed not printed without all argument.
> Fixed inaccurate pasring result with lastest hg and changed test case.
>
> diff -r 868a903689fd -r 0bea9671f133 hglib/client.py
> --- a/hglib/client.py Wed Dec 11 10:25:17 2019 -0500
> +++ b/hglib/client.py Sat Mar 21 19:59:50 2020 -0700
> @@ -881,9 +881,11 @@
> raise error.CommandError(args, ret, out, err)
> return b('')
>
> - out = self.rawcommand(args, eh=eh).split(b('\0'))
> + out = self.rawcommand(args, eh=eh).split(b('\0'))[:-1]
>
> - fieldcount = 3
> + fieldcount = 1
> + if all or self.version < (5, 2):
> + fieldcount += 1
> if user:
> fieldcount += 1
> if date:
> @@ -892,8 +894,8 @@
> fieldcount += 1
> if all:
> fieldcount += 1
> - if fileswithmatches:
> - fieldcount -= 1
> + if not fileswithmatches:
> + fieldcount += 1
>
> return util.grouper(fieldcount, out)
>
> diff -r 868a903689fd -r 0bea9671f133 tests/test-grep.py
> --- a/tests/test-grep.py Wed Dec 11 10:25:17 2019 -0500
> +++ b/tests/test-grep.py Sat Mar 21 19:59:50 2020 -0700
> @@ -3,62 +3,62 @@
>
> class test_grep(common.basetest):
> def test_basic(self):
> - self.append('a', 'a\n')
> - self.append('b', 'ab\n')
> + self.append('a', 'x\n')
> + self.append('b', 'xy\n')
> self.client.commit(b('first'), addremove=True)
>
> # no match
> self.assertEquals(list(self.client.grep(b('c'))), [])
>
> if self.client.version >= (5, 2):
> - self.assertEquals(list(self.client.grep(b('a'))),
> - [(b('a'), b('a'), b('b'))])
> - self.assertEquals(list(self.client.grep(b('a'), b('a'))),
> - [(b('a'), b('a'), b(''))])
> + self.assertEquals(list(self.client.grep(b('x'))),
> + [(b('a'), b('x')), (b('b'), b('xy'))])
> + self.assertEquals(list(self.client.grep(b('x'), b('a'))),
> + [(b('a'), b('x'))])
>
> - self.assertEquals(list(self.client.grep(b('b'))),
> - [(b('b'), b('ab'), b(''))])
> + self.assertEquals(list(self.client.grep(b('y'))),
> + [(b('b'), b('xy'))])
> else:
> - self.assertEquals(list(self.client.grep(b('a'))),
> - [(b('a'), b('0'), b('a')), (b('b'), b('0'), b('ab'))])
> - self.assertEquals(list(self.client.grep(b('a'), b('a'))),
> - [(b('a'), b('0'), b('a'))])
> -
> - self.assertEquals(list(self.client.grep(b('b'))),
> - [(b('b'), b('0'), b('ab'))])
> + self.assertEquals(list(self.client.grep(b('x'))),
> + [(b('a'), b('0'), b('x')), (b('b'), b('0'), b('xy'))])
> + self.assertEquals(list(self.client.grep(b('x'), b('a'))),
> + [(b('a'), b('0'), b('x'))])
> + self.assertEquals(list(self.client.grep(b('y'))),
> + [(b('b'), b('0'), b('xy'))])
>
> def test_options(self):
> - self.append('a', 'a\n')
> - self.append('b', 'ab\n')
> + self.append('a', 'x\n')
> + self.append('b', 'xy\n')
> rev, node = self.client.commit(b('first'), addremove=True)
>
> - self.assertEquals([(b('a'), b('0'), b('+'), b('a')),
> - (b('b'), b('0'), b('+'), b('ab'))],
> - list(self.client.grep(b('a'), all=True)))
> + self.assertEquals([(b('a'), b('0'), b('+'), b('x')),
> + (b('b'), b('0'), b('+'), b('xy'))],
> + list(self.client.grep(b('x'), all=True)))
>
> if self.client.version >= (5, 2):
> - self.assertEquals([(b('a'), b('b'))],
> - list(self.client.grep(b('a'), fileswithmatches=True)))
> + self.assertEquals([(b('a'),), (b('b'),)],
> + list(self.client.grep(b('x'), fileswithmatches=True)))
>
> - self.assertEquals([(b('a'), b('1'), b('a'), b('b'))],
> - list(self.client.grep(b('a'), line=True)))
> + self.assertEquals([(b('a'), b('1'), b('x')), (b('b'), b('1'), b('xy'))],
> + list(self.client.grep(b('x'), line=True)))
>
> - self.assertEquals([(b('a'), b('test'), b('a'), b('b'))],
> - list(self.client.grep(b('a'), user=True)))
> + self.assertEquals([(b('a'), b('test'), b('x')),
> + (b('b'), b('test'), b('xy'))],
> + list(self.client.grep(b('x'), user=True)))
> else:
> self.assertEquals([(b('a'), b('0')), (b('b'), b('0'))],
> - list(self.client.grep(b('a'), fileswithmatches=True)))
> + list(self.client.grep(b('x'), fileswithmatches=True)))
>
> - self.assertEquals([(b('a'), b('0'), b('1'), b('a')),
> - (b('b'), b('0'), b('1'), b('ab'))],
> - list(self.client.grep(b('a'), line=True)))
> + self.assertEquals([(b('a'), b('0'), b('1'), b('x')),
> + (b('b'), b('0'), b('1'), b('xy'))],
> + list(self.client.grep(b('x'), line=True)))
>
> - self.assertEquals([(b('a'), b('0'), b('test'), b('a')),
> - (b('b'), b('0'), b('test'), b('ab'))],
> - list(self.client.grep(b('a'), user=True)))
> + self.assertEquals([(b('a'), b('0'), b('test'), b('x')),
> + (b('b'), b('0'), b('test'), b('xy'))],
> + list(self.client.grep(b('x'), user=True)))
>
> self.assertEquals([(b('a'), b('0'), b('1'), b('+'), b('test')),
> (b('b'), b('0'), b('1'), b('+'), b('test'))],
> - list(self.client.grep(b('a'), all=True, user=True,
> + list(self.client.grep(b('x'), all=True, user=True,
> line=True,
> fileswithmatches=True)))
>
> _______________________________________________
> Mercurial mailing list
> Mercurial at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial
More information about the Mercurial
mailing list