MCPcopy Index your code
hub / github.com/git/git / parse_chunk

Function parse_chunk

apply.c:2251–2328  ·  view source on GitHub ↗

* Read the patch text in "buffer" that extends for "size" bytes; stop * reading after seeing a single patch (i.e. changes to a single file). * Create fragments (i.e. patch hunks) and hang them to the given patch. * * Returns: * -1 if no header was found or parse_binary() failed, * -128 on another error, * the number of bytes consumed otherwise, * so that the caller can call us ag

Source from the content-addressed store, hash-verified

2249 * so that the caller can call us again for the next patch.
2250 */
2251static int parse_chunk(struct apply_state *state, char *buffer, unsigned long size, struct patch *patch)
2252{
2253 int hdrsize, patchsize;
2254 int offset = find_header(state, buffer, size, &hdrsize, patch);
2255
2256 if (offset < 0)
2257 return offset;
2258
2259 prefix_patch(state, patch);
2260
2261 if (!use_patch(state, patch))
2262 patch->ws_rule = 0;
2263 else if (patch->new_name)
2264 patch->ws_rule = whitespace_rule(state->repo->index,
2265 patch->new_name);
2266 else
2267 patch->ws_rule = whitespace_rule(state->repo->index,
2268 patch->old_name);
2269
2270 patchsize = parse_single_patch(state,
2271 buffer + offset + hdrsize,
2272 size - offset - hdrsize,
2273 patch);
2274
2275 if (patchsize < 0)
2276 return -128;
2277
2278 if (!patchsize) {
2279 static const char git_binary[] = "GIT binary patch\n";
2280 int hd = hdrsize + offset;
2281 unsigned long llen = linelen(buffer + hd, size - hd);
2282
2283 if (llen == sizeof(git_binary) - 1 &&
2284 !memcmp(git_binary, buffer + hd, llen)) {
2285 int used;
2286 state->linenr++;
2287 used = parse_binary(state, buffer + hd + llen,
2288 size - hd - llen, patch);
2289 if (used < 0)
2290 return -1;
2291 if (used)
2292 patchsize = used + llen;
2293 else
2294 patchsize = 0;
2295 }
2296 else if (!memcmp(" differ\n", buffer + hd + llen - 8, 8)) {
2297 static const char *binhdr[] = {
2298 "Binary files ",
2299 "Files ",
2300 NULL,
2301 };
2302 int i;
2303 for (i = 0; binhdr[i]; i++) {
2304 int len = strlen(binhdr[i]);
2305 if (len < size - hd &&
2306 !memcmp(binhdr[i], buffer + hd, len)) {
2307 state->linenr++;
2308 patch->is_binary = 1;

Callers 1

apply_patchFunction · 0.85

Calls 9

find_headerFunction · 0.85
prefix_patchFunction · 0.85
use_patchFunction · 0.85
parse_single_patchFunction · 0.85
parse_binaryFunction · 0.85
metadata_changesFunction · 0.85
errorFunction · 0.85
whitespace_ruleFunction · 0.70
linelenFunction · 0.70

Tested by

no test coverage detected