rasdani commited on
Commit
63d9306
·
verified ·
1 Parent(s): 4de963d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +54 -0
README.md CHANGED
@@ -33,3 +33,57 @@ configs:
33
  - split: train
34
  path: data/train-*
35
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  - split: train
34
  path: data/train-*
35
  ---
36
+ ```python
37
+ import re
38
+ import json
39
+ from datasets import load_dataset
40
+
41
+
42
+ ds = load_dataset("rasdani/github-patches-10k-sample-sorted", split="train")
43
+
44
+
45
+ def normalize_diff(diff_text: str) -> str:
46
+ diff_text = re.sub(r'(?m)^index [^\n]*\n', '', diff_text)
47
+ diff_text = re.sub(r'(?m)^(@@[^@]*@@).*', r'\1', diff_text)
48
+ return diff_text
49
+
50
+ def filter_diff_by_files(diff: str, touched_files: set) -> str:
51
+ """Filter a git diff to only include changes for specific files."""
52
+ if not touched_files:
53
+ return diff
54
+
55
+ lines = diff.split('\n')
56
+ filtered_lines = []
57
+ include_section = False
58
+
59
+ for line in lines:
60
+ if line.startswith('diff --git'):
61
+ # Check if this file should be included
62
+ # Extract the file path from "diff --git a/path b/path"
63
+ match = re.match(r'diff --git a/(.*?) b/', line)
64
+ if match:
65
+ file_path = match.group(1)
66
+ include_section = file_path in touched_files
67
+ else:
68
+ include_section = False
69
+
70
+ if include_section:
71
+ filtered_lines.append(line)
72
+
73
+ return '\n'.join(filtered_lines)
74
+
75
+ def create_golden_diff(example):
76
+ before_paths = [b["path"] for b in example["before_files"]]
77
+ after_paths = [a["path"] for a in example["after_files"]]
78
+ touched_files = set(before_paths) | set(after_paths)
79
+ filtered_diff = filter_diff_by_files(example["pr_diff"], touched_files)
80
+ golden_diff = normalize_diff(filtered_diff)
81
+ for path in touched_files:
82
+ assert path in golden_diff, f"Path {path} not found in golden diff {golden_diff}"
83
+ verification_info = json.dumps({"golden_diff": golden_diff})
84
+ return {"golden_diff": golden_diff, "verification_info": verification_info}
85
+
86
+
87
+ ds_gen = ds.map(create_golden_diff, num_proc=10)
88
+ ds_gen.push_to_hub("rasdani/github-patches-genesys-debug")
89
+ ```