Merge lp:~jelmer/brz/bzrignore into lp:brz

Proposed by Jelmer Vernooij on 2018-03-04
Status: Merged
Approved by: Jelmer Vernooij on 2018-03-05
Approved revision: 6877
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/bzrignore
Merge into: lp:brz
Diff against target: 209 lines (+26/-57)
6 files modified
breezy/__init__.py (+0/-3)
breezy/bzr/workingtree.py (+3/-41)
breezy/ignores.py (+5/-5)
breezy/plugins/weave_fmt/workingtree.py (+4/-0)
breezy/tests/per_workingtree/test_is_ignored.py (+11/-8)
breezy/workingtree.py (+3/-0)
To merge this branch: bzr merge lp:~jelmer/brz/bzrignore
Reviewer Review Type Date Requested Status
Martin Packman 2018-03-04 Approve on 2018-03-05
Review via email: mp+340633@code.launchpad.net

Commit message

Add a WorkingTreeFormat flag for the ignore pattern filename.

Description of the change

Add a WorkingTreeFormat flag for the ignore pattern filename.

Using this, only run .bzrignore-specific tests on bzr formats.

To post a comment you must log in.
Martin Packman (gz) wrote :

This is quite neat.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/__init__.py'
2--- breezy/__init__.py 2017-08-26 19:06:32 +0000
3+++ breezy/__init__.py 2018-03-04 23:18:01 +0000
4@@ -42,9 +42,6 @@
5 import sys
6
7
8-IGNORE_FILENAME = ".bzrignore"
9-
10-
11 __copyright__ = "Copyright 2005-2012 Canonical Ltd."
12
13 # same format as sys.version_info: "A tuple containing the five components of
14
15=== modified file 'breezy/bzr/workingtree.py'
16--- breezy/bzr/workingtree.py 2018-02-26 13:36:15 +0000
17+++ breezy/bzr/workingtree.py 2018-03-04 23:18:01 +0000
18@@ -569,8 +569,8 @@
19 ignore_globs = set()
20 ignore_globs.update(ignores.get_runtime_ignores())
21 ignore_globs.update(ignores.get_user_ignores())
22- if self.has_filename(breezy.IGNORE_FILENAME):
23- f = self.get_file(breezy.IGNORE_FILENAME)
24+ if self.has_filename(self._format.ignore_filename):
25+ f = self.get_file(self._format.ignore_filename)
26 try:
27 ignore_globs.update(ignores.parse_ignore_file(f))
28 finally:
29@@ -1715,45 +1715,7 @@
30 class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
31 """Base class for working trees that live in bzr meta directories."""
32
33- def __init__(self):
34- WorkingTreeFormat.__init__(self)
35- bzrdir.BzrFormat.__init__(self)
36-
37- @classmethod
38- def find_format_string(klass, controldir):
39- """Return format name for the working tree object in controldir."""
40- try:
41- transport = controldir.get_workingtree_transport(None)
42- return transport.get_bytes("format")
43- except errors.NoSuchFile:
44- raise errors.NoWorkingTree(base=transport.base)
45-
46- @classmethod
47- def find_format(klass, controldir):
48- """Return the format for the working tree object in controldir."""
49- format_string = klass.find_format_string(controldir)
50- return klass._find_format(format_registry, 'working tree',
51- format_string)
52-
53- def check_support_status(self, allow_unsupported, recommend_upgrade=True,
54- basedir=None):
55- WorkingTreeFormat.check_support_status(self,
56- allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
57- basedir=basedir)
58- bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
59- recommend_upgrade=recommend_upgrade, basedir=basedir)
60-
61- def get_controldir_for_branch(self):
62- """Get the control directory format for creating branches.
63-
64- This is to support testing of working tree formats that can not exist
65- in the same control directory as a branch.
66- """
67- return self._matchingcontroldir
68-
69-
70-class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
71- """Base class for working trees that live in bzr meta directories."""
72+ ignore_filename = '.bzrignore'
73
74 def __init__(self):
75 WorkingTreeFormat.__init__(self)
76
77=== modified file 'breezy/ignores.py'
78--- breezy/ignores.py 2018-02-15 19:38:33 +0000
79+++ breezy/ignores.py 2018-03-04 23:18:01 +0000
80@@ -190,7 +190,7 @@
81 :return: None
82 """
83 # read in the existing ignores set
84- ifn = tree.abspath(breezy.IGNORE_FILENAME)
85+ ifn = tree.abspath(tree._format.ignore_filename)
86 if tree.has_filename(ifn):
87 with open(ifn, 'rbU') as f:
88 file_contents = f.read()
89@@ -203,13 +203,13 @@
90 else:
91 file_contents = b""
92 newline = os.linesep.encode()
93-
94+
95 sio = BytesIO(file_contents)
96 try:
97 ignores = parse_ignore_file(sio)
98 finally:
99 sio.close()
100-
101+
102 # write out the updated ignores set
103 f = atomicfile.AtomicFile(ifn, 'wb')
104 try:
105@@ -225,5 +225,5 @@
106 finally:
107 f.close()
108
109- if not tree.is_versioned(breezy.IGNORE_FILENAME):
110- tree.add([breezy.IGNORE_FILENAME])
111+ if not tree.is_versioned(tree._format.ignore_filename):
112+ tree.add([tree._format.ignore_filename])
113
114=== modified file 'breezy/plugins/weave_fmt/workingtree.py'
115--- breezy/plugins/weave_fmt/workingtree.py 2017-08-29 13:25:07 +0000
116+++ breezy/plugins/weave_fmt/workingtree.py 2018-03-04 23:18:01 +0000
117@@ -18,6 +18,8 @@
118
119 from __future__ import absolute_import
120
121+import breezy
122+
123 from ... import (
124 conflicts as _mod_conflicts,
125 errors,
126@@ -65,6 +67,8 @@
127
128 supports_versioned_directories = True
129
130+ ignore_filename = '.bzrignore'
131+
132 def get_format_description(self):
133 """See WorkingTreeFormat.get_format_description()."""
134 return "Working tree format 2"
135
136=== modified file 'breezy/tests/per_workingtree/test_is_ignored.py'
137--- breezy/tests/per_workingtree/test_is_ignored.py 2017-10-27 09:03:47 +0000
138+++ breezy/tests/per_workingtree/test_is_ignored.py 2018-03-04 23:18:01 +0000
139@@ -15,21 +15,24 @@
140 # along with this program; if not, write to the Free Software
141 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
142
143-from breezy import config, ignores
144+from breezy import config, ignores, tests
145 from breezy.tests.per_workingtree import TestCaseWithWorkingTree
146
147
148 class TestIsIgnored(TestCaseWithWorkingTree):
149
150+ def setUp(self):
151+ super(TestIsIgnored, self).setUp()
152+ if self.workingtree_format.ignore_filename != '.bzrignore':
153+ raise tests.TestNotApplicable(
154+ 'format does not use .bzrignore for ignore patterns')
155+
156 def _set_user_ignore_content(self, ignores):
157 """Create user ignore file and set its content to ignores."""
158 config.ensure_config_dir_exists()
159 user_ignore_file = config.user_ignore_config_filename()
160- f = open(user_ignore_file, 'wb')
161- try:
162+ with open(user_ignore_file, 'wb') as f:
163 f.write(ignores)
164- finally:
165- f.close()
166
167 def test_is_ignored(self):
168 tree = self.make_branch_and_tree('.')
169@@ -76,7 +79,7 @@
170 self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/root'))
171 self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/roat'))
172 self.assertEqual(None, tree.is_ignored('roat'))
173-
174+
175 self.assertEqual('**/piffle.py', tree.is_ignored('piffle.py'))
176 self.assertEqual('**/piffle.py', tree.is_ignored('a/piffle.py'))
177 self.assertEqual(None, tree.is_ignored('b/piffle.py')) # exclusion
178@@ -96,7 +99,7 @@
179 self.assertEqual('*bar', tree.is_ignored(r'foo\nbar'))
180 self.assertEqual('*bar', tree.is_ignored('bar'))
181 self.assertEqual('*bar', tree.is_ignored('.bar'))
182-
183+
184 self.assertEqual(None, tree.is_ignored('bazbar')) # exclusion
185
186 self.assertEqual('?foo', tree.is_ignored('afoo'))
187@@ -110,7 +113,7 @@
188
189 self.assertEqual('dir1/?f2', tree.is_ignored('dir1/ff2'))
190 self.assertEqual('dir1/?f2', tree.is_ignored('dir1/.f2'))
191-
192+
193 self.assertEqual('RE:dir2/.*\.wombat', tree.is_ignored('dir2/foo.wombat'))
194 self.assertEqual(None, tree.is_ignored('dir2/foo'))
195
196
197=== modified file 'breezy/workingtree.py'
198--- breezy/workingtree.py 2018-02-25 15:31:42 +0000
199+++ breezy/workingtree.py 2018-03-04 23:18:01 +0000
200@@ -1421,6 +1421,9 @@
201
202 supports_righthand_parent_id_as_ghost = True
203
204+ ignore_filename = None
205+ """Name of file with ignore patterns, if any. """
206+
207 def initialize(self, controldir, revision_id=None, from_branch=None,
208 accelerator_tree=None, hardlink=False):
209 """Initialize a new working tree in controldir.

Subscribers

People subscribed via source and target branches