File size: 1,174 Bytes
b7bd098 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# merge_diff_with_comments.py
# Usage: python merge_diff_with_comments.py diff.txt merged_left.txt
import sys
def merge_diff(diff_file, out_file):
output_lines = []
with open(diff_file, "r", encoding="utf-8") as f:
for line in f:
if line.startswith(">"):
# Take the right file's version, strip "> " and add comment
updated_line = line[2:].rstrip("\n") + " //Pratham : updated\n"
output_lines.append(updated_line)
elif line.startswith("<"):
# Skip the left side's outdated version
continue
elif line.startswith("|"):
# Skip the diff separator
continue
else:
# Common line, keep as-is
output_lines.append(line)
with open(out_file, "w", encoding="utf-8") as out:
out.writelines(output_lines)
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python merge_diff_with_comments.py diff.txt merged_left.txt")
else:
merge_diff(sys.argv[1], sys.argv[2])
print(f"Merged file with comments written to {sys.argv[2]}") |