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
=== modified file 'bzrlib/cmd_version_info.py'
--- bzrlib/cmd_version_info.py 2011-10-06 10:25:48 +0000
+++ bzrlib/cmd_version_info.py 2011-11-08 11:53:38 +0000
@@ -113,10 +113,15 @@
113 else:113 else:
114 b = wt.branch114 b = wt.branch
115115
116 if all or template:116 if all:
117 include_history = True117 include_history = True
118 check_clean = True118 check_clean = True
119 include_file_revisions = True119 include_file_revisions = True
120 if template:
121 include_history = True
122 include_file_revisions = True
123 if '{clean}' in template:
124 check_clean = True
120125
121 if revision is not None:126 if revision is not None:
122 revision_id = revision[0].as_revision_id(b)127 revision_id = revision[0].as_revision_id(b)
123128
=== modified file 'bzrlib/tests/blackbox/test_version_info.py'
--- bzrlib/tests/blackbox/test_version_info.py 2011-10-14 13:56:45 +0000
+++ bzrlib/tests/blackbox/test_version_info.py 2011-11-08 11:53:38 +0000
@@ -20,7 +20,7 @@
2020
21from bzrlib.revision import NULL_REVISION21from bzrlib.revision import NULL_REVISION
22from bzrlib.tests import TestCaseWithTransport22from bzrlib.tests import TestCaseWithTransport
2323from bzrlib.version_info_formats import VersionInfoBuilder
2424
25class TestVersionInfo(TestCaseWithTransport):25class TestVersionInfo(TestCaseWithTransport):
2626
@@ -150,7 +150,17 @@
150 '"{revno} {branch_nick} {clean}\n" branch')150 '"{revno} {branch_nick} {clean}\n" branch')
151 self.assertEqual("2 branch 0\n", out)151 self.assertEqual("2 branch 0\n", out)
152 self.assertEqual("", err)152 self.assertEqual("", err)
153 153
154 def test_custom_no_clean_in_template(self):
155 def should_not_be_called(self):
156 raise AssertionError("Method on %r should not have been used" % (self,))
157 self.overrideAttr(VersionInfoBuilder, "_extract_file_revisions",
158 should_not_be_called)
159 self.create_tree()
160 out, err = self.run_bzr('version-info --custom --template=r{revno} branch')
161 self.assertEqual("r2", out)
162 self.assertEqual("", err)
163
154 def test_non_ascii(self):164 def test_non_ascii(self):
155 """Test that we can output non-ascii data"""165 """Test that we can output non-ascii data"""
156 166
157167
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- doc/en/release-notes/bzr-2.5.txt 2011-11-07 15:08:19 +0000
+++ doc/en/release-notes/bzr-2.5.txt 2011-11-08 11:53:38 +0000
@@ -72,6 +72,10 @@
72* ``bzr upgrade`` no longer treats 'already up-to-date' exceptions as72* ``bzr upgrade`` no longer treats 'already up-to-date' exceptions as
73 errors. (Benoît Pierre, #716560).73 errors. (Benoît Pierre, #716560).
7474
75* ``bzr version-info`` no longer populates the clean state for custom
76 templates unless {clean} is explicitly asked for.
77 (Lawrence Mitchell, #882541)
78
75* Fix finding the CPU count when using Python >= 2.6 on BSD-based systems.79* Fix finding the CPU count when using Python >= 2.6 on BSD-based systems.
76 (Jelmer Vernooij, #887151)80 (Jelmer Vernooij, #887151)
7781