diff options
Diffstat (limited to 'scripts/rfr')
-rwxr-xr-x | scripts/rfr | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/scripts/rfr b/scripts/rfr index b225bc3a..bca32d3b 100755 --- a/scripts/rfr +++ b/scripts/rfr | |||
@@ -113,6 +113,13 @@ def commit_info_from_gerrit_change_id(change_id): | |||
113 | 113 | ||
114 | return gerrit_query(change_id) | 114 | return gerrit_query(change_id) |
115 | 115 | ||
116 | def commit_info_from_git_sha1(rev): | ||
117 | """ | ||
118 | Return a dict with all the gerrit info from a git sha1 rev. | ||
119 | """ | ||
120 | |||
121 | return gerrit_query(rev) | ||
122 | |||
116 | def commit_info_from_gerrit_cl(cmt): | 123 | def commit_info_from_gerrit_cl(cmt): |
117 | """ | 124 | """ |
118 | Return a dict with all the gerrit info from a Gerrit URL. | 125 | Return a dict with all the gerrit info from a Gerrit URL. |
@@ -124,28 +131,21 @@ def commit_info_from_gerrit_cl(cmt): | |||
124 | 131 | ||
125 | return gerrit_query(cl) | 132 | return gerrit_query(cl) |
126 | 133 | ||
127 | def gerrit_change_id_from_git_commit(cmt_id): | 134 | def git_sha1_from_commit(commit_ish): |
128 | """ | 135 | """ |
129 | Return the gerrit Change-Id from the passed git cmt_id. Returns None if | 136 | Return sha1 revision from a commit-ish string, or None if this doesn't |
130 | this doesn't appear to be a cmt_id or doesn't have a Change-Id line. | 137 | appear to be a commit. |
131 | """ | 138 | """ |
132 | 139 | ||
133 | cid_re = re.compile(r'Change-Id: (I[a-z0-9]{40})') | 140 | prog = subprocess.Popen('git rev-parse %s' % commit_ish, shell=True, |
134 | |||
135 | # First obtain the commit message itself. | ||
136 | prog = subprocess.Popen('git show --stat %s' % cmt_id, shell=True, | ||
137 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 141 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
138 | 142 | ||
139 | stdout_data, stderr_data = prog.communicate() | 143 | stdout_data, stderr_data = prog.communicate() |
140 | if prog.returncode != 0: | 144 | if prog.returncode != 0: |
141 | print('`git show %s\' failed?!' % cmt_id) | 145 | print('`git rev-parse %s\' failed?!' % commit_ish) |
142 | return None | 146 | return None |
143 | 147 | ||
144 | m = cid_re.search(stdout_data.decode('utf-8')) | 148 | return stdout_data.decode('utf-8') |
145 | if m: | ||
146 | return m.group(1) | ||
147 | |||
148 | return None | ||
149 | 149 | ||
150 | def indent_lines(text, ind): | 150 | def indent_lines(text, ind): |
151 | """ | 151 | """ |
@@ -220,7 +220,7 @@ def main(): | |||
220 | elif get_gerrit_url_id(cmt): | 220 | elif get_gerrit_url_id(cmt): |
221 | info = commit_info_from_gerrit_cl(cmt) | 221 | info = commit_info_from_gerrit_cl(cmt) |
222 | else: | 222 | else: |
223 | info = commit_info_from_gerrit_change_id(gerrit_change_id_from_git_commit(cmt)) | 223 | info = commit_info_from_git_sha1(git_sha1_from_commit(cmt)) |
224 | 224 | ||
225 | if info: | 225 | if info: |
226 | commits_info.append(info) | 226 | commits_info.append(info) |