|
6 | 6 | import os
|
7 | 7 | import subprocess
|
8 | 8 | import sys
|
| 9 | +import urllib.parse |
| 10 | +import urllib.request |
9 | 11 |
|
10 | 12 | from sarif.sarif_file import SarifFileSet
|
11 | 13 |
|
@@ -94,10 +96,20 @@ def _enhance_with_blame(input_files, repo_path):
|
94 | 96 | print(f"Found blame information for {blame_info_count} of {item_count} results")
|
95 | 97 |
|
96 | 98 |
|
| 99 | +def _make_path_git_compatible(file_path): |
| 100 | + try: |
| 101 | + path_as_url = urllib.parse.urlparse(file_path) |
| 102 | + if path_as_url.scheme == "file": |
| 103 | + return urllib.request.url2pathname(path_as_url.path) |
| 104 | + return file_path |
| 105 | + except ValueError: |
| 106 | + return file_path |
| 107 | + |
| 108 | + |
97 | 109 | def _run_git_blame_on_files(files_to_blame, repo_path):
|
98 | 110 | file_blame_info = {}
|
99 | 111 | for file_path in files_to_blame:
|
100 |
| - cmd = ["git", "blame", "--porcelain", file_path] |
| 112 | + cmd = ["git", "blame", "--porcelain", _make_path_git_compatible(file_path)] |
101 | 113 | with subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=repo_path) as proc:
|
102 | 114 | blame_info = {"commits": {}, "line_to_commit": {}}
|
103 | 115 | file_blame_info[file_path] = blame_info
|
@@ -131,6 +143,7 @@ def _run_git_blame_on_files(files_to_blame, repo_path):
|
131 | 143 | if proc.returncode:
|
132 | 144 | cmd_str = " ".join(cmd)
|
133 | 145 | sys.stderr.write(
|
134 |
| - f"WARNING: Command `{cmd_str}` failed with exit code {proc.returncode} in {repo_path}\n" |
| 146 | + f"WARNING: Command `{cmd_str} " |
| 147 | + f"failed with exit code {proc.returncode} in {repo_path}\n" |
135 | 148 | )
|
136 | 149 | return file_blame_info
|
0 commit comments