[llvm-exegesis] Fix missing std::move.
[llvm-complete.git] / utils / git / find-rev
blob059ca0b78de84189ae575cd6f92b560c2001c5f5
1 #!/usr/bin/python
3 import os, sys, subprocess
5 def main():
6 from optparse import OptionParser, OptionGroup
7 parser = OptionParser("usage: %prog [options] <repo> <revision>")
8 parser.add_option("", "--branch", dest="branch",
9 help="Ref for the branch to search [%default]",
10 action="store", default="git-svn")
11 (opts, args) = parser.parse_args()
13 if len(args) != 2:
14 parser.error("invalid number of arguments")
16 repo,rev = args
18 try:
19 rev = int(rev)
20 except:
21 parser.error("invalid revision argument (not an integer)")
23 os.chdir(repo)
24 p = subprocess.Popen(['git', 'rev-list', opts.branch, '--pretty'],
25 stdout=subprocess.PIPE)
27 bestRev = bestCommit = None
28 lastCommit = None
29 for ln in p.stdout:
30 if ln.startswith('commit '):
31 lastCommit = ln.split(' ',2)[1]
32 elif ln.startswith(' git-svn-id: '):
33 _,repo,_ = ln.strip().split(' ')
34 _,lrev = repo.rsplit('@',1)
35 lrev = int(lrev)
36 if lrev<=rev:
37 if bestRev is None or lrev>bestRev:
38 assert lastCommit
39 bestCommit = lastCommit
40 bestRev = lrev
41 if lrev == rev:
42 break
44 if bestCommit is not None:
45 print bestCommit
46 sys.exit(0)
47 sys.exit(1)
49 if __name__=='__main__':
50 main()