Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- from subprocess import check_output
- import shlex
- def helpAndQuit():
- print "svnbinsearch -r[low_revision]:[high_revision] [local_svn_repo]"
- print "\tlow/high_revision: The revision range to binary search. Low revision should work, high revision should not."
- print "\t This argument string gets passed, in its entirety, to our svn log command."
- print "\t ex: svnbinsearch -r167165:167344"
- print "\tlocal_svn_repo: Your local SVN working copy. If not given, it uses the current directory."
- sys.exit(1)
- def askUserIfWorks(rev):
- response = ''
- while len(response) == 0 or (response[0] != 'Y' and response[0] != 'N'):
- sys.stdout.write("Try revision {0}... does it work? (input Y/N): ".format(rev))
- response = raw_input().strip().upper()
- return response[0] == 'Y'
- svn_revision_range = ''
- svn_repo = '.'
- if len(sys.argv) < 2:
- helpAndQuit()
- else:
- svn_revision_range = sys.argv[1]
- if len(sys.argv) >= 3:
- svn_repo = sys.argv[2]
- svn_argstr = "svn log -q {0} {1}".format(svn_revision_range, svn_repo)
- print "Getting revision list with `{0}`...".format(svn_argstr)
- svn_output = check_output(shlex.split(svn_argstr))
- svn_output = svn_output.split("\n")
- rev_list = []
- for s in svn_output:
- if len(s) == 0:
- continue
- if s[0] == '-':
- continue
- spacePos = s.find(' ')
- if spacePos == -1:
- continue
- rev_list.append(s[:spacePos])
- lo = 0
- hi = len(rev_list)-1
- while (lo <= hi):
- mid = lo + (hi - lo) / 2
- doesWork = askUserIfWorks(rev_list[mid])
- if doesWork:
- lo = mid+1
- else:
- hi = mid-1
- if hi < 0:
- print "Error: the lowest revision given ({0}) does not work!".format(rev_list[0])
- elif lo >= len(rev_list):
- print "Error: the highest revision given ({0}) works fine!".format(rev_list[-1])
- else:
- print "Problem revision is {0}!".format(rev_list[lo])
Add Comment
Please, Sign In to add comment