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 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 | |
12 def describe_commit(gitWorkingDir, hashToSearch, prettyPrint=True): | |
Michael Achenbach
2015/09/17 14:19:00
nit: Still think our python style guide recommends
Michael Hablich
2015/09/18 07:38:47
I sticked to the style which was already present .
| |
13 if not prettyPrint: | |
14 return git_execute(gitWorkingDir, ['show', | |
15 '--quiet', | |
16 '--pretty=format:%H', | |
Michael Achenbach
2015/09/17 14:19:00
Could you deduplicate this code? E.g. using someth
Michael Hablich
2015/09/18 07:38:47
Makes sense, will do.
| |
17 hashToSearch]).strip() | |
18 | |
19 return git_execute(gitWorkingDir, ['show', | |
20 '--quiet', | |
21 hashToSearch]).strip() | |
22 | |
23 | |
24 def get_followup_commits(gitWorkingDir, hashToSearch, prettyPrint=True): | |
25 if not prettyPrint: | |
26 raise Exception("NotImplemented") | |
Michael Achenbach
2015/09/17 14:19:00
So: The non-pretty printed version wouldn't work y
Michael Hablich
2015/09/18 07:38:47
Well, it started out as an idea to simply add the
| |
27 git_execute(gitWorkingDir, ['log', | |
28 '--grep='+hashToSearch, | |
Michael Achenbach
2015/09/17 14:19:00
nit: indentation.
Michael Hablich
2015/09/18 07:38:47
Acknowledged.
| |
29 '--oneline', | |
30 'master']).strip() | |
31 | |
32 def get_merge_commits(gitWorkingDir, hashToSearch): | |
33 merges = git_execute(gitWorkingDir, ['log', | |
34 '--all', | |
Michael Achenbach
2015/09/17 14:19:00
nit: indentation
Michael Hablich
2015/09/18 07:38:47
Acknowledged.
| |
35 '--grep='+hashToSearch, | |
36 '--oneline', | |
37 '--decorate', | |
38 '--not', | |
39 'master', | |
40 '--pretty=format:%H']) | |
41 merges = merges.splitlines() | |
42 return merges | |
11 | 43 |
12 def print_analysis(gitWorkingDir, hashToSearch): | 44 def print_analysis(gitWorkingDir, hashToSearch): |
13 print '1.) Info' | 45 print '1.) Searching for "' + hashToSearch + '"' |
14 git_execute(gitWorkingDir, ['status']) | 46 print '=====================ORIGINAL COMMIT START===================' |
15 print '2.) Searching for "' + hashToSearch + '"' | 47 print describe_commit(gitWorkingDir, hashToSearch, True) |
16 print '=====================ORIGINAL COMMIT START=====================' | |
17 git_execute(gitWorkingDir, ['show', hashToSearch]) | |
18 print '=====================ORIGINAL COMMIT END=====================' | 48 print '=====================ORIGINAL COMMIT END=====================' |
19 print '#####################FOUND MERGES & REVERTS START#####################' | 49 print '2.) Found follow-up commits, reverts and ports:' |
20 git_execute(gitWorkingDir, ["log",'--all', '--grep='+hashToSearch]) | 50 print get_followup_commits(gitWorkingDir, hashToSearch, True) |
21 print '#####################FOUND MERGES & REVERTS END#####################' | 51 print '3.) Found merges:' |
52 merges = get_merge_commits(gitWorkingDir, hashToSearch) | |
53 for currentMerge in merges: | |
54 print git_execute(gitWorkingDir, ['show', | |
55 '--oneline', | |
56 '--quiet', | |
57 currentMerge]).strip() | |
58 print '---Merged to:' | |
59 mergeOutput = git_execute(gitWorkingDir, ['branch', | |
60 '--contains', | |
61 currentMerge, | |
62 '-r']).strip() | |
63 print '---' + mergeOutput | |
22 print 'Finished successfully' | 64 print 'Finished successfully' |
23 | 65 |
24 def git_execute(workingDir, commands): | |
25 return call(["git", '-C', workingDir] + commands) | |
26 | 66 |
27 if __name__ == "__main__": # pragma: no cover | 67 if __name__ == '__main__': # pragma: no cover |
28 parser = argparse.ArgumentParser('Tool to check where a git commit was merged and reverted.') | 68 parser = argparse.ArgumentParser('''Tool to check where a git commit was |
Michael Achenbach
2015/09/17 14:19:00
nit: I wouldn't use ''' as this will add the lineb
Michael Hablich
2015/09/18 07:38:47
Acknowledged.
| |
29 parser.add_argument("-g", "--git-dir", required=False, default='.', | 69 merged and reverted.''') |
30 help="The path to your git working directory.") | 70 parser.add_argument('-g', '--git-dir', required=False, default='.', |
71 help='The path to your git working directory.') | |
31 | 72 |
32 parser.add_argument('hash', nargs=1, help="Hash of the commit to be searched." ) | 73 parser.add_argument('hash', |
74 nargs=1, | |
75 help='Hash of the commit to be searched.') | |
33 | 76 |
34 args = sys.argv[1:] | 77 args = sys.argv[1:] |
35 options = parser.parse_args(args) | 78 options = parser.parse_args(args) |
36 | 79 |
37 sys.exit(print_analysis(options.git_dir, options.hash[0])) | 80 sys.exit(print_analysis(options.git_dir, options.hash[0])) |
OLD | NEW |