Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1448)

Side by Side Diff: tools/release/search_related_commits.py

Issue 1098123002: [release-tools] Tool to find related commits (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Prettyprint, sorting by date Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 the V8 project authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import argparse
7 import os
8 import sys
9 import re
10 import operator
11 from subprocess import Popen, PIPE
12
13 def search_all_related_commits(
14 git_working_dir, of, until, deadline, verbose=False):
Michael Achenbach 2015/04/24 12:45:12 Suggestion: Better name for "of"? It know it sound
Michael Achenbach 2015/04/24 12:45:12 nit: 4 space indentation for params.
Michael Hablich 2015/04/27 11:06:07 Done.
Michael Hablich 2015/04/27 11:06:08 Renamed it inside the function.
15
16 all_commits_raw = (_git_execute(
17 git_working_dir, ["rev-list", "--reverse", of + ".." + until], verbose))
18 if verbose:
19 print "All commits between <of> and <until>: " + all_commits_raw
20
21 all_commits = all_commits_raw.splitlines()
22 all_related_commits = {}
23 already_treated_commits = []
24 for commit in all_commits:
25 if commit in already_treated_commits:
26 continue
27
28 related_commits = (search_related_commits(
29 git_working_dir, commit, until, deadline, verbose))
30 if len(related_commits) > 0:
Michael Achenbach 2015/04/24 12:45:12 nit: if related_commits:
Michael Hablich 2015/04/27 11:06:08 I like it that way as it is more explicit and bett
Michael Achenbach 2015/04/27 13:09:43 Hmm, but not pythonish. Most places in the infrast
31 all_related_commits[commit] = related_commits
32 already_treated_commits = already_treated_commits + related_commits
Michael Achenbach 2015/04/24 12:45:12 already_treated_commits.extend(related_commits)
Michael Hablich 2015/04/27 11:06:07 Done.
33
34 already_treated_commits.append(commit)
35
36 return all_related_commits
37
38 def search_related_commits(git_working_dir, of, until, deadline, verbose=False):
39
40 if deadline != "":
Michael Achenbach 2015/04/24 12:45:12 Better no default for deadline (i.e. default is No
Michael Hablich 2015/04/27 11:06:08 Done.
41 afterDeadline = False
Michael Achenbach 2015/04/24 12:45:12 unused variable?
Michael Hablich 2015/04/27 11:06:08 Done.
42
43 commits_between = (_git_execute(
44 git_working_dir,
45 ["rev-list", "--reverse", of + ".." + deadline],
46 verbose))
47 if commits_between.strip() == "":
48 return []
49
50 #Extract commit position
51 original_message = _git_execute(git_working_dir,
52 ["show", "-s", "--format=%B", of], verbose)
53 title = original_message.splitlines()[0]
54
55 matches = re.search("(\{#)([0-9]*)(\})", original_message)
56 commit_position = matches.group(2)
57 if verbose:
58 print "1.) Commit position to look for: " + commit_position
59
60 found_by_hash = (_git_execute(
Michael Achenbach 2015/04/27 13:09:43 I don't know for what the outer parentheses are ne
61 git_working_dir,
62 ["log", "--reverse", of + ".." + until, "--grep=" + of, "--format=%H"],
63 verbose))
64 found_by_hash = found_by_hash.strip()
65
66 if verbose:
67 print "2.) Found by hash: " + found_by_hash
68
69 found_by_commit_pos = (_git_execute(
70 git_working_dir,(
71 ["log", "--reverse",
72 of + ".." + until,
73 "--grep=" + commit_position,
74 "--format=%H"]),
75 verbose))
76
77 found_by_commit_pos = found_by_commit_pos.strip()
78
79 if verbose:
80 print "3.) Found by commit position: " + found_by_commit_pos
81
82 #Replace brackets or else they are wrongly interpreted by --grep
83 title = title.replace("[", "\\[")
84 title = title.replace("]", "\\]")
85
86 found_by_title = (_git_execute(
87 git_working_dir,
88 ["log", "--reverse", of + ".." + until, '--grep=' + title, "--format=%H"],
89 verbose))
90
91 found_by_title = found_by_title.strip()
92
93 if verbose:
94 print "4.) Found by title: " + found_by_title
95
96 hits = (_convert_to_array(found_by_hash)
Michael Achenbach 2015/04/24 12:45:12 nit: Indentation: Either use 4 space indentation o
Michael Hablich 2015/04/27 11:06:07 Done.
97 + _convert_to_array(found_by_commit_pos)
98 + _convert_to_array(found_by_title))
99 hits = _remove_duplicates(hits)
100
101 return hits
102
103 def _convert_to_array(string_of_hashes):
104 if len(string_of_hashes) == 0:
105 return []
106 return string_of_hashes.splitlines()
107
108 def _remove_duplicates(array):
109 no_duplicates = []
110 for current in array:
111 if not current in no_duplicates:
112 no_duplicates.append(current)
113 return no_duplicates
114
115 def _git_execute(working_dir, commands, verbose=False):
116
117 fullCommand = ["git", "-C", working_dir] + commands
118 if verbose:
119 print "Git working dir: " + working_dir
120 print "Executing git command:" + str(fullCommand)
121 p = Popen(args=fullCommand, stdin=PIPE,
122 stdout=PIPE, stderr=PIPE)
123 output, err = p.communicate()
124 rc = p.returncode
125 if rc != 0:
126 raise Exception(err)
127 if verbose:
128 print "Git return value: " + output
129 return output
130
131 if __name__ == "__main__": # pragma: no cover
132 parser = argparse.ArgumentParser(
133 ("This tool searches the git repository for "
134 "commits which are related to the commit <of>."))
135 parser.add_argument("-g", "--git-dir", required=False, default=".",
136 help="The path to your git working directory.")
137 parser.add_argument("--verbose", action="store_true",
138 help="Enables verbose output")
139 parser.add_argument("of", nargs=1,
140 help="Hash of the commit to be searched.")
141 parser.add_argument("until", nargs=1,
142 help="Commit when searching should stop")
143 parser.add_argument("--all", action="store_true",
144 help=("Searches for related commits in all "
145 "commits between <of> and <until>"))
146 parser.add_argument("--deadline", required=False, default="",
147 help=("The script will only list related commits "
148 "which are separated by hash <--deadline>."))
149 parser.add_argument("--prettyprint", action="store_true",
150 help=("Pretty prints the output"))
151
152 args = sys.argv[1:]
153 options = parser.parse_args(args)
154 if options.all:
155 all_related_commits = (search_all_related_commits(options.git_dir,
Michael Achenbach 2015/04/24 12:45:12 nit: Doesn't need the outer parenthesis + params a
Michael Hablich 2015/04/27 11:06:07 Done.
156 options.of[0],
157 options.until[0],
158 options.deadline,
159 options.verbose))
160
161 high_level_commits = sorted(all_related_commits.keys(),key = lambda x:(
Michael Achenbach 2015/04/24 12:45:12 nit: ,space :space
162 (_git_execute(options.git_dir,
Michael Achenbach 2015/04/24 12:45:12 nit: too many parenthesis
Michael Achenbach 2015/04/27 13:09:43 What about this? Maybe also move the lambda into a
Michael Achenbach 2015/04/28 21:23:51 I still have the feeling this comment was overlook
163 ["show", "--quiet", "--date=iso", x, "--format=%ad"],
164 options.verbose)).strip()))
165
166 for current_key in high_level_commits:
167 if options.prettyprint:
168 print "+" + (_git_execute(
Michael Achenbach 2015/04/24 12:45:12 Difficult to read the way the parenthesis are set
Michael Hablich 2015/04/27 11:06:07 Done.
Michael Achenbach 2015/04/27 13:09:43 Much more readable :)
169 options.git_dir,
170 (
171 ["show",
172 "--quiet",
173 "--date=iso",
174 current_key,
175 "--format=%ad # %H # %s"]),
176 options.verbose)).strip()
177 else:
178 print "+" + current_key
179
180 found_commits = all_related_commits[current_key]
181 for current_commit in found_commits:
182 if options.prettyprint:
183 print "| " + (_git_execute(
Michael Achenbach 2015/04/24 12:45:12 Same here.
Michael Hablich 2015/04/27 11:06:08 Done.
184 options.git_dir,
185 (
186 ["show",
187 "--quiet",
188 "--date=iso",
189 current_commit,
190 "--format=%ad # %H # %s"]),
191 options.verbose)).strip()
192 else:
193 print "| " + current_commit
194 else:
195 hits = search_related_commits(options.git_dir, options.of[0],
196 options.until[0], options.deadline, options.verbose)
197 if len(hits) > 0:
198 print "\n".join(hits)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698