Skip to content

Commit

Permalink
Merge branch 'ag/maint-apply-too-large-p'
Browse files Browse the repository at this point in the history
* ag/maint-apply-too-large-p:
  builtin-apply.c: Skip filenames without enough components
  • Loading branch information
Junio C Hamano committed Jan 21, 2010
2 parents fcb2a7e + 1586208 commit df91d0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ static char *squash_slash(char *name)
{
int i = 0, j = 0;

if (!name)
return NULL;

while (name[i]) {
if ((name[j++] = name[i++]) == '/')
while (name[i] == '/')
Expand All @@ -416,7 +419,10 @@ static char *squash_slash(char *name)
static char *find_name(const char *line, char *def, int p_value, int terminate)
{
int len;
const char *start = line;
const char *start = NULL;

if (p_value == 0)
start = line;

if (*line == '"') {
struct strbuf name = STRBUF_INIT;
Expand Down Expand Up @@ -1199,7 +1205,8 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
continue;
if (!patch->old_name && !patch->new_name) {
if (!patch->def_name)
die("git diff header lacks filename information (line %d)", linenr);
die("git diff header lacks filename information when removing "
"%d leading pathname components (line %d)" , p_value, linenr);
patch->old_name = patch->new_name = patch->def_name;
}
patch->is_toplevel_relative = 1;
Expand Down
5 changes: 5 additions & 0 deletions t/t4120-apply-popt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ test_expect_success 'apply git diff with -p2' '
git apply -p2 patch.file
'

test_expect_success 'apply with too large -p' '
test_must_fail git apply --stat -p3 patch.file 2>err &&
grep "removing 3 leading" err
'

test_done

0 comments on commit df91d0e

Please sign in to comment.