Merge lp:~jelmer/brz/git-grep 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/git-grep
Merge into: lp:brz
Diff against target: 121 lines (+19/-18)
5 files modified
breezy/git/tests/test_blackbox.py (+11/-0)
breezy/git/tree.py (+1/-1)
breezy/git/workingtree.py (+1/-1)
breezy/tests/per_tree/test_list_files.py (+4/-16)
breezy/transform.py (+2/-0)
To merge this branch: bzr merge lp:~jelmer/brz/git-grep
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+358605@code.launchpad.net

Commit message

Fix 'bzr grep' in git working trees.

Description of the change

Fix 'bzr grep' in git working trees.

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

Thanks!

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/git/tests/test_blackbox.py'
2--- breezy/git/tests/test_blackbox.py 2018-11-11 04:08:32 +0000
3+++ breezy/git/tests/test_blackbox.py 2018-11-16 19:48:09 +0000
4@@ -336,3 +336,14 @@
5 'gitr'])
6 self.assertEqual(error, '')
7 self.assertEqual(output, 'VERSION_INFO \n')
8+
9+
10+class GrepTests(ExternalBase):
11+
12+ def test_simple_grep(self):
13+ tree = self.make_branch_and_tree('.', format='git')
14+ self.build_tree_contents([('a', 'text for a\n')])
15+ tree.add(['a'])
16+ output, error = self.run_bzr('grep text')
17+ self.assertEqual(output, 'a:text for a\n')
18+ self.assertEqual(error, '')
19
20=== modified file 'breezy/git/tree.py'
21--- breezy/git/tree.py 2018-11-16 18:33:17 +0000
22+++ breezy/git/tree.py 2018-11-16 19:48:09 +0000
23@@ -394,7 +394,7 @@
24 def list_files(self, include_root=False, from_dir=None, recursive=True):
25 if self.tree is None:
26 return
27- if from_dir is None:
28+ if from_dir is None or from_dir == '.':
29 from_dir = u""
30 (store, mode, hexsha) = self._lookup_path(from_dir)
31 if mode is None: # Root
32
33=== modified file 'breezy/git/workingtree.py'
34--- breezy/git/workingtree.py 2018-11-16 18:33:17 +0000
35+++ breezy/git/workingtree.py 2018-11-16 19:48:09 +0000
36@@ -764,7 +764,7 @@
37 path, stat_result)
38
39 def list_files(self, include_root=False, from_dir=None, recursive=True):
40- if from_dir is None:
41+ if from_dir is None or from_dir == '.':
42 from_dir = u""
43 dir_ids = {}
44 fk_entries = {'directory': tree.TreeDirectory,
45
46=== modified file 'breezy/tests/per_tree/test_list_files.py'
47--- breezy/tests/per_tree/test_list_files.py 2018-11-11 04:08:32 +0000
48+++ breezy/tests/per_tree/test_list_files.py 2018-11-16 19:48:09 +0000
49@@ -29,13 +29,10 @@
50 ('b', 'V', 'directory', tree.path2id('b')),
51 ('b/c', 'V', 'file', tree.path2id('b/c')),
52 ]
53- tree.lock_read()
54- try:
55+ with tree.lock_read():
56 actual = [(path, status, kind, file_id)
57 for path, status, kind, file_id, ie in
58 tree.list_files(include_root=True)]
59- finally:
60- tree.unlock()
61 self.assertEqual(expected, actual)
62
63 def test_list_files_no_root(self):
64@@ -45,13 +42,10 @@
65 ('b', 'V', 'directory', tree.path2id('b')),
66 ('b/c', 'V', 'file', tree.path2id('b/c')),
67 ]
68- tree.lock_read()
69- try:
70+ with tree.lock_read():
71 actual = [(path, status, kind, file_id)
72 for path, status, kind, file_id, ie in
73 tree.list_files()]
74- finally:
75- tree.unlock()
76 self.assertEqual(expected, actual)
77
78 def test_list_files_with_root_no_recurse(self):
79@@ -74,13 +68,10 @@
80 expected = [('a', 'V', 'file', tree.path2id('a'))]
81 expected.append(
82 ('b', 'V', 'directory', tree.path2id('b')))
83- tree.lock_read()
84- try:
85+ with tree.lock_read():
86 actual = [(path, status, kind, file_id)
87 for path, status, kind, file_id, ie in
88 tree.list_files(recursive=False)]
89- finally:
90- tree.unlock()
91 self.assertEqual(expected, actual)
92
93 def test_list_files_from_dir(self):
94@@ -88,13 +79,10 @@
95 tree = self.get_tree_no_parents_abc_content(work_tree)
96 expected = [('c', 'V', 'file', tree.path2id('b/c')),
97 ]
98- tree.lock_read()
99- try:
100+ with tree.lock_read():
101 actual = [(path, status, kind, file_id)
102 for path, status, kind, file_id, ie in
103 tree.list_files(from_dir=u'b')]
104- finally:
105- tree.unlock()
106 self.assertEqual(expected, actual)
107
108 def test_list_files_from_dir_no_recurse(self):
109
110=== modified file 'breezy/transform.py'
111--- breezy/transform.py 2018-11-16 18:40:46 +0000
112+++ breezy/transform.py 2018-11-16 19:48:09 +0000
113@@ -2212,6 +2212,8 @@
114 """See WorkingTree.list_files."""
115 # XXX This should behave like WorkingTree.list_files, but is really
116 # more like RevisionTree.list_files.
117+ if from_dir == '.':
118+ from_dir = None
119 if recursive:
120 prefix = None
121 if from_dir:

Subscribers

People subscribed via source and target branches