| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 the V8 project authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import operator | 7 import operator |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 from sets import Set | 10 from sets import Set |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 def _search_related_commits( | 41 def _search_related_commits( |
| 42 git_working_dir, start_hash, until, separator, verbose=False): | 42 git_working_dir, start_hash, until, separator, verbose=False): |
| 43 | 43 |
| 44 if separator: | 44 if separator: |
| 45 commits_between = _find_commits_inbetween( | 45 commits_between = _find_commits_inbetween( |
| 46 start_hash, separator, git_working_dir, verbose) | 46 start_hash, separator, git_working_dir, verbose) |
| 47 if commits_between == "": | 47 if commits_between == "": |
| 48 return [] | 48 return [] |
| 49 | 49 |
| 50 # Extract commit position | 50 # Extract commit position |
| 51 original_message = _git_execute( | 51 original_message = git_execute( |
| 52 git_working_dir, | 52 git_working_dir, |
| 53 ["show", "-s", "--format=%B", start_hash], | 53 ["show", "-s", "--format=%B", start_hash], |
| 54 verbose) | 54 verbose) |
| 55 title = original_message.splitlines()[0] | 55 title = original_message.splitlines()[0] |
| 56 | 56 |
| 57 matches = re.search("(\{#)([0-9]*)(\})", original_message) | 57 matches = re.search("(\{#)([0-9]*)(\})", original_message) |
| 58 | 58 |
| 59 if not matches: | 59 if not matches: |
| 60 return [] | 60 return [] |
| 61 | 61 |
| 62 commit_position = matches.group(2) | 62 commit_position = matches.group(2) |
| 63 if verbose: | 63 if verbose: |
| 64 print "1.) Commit position to look for: " + commit_position | 64 print "1.) Commit position to look for: " + commit_position |
| 65 | 65 |
| 66 search_range = start_hash + ".." + until | 66 search_range = start_hash + ".." + until |
| 67 | 67 |
| 68 def git_args(grep_pattern): | 68 def git_args(grep_pattern): |
| 69 return [ | 69 return [ |
| 70 "log", | 70 "log", |
| 71 "--reverse", | 71 "--reverse", |
| 72 "--grep=" + grep_pattern, | 72 "--grep=" + grep_pattern, |
| 73 "--format=%H", | 73 "--format=%H", |
| 74 search_range, | 74 search_range, |
| 75 ] | 75 ] |
| 76 | 76 |
| 77 found_by_hash = _git_execute( | 77 found_by_hash = git_execute( |
| 78 git_working_dir, git_args(start_hash), verbose).strip() | 78 git_working_dir, git_args(start_hash), verbose).strip() |
| 79 | 79 |
| 80 if verbose: | 80 if verbose: |
| 81 print "2.) Found by hash: " + found_by_hash | 81 print "2.) Found by hash: " + found_by_hash |
| 82 | 82 |
| 83 found_by_commit_pos = _git_execute( | 83 found_by_commit_pos = git_execute( |
| 84 git_working_dir, git_args(commit_position), verbose).strip() | 84 git_working_dir, git_args(commit_position), verbose).strip() |
| 85 | 85 |
| 86 if verbose: | 86 if verbose: |
| 87 print "3.) Found by commit position: " + found_by_commit_pos | 87 print "3.) Found by commit position: " + found_by_commit_pos |
| 88 | 88 |
| 89 # Replace brackets or else they are wrongly interpreted by --grep | 89 # Replace brackets or else they are wrongly interpreted by --grep |
| 90 title = title.replace("[", "\\[") | 90 title = title.replace("[", "\\[") |
| 91 title = title.replace("]", "\\]") | 91 title = title.replace("]", "\\]") |
| 92 | 92 |
| 93 found_by_title = _git_execute( | 93 found_by_title = git_execute( |
| 94 git_working_dir, git_args(title), verbose).strip() | 94 git_working_dir, git_args(title), verbose).strip() |
| 95 | 95 |
| 96 if verbose: | 96 if verbose: |
| 97 print "4.) Found by title: " + found_by_title | 97 print "4.) Found by title: " + found_by_title |
| 98 | 98 |
| 99 hits = ( | 99 hits = ( |
| 100 _convert_to_array(found_by_hash) + | 100 _convert_to_array(found_by_hash) + |
| 101 _convert_to_array(found_by_commit_pos) + | 101 _convert_to_array(found_by_commit_pos) + |
| 102 _convert_to_array(found_by_title)) | 102 _convert_to_array(found_by_title)) |
| 103 hits = _remove_duplicates(hits) | 103 hits = _remove_duplicates(hits) |
| 104 | 104 |
| 105 if separator: | 105 if separator: |
| 106 for current_hit in hits: | 106 for current_hit in hits: |
| 107 commits_between = _find_commits_inbetween( | 107 commits_between = _find_commits_inbetween( |
| 108 separator, current_hit, git_working_dir, verbose) | 108 separator, current_hit, git_working_dir, verbose) |
| 109 if commits_between != "": | 109 if commits_between != "": |
| 110 return hits | 110 return hits |
| 111 return [] | 111 return [] |
| 112 | 112 |
| 113 return hits | 113 return hits |
| 114 | 114 |
| 115 def _find_commits_inbetween(start_hash, end_hash, git_working_dir, verbose): | 115 def _find_commits_inbetween(start_hash, end_hash, git_working_dir, verbose): |
| 116 commits_between = _git_execute( | 116 commits_between = git_execute( |
| 117 git_working_dir, | 117 git_working_dir, |
| 118 ["rev-list", "--reverse", start_hash + ".." + end_hash], | 118 ["rev-list", "--reverse", start_hash + ".." + end_hash], |
| 119 verbose) | 119 verbose) |
| 120 return commits_between.strip() | 120 return commits_between.strip() |
| 121 | 121 |
| 122 def _convert_to_array(string_of_hashes): | 122 def _convert_to_array(string_of_hashes): |
| 123 return string_of_hashes.splitlines() | 123 return string_of_hashes.splitlines() |
| 124 | 124 |
| 125 def _remove_duplicates(array): | 125 def _remove_duplicates(array): |
| 126 no_duplicates = [] | 126 no_duplicates = [] |
| 127 for current in array: | 127 for current in array: |
| 128 if not current in no_duplicates: | 128 if not current in no_duplicates: |
| 129 no_duplicates.append(current) | 129 no_duplicates.append(current) |
| 130 return no_duplicates | 130 return no_duplicates |
| 131 | 131 |
| 132 def _git_execute(working_dir, args, verbose=False): | 132 def git_execute(working_dir, args, verbose=False): |
| 133 command = ["git", "-C", working_dir] + args | 133 command = ["git", "-C", working_dir] + args |
| 134 if verbose: | 134 if verbose: |
| 135 print "Git working dir: " + working_dir | 135 print "Git working dir: " + working_dir |
| 136 print "Executing git command:" + str(command) | 136 print "Executing git command:" + str(command) |
| 137 p = Popen(args=command, stdin=PIPE, | 137 p = Popen(args=command, stdin=PIPE, |
| 138 stdout=PIPE, stderr=PIPE) | 138 stdout=PIPE, stderr=PIPE) |
| 139 output, err = p.communicate() | 139 output, err = p.communicate() |
| 140 rc = p.returncode | 140 rc = p.returncode |
| 141 if rc != 0: | 141 if rc != 0: |
| 142 raise Exception(err) | 142 raise Exception(err) |
| 143 if verbose: | 143 if verbose: |
| 144 print "Git return value: " + output | 144 print "Git return value: " + output |
| 145 return output | 145 return output |
| 146 | 146 |
| 147 def _pretty_print_entry(hash, git_dir, pre_text, verbose): | 147 def _pretty_print_entry(hash, git_dir, pre_text, verbose): |
| 148 text_to_print = _git_execute( | 148 text_to_print = git_execute( |
| 149 git_dir, | 149 git_dir, |
| 150 ["show", | 150 ["show", |
| 151 "--quiet", | 151 "--quiet", |
| 152 "--date=iso", | 152 "--date=iso", |
| 153 hash, | 153 hash, |
| 154 "--format=%ad # %H # %s"], | 154 "--format=%ad # %H # %s"], |
| 155 verbose) | 155 verbose) |
| 156 return pre_text + text_to_print.strip() | 156 return pre_text + text_to_print.strip() |
| 157 | 157 |
| 158 def main(options): | 158 def main(options): |
| 159 all_related_commits = search_all_related_commits( | 159 all_related_commits = search_all_related_commits( |
| 160 options.git_dir, | 160 options.git_dir, |
| 161 options.of[0], | 161 options.of[0], |
| 162 options.until[0], | 162 options.until[0], |
| 163 options.separator, | 163 options.separator, |
| 164 options.verbose) | 164 options.verbose) |
| 165 | 165 |
| 166 sort_key = lambda x: ( | 166 sort_key = lambda x: ( |
| 167 _git_execute( | 167 git_execute( |
| 168 options.git_dir, | 168 options.git_dir, |
| 169 ["show", "--quiet", "--date=iso", x, "--format=%ad"], | 169 ["show", "--quiet", "--date=iso", x, "--format=%ad"], |
| 170 options.verbose)).strip() | 170 options.verbose)).strip() |
| 171 | 171 |
| 172 high_level_commits = sorted(all_related_commits.keys(), key=sort_key) | 172 high_level_commits = sorted(all_related_commits.keys(), key=sort_key) |
| 173 | 173 |
| 174 for current_key in high_level_commits: | 174 for current_key in high_level_commits: |
| 175 if options.prettyprint: | 175 if options.prettyprint: |
| 176 yield _pretty_print_entry( | 176 yield _pretty_print_entry( |
| 177 current_key, | 177 current_key, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 parser.add_argument("--separator", required=False, | 209 parser.add_argument("--separator", required=False, |
| 210 help="The script will only list related commits " | 210 help="The script will only list related commits " |
| 211 "which are separated by hash <--separator>.") | 211 "which are separated by hash <--separator>.") |
| 212 parser.add_argument("--prettyprint", action="store_true", | 212 parser.add_argument("--prettyprint", action="store_true", |
| 213 help="Pretty prints the output") | 213 help="Pretty prints the output") |
| 214 | 214 |
| 215 args = sys.argv[1:] | 215 args = sys.argv[1:] |
| 216 options = parser.parse_args(args) | 216 options = parser.parse_args(args) |
| 217 for current_line in main(options): | 217 for current_line in main(options): |
| 218 print current_line | 218 print current_line |
| OLD | NEW |