Merge lp:~wence/bzr/check-clean into lp:bzr

Proposed by Lawrence Mitchell
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 6245
Proposed branch: lp:~wence/bzr/check-clean
Merge into: lp:bzr
Diff against target: 66 lines (+22/-3)
3 files modified
bzrlib/cmd_version_info.py (+6/-1)
bzrlib/tests/blackbox/test_version_info.py (+12/-2)
doc/en/release-notes/bzr-2.5.txt (+4/-0)
To merge this branch: bzr merge lp:~wence/bzr/check-clean
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Martin Packman (community) Approve
Review via email: mp+80657@code.launchpad.net

Commit message

Only imply --check-clean for version-info if {clean} is in the template

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks Lawrence! This change looks like the right approach.

+ if template:
+ include_history = True
             include_file_revisions = True
+ if '{clean}' in template:
+ check_clean = True

Looking at bzrlib.version_info_formats.format_custom the other two options are ignored in this case anyway, so you could collapse the check to:

    elif template and "{clean}" in template:
        check_clean = True

The version info command seems generally a little confused about which options are usefully combined, arguably `--template "{clean}"` shouldn't work at all unless `--check-clean` is also passed, but as your branch shows it's easy enough to do the right thing. The templating format is pretty simplistic so a basic contains substring check is correct.

There are three things needed before this can land.

1) Describe the fix and credit yourself in doc/en/release-notes/bzr-2.5.txt - see doc/developers/HACKING.txt for details but basically add an entry under the 2.5b3 Bug Fixes section, sorted alphabetically.

2) The hard bit, this really needs a test so we don't regress this with future changes to version-info. I'm failing to come up with an elegant way to do this, but a test method in bzrlib.blackbox.test_version_info which does run_bzr with a template not containing "{clean}" is the basic setup. The best idea I've had from there is doing before run_bzr something like:

    def should_not_be_called(self):
        raise AssertionError("Method on %r should not have been used" % (self,))
    self.overrideAttr(version_info_formats.VersionInfoBuilder,
        "_extract_file_revisions", should_not_be_called)
    out = self.run_bzr(["version-info", "--custom", "--template r{revno}\\n"])
    self.assertEqual("r0\n", out)

This is ugly monkey patching depending on a private method and is vulnerable to refactoring, but there don't seem to be any better placed hooks.

You'll want to check that the test fails without your fix, and passes with it, using `./bzr selftest -s bb.test_version_info` or similar.

3) Execute <http://www.canonical.com/contributors> copied to Martin Pool.

review: Needs Fixing
Revision history for this message
Lawrence Mitchell (wence) wrote :

> Thanks Lawrence! This change looks like the right approach.
>
> Looking at bzrlib.version_info_formats.format_custom the other two options are
> ignored in this case anyway, so you could collapse the check to:
>
> elif template and "{clean}" in template:
> check_clean = True

I don't understand how this would work. If template is not None this else leg would never be taken.

Do you mean?

if template and "{clean}" in template:
    check_clean = True
elif template:
    ...

> The version info command seems generally a little confused about which options
> are usefully combined, arguably `--template "{clean}"` shouldn't work at all
> unless `--check-clean` is also passed, but as your branch shows it's easy
> enough to do the right thing. The templating format is pretty simplistic so a
> basic contains substring check is correct.

The test suite disagrees, it has a test "custom_implies_all"

>
> There are three things needed before this can land.
>
> 1) Describe the fix and credit yourself in doc/en/release-notes/bzr-2.5.txt -
> see doc/developers/HACKING.txt for details but basically add an entry under
> the 2.5b3 Bug Fixes section, sorted alphabetically.
>
> 2) The hard bit, this really needs a test so we don't regress this with future
> changes to version-info. I'm failing to come up with an elegant way to do
> this, but a test method in bzrlib.blackbox.test_version_info which does
> run_bzr with a template not containing "{clean}" is the basic setup. The best
> idea I've had from there is doing before run_bzr something like:
>
> def should_not_be_called(self):
> raise AssertionError("Method on %r should not have been used" %
> (self,))
> self.overrideAttr(version_info_formats.VersionInfoBuilder,
> "_extract_file_revisions", should_not_be_called)
> out = self.run_bzr(["version-info", "--custom", "--template r{revno}\\n"])
> self.assertEqual("r0\n", out)
>
> This is ugly monkey patching depending on a private method and is vulnerable
> to refactoring, but there don't seem to be any better placed hooks.

I can't see anything obvious, but I don't know the code base that well, so I've gone with this.

> You'll want to check that the test fails without your fix, and passes with it,
> using `./bzr selftest -s bb.test_version_info` or similar.

Seems to work fine.

> 3) Execute <http://www.canonical.com/contributors> copied to Martin Pool.

Done

Revision history for this message
Martin Packman (gz) wrote :

Great! Thanks for following up.

> > elif template and "{clean}" in template:
> > check_clean = True
>
> I don't understand how this would work. If template is not None this else leg
> would never be taken.

I meant instead of the current `if template` logic, rather than in addition to it.

> The test suite disagrees, it has a test "custom_implies_all"

That suggested change would upset this test though. I think the test is... probably asserting the wrong behaviour, but there's no need to change it for this bug fix, so let's not do that in this branch.

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

Looks good to me, just one not that could be fixed when landing:

62 + templates unless {clean} is explicitly asked for. (Lawrence
63 + Mitchell, #882541)

Author and bug number should be on the same line or some of our release related scripts will fail.

review: Approve
Revision history for this message
Lawrence Mitchell (wence) wrote :

> Looks good to me, just one not that could be fixed when landing:
>
> 62 + templates unless {clean} is explicitly asked for. (Lawrence
> 63 + Mitchell, #882541)
>
> Author and bug number should be on the same line or some of our release
> related scripts will fail.

Fixed

Revision history for this message
Martin Packman (gz) wrote :

You'll just need to merge bzr.dev to resolve the new conflict in the release notes. PQM which we use for landing branches is unfortunately not configured smart enough to move your news above the one just added by Jelmer. After that I'll land this,

Revision history for this message
Lawrence Mitchell (wence) wrote :

> You'll just need to merge bzr.dev to resolve the new conflict in the release
> notes. PQM which we use for landing branches is unfortunately not configured
> smart enough to move your news above the one just added by Jelmer. After that
> I'll land this,

Done in r6237.

Thanks,
Lawrence

Revision history for this message
Martin Packman (gz) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/cmd_version_info.py'
2--- bzrlib/cmd_version_info.py 2011-10-06 10:25:48 +0000
3+++ bzrlib/cmd_version_info.py 2011-11-08 11:53:38 +0000
4@@ -113,10 +113,15 @@
5 else:
6 b = wt.branch
7
8- if all or template:
9+ if all:
10 include_history = True
11 check_clean = True
12 include_file_revisions = True
13+ if template:
14+ include_history = True
15+ include_file_revisions = True
16+ if '{clean}' in template:
17+ check_clean = True
18
19 if revision is not None:
20 revision_id = revision[0].as_revision_id(b)
21
22=== modified file 'bzrlib/tests/blackbox/test_version_info.py'
23--- bzrlib/tests/blackbox/test_version_info.py 2011-10-14 13:56:45 +0000
24+++ bzrlib/tests/blackbox/test_version_info.py 2011-11-08 11:53:38 +0000
25@@ -20,7 +20,7 @@
26
27 from bzrlib.revision import NULL_REVISION
28 from bzrlib.tests import TestCaseWithTransport
29-
30+from bzrlib.version_info_formats import VersionInfoBuilder
31
32 class TestVersionInfo(TestCaseWithTransport):
33
34@@ -150,7 +150,17 @@
35 '"{revno} {branch_nick} {clean}\n" branch')
36 self.assertEqual("2 branch 0\n", out)
37 self.assertEqual("", err)
38-
39+
40+ def test_custom_no_clean_in_template(self):
41+ def should_not_be_called(self):
42+ raise AssertionError("Method on %r should not have been used" % (self,))
43+ self.overrideAttr(VersionInfoBuilder, "_extract_file_revisions",
44+ should_not_be_called)
45+ self.create_tree()
46+ out, err = self.run_bzr('version-info --custom --template=r{revno} branch')
47+ self.assertEqual("r2", out)
48+ self.assertEqual("", err)
49+
50 def test_non_ascii(self):
51 """Test that we can output non-ascii data"""
52
53
54=== modified file 'doc/en/release-notes/bzr-2.5.txt'
55--- doc/en/release-notes/bzr-2.5.txt 2011-11-07 15:08:19 +0000
56+++ doc/en/release-notes/bzr-2.5.txt 2011-11-08 11:53:38 +0000
57@@ -72,6 +72,10 @@
58 * ``bzr upgrade`` no longer treats 'already up-to-date' exceptions as
59 errors. (Benoît Pierre, #716560).
60
61+* ``bzr version-info`` no longer populates the clean state for custom
62+ templates unless {clean} is explicitly asked for.
63+ (Lawrence Mitchell, #882541)
64+
65 * Fix finding the CPU count when using Python >= 2.6 on BSD-based systems.
66 (Jelmer Vernooij, #887151)
67