Merge lp:~jelmer/bzr/diff-git into lp:bzr

Proposed by Jelmer Vernooij
Status: Superseded
Proposed branch: lp:~jelmer/bzr/diff-git
Merge into: lp:bzr
Diff against target: 70 lines (+15/-3)
4 files modified
bzrlib/builtins.py (+2/-1)
bzrlib/option.py (+2/-2)
bzrlib/tests/blackbox/test_diff.py (+3/-0)
bzrlib/tests/test_options.py (+8/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/diff-git
Reviewer Review Type Date Requested Status
Vincent Ladeuil Abstain
Review via email: mp+44185@code.launchpad.net

This proposal has been superseded by a proposal from 2011-01-14.

Commit message

Support value switches for 'bzr diff' formats.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This makes it possible to use value switches for the formats of "bzr diff". I use "bzr diff --format=git" quite a lot these days when communicating with upstreams, and it'd be great if I can just use "bzr diff --git".

Revision history for this message
Andrew Bennetts (spiv) wrote :

I'm +0 on the UI change... I think it's probably ok, but I'm a big user of non-default diff formats so I'd feel more comfortable if Martin's impeccable UI taste says so too. Martin?

The diff itself is reasonable, although you should add release-notes and whats-new entries.

Revision history for this message
Martin Pool (mbp) wrote :

On 20 December 2010 17:16, Andrew Bennetts
<email address hidden> wrote:
> I'm +0 on the UI change... I think it's probably ok, but I'm a big user of non-default diff formats so I'd feel more comfortable if Martin's impeccable UI taste says so too.  Martin?
>
> The diff itself is reasonable, although you should add release-notes and whats-new entries.

Generally speaking I'm not a big fan of format_switches, because

- it makes the help a bit less readable (though that could in
principle be fixed)
- it looks like there are more options than there actually are
- related, values that are reasonable option arguments cause trouble
with sphinx etc when presented as actual options, eg things that
contain a dot
- if we get an unknown option (because eg we don't have a plugin
installed) it is a bit harder to explain why (though this is only
theoretical because we don't currently explain why in this case)

I wonder here if we could instead support say -Fgit? Would that both
work, and be reasonably concise?

--
Martin

Revision history for this message
Vincent Ladeuil (vila) wrote :

I'm not a big fan of format_switches either :-/

On the other hand either we should stop using them or not object when they *can* be used...

But for your current issue, why don't you just use "bzr alias diff-git='bzr diff --format=git" ?

This will save you 2 keystrokes by invocation so the definition should be amortized with as little as 21 uses ;)

review: Abstain
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Mon, 2010-12-20 at 07:37 +0000, Martin Pool wrote:
> On 20 December 2010 17:16, Andrew Bennetts
> <email address hidden> wrote:
> > I'm +0 on the UI change... I think it's probably ok, but I'm a big user of non-default diff formats so I'd feel more comfortable if Martin's impeccable UI taste says so too. Martin?
> >
> > The diff itself is reasonable, although you should add release-notes and whats-new entries.
>
> Generally speaking I'm not a big fan of format_switches, because
>
> - it makes the help a bit less readable (though that could in
> principle be fixed)
> - it looks like there are more options than there actually are
> - related, values that are reasonable option arguments cause trouble
> with sphinx etc when presented as actual options, eg things that
> contain a dot
> - if we get an unknown option (because eg we don't have a plugin
> installed) it is a bit harder to explain why (though this is only
> theoretical because we don't currently explain why in this case)
>
> I wonder here if we could instead support say -Fgit? Would that both
> work, and be reasonably concise?
Hmm, that's true. I guess there's a bit of hypocrisy here on my part as
I've complained about format switches myself in the past, in particular
in upgrade.

A short format option would be nice.

Another reason for having value switches was discoverability. I wonder
if we could perhaps list the possible values in the help string for a
RegistryOption if value_switches is not set? At the moment "bzr diff
--format=git" is not very discoverable. I'm thinking along the lines of:

...
  --format=ARG Diff format to use. (unified, git) [unified]
...

Cheers,

Jelmer

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Mon, 2010-12-20 at 12:41 +0000, Vincent Ladeuil wrote:
> Review: Abstain
> I'm not a big fan of format_switches either :-/
>
> On the other hand either we should stop using them or not object when they *can* be used...
>
> But for your current issue, why don't you just use "bzr alias diff-git='bzr diff --format=git" ?
>
> This will save you 2 keystrokes by invocation so the definition should be amortized with as little as 21 uses ;)
Bazaar should have good usability out of the box as much as possible. As
this is something that would affect other users too I'm wary of working
around it with a local alias.

There are two issues with --format=git:

* it's not discoverable
* it's not very short

Having "bzr git --diff" is one way of addressing those. Perhaps there
are better alternatives (see my other reply).

Cheers,

Jelmer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/builtins.py'
2--- bzrlib/builtins.py 2011-01-12 01:01:53 +0000
3+++ bzrlib/builtins.py 2011-01-14 05:17:36 +0000
4@@ -1961,9 +1961,10 @@
5 type=unicode,
6 ),
7 RegistryOption('format',
8+ short_name='F',
9 help='Diff format to use.',
10 lazy_registry=('bzrlib.diff', 'format_registry'),
11- value_switches=False, title='Diff format'),
12+ title='Diff format'),
13 ]
14 aliases = ['di', 'dif']
15 encoding_type = 'exact'
16
17=== modified file 'bzrlib/option.py'
18--- bzrlib/option.py 2010-05-23 18:57:38 +0000
19+++ bzrlib/option.py 2011-01-14 05:17:36 +0000
20@@ -312,7 +312,7 @@
21
22 def __init__(self, name, help, registry=None, converter=None,
23 value_switches=False, title=None, enum_switch=True,
24- lazy_registry=None):
25+ lazy_registry=None, short_name=None):
26 """
27 Constructor.
28
29@@ -329,7 +329,7 @@
30 :param lazy_registry: A tuple of (module name, attribute name) for a
31 registry to be lazily loaded.
32 """
33- Option.__init__(self, name, help, type=self.convert)
34+ Option.__init__(self, name, help, type=self.convert, short_name=short_name)
35 self._registry = registry
36 if registry is None:
37 if lazy_registry is None:
38
39=== modified file 'bzrlib/tests/blackbox/test_diff.py'
40--- bzrlib/tests/blackbox/test_diff.py 2011-01-10 22:20:12 +0000
41+++ bzrlib/tests/blackbox/test_diff.py 2011-01-14 05:17:36 +0000
42@@ -323,6 +323,9 @@
43 self.build_tree_contents([('hello', 'hello world!\n')])
44 output = self.run_bzr('diff --format=boo', retcode=1)
45 self.assertTrue("BOO!" in output[0])
46+ output = self.run_bzr('diff --boo', retcode=1)
47+ self.assertTrue("BOO!" in output[0])
48+
49
50 class TestCheckoutDiff(TestDiff):
51
52
53=== modified file 'bzrlib/tests/test_options.py'
54--- bzrlib/tests/test_options.py 2011-01-12 01:01:53 +0000
55+++ bzrlib/tests/test_options.py 2011-01-14 05:17:36 +0000
56@@ -396,6 +396,14 @@
57 self.assertTrue(format.is_hidden('hidden'))
58 self.assertFalse(format.is_hidden('visible'))
59
60+ def test_short_name(self):
61+ registry = controldir.ControlDirFormatRegistry()
62+ opt = option.RegistryOption('format', help='', registry=registry)
63+ self.assertEquals(None, opt.short_name())
64+ opt = option.RegistryOption('format', short_name='F', help='',
65+ registry=registry)
66+ self.assertEquals('F', opt.short_name())
67+
68 def test_option_custom_help(self):
69 the_opt = option.Option.OPTIONS['help']
70 orig_help = the_opt.help[:]