Merge lp:~knittl/bzr/cat-signature into lp:bzr

Proposed by Daniel Knittl-Frank
Status: Work in progress
Proposed branch: lp:~knittl/bzr/cat-signature
Merge into: lp:bzr
Diff against target: 110 lines (+84/-0)
3 files modified
bzrlib/builtins.py (+25/-0)
bzrlib/tests/blackbox/__init__.py (+1/-0)
bzrlib/tests/blackbox/test_cat_signature.py (+58/-0)
To merge this branch: bzr merge lp:~knittl/bzr/cat-signature
Reviewer Review Type Date Requested Status
Daniel Knittl-Frank (community) Needs Resubmitting
John A Meinel Needs Fixing
Review via email: mp+36467@code.launchpad.net

Description of the change

new hidden command `cat-signature` to print the signature for a commit

To post a comment you must log in.
lp:~knittl/bzr/cat-signature updated
5438. By Daniel Knittl-Frank <email address hidden>

Fix whitespace (4, not 2 per level)

Revision history for this message
John A Meinel (jameinel) wrote :

cmd_cat_signature should be indented to 4 spaces, not 2 as per our guidelines, and there should be some more spacing between options.

We probably also want the output encoding to be exact. The content should be 7-bit safe, but just in case.

I'm not sure that @display_command actually makes sense. It means that we'll ignore stuff like EPIPE, I'd probably take it off, but it isn't a big deal.

Something like:

+class cmd_cat_signature(Command):
+ __doc__ = """Show signature of a revision's testament"""
+
+ hidden = True
+ takes_options = ['revision']
+ takes_args = ['branch?']
+ encoding = 'exact'
+
+ def run(self, branch=u'.', revision=None):

46
47 === added file 'bzrlib/tests/blackbox/test_cat_signature.py'
48 --- bzrlib/tests/blackbox/test_cat_signature.py 1970-01-01 00:00:00 +0000
49 +++ bzrlib/tests/blackbox/test_cat_signature.py 2010-09-23 16:27:46 +0000
50 @@ -0,0 +1,58 @@
51 +# Copyright (C) 2007-2010 Canonical Ltd

Copyright for this file should be only 2010

But the tests themselves seem fine to me. And the actual functional code seems good.

review: Needs Fixing
lp:~knittl/bzr/cat-signature updated
5439. By Daniel Knittl-Frank <email address hidden>

Use exact encoding

5440. By Daniel Knittl-Frank <email address hidden>

Copyright 2010

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

Also, could you please execute the contributor agreement at
http://canonical.com/contributors/

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

Will mark as wip until the contributor agreement is sorted out.

Revision history for this message
Daniel Knittl-Frank (knittl) wrote :

> Will mark as wip until the contributor agreement is sorted out.

Does bzr still require contributors to sign a (canonical) CLA? Couldn't find anything in the Bazaar documentation.

review: Needs Resubmitting

Unmerged revisions

5440. By Daniel Knittl-Frank <email address hidden>

Copyright 2010

5439. By Daniel Knittl-Frank <email address hidden>

Use exact encoding

5438. By Daniel Knittl-Frank <email address hidden>

Fix whitespace (4, not 2 per level)

5437. By Daniel Knittl-Frank <email address hidden>

Add blackbox tests for cat-signature

5436. By Daniel Knittl-Frank <email address hidden>

Return non-zero exit code when there is no signature

5435. By Daniel Knittl-Frank <email address hidden>

Make command hidden

5434. By Daniel Knittl-Frank <email address hidden>

add cleanup line (used in cmd_testament)

5433. By Daniel Knittl-Frank <email address hidden>

rename to cat-signature to be consistent with cat-revision, etc.

5432. By Daniel Knittl-Frank <email address hidden>

new command: show-signature [-r revision] [branch]

prints the signature for the testament of a given revision

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 2010-09-20 04:56:26 +0000
3+++ bzrlib/builtins.py 2010-09-23 18:25:59 +0000
4@@ -4504,6 +4504,31 @@
5 self.outf.write(" %s\n" % path)
6 self.outf.write("\n")
7
8+class cmd_cat_signature(Command):
9+ __doc__ = """Show signature of a revision's testament"""
10+
11+ hidden = True
12+ takes_options = ['revision']
13+ takes_args = ['branch?']
14+ encoding = 'exact'
15+
16+ def run(self, branch=u'.', revision=None):
17+ if branch == u'.':
18+ b = Branch.open_containing(branch)[0]
19+ else:
20+ b = Branch.open(branch)
21+ self.add_cleanup(b.lock_read().unlock)
22+
23+ if revision is None:
24+ rev_id = b.last_revision()
25+ else:
26+ rev_id = revision[0].as_revision_id(b)
27+
28+ try:
29+ self.outf.write(b.repository.get_signature_text(rev_id))
30+ except errors.NoSuchRevision:
31+ return 1
32+
33
34 class cmd_testament(Command):
35 __doc__ = """Show testament (signing-form) of a revision."""
36
37=== modified file 'bzrlib/tests/blackbox/__init__.py'
38--- bzrlib/tests/blackbox/__init__.py 2010-07-28 07:05:19 +0000
39+++ bzrlib/tests/blackbox/__init__.py 2010-09-23 18:25:59 +0000
40@@ -49,6 +49,7 @@
41 'bzrlib.tests.blackbox.test_bundle_info',
42 'bzrlib.tests.blackbox.test_cat',
43 'bzrlib.tests.blackbox.test_cat_revision',
44+ 'bzrlib.tests.blackbox.test_cat_signature',
45 'bzrlib.tests.blackbox.test_check',
46 'bzrlib.tests.blackbox.test_checkout',
47 'bzrlib.tests.blackbox.test_clean_tree',
48
49=== added file 'bzrlib/tests/blackbox/test_cat_signature.py'
50--- bzrlib/tests/blackbox/test_cat_signature.py 1970-01-01 00:00:00 +0000
51+++ bzrlib/tests/blackbox/test_cat_signature.py 2010-09-23 18:25:59 +0000
52@@ -0,0 +1,58 @@
53+# Copyright (C) 2010 Canonical Ltd
54+#
55+# This program is free software; you can redistribute it and/or modify
56+# it under the terms of the GNU General Public License as published by
57+# the Free Software Foundation; either version 2 of the License, or
58+# (at your option) any later version.
59+#
60+# This program is distributed in the hope that it will be useful,
61+# but WITHOUT ANY WARRANTY; without even the implied warranty of
62+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+# GNU General Public License for more details.
64+#
65+# You should have received a copy of the GNU General Public License
66+# along with this program; if not, write to the Free Software
67+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
68+
69+"""Black-box tests for bzr cat-revision.
70+"""
71+
72+from bzrlib.bzrdir import BzrDir
73+from bzrlib.tests import TestCaseWithTransport
74+
75+
76+class TestCatSignature(TestCaseWithTransport):
77+
78+ def setup_tree(self):
79+ wt = BzrDir.create_standalone_workingtree('.')
80+ b = wt.branch
81+ # commit without signature
82+ wt.commit("base A", allow_pointless=True, rev_id='A')
83+ # next commit has a dummy signature attached
84+ wt.commit("base B", allow_pointless=True, rev_id='B')
85+ b.repository.lock_write()
86+ b.repository.start_write_group()
87+ try:
88+ wt.branch.repository.add_signature_text('B', 'dummy signature')
89+ except:
90+ b.repository.abort_write_group()
91+ raise
92+ else:
93+ b.repository.commit_write_group()
94+ finally:
95+ b.repository.unlock()
96+
97+ return wt
98+
99+ def test_cat_signature(self):
100+ """Print out the signature for a revision"""
101+ wt = self.setup_tree()
102+ out, err = self.run_bzr('cat-signature -r revid:B')
103+ self.assertEquals(out, 'dummy signature')
104+
105+ def test_cat_signature_unsigned(self):
106+ """Do not output anything when there is no signature,
107+ but exit with code 1"""
108+ self.setup_tree()
109+ out, err = self.run_bzr('cat-signature -r revid:A', retcode=1)
110+ self.assertEquals(out, '')