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

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

Issue 1341303002: [Release] Distinguish between merges and follow-up CLs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Please review Created 5 years, 3 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 | tools/release/search_related_commits.py » ('j') | tools/release/test_mergeinfo.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 os 7 import os
8 import sys 8 import sys
9 9
10 from subprocess import call 10 from search_related_commits import git_execute
11 11
12 def print_analysis(gitWorkingDir, hashToSearch): 12 GIT_OPTION_HASH_ONLY = '--pretty=format:%H'
13 print '1.) Info' 13 GIT_OPTION_NO_DIFF = '--quiet'
14 git_execute(gitWorkingDir, ['status']) 14 GIT_OPTION_ONELINE = '--oneline'
15 print '2.) Searching for "' + hashToSearch + '"' 15
16 print '=====================ORIGINAL COMMIT START=====================' 16 def describe_commit(git_working_dir, hash_to_search, one_line=False):
17 git_execute(gitWorkingDir, ['show', hashToSearch]) 17 if one_line:
18 return git_execute(git_working_dir, ['show',
19 GIT_OPTION_NO_DIFF,
20 GIT_OPTION_ONELINE,
21 hash_to_search]).strip()
22 return git_execute(git_working_dir, ['show',
23 GIT_OPTION_NO_DIFF,
24 hash_to_search]).strip()
25
26
27 def get_followup_commits(git_working_dir, hash_to_search):
28 return git_execute(git_working_dir, ['log',
29 '--grep='+hash_to_search,
Michael Achenbach 2015/10/01 08:24:18 nit: space around +
Michael Achenbach 2015/10/01 08:24:18 How often does it happen that developers use the f
Michael Hablich 2015/10/01 10:33:25 Done.
Michael Hablich 2015/10/01 10:33:25 As far as I have seen the most prominent form is r
30 GIT_OPTION_HASH_ONLY,
31 'master']).strip().splitlines()
32
33 def get_merge_commits(git_working_dir, hash_to_search):
34 merges = get_related_commits_not_on_master(git_working_dir, hash_to_search)
35 false_merges = get_related_commits_not_on_master(
36 git_working_dir, 'Cr-Branched-From: ' + hash_to_search)
37 return list(set(merges) - set(false_merges))
Michael Achenbach 2015/10/01 08:24:18 you might loose the original order while going thr
Michael Hablich 2015/10/01 10:33:25 Done.
38
39 def get_related_commits_not_on_master(git_working_dir, grep_command):
40 commits = git_execute(git_working_dir, ['log',
41 '--all',
Michael Achenbach 2015/10/01 08:24:18 nit: indentation
Michael Hablich 2015/10/01 10:33:25 Done.
42 '--grep=' + grep_command,
43 GIT_OPTION_ONELINE,
44 '--decorate',
45 '--not',
46 'master',
47 GIT_OPTION_HASH_ONLY])
48 return commits.splitlines()
49
50 def get_branches_for_commit(git_working_dir, hash_to_search):
51 branches = git_execute(git_working_dir, ['branch',
52 '--contains',
53 hash_to_search,
54 '-a']).strip()
55 branches = branches.splitlines()
56 branches = [ current.strip() for current in branches]
Michael Achenbach 2015/10/01 08:24:18 3 in 1: return map(str.strip, branches.splitlines(
Michael Hablich 2015/10/01 10:33:25 Did a mixture because I like it a little bit more
Michael Achenbach 2015/10/01 10:40:29 ok - 2 in 1 :)
57 return branches
58
59 def is_rolled(git_working_dir, hash_to_search):
60 branches = get_branches_for_commit(git_working_dir, hash_to_search)
61 return 'remotes/origin/roll' in branches
62
63 def is_lkgr(git_working_dir, hash_to_search):
64 branches = get_branches_for_commit(git_working_dir, hash_to_search)
65 return 'remotes/origin/lkgr' in branches
66
67 def get_first_canary(git_working_dir, hash_to_search):
68 branches = get_branches_for_commit(git_working_dir, hash_to_search)
69 canaries = ([currentBranch for currentBranch in branches if
70 currentBranch.startswith('remotes/origin/chromium/')])
71 canaries.sort()
Michael Achenbach 2015/10/01 08:24:18 or put sorted() around the call above...
Michael Hablich 2015/10/01 10:33:25 I don't want to nest the list operation above even
72 if len(canaries) == 0:
73 return 'No Canary coverage'
74 return canaries[0].split('/')[-1]
75
76 def print_analysis(git_working_dir, hash_to_search):
77 print '1.) Searching for "' + hash_to_search + '"'
78 print '=====================ORIGINAL COMMIT START==================='
79 print describe_commit(git_working_dir, hash_to_search)
18 print '=====================ORIGINAL COMMIT END=====================' 80 print '=====================ORIGINAL COMMIT END====================='
19 print '#####################FOUND MERGES & REVERTS START#####################' 81
20 git_execute(gitWorkingDir, ["log",'--all', '--grep='+hashToSearch]) 82 print '2.) General information:'
21 print '#####################FOUND MERGES & REVERTS END#####################' 83 print 'Is rolled: ' + str(is_rolled(git_working_dir, hash_to_search))
84 print 'Is LKGR: ' + str(is_lkgr(git_working_dir, hash_to_search))
85 print 'Is on Canary: ' + (
86 str(get_first_canary(git_working_dir, hash_to_search)))
87 print '3.) Found follow-up commits, reverts and ports:'
88 followups = get_followup_commits(git_working_dir, hash_to_search)
89 for followup in followups:
90 print describe_commit(git_working_dir, followup, True)
91
92 print '4.) Found merges:'
93 merges = get_merge_commits(git_working_dir, hash_to_search)
94 for currentMerge in merges:
95 print describe_commit(git_working_dir, currentMerge, True)
96 print '---Merged to:'
97 mergeOutput = git_execute(git_working_dir, ['branch',
98 '--contains',
99 currentMerge,
100 '-r']).strip()
101 print mergeOutput
22 print 'Finished successfully' 102 print 'Finished successfully'
23 103
24 def git_execute(workingDir, commands): 104 if __name__ == '__main__': # pragma: no cover
25 return call(["git", '-C', workingDir] + commands) 105 parser = argparse.ArgumentParser('Tool to check where a git commit was'
106 ' merged and reverted.')
26 107
27 if __name__ == "__main__": # pragma: no cover 108 parser.add_argument('-g', '--git-dir', required=False, default='.',
28 parser = argparse.ArgumentParser('Tool to check where a git commit was merged and reverted.') 109 help='The path to your git working directory.')
29 parser.add_argument("-g", "--git-dir", required=False, default='.',
30 help="The path to your git working directory.")
31 110
32 parser.add_argument('hash', nargs=1, help="Hash of the commit to be searched." ) 111 parser.add_argument('hash',
112 nargs=1,
113 help='Hash of the commit to be searched.')
33 114
34 args = sys.argv[1:] 115 args = sys.argv[1:]
35 options = parser.parse_args(args) 116 options = parser.parse_args(args)
36 117
37 sys.exit(print_analysis(options.git_dir, options.hash[0])) 118 sys.exit(print_analysis(options.git_dir, options.hash[0]))
OLDNEW
« no previous file with comments | « no previous file | tools/release/search_related_commits.py » ('j') | tools/release/test_mergeinfo.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698