Notes / Diff_update_script.py
PrathamGV's picture
Create Diff_update_script.py
b7bd098 verified
raw
history blame
1.17 kB
# 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]}")