Fix typo pointed out in pr9339.
[llvm/stm8.git] / utils / git / find-rev
bloba6161db18985ff1f930483382671c2df5eefe34b
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("", "--dump-section-data", dest="dumpSectionData",
9 help="Dump the contents of sections",
10 action="store_true", default=False)
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', 'git-svn', '--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()