Guest User

Untitled

a guest
Jun 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. from subprocess import check_output
  5. import shlex
  6.  
  7. def helpAndQuit():
  8. print "svnbinsearch -r[low_revision]:[high_revision] [local_svn_repo]"
  9. print "\tlow/high_revision: The revision range to binary search. Low revision should work, high revision should not."
  10. print "\t This argument string gets passed, in its entirety, to our svn log command."
  11. print "\t ex: svnbinsearch -r167165:167344"
  12. print "\tlocal_svn_repo: Your local SVN working copy. If not given, it uses the current directory."
  13. sys.exit(1)
  14.  
  15. def askUserIfWorks(rev):
  16. response = ''
  17. while len(response) == 0 or (response[0] != 'Y' and response[0] != 'N'):
  18. sys.stdout.write("Try revision {0}... does it work? (input Y/N): ".format(rev))
  19. response = raw_input().strip().upper()
  20.  
  21. return response[0] == 'Y'
  22.  
  23. svn_revision_range = ''
  24. svn_repo = '.'
  25.  
  26. if len(sys.argv) < 2:
  27. helpAndQuit()
  28. else:
  29. svn_revision_range = sys.argv[1]
  30.  
  31. if len(sys.argv) >= 3:
  32. svn_repo = sys.argv[2]
  33.  
  34. svn_argstr = "svn log -q {0} {1}".format(svn_revision_range, svn_repo)
  35. print "Getting revision list with `{0}`...".format(svn_argstr)
  36. svn_output = check_output(shlex.split(svn_argstr))
  37.  
  38. svn_output = svn_output.split("\n")
  39.  
  40. rev_list = []
  41. for s in svn_output:
  42. if len(s) == 0:
  43. continue
  44. if s[0] == '-':
  45. continue
  46. spacePos = s.find(' ')
  47. if spacePos == -1:
  48. continue
  49. rev_list.append(s[:spacePos])
  50.  
  51. lo = 0
  52. hi = len(rev_list)-1
  53. while (lo <= hi):
  54. mid = lo + (hi - lo) / 2
  55. doesWork = askUserIfWorks(rev_list[mid])
  56. if doesWork:
  57. lo = mid+1
  58. else:
  59. hi = mid-1
  60.  
  61. if hi < 0:
  62. print "Error: the lowest revision given ({0}) does not work!".format(rev_list[0])
  63. elif lo >= len(rev_list):
  64. print "Error: the highest revision given ({0}) works fine!".format(rev_list[-1])
  65. else:
  66. print "Problem revision is {0}!".format(rev_list[lo])
Add Comment
Please, Sign In to add comment