MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / parse_hunk_line

Function parse_hunk_line

src/pipeline/pass_gitdiff.c:113–152  ·  view source on GitHub ↗

Parse a single @@ hunk header line and emit a hunk entry if valid. * Returns true if a hunk was added. */

Source from the content-addressed store, hash-verified

111/* Parse a single @@ hunk header line and emit a hunk entry if valid.
112 * Returns true if a hunk was added. */
113static bool parse_hunk_line(const char *line, size_t line_len, const char *current_file,
114 cbm_changed_hunk_t *out_h) {
115 const char *plus = memchr(line, '+', line_len);
116 if (!plus || plus <= line) {
117 return false;
118 }
119
120 const char *end_at = strstr(plus, " @@");
121 size_t range_len;
122 if (end_at) {
123 range_len = (size_t)(end_at - plus - SKIP_ONE);
124 } else {
125 range_len = (size_t)(line + line_len - plus - SKIP_ONE);
126 }
127
128 char range_str[CBM_SZ_64];
129 if (range_len >= sizeof(range_str)) {
130 range_len = sizeof(range_str) - SKIP_ONE;
131 }
132 memcpy(range_str, plus + SKIP_ONE, range_len);
133 range_str[range_len] = '\0';
134
135 int start;
136 int cnt;
137 cbm_parse_range(range_str, &start, &cnt);
138
139 if (start <= 0 || !cbm_is_trackable_file(current_file)) {
140 return false;
141 }
142
143 int end = start + cnt - SKIP_ONE;
144 if (end < start) {
145 end = start;
146 }
147
148 snprintf(out_h->path, sizeof(out_h->path), "%s", current_file);
149 out_h->start_line = start;
150 out_h->end_line = end;
151 return true;
152}
153
154int cbm_parse_hunks(const char *output, cbm_changed_hunk_t *out, int max_out) {
155 if (!output || !out || max_out <= 0) {

Callers 1

cbm_parse_hunksFunction · 0.85

Calls 2

cbm_parse_rangeFunction · 0.85
cbm_is_trackable_fileFunction · 0.85

Tested by

no test coverage detected