llvm.org GIT mirror llvm / 99fe6d9
Add simple script for finding most-recent-rev-before-N in a git-svn repo; useful when bisecting multiple repos in sync. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97150 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
1 changed file(s) with 50 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/python
1
2 import os, sys, subprocess
3
4 def main():
5 from optparse import OptionParser, OptionGroup
6 parser = OptionParser("usage: %prog [options] ")
7 parser.add_option("", "--dump-section-data", dest="dumpSectionData",
8 help="Dump the contents of sections",
9 action="store_true", default=False)
10 (opts, args) = parser.parse_args()
11
12 if len(args) != 2:
13 parser.error("invalid number of arguments")
14
15 repo,rev = args
16
17 try:
18 rev = int(rev)
19 except:
20 parser.error("invalid revision argument (not an integer)")
21
22 os.chdir(repo)
23 p = subprocess.Popen(['git', 'rev-list', 'git-svn', '--pretty'],
24 stdout=subprocess.PIPE)
25
26 bestRev = bestCommit = None
27 lastCommit = None
28 for ln in p.stdout:
29 if ln.startswith('commit '):
30 lastCommit = ln.split(' ',2)[1]
31 elif ln.startswith(' git-svn-id: '):
32 _,repo,_ = ln.strip().split(' ')
33 _,lrev = repo.rsplit('@',1)
34 lrev = int(lrev)
35 if lrev<=rev:
36 if bestRev is None or lrev>bestRev:
37 assert lastCommit
38 bestCommit = lastCommit
39 bestRev = lrev
40 if lrev == rev:
41 break
42
43 if bestCommit is not None:
44 print bestCommit
45 sys.exit(0)
46 sys.exit(1)
47
48 if __name__=='__main__':
49 main()