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()maint
commit
c7a9ec4728
15
apply.c
15
apply.c
|
@ -4448,6 +4448,7 @@ static int create_one_file(struct apply_state *state,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
unsigned long size)
|
unsigned long size)
|
||||||
{
|
{
|
||||||
|
char *newpath = NULL;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (state->cached)
|
if (state->cached)
|
||||||
|
@ -4509,24 +4510,26 @@ static int create_one_file(struct apply_state *state,
|
||||||
unsigned int nr = getpid();
|
unsigned int nr = getpid();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char newpath[PATH_MAX];
|
newpath = mkpathdup("%s~%u", path, nr);
|
||||||
mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
|
|
||||||
res = try_create_file(state, newpath, mode, buf, size);
|
res = try_create_file(state, newpath, mode, buf, size);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
goto out;
|
||||||
if (!res) {
|
if (!res) {
|
||||||
if (!rename(newpath, path))
|
if (!rename(newpath, path))
|
||||||
return 0;
|
goto out;
|
||||||
unlink_or_warn(newpath);
|
unlink_or_warn(newpath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (errno != EEXIST)
|
if (errno != EEXIST)
|
||||||
break;
|
break;
|
||||||
++nr;
|
++nr;
|
||||||
|
FREE_AND_NULL(newpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return error_errno(_("unable to write file '%s' mode %o"),
|
res = error_errno(_("unable to write file '%s' mode %o"), path, mode);
|
||||||
path, mode);
|
out:
|
||||||
|
free(newpath);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_conflicted_stages_file(struct apply_state *state,
|
static int add_conflicted_stages_file(struct apply_state *state,
|
||||||
|
|
|
@ -92,7 +92,6 @@ cat >.vscode/settings.json.new <<\EOF ||
|
||||||
"isexe",
|
"isexe",
|
||||||
"iskeychar",
|
"iskeychar",
|
||||||
"kompare",
|
"kompare",
|
||||||
"mksnpath",
|
|
||||||
"mktag",
|
"mktag",
|
||||||
"mktree",
|
"mktree",
|
||||||
"mmblob",
|
"mmblob",
|
||||||
|
|
17
path.c
17
path.c
|
@ -28,8 +28,6 @@ static int get_st_mode_bits(const char *path, int *mode)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char bad_path[] = "/bad-path/";
|
|
||||||
|
|
||||||
static struct strbuf *get_pathname(void)
|
static struct strbuf *get_pathname(void)
|
||||||
{
|
{
|
||||||
static struct strbuf pathname_array[4] = {
|
static struct strbuf pathname_array[4] = {
|
||||||
|
@ -59,21 +57,6 @@ static void strbuf_cleanup_path(struct strbuf *sb)
|
||||||
strbuf_remove(sb, 0, path - sb->buf);
|
strbuf_remove(sb, 0, path - sb->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
unsigned len;
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
len = vsnprintf(buf, n, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
if (len >= n) {
|
|
||||||
strlcpy(buf, bad_path, n);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
return (char *)cleanup_path(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int dir_prefix(const char *buf, const char *dir)
|
static int dir_prefix(const char *buf, const char *dir)
|
||||||
{
|
{
|
||||||
int len = strlen(dir);
|
int len = strlen(dir);
|
||||||
|
|
6
path.h
6
path.h
|
@ -23,12 +23,6 @@ const char *mkpath(const char *fmt, ...)
|
||||||
char *mkpathdup(const char *fmt, ...)
|
char *mkpathdup(const char *fmt, ...)
|
||||||
__attribute__((format (printf, 1, 2)));
|
__attribute__((format (printf, 1, 2)));
|
||||||
|
|
||||||
/*
|
|
||||||
* Construct a path and place the result in the provided buffer `buf`.
|
|
||||||
*/
|
|
||||||
char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
|
||||||
__attribute__((format (printf, 3, 4)));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The `git_common_path` family of functions will construct a path into a
|
* The `git_common_path` family of functions will construct a path into a
|
||||||
* repository's common git directory, which is shared by all worktrees.
|
* repository's common git directory, which is shared by all worktrees.
|
||||||
|
|
Loading…
Reference in New Issue