Small Tools: Bisect
2018-02-23 11:59 - Programming
Git provides a great bisect tool. When something has been broken, it will automatically help you find out how and why, by bisecting (splitting into halves) the source control history, incrementally narrowing down on changes. I've sometimes got situations where I'd like to do a similar operation on something else that's not git history, but is instead numbered. A while ago I threw together a python script to help me do this:
#!/usr/bin/env python def main(argv): if len(argv) != 3: print "Usage: bisect.py <good> <bad>" return good = int(argv[1]) bad = int(argv[2]) while True: if bad == good + 1: print "First bad:", bad return totry = ((bad - good) / 2) + good inp = raw_input('At %s [g/b]: ' % totry) if 'g' == inp: good = totry elif 'b' == inp: bad = totry else: print "I don't understand." if __name__ == '__main__': import sys main(sys.argv)
Save this in your path, mark it executable, and run it with two arguments: the (smaller) number which was good and the (larger) number that is now bad. It will find the midpoint, you test that number and tell it good or bad and it repeats until you've tested immediate neighbors, indicating the first number which was bad: the one that introduced the problem.