# HG changeset patch # User Yuya Nishihara # Date 1525070609 -32400 # Node ID 2d0ec6097d7894b9688e0cc772b37754c944d99e # Parent b8edcb6935186a5f31c459b03818220b3152559e util: fix handling of empty short option This one was overlooked at 32e8d51ec16c. A dense form, '-sVALUE', shouldn't be used if an empty value is specified. diff -r b8edcb693518 -r 2d0ec6097d78 hglib/util.py --- a/hglib/util.py Wed Apr 25 13:32:18 2018 -0400 +++ b/hglib/util.py Mon Apr 30 15:43:29 2018 +0900 @@ -111,6 +111,14 @@ True >>> cmdbuilder(b('cmd'), b('-a')) == [b('cmd'), b('--'), b('-a')] True + >>> cmdbuilder(b('cmd'), b('')) == [b('cmd'), b('--'), b('')] + True + >>> cmdbuilder(b('cmd'), s=b('')) == [b('cmd'), b('-s'), b('')] + True + >>> cmdbuilder(b('cmd'), s=[b('')]) == [b('cmd'), b('-s'), b('')] + True + >>> cmdbuilder(b('cmd'), long=b('')) == [b('cmd'), b('--long=')] + True """ cmd = [name] for arg, val in kwargs.items(): @@ -118,8 +126,9 @@ continue arg = pfx = arg.encode('latin-1').replace(b('_'), b('-')) + short = (len(arg) == 1) if arg != b('-'): - if len(arg) == 1: + if short: arg = pfx = b('-') + arg else: arg = b('--') + arg @@ -129,9 +138,17 @@ cmd.append(arg) elif isinstance(val, list): for v in val: - cmd.append(pfx + _cmdval(v)) + s = _cmdval(v) + if s or not short: + cmd.append(pfx + s) + else: + cmd.extend([arg, s]) else: - cmd.append(pfx + _cmdval(val)) + s = _cmdval(val) + if s or not short: + cmd.append(pfx + s) + else: + cmd.extend([arg, s]) args = [a for a in args if a is not None] if args: diff -r b8edcb693518 -r 2d0ec6097d78 tests/test-log.py --- a/tests/test-log.py Wed Apr 25 13:32:18 2018 -0400 +++ b/tests/test-log.py Mon Apr 30 15:43:29 2018 +0900 @@ -27,6 +27,13 @@ self.assertTrue(len(revs) == 1) self.assertEquals(revs[0].rev, b('0')) + def test_empty_short_option(self): + self.append('foobar', 'foobar') + self.client.commit(b('first'), addremove=True) + revs = self.client.log(keyword=b(''), files=[b('foobar')]) + self.assertTrue(len(revs) == 1) + self.assertEquals(revs[0].rev, b('0')) + # def test_errors(self): # self.assertRaisesRegexp(CommandError, 'abort: unknown revision', # self.client.log, 'foo')