Skip to content

Commit c7a9ec4

Browse files
committed
Merge branch 'rs/apply-lift-path-length-limit'
"git apply" has been updated to lift the hardcoded pathname length limit, which in turn allowed a mksnpath() function that is no longer used. * rs/apply-lift-path-length-limit: path: remove mksnpath() apply: avoid fixed-size buffer in create_one_file()
2 parents 509cc1d + 708f7e0 commit c7a9ec4

File tree

4 files changed

+9
-30
lines changed

4 files changed

+9
-30
lines changed

apply.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4448,6 +4448,7 @@ static int create_one_file(struct apply_state *state,
44484448
const char *buf,
44494449
unsigned long size)
44504450
{
4451+
char *newpath = NULL;
44514452
int res;
44524453

44534454
if (state->cached)
@@ -4509,24 +4510,26 @@ static int create_one_file(struct apply_state *state,
45094510
unsigned int nr = getpid();
45104511

45114512
for (;;) {
4512-
char newpath[PATH_MAX];
4513-
mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
4513+
newpath = mkpathdup("%s~%u", path, nr);
45144514
res = try_create_file(state, newpath, mode, buf, size);
45154515
if (res < 0)
4516-
return -1;
4516+
goto out;
45174517
if (!res) {
45184518
if (!rename(newpath, path))
4519-
return 0;
4519+
goto out;
45204520
unlink_or_warn(newpath);
45214521
break;
45224522
}
45234523
if (errno != EEXIST)
45244524
break;
45254525
++nr;
4526+
FREE_AND_NULL(newpath);
45264527
}
45274528
}
4528-
return error_errno(_("unable to write file '%s' mode %o"),
4529-
path, mode);
4529+
res = error_errno(_("unable to write file '%s' mode %o"), path, mode);
4530+
out:
4531+
free(newpath);
4532+
return res;
45304533
}
45314534

45324535
static int add_conflicted_stages_file(struct apply_state *state,

contrib/vscode/init.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ cat >.vscode/settings.json.new <<\EOF ||
9292
"isexe",
9393
"iskeychar",
9494
"kompare",
95-
"mksnpath",
9695
"mktag",
9796
"mktree",
9897
"mmblob",

path.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ static int get_st_mode_bits(const char *path, int *mode)
2828
return 0;
2929
}
3030

31-
static char bad_path[] = "/bad-path/";
32-
3331
static struct strbuf *get_pathname(void)
3432
{
3533
static struct strbuf pathname_array[4] = {
@@ -59,21 +57,6 @@ static void strbuf_cleanup_path(struct strbuf *sb)
5957
strbuf_remove(sb, 0, path - sb->buf);
6058
}
6159

62-
char *mksnpath(char *buf, size_t n, const char *fmt, ...)
63-
{
64-
va_list args;
65-
unsigned len;
66-
67-
va_start(args, fmt);
68-
len = vsnprintf(buf, n, fmt, args);
69-
va_end(args);
70-
if (len >= n) {
71-
strlcpy(buf, bad_path, n);
72-
return buf;
73-
}
74-
return (char *)cleanup_path(buf);
75-
}
76-
7760
static int dir_prefix(const char *buf, const char *dir)
7861
{
7962
int len = strlen(dir);

path.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ const char *mkpath(const char *fmt, ...)
2323
char *mkpathdup(const char *fmt, ...)
2424
__attribute__((format (printf, 1, 2)));
2525

26-
/*
27-
* Construct a path and place the result in the provided buffer `buf`.
28-
*/
29-
char *mksnpath(char *buf, size_t n, const char *fmt, ...)
30-
__attribute__((format (printf, 3, 4)));
31-
3226
/*
3327
* The `git_common_path` family of functions will construct a path into a
3428
* repository's common git directory, which is shared by all worktrees.

0 commit comments

Comments
 (0)