Merge lp:~jelmer/brz/commit-exclude into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/commit-exclude
Merge into: lp:brz
Diff against target: 138 lines (+70/-5)
3 files modified
breezy/commit.py (+29/-4)
breezy/tests/test_commit.py (+38/-1)
doc/en/release-notes/brz-3.0.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/brz/commit-exclude
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+325894@code.launchpad.net

Commit message

Support excludes when using record_iter_changes() to create a commit.

Description of the change

Support excludes when using record_iter_changes() to create a commit.

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

Seems like a step in the right direction as discussed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/commit.py'
2--- breezy/commit.py 2017-06-11 13:48:12 +0000
3+++ breezy/commit.py 2017-06-18 22:43:28 +0000
4@@ -75,6 +75,33 @@
5 from .i18n import gettext
6
7
8+def filter_excluded(iter_changes, exclude):
9+ """Filter exclude filenames.
10+
11+ :param iter_changes: iter_changes function
12+ :param exclude: List of paths to exclude
13+ :return: iter_changes function
14+ """
15+ for change in iter_changes:
16+ old_path = change[1][0]
17+ new_path = change[1][1]
18+
19+ new_excluded = (new_path is not None and
20+ is_inside_any(exclude, new_path))
21+
22+ old_excluded = (old_path is not None and
23+ is_inside_any(exclude, old_path))
24+
25+ if old_excluded and new_excluded:
26+ continue
27+
28+ if old_excluded or new_excluded:
29+ # TODO(jelmer): Perhaps raise an error here instead?
30+ continue
31+
32+ yield change
33+
34+
35 class NullCommitReporter(object):
36 """I report on progress of a commit."""
37
38@@ -321,7 +348,6 @@
39 # the command line parameters, and the repository has fast delta
40 # generation. See bug 347649.
41 self.use_record_iter_changes = (
42- not self.exclude and
43 not self.branch.repository._format.supports_tree_reference and
44 (self.branch.repository._format.fast_deltas or
45 len(self.parents) < 2))
46@@ -383,9 +409,6 @@
47 self.builder = self.branch.get_commit_builder(self.parents,
48 self.config_stack, timestamp, timezone, committer, self.revprops,
49 rev_id, lossy=lossy)
50- if not self.builder.supports_record_entry_contents and self.exclude:
51- self.builder.abort()
52- raise errors.ExcludesUnsupported(self.branch.repository)
53
54 if self.builder.updates_branch and self.bound_branch:
55 self.builder.abort()
56@@ -663,6 +686,8 @@
57 if self.use_record_iter_changes:
58 iter_changes = self.work_tree.iter_changes(self.basis_tree,
59 specific_files=specific_files)
60+ if self.exclude:
61+ iter_changes = filter_excluded(iter_changes, self.exclude)
62 iter_changes = self._filter_iter_changes(iter_changes)
63 for file_id, path, fs_hash in self.builder.record_iter_changes(
64 self.work_tree, self.basis_revid, iter_changes):
65
66=== modified file 'breezy/tests/test_commit.py'
67--- breezy/tests/test_commit.py 2017-06-10 16:40:42 +0000
68+++ breezy/tests/test_commit.py 2017-06-18 22:43:28 +0000
69@@ -25,7 +25,11 @@
70 )
71 from ..branch import Branch
72 from ..bzr.bzrdir import BzrDirMetaFormat1
73-from ..commit import Commit, NullCommitReporter
74+from ..commit import (
75+ Commit,
76+ NullCommitReporter,
77+ filter_excluded,
78+ )
79 from ..errors import (
80 PointlessCommit,
81 BzrError,
82@@ -33,6 +37,7 @@
83 LockContention,
84 )
85 from . import (
86+ TestCase,
87 TestCaseWithTransport,
88 test_foreign,
89 )
90@@ -832,3 +837,35 @@
91 tree2 = branch.create_checkout('repo/tree2')
92 tree2.commit('message', rev_id='rev1')
93 self.assertTrue(tree2.branch.repository.has_revision('rev1'))
94+
95+
96+class FilterExcludedTests(TestCase):
97+
98+ def test_add_file_not_excluded(self):
99+ changes = [
100+ ('fid', (None, 'newpath'),
101+ 0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
102+ ('file', 'file'), (True, True))]
103+ self.assertEqual(changes, list(filter_excluded(changes, ['otherpath'])))
104+
105+ def test_add_file_excluded(self):
106+ changes = [
107+ ('fid', (None, 'newpath'),
108+ 0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
109+ ('file', 'file'), (True, True))]
110+ self.assertEqual([], list(filter_excluded(changes, ['newpath'])))
111+
112+ def test_delete_file_excluded(self):
113+ changes = [
114+ ('fid', ('somepath', None),
115+ 0, (False, None), ('pid', None), ('newpath', None),
116+ ('file', None), (True, None))]
117+ self.assertEqual([], list(filter_excluded(changes, ['somepath'])))
118+
119+ def test_move_from_or_to_excluded(self):
120+ changes = [
121+ ('fid', ('oldpath', 'newpath'),
122+ 0, (False, False), ('pid', 'pid'), ('oldpath', 'newpath'),
123+ ('file', 'file'), (True, True))]
124+ self.assertEqual([], list(filter_excluded(changes, ['oldpath'])))
125+ self.assertEqual([], list(filter_excluded(changes, ['newpath'])))
126
127=== modified file 'doc/en/release-notes/brz-3.0.txt'
128--- doc/en/release-notes/brz-3.0.txt 2017-06-15 23:41:34 +0000
129+++ doc/en/release-notes/brz-3.0.txt 2017-06-18 22:43:28 +0000
130@@ -96,6 +96,9 @@
131 accessible for other users when it starts.
132 (Joke de Buhr, Jelmer Vernooij, #475501)
133
134+* Support ``brz commit -x`` in combination with iter_changes.
135+ (Jelmer Vernooij, #796582, #403811, #694946, #268135, #299879)
136+
137 Documentation
138 *************
139

Subscribers

People subscribed via source and target branches