| #!/usr/bin/env python3 | |
| import sys | |
| import difflib | |
| import subprocess | |
| commit = sys.argv[1] | |
| file = sys.argv[2] | |
| line = int(sys.argv[3]) - 1 | |
| prev = subprocess.check_output(["git", "show", "%s:%s" % (commit, file)]).decode('utf-8').split("\n") | |
| cur = open(file).read().split("\n") | |
| sm = difflib.SequenceMatcher(None, prev, cur) | |
| for tag, i1, i2, j1, j2 in sm.get_opcodes(): | |
| if i1 <= line < i2: | |
| if tag != "equal": | |
| print("line was deleted") | |
| sys.exit(1) | |
| corr_line = line - i1 + j1 | |
| break | |
| prev[line] = ">>>" + prev[line] + "<<<" | |
| cur[corr_line] = ">>>" + cur[corr_line] + "<<<" | |
| for i in range(len(prev)): | |
| prev[i] = str(i+1) + ": " + prev[i] | |
| for i in range(len(cur)): | |
| cur[i] = str(i+1) + ": " + cur[i] | |
| print("PREV") | |
| print("==================================") | |
| print("\n".join(prev)) | |
| print("") | |
| print("CUR, found in", corr_line + 1) | |
| print("==================================") | |
| print("\n".join(cur)) | |
| print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment