PrathamGV commited on
Commit
b7bd098
·
verified ·
1 Parent(s): a31d72f

Create Diff_update_script.py

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