Merge lp:~thomir-deactivatedaccount/bzr/fig-bug-747958 into lp:bzr

Proposed by Thomi Richards
Status: Merged
Approved by: Martin Pool
Approved revision: no longer in the source branch.
Merged at revision: 6049
Proposed branch: lp:~thomir-deactivatedaccount/bzr/fig-bug-747958
Merge into: lp:bzr
Diff against target: 178 lines (+58/-16)
2 files modified
bzrlib/log.py (+19/-15)
bzrlib/tests/test_log.py (+39/-1)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/bzr/fig-bug-747958
Reviewer Review Type Date Requested Status
Thomi Richards (community) Needs Resubmitting
bzr-core Pending
Review via email: mp+69023@code.launchpad.net

Commit message

Log levels are no longer reset to what the log formatter supports (bug 747958)

Description of the change

Fig bug #747958. Log levels are no longer overridden by what the log formatter supports if the user explicitly asked for a certain log level.

This is my second attempt at fixing this bug (my first was several months ago). There's now a unit test that reproduces the issue and passed with the new code.

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

That looks good, thanks. Just a couple of nits:

+ a sensible default..

Just one dot will do.

+class TestLogDefaults(TestCaseForLogFormatter):
+ def test_default_log_level(self):

Can you add a docstring explaining the purpose of the test, maybe with a link to the bug, and then a blank line after it.

The assertions would be a little better as assertEquals.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Thanks, I've made those changes and re-pushed. Does the diff get updated automatically?

review: Needs Resubmitting
Revision history for this message
Martin Pool (mbp) 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/log.py'
2--- bzrlib/log.py 2011-07-15 13:52:32 +0000
3+++ bzrlib/log.py 2011-07-25 07:43:29 +0000
4@@ -183,7 +183,7 @@
5 if None or 0.
6
7 :param show_diff: If True, output a diff after each revision.
8-
9+
10 :param match: Dictionary of search lists to use when matching revision
11 properties.
12 """
13@@ -219,7 +219,7 @@
14 # make_log_request_dict() below
15 _DEFAULT_REQUEST_PARAMS = {
16 'direction': 'reverse',
17- 'levels': 1,
18+ 'levels': None,
19 'generate_tags': True,
20 'exclude_common_ancestry': False,
21 '_match_using_deltas': True,
22@@ -228,7 +228,7 @@
23
24 def make_log_request_dict(direction='reverse', specific_fileids=None,
25 start_revision=None, end_revision=None, limit=None,
26- message_search=None, levels=1, generate_tags=True,
27+ message_search=None, levels=None, generate_tags=True,
28 delta_type=None,
29 diff_type=None, _match_using_deltas=True,
30 exclude_common_ancestry=False, match=None,
31@@ -259,7 +259,8 @@
32 matching commit messages
33
34 :param levels: the number of levels of revisions to
35- generate; 1 for just the mainline; 0 for all levels.
36+ generate; 1 for just the mainline; 0 for all levels, or None for
37+ a sensible default.
38
39 :param generate_tags: If True, include tags for matched revisions.
40 `
41@@ -282,11 +283,11 @@
42 range operator or as a graph difference.
43
44 :param signature: show digital signature information
45-
46+
47 :param match: Dictionary of list of search strings to use when filtering
48 revisions. Keys can be 'message', 'author', 'committer', 'bugs' or
49- the empty string to match any of the preceding properties.
50-
51+ the empty string to match any of the preceding properties.
52+
53 """
54 # Take care of old style message_search parameter
55 if message_search:
56@@ -325,7 +326,7 @@
57
58 def format_signature_validity(rev_id, repo):
59 """get the signature validity
60-
61+
62 :param rev_id: revision id to validate
63 :param repo: repository of revision
64 :return: human readable string to print to log
65@@ -394,7 +395,10 @@
66 # Tweak the LogRequest based on what the LogFormatter can handle.
67 # (There's no point generating stuff if the formatter can't display it.)
68 rqst = self.rqst
69- rqst['levels'] = lf.get_levels()
70+ if rqst['levels'] is None or lf.get_levels() > rqst['levels']:
71+ # user didn't specify levels, use whatever the LF can handle:
72+ rqst['levels'] = lf.get_levels()
73+
74 if not getattr(lf, 'supports_tags', False):
75 rqst['generate_tags'] = False
76 if not getattr(lf, 'supports_delta', False):
77@@ -412,7 +416,7 @@
78
79 def _generator_factory(self, branch, rqst):
80 """Make the LogGenerator object to use.
81-
82+
83 Subclasses may wish to override this.
84 """
85 return _DefaultLogGenerator(branch, rqst)
86@@ -967,7 +971,7 @@
87
88 def _update_fileids(delta, fileids, stop_on):
89 """Update the set of file-ids to search based on file lifecycle events.
90-
91+
92 :param fileids: a set of fileids to update
93 :param stop_on: either 'add' or 'remove' - take file-ids out of the
94 fileids set once their add or remove entry is detected respectively
95@@ -1344,7 +1348,7 @@
96 """Create a LogFormatter.
97
98 :param to_file: the file to output to
99- :param to_exact_file: if set, gives an output stream to which
100+ :param to_exact_file: if set, gives an output stream to which
101 non-Unicode diffs are written.
102 :param show_ids: if True, revision-ids are to be displayed
103 :param show_timezone: the timezone to use
104@@ -1586,7 +1590,7 @@
105 if revision.delta is not None:
106 # Use the standard status output to display changes
107 from bzrlib.delta import report_delta
108- report_delta(to_file, revision.delta, short_status=False,
109+ report_delta(to_file, revision.delta, short_status=False,
110 show_ids=self.show_ids, indent=indent)
111 if revision.diff is not None:
112 to_file.write(indent + 'diff:\n')
113@@ -1658,8 +1662,8 @@
114 if revision.delta is not None:
115 # Use the standard status output to display changes
116 from bzrlib.delta import report_delta
117- report_delta(to_file, revision.delta,
118- short_status=self.delta_format==1,
119+ report_delta(to_file, revision.delta,
120+ short_status=self.delta_format==1,
121 show_ids=self.show_ids, indent=indent + offset)
122 if revision.diff is not None:
123 self.show_diff(self.to_exact_file, revision.diff, ' ')
124
125=== modified file 'bzrlib/tests/test_log.py'
126--- bzrlib/tests/test_log.py 2011-07-15 13:49:47 +0000
127+++ bzrlib/tests/test_log.py 2011-07-25 07:43:29 +0000
128@@ -1537,7 +1537,7 @@
129 def make_branch_with_alternate_ancestries(self, relpath='.'):
130 # See test_merge_sorted_exclude_ancestry below for the difference with
131 # bt.per_branch.test_iter_merge_sorted_revision.
132- # TestIterMergeSortedRevisionsBushyGraph.
133+ # TestIterMergeSortedRevisionsBushyGraph.
134 # make_branch_with_alternate_ancestries
135 # and test_merge_sorted_exclude_ancestry
136 # See the FIXME in assertLogRevnos too.
137@@ -1598,3 +1598,41 @@
138 b, '1', '3', exclude_common_ancestry=True,
139 generate_merge_revisions=True)
140
141+
142+class TestLogDefaults(TestCaseForLogFormatter):
143+ def test_default_log_level(self):
144+ """
145+ Test to ensure that specifying 'levels=1' to make_log_request_dict
146+ doesn't get overwritten when using a LogFormatter that supports more
147+ detail.
148+ Fixes bug #747958.
149+ """
150+ wt = self._prepare_tree_with_merges()
151+ b = wt.branch
152+
153+ class CustomLogFormatter(log.LogFormatter):
154+ def __init__(self, *args, **kwargs):
155+ super(CustomLogFormatter, self).__init__(*args, **kwargs)
156+ self.revisions = []
157+ def get_levels(self):
158+ # log formatter supports all levels:
159+ return 0
160+ def log_revision(self, revision):
161+ self.revisions.append(revision)
162+
163+ log_formatter = LogCatcher()
164+ # First request we don't specify number of levels, we should get a
165+ # sensible default (whatever the LogFormatter handles - which in this
166+ # case is 0/everything):
167+ request = log.make_log_request_dict(limit=10)
168+ log.Logger(b, request).show(log_formatter)
169+ # should have all three revisions:
170+ self.assertEquals(len(log_formatter.revisions), 3)
171+
172+ del log_formatter
173+ log_formatter = LogCatcher()
174+ # now explicitly request mainline revisions only:
175+ request = log.make_log_request_dict(limit=10, levels=1)
176+ log.Logger(b, request).show(log_formatter)
177+ # should now only have 2 revisions:
178+ self.assertEquals(len(log_formatter.revisions), 2)