-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdiff_utils.hpp
More file actions
64 lines (54 loc) · 1.77 KB
/
Copy pathdiff_utils.hpp
File metadata and controls
64 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <optional>
#include <string>
#include <vector>
namespace acecode {
// Line-change counters derived while building a unified diff.
struct DiffStats {
int additions = 0;
int deletions = 0;
};
// 一条 diff 行的种类。和 claudecodehaha 里 `StructuredDiffFallback` 的
// 'add' / 'remove' / 'nochange' 一一对应。
enum class DiffLineKind {
Context,
Added,
Removed,
};
// 结构化 diff 的单行:携带 marker、内容以及对应的 1-based 行号(纯增行
// `old_line_no` 为空,纯删行 `new_line_no` 为空)。
struct DiffLine {
DiffLineKind kind = DiffLineKind::Context;
std::string text; // 不含 '+' / '-' / ' ' 前缀
std::optional<int> old_line_no;
std::optional<int> new_line_no;
};
// 一个 hunk。行号起点 / 行数和 unified diff 的 `@@ -a,b +c,d @@` 对应。
struct DiffHunk {
int old_start = 0; // 1-based;无 old 侧时为 0
int old_count = 0;
int new_start = 0;
int new_count = 0;
std::vector<DiffLine> lines;
};
// 生成结构化 diff。内容完全相同时返回空向量。
std::vector<DiffHunk> generate_structured_diff(
const std::string& old_content,
const std::string& new_content,
const std::string& file_path
);
// Generate a unified diff between old and new content for a given file path.
std::string generate_unified_diff(
const std::string& old_content,
const std::string& new_content,
const std::string& file_path
);
// Variant that also reports additions/deletions via an out-parameter so
// callers can populate ToolSummary.metrics without re-parsing the diff.
std::string generate_unified_diff(
const std::string& old_content,
const std::string& new_content,
const std::string& file_path,
DiffStats& stats
);
} // namespace acecode