83
81
except re.error, e:
84
82
raise errors.BzrError("Invalid pattern: '%s'" % pattern)
87
self.add_cleanup(tree.unlock)
88
84
for path in path_list:
85
path = os.path.abspath(path)
89
86
if osutils.isdir(path):
90
from_dir = os.path.abspath(os.path.join(relpath, path))
91
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
92
from_dir=from_dir, recursive=recursive):
93
if fc == 'V' and fkind == 'file':
94
self.file_grep(fp, patternc, eol_marker)
87
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(path)
90
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
91
from_dir=relpath, recursive=recursive):
92
if fc == 'V' and fkind == 'file':
93
self.file_grep(relpath, fp, patternc, eol_marker)
96
97
# if user has explicitly specified a file
97
98
# we don't care if its versioned
98
self.file_grep(path, patternc, eol_marker)
99
self.file_grep('.', path, patternc, eol_marker)
100
def file_grep(self, path, patternc, eol_marker):
101
def file_grep(self, relpath, path, patternc, eol_marker):
102
fmt = "%s:%d:%s" + eol_marker
103
path = os.path.normpath(os.path.join('..', relpath, path))
104
fmt = path + ":%d:%s" + eol_marker
103
105
for line in open(path):
104
106
res = patternc.search(line)
106
self.outf.write( fmt % (path, index, line.strip()))
108
self.outf.write( fmt % (index, line.strip()))
109
111
register_command(cmd_grep)