MCPcopy Index your code
hub / github.com/AI45Lab/Code / parse_hunks

Function parse_hunks

core/src/tools/builtin/patch.rs:23–45  ·  view source on GitHub ↗

Parse a unified diff into hunks

(diff: &str)

Source from the content-addressed store, hash-verified

21
22/// Parse a unified diff into hunks
23fn parse_hunks(diff: &str) -> Result<Vec<Hunk>, String> {
24 let mut hunks = Vec::new();
25 let lines: Vec<&str> = diff.lines().collect();
26 let mut i = 0;
27
28 while i < lines.len() {
29 let line = lines[i];
30
31 // Look for @@ header
32 if line.starts_with("@@") {
33 let hunk = parse_single_hunk(&lines, &mut i)?;
34 hunks.push(hunk);
35 } else {
36 i += 1;
37 }
38 }
39
40 if hunks.is_empty() {
41 return Err("No @@ hunk headers found in diff".to_string());
42 }
43
44 Ok(hunks)
45}
46
47fn parse_single_hunk(lines: &[&str], i: &mut usize) -> Result<Hunk, String> {
48 let header = lines[*i];

Callers 3

executeMethod · 0.85
test_parse_hunks_simpleFunction · 0.85
test_apply_hunks_simpleFunction · 0.85

Calls 3

parse_single_hunkFunction · 0.85
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by 2

test_parse_hunks_simpleFunction · 0.68
test_apply_hunks_simpleFunction · 0.68