144
unsigned long deflate_origlen;
145
int lines_added, lines_deleted;
146
int score;
147
+ unsigned int is_toplevel_relative:1;
148
unsigned int inaccurate_eof:1;
149
unsigned int is_binary:1;
150
unsigned int is_copy:1;
363
static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, const char *oldnew)
364
{
365
if (!orig_name && !isnull)
365
- return find_name(line, NULL, p_value, TERM_TAB);
366
+ return find_name(line, NULL, 1, TERM_TAB);
367
368
if (orig_name) {
369
int len;
373
len = strlen(name);
374
if (isnull)
375
die("git-apply: bad git-diff - expected /dev/null, got %s on line %d", name, linenr);
375
- another = find_name(line, NULL, p_value, TERM_TAB);
376
+ another = find_name(line, NULL, 1, TERM_TAB);
377
if (!another || memcmp(another, name, len))
378
die("git-apply: bad git-diff - inconsistent %s filename on line %d", oldnew, linenr);
379
free(another);
428
static int gitdiff_copysrc(const char *line, struct patch *patch)
429
{
430
patch->is_copy = 1;
430
- patch->old_name = find_name(line, NULL, p_value-1, 0);
431
+ patch->old_name = find_name(line, NULL, 0, 0);
432
return 0;
433
}
434
435
static int gitdiff_copydst(const char *line, struct patch *patch)
436
{
437
patch->is_copy = 1;
437
- patch->new_name = find_name(line, NULL, p_value-1, 0);
438
+ patch->new_name = find_name(line, NULL, 0, 0);
439
return 0;
440
}
441
442
static int gitdiff_renamesrc(const char *line, struct patch *patch)
443
{
444
patch->is_rename = 1;
444
- patch->old_name = find_name(line, NULL, p_value-1, 0);
445
+ patch->old_name = find_name(line, NULL, 0, 0);
446
return 0;
447
}
448
449
static int gitdiff_renamedst(const char *line, struct patch *patch)
450
{
451
patch->is_rename = 1;
451
- patch->new_name = find_name(line, NULL, p_value-1, 0);
452
+ patch->new_name = find_name(line, NULL, 0, 0);
453
return 0;
454
}
455
788
{
789
unsigned long offset, len;
790
791
+ patch->is_toplevel_relative = 0;
792
patch->is_rename = patch->is_copy = 0;
793
patch->is_new = patch->is_delete = -1;
794
patch->old_mode = patch->new_mode = 0;
833
die("git diff header lacks filename information (line %d)", linenr);
834
patch->old_name = patch->new_name = patch->def_name;
835
}
836
+ patch->is_toplevel_relative = 1;
837
*hdrsize = git_hdr_len;
838
return offset;
839
}
2502
return 0;
2503
x = x->next;
2504
}
2505
+ if (0 < prefix_length) {
2506
+ int pathlen = strlen(pathname);
2507
+ if (pathlen <= prefix_length ||
2508
+ memcmp(prefix, pathname, prefix_length))
2509
+ return 0;
2510
+ }
2511
return 1;
2512
}
2513
2522
2523
static void prefix_patches(struct patch *p)
2524
{
2516
- if (!prefix)
2525
+ if (!prefix || p->is_toplevel_relative)
2526
return;
2527
for ( ; p; p = p->next) {
2528
if (p->new_name == p->old_name) {