Skip to content

Commit 5c14560

Browse files
committed
Issue #15: Add support for blame results with file names in "blame_show_all" command.
1 parent 6c3867a commit 5c14560

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

git-blame.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ def get_blame_lines(self, path):
245245
'''Run `git blame` and get the output lines.
246246
'''
247247
try:
248-
output = shell(["git", "blame", "--minimal", "-w", path],
248+
# The option --show-name is necessary to force file name display.
249+
command = ["git", "blame", "--show-name", "--minimal", "-w", path]
250+
output = shell(command,
249251
cwd=os.path.dirname(os.path.realpath(path)),
250252
startupinfo=si,
251253
stderr=subprocess.STDOUT)
@@ -264,6 +266,8 @@ def parse_blame(self, blame):
264266
m = self.pattern.match(blame)
265267
if m:
266268
sha = m.group('sha')
269+
# Currently file is not used.
270+
# file = m.group('file')
267271
author = m.group('author')
268272
date = m.group('date')
269273
time = m.group('time')
@@ -278,15 +282,16 @@ def prepare_pattern(self):
278282
# The SHA output by git-blame may have a leading caret to indicate
279283
# that it is a "boundary commit".
280284
p_sha = r'(?P<sha>\^?\w+)'
285+
p_file = r'((?P<file>[\S ]+)\s+)'
281286
p_author = r'(?P<author>.+?)'
282287
p_date = r'(?P<date>\d{4}-\d{2}-\d{2})'
283288
p_time = r'(?P<time>\d{2}:\d{2}:\d{2})'
284289
p_timezone = r'(?P<timezone>[\+-]\d+)'
285290
p_line = r'(?P<line_number>\d+)'
286291
s = r'\s+'
287292

288-
self.pattern = re.compile(r'^' + p_sha + s + r'\(' + p_author +
289-
s + p_date + s + p_time + s +
293+
self.pattern = re.compile(r'^' + p_sha + s + p_file + r'\(' +
294+
p_author + s + p_date + s + p_time + s +
290295
p_timezone + s + p_line + r'\) ')
291296

292297
def format_name(self, name):

0 commit comments

Comments
 (0)