Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created October 12, 2017 17:06
Show Gist options
  • Save hughdbrown/136dafde53a41ce8969a67af78d7925c to your computer and use it in GitHub Desktop.
Save hughdbrown/136dafde53a41ce8969a67af78d7925c to your computer and use it in GitHub Desktop.
Which revisions have a particular phrase in their git diff?
import os
import os.path
from itertools import tee, izip
from subprocess import Popen, PIPE
BUFSIZE = 16 * 1024 * 1024
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
cmd = ["git", "rev-list", "release_prod_20170902_214223..release_prod_20170927_223603"]
p = Popen(cmd, stdout=PIPE, stderr=PIPE, bufsize=BUFSIZE)
output, errors = p.communicate()
if not errors:
hashes = output.splitlines()
for a, b in pairwise(hashes):
cmd = ["git", "diff", a, b]
p = Popen(cmd, stdout=PIPE, stderr=PIPE, bufsize=BUFSIZE)
output, errors = p.communicate()
if errors:
print("Error: {0} {1}".format(a, b))
break
else:
if "MissingColumn" in output:
print(a, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment