def pickaxe(snippet, git_range, filename=None):
"""Run git log -S <snippet> <git_range> <filename>
Use git pickaxe to 'Look for differences that change the number of occurrences of the
specified string'
If filename is passed in only look in that file
Return list of commits that modified that snippet
"""
cmd = 'git', 'log', '-b', '--pretty=%H', '-S', six.u(snippet), git_range
if filename:
cmd = cmd + ('--', filename,)
commits = run_command(*cmd).splitlines()
commits = [(commit, line_removed(snippet, commit)) for commit in commits]
# Couldn't find a good way to POSIX regex escape the code and use regex
# pickaxe to match full lines, so filter out partial results here.
# Filter out results that aren't a full line
commits = [commit for commit in commits if commit[1] is not None]
return commits
评论列表
文章目录