Merge lp:~jr/bzr/667408-bzr-blame-no-whoami into lp:bzr

Proposed by Jonathan Riddell
Status: Merged
Approved by: Jonathan Riddell
Approved revision: no longer in the source branch.
Merged at revision: 5971
Proposed branch: lp:~jr/bzr/667408-bzr-blame-no-whoami
Merge into: lp:bzr
Diff against target: 130 lines (+30/-9)
5 files modified
bzrlib/annotate.py (+5/-1)
bzrlib/tests/blackbox/test_ancestry.py (+0/-3)
bzrlib/tests/blackbox/test_annotate.py (+22/-4)
bzrlib/tests/per_repository/test_commit_builder.py (+0/-1)
doc/en/release-notes/bzr-2.4.txt (+3/-0)
To merge this branch: bzr merge lp:~jr/bzr/667408-bzr-blame-no-whoami
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Review via email: mp+64375@code.launchpad.net

Commit message

``bzr annotate`` can be run without setting whoami data first. (Jonathan Riddell, LP: #667408)

Description of the change

simple fix to allow for bzr annotate without whoami being set

Another slightly more generic way to do this might be to alter config.username() to take a allow_no_email paramater that means it returns only the username if it can't find an e-mail.

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

Thanks, I'm surprised it's as simple as this..

Please merge lp:~jelmer/bzr/667408-bzr-blame-no-whoami which adds a test for this behaviour.

Please add a entry to the release notes.

review: Approve (code)
Revision history for this message
Jonathan Riddell (jr) wrote :

sent to pqm by email

Revision history for this message
Jonathan Riddell (jr) 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/annotate.py'
2--- bzrlib/annotate.py 2011-05-03 15:04:00 +0000
3+++ bzrlib/annotate.py 2011-06-14 09:08:42 +0000
4@@ -38,6 +38,7 @@
5 from bzrlib import (
6 errors,
7 osutils,
8+ i18n,
9 )
10 from bzrlib.config import extract_email_address
11 from bzrlib.repository import _strip_NULL_ghosts
12@@ -104,7 +105,10 @@
13 # bugfixes etc.
14 current_rev = Revision(CURRENT_REVISION)
15 current_rev.parent_ids = tree.get_parent_ids()
16- current_rev.committer = branch.get_config().username()
17+ try:
18+ current_rev.committer = branch.get_config().username()
19+ except errors.NoWhoami:
20+ current_rev.committer = i18n.gettext("local user")
21 current_rev.message = "?"
22 current_rev.timestamp = round(time.time(), 3)
23 current_rev.timezone = osutils.local_time_offset()
24
25=== modified file 'bzrlib/tests/blackbox/test_ancestry.py'
26--- bzrlib/tests/blackbox/test_ancestry.py 2009-08-18 16:53:50 +0000
27+++ bzrlib/tests/blackbox/test_ancestry.py 2011-06-14 09:08:42 +0000
28@@ -17,9 +17,6 @@
29 import os
30
31 from bzrlib.tests import TestCaseWithTransport
32-from bzrlib.workingtree import WorkingTree
33-from bzrlib.branch import Branch
34-
35
36 class TestAncestry(TestCaseWithTransport):
37
38
39=== modified file 'bzrlib/tests/blackbox/test_annotate.py'
40--- bzrlib/tests/blackbox/test_annotate.py 2011-02-09 08:37:08 +0000
41+++ bzrlib/tests/blackbox/test_annotate.py 2011-06-14 09:08:42 +0000
42@@ -24,9 +24,11 @@
43 """
44
45
46-from bzrlib import tests
47+from bzrlib import (
48+ config,
49+ tests,
50+ )
51
52-from bzrlib.config import extract_email_address
53 from bzrlib.urlutils import joinpath
54
55
56@@ -160,7 +162,6 @@
57 tree.add('file')
58 tree.commit('add file', committer="test@host", rev_id="rev1")
59 self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
60- tree.branch.get_config().set_user_option('email', 'current@host2')
61 return tree
62
63 def test_annotate_cmd_revspec_branch(self):
64@@ -176,6 +177,7 @@
65
66 def test_annotate_edited_file(self):
67 tree = self._setup_edited_file()
68+ tree.branch.get_config().set_user_option('email', 'current@host2')
69 out, err = self.run_bzr('annotate file')
70 self.assertEqual(
71 '1 test@ho | foo\n'
72@@ -183,8 +185,24 @@
73 '1 test@ho | gam\n',
74 out)
75
76+ def test_annotate_edited_file_no_default(self):
77+ # Ensure that when no username is available annotate still works.
78+ self.overrideEnv('EMAIL', None)
79+ self.overrideEnv('BZR_EMAIL', None)
80+ # Also, make sure that it's not inferred from mailname.
81+ self.overrideAttr(config, '_auto_user_id',
82+ lambda: (None, None))
83+ tree = self._setup_edited_file()
84+ out, err = self.run_bzr('annotate file')
85+ self.assertEqual(
86+ '1 test@ho | foo\n'
87+ '2? local u | bar\n'
88+ '1 test@ho | gam\n',
89+ out)
90+
91 def test_annotate_edited_file_show_ids(self):
92 tree = self._setup_edited_file()
93+ tree.branch.get_config().set_user_option('email', 'current@host2')
94 out, err = self.run_bzr('annotate file --show-ids')
95 self.assertEqual(
96 ' rev1 | foo\n'
97@@ -214,7 +232,7 @@
98 def test_annotated_edited_merged_file_revnos(self):
99 wt = self._create_merged_file()
100 out, err = self.run_bzr(['annotate', 'file'])
101- email = extract_email_address(wt.branch.get_config().username())
102+ email = config.extract_email_address(wt.branch.get_config().username())
103 self.assertEqual(
104 '3? %-7s | local\n'
105 '1 test@ho | foo\n'
106
107=== modified file 'bzrlib/tests/per_repository/test_commit_builder.py'
108--- bzrlib/tests/per_repository/test_commit_builder.py 2011-05-17 15:19:59 +0000
109+++ bzrlib/tests/per_repository/test_commit_builder.py 2011-06-14 09:08:42 +0000
110@@ -21,7 +21,6 @@
111 from bzrlib import (
112 config,
113 errors,
114- graph,
115 inventory,
116 osutils,
117 repository,
118
119=== modified file 'doc/en/release-notes/bzr-2.4.txt'
120--- doc/en/release-notes/bzr-2.4.txt 2011-06-14 08:08:36 +0000
121+++ doc/en/release-notes/bzr-2.4.txt 2011-06-14 09:08:42 +0000
122@@ -37,6 +37,9 @@
123 .. Improvements to existing commands, especially improved performance
124 or memory usage, or better results.
125
126+* ``bzr annotate`` can be run without setting whoami data first. (Jonathan
127+ Riddell, #667408)
128+
129 Bug Fixes
130 *********
131