238
return 1;
239
}
240
241
-static char * find_name(const char *line, char *def, int p_value, int terminate)
241
+static char *find_name(const char *line, char *def, int p_value, int terminate)
242
{
243
int len;
244
const char *start = line;
362
static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, const char *oldnew)
363
{
364
if (!orig_name && !isnull)
365
- return find_name(line, NULL, 1, TERM_TAB);
365
+ return find_name(line, NULL, p_value, TERM_TAB);
366
367
if (orig_name) {
368
int len;
372
len = strlen(name);
373
if (isnull)
374
die("git-apply: bad git-diff - expected /dev/null, got %s on line %d", name, linenr);
375
- another = find_name(line, NULL, 1, TERM_TAB);
375
+ another = find_name(line, NULL, p_value, TERM_TAB);
376
if (!another || memcmp(another, name, len))
377
die("git-apply: bad git-diff - inconsistent %s filename on line %d", oldnew, linenr);
378
free(another);
427
static int gitdiff_copysrc(const char *line, struct patch *patch)
428
{
429
patch->is_copy = 1;
430
- patch->old_name = find_name(line, NULL, 0, 0);
430
+ patch->old_name = find_name(line, NULL, p_value-1, 0);
431
return 0;
432
}
433
434
static int gitdiff_copydst(const char *line, struct patch *patch)
435
{
436
patch->is_copy = 1;
437
- patch->new_name = find_name(line, NULL, 0, 0);
437
+ patch->new_name = find_name(line, NULL, p_value-1, 0);
438
return 0;
439
}
440
441
static int gitdiff_renamesrc(const char *line, struct patch *patch)
442
{
443
patch->is_rename = 1;
444
- patch->old_name = find_name(line, NULL, 0, 0);
444
+ patch->old_name = find_name(line, NULL, p_value-1, 0);
445
return 0;
446
}
447
448
static int gitdiff_renamedst(const char *line, struct patch *patch)
449
{
450
patch->is_rename = 1;
451
- patch->new_name = find_name(line, NULL, 0, 0);
451
+ patch->new_name = find_name(line, NULL, p_value-1, 0);
452
return 0;
453
}
454
2499
return 0;
2500
x = x->next;
2501
}
2502
- if (0 < prefix_length) {
2503
- int pathlen = strlen(pathname);
2504
- if (pathlen <= prefix_length ||
2505
- memcmp(prefix, pathname, prefix_length))
2506
- return 0;
2507
- }
2502
return 1;
2503
}
2504
2505
+static char *prefix_one(char *name)
2506
+{
2507
+ if (!name)
2508
+ return name;
2509
+ return xstrdup(prefix_filename(prefix, prefix_length, name));
2510
+}
2511
+
2512
+static void prefix_patches(struct patch *p)
2513
+{
2514
+ if (!prefix)
2515
+ return;
2516
+ for ( ; p; p = p->next) {
2517
+ p->new_name = prefix_one(p->new_name);
2518
+ p->old_name = prefix_one(p->old_name);
2519
+ }
2520
+}
2521
+
2522
static int apply_patch(int fd, const char *filename, int inaccurate_eof)
2523
{
2524
unsigned long offset, size;
2541
break;
2542
if (apply_in_reverse)
2543
reverse_patches(patch);
2544
+ if (prefix)
2545
+ prefix_patches(patch);
2546
if (use_patch(patch)) {
2547
patch_stats(patch);
2548
*listp = patch;
2549
listp = &patch->next;
2537
- } else {
2550
+ }
2551
+ else {
2552
/* perhaps free it a bit better? */
2553
free(patch);
2554
skipped_patch++;