mirror of
https://github.com/openai/codex.git
synced 2026-10-30 19:18:49 +00:00
[app-server] feat: add old_content and new_content to FileChange update patches
This commit is contained in:
@@ -194,6 +194,8 @@ pub enum ApplyPatchFileChange {
|
||||
move_path: Option<PathBuf>,
|
||||
/// new_content that will result after the unified_diff is applied.
|
||||
new_content: String,
|
||||
/// original content before the diff was applied.
|
||||
old_content: String,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -329,6 +331,7 @@ pub fn maybe_parse_apply_patch_verified(argv: &[String], cwd: &Path) -> MaybeApp
|
||||
let ApplyPatchFileUpdate {
|
||||
unified_diff,
|
||||
content: contents,
|
||||
old_content,
|
||||
} = match unified_diff_from_chunks(&path, &chunks) {
|
||||
Ok(diff) => diff,
|
||||
Err(e) => {
|
||||
@@ -341,6 +344,7 @@ pub fn maybe_parse_apply_patch_verified(argv: &[String], cwd: &Path) -> MaybeApp
|
||||
unified_diff,
|
||||
move_path: move_path.map(|p| effective_cwd.join(p)),
|
||||
new_content: contents,
|
||||
old_content,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -846,6 +850,7 @@ fn apply_replacements(
|
||||
pub struct ApplyPatchFileUpdate {
|
||||
unified_diff: String,
|
||||
content: String,
|
||||
old_content: String,
|
||||
}
|
||||
|
||||
pub fn unified_diff_from_chunks(
|
||||
@@ -869,6 +874,7 @@ pub fn unified_diff_from_chunks_with_context(
|
||||
Ok(ApplyPatchFileUpdate {
|
||||
unified_diff,
|
||||
content: new_contents,
|
||||
old_content: original_contents,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1467,6 +1473,7 @@ PATCH"#,
|
||||
let expected = ApplyPatchFileUpdate {
|
||||
unified_diff: expected_diff.to_string(),
|
||||
content: "foo\nBAR\nbaz\nQUX\n".to_string(),
|
||||
old_content: "foo\nbar\nbaz\nqux\n".to_string(),
|
||||
};
|
||||
assert_eq!(expected, diff);
|
||||
}
|
||||
@@ -1503,6 +1510,7 @@ PATCH"#,
|
||||
let expected = ApplyPatchFileUpdate {
|
||||
unified_diff: expected_diff.to_string(),
|
||||
content: "FOO\nbar\nbaz\n".to_string(),
|
||||
old_content: "foo\nbar\nbaz\n".to_string(),
|
||||
};
|
||||
assert_eq!(expected, diff);
|
||||
}
|
||||
@@ -1540,6 +1548,7 @@ PATCH"#,
|
||||
let expected = ApplyPatchFileUpdate {
|
||||
unified_diff: expected_diff.to_string(),
|
||||
content: "foo\nbar\nBAZ\n".to_string(),
|
||||
old_content: "foo\nbar\nbaz\n".to_string(),
|
||||
};
|
||||
assert_eq!(expected, diff);
|
||||
}
|
||||
@@ -1574,6 +1583,7 @@ PATCH"#,
|
||||
let expected = ApplyPatchFileUpdate {
|
||||
unified_diff: expected_diff.to_string(),
|
||||
content: "foo\nbar\nbaz\nquux\n".to_string(),
|
||||
old_content: "foo\nbar\nbaz\n".to_string(),
|
||||
};
|
||||
assert_eq!(expected, diff);
|
||||
}
|
||||
@@ -1629,6 +1639,7 @@ PATCH"#,
|
||||
let expected = ApplyPatchFileUpdate {
|
||||
unified_diff: expected_diff.to_string(),
|
||||
content: "a\nB\nc\nd\nE\nf\ng\n".to_string(),
|
||||
old_content: "a\nb\nc\nd\ne\nf\n".to_string(),
|
||||
};
|
||||
|
||||
assert_eq!(expected, diff);
|
||||
@@ -1688,6 +1699,7 @@ g
|
||||
.to_string(),
|
||||
move_path: None,
|
||||
new_content: "updated session directory content\n".to_string(),
|
||||
old_content: "session directory content\n".to_string(),
|
||||
},
|
||||
)]),
|
||||
patch: argv[1].clone(),
|
||||
|
||||
Reference in New Issue
Block a user