Skip to content

Commit c02e1e4

Browse files
committed
Merge branch 'nd/lift-path-max'
* nd/lift-path-max: checkout_entry(): clarify the use of topath[] parameter entry.c: convert checkout_entry to use strbuf
2 parents f989180 + af2a651 commit c02e1e4

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

builtin/checkout-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
static int line_termination = '\n';
1515
static int checkout_stage; /* default to checkout stage0 */
1616
static int to_tempfile;
17-
static char topath[4][PATH_MAX + 1];
17+
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
1818

1919
static struct checkout state;
2020

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ struct checkout {
976976
refresh_cache:1;
977977
};
978978

979+
#define TEMPORARY_FILENAME_LENGTH 25
979980
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
980981

981982
struct cache_def {

entry.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,30 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
234234
return lstat(path, st);
235235
}
236236

237+
/*
238+
* Write the contents from ce out to the working tree.
239+
*
240+
* When topath[] is not NULL, instead of writing to the working tree
241+
* file named by ce, a temporary file is created by this function and
242+
* its name is returned in topath[], which must be able to hold at
243+
* least TEMPORARY_FILENAME_LENGTH bytes long.
244+
*/
237245
int checkout_entry(struct cache_entry *ce,
238246
const struct checkout *state, char *topath)
239247
{
240-
static char path[PATH_MAX + 1];
248+
static struct strbuf path_buf = STRBUF_INIT;
249+
char *path;
241250
struct stat st;
242-
int len = state->base_dir_len;
251+
int len;
243252

244253
if (topath)
245254
return write_entry(ce, topath, state, 1);
246255

247-
memcpy(path, state->base_dir, len);
248-
strcpy(path + len, ce->name);
249-
len += ce_namelen(ce);
256+
strbuf_reset(&path_buf);
257+
strbuf_add(&path_buf, state->base_dir, state->base_dir_len);
258+
strbuf_add(&path_buf, ce->name, ce_namelen(ce));
259+
path = path_buf.buf;
260+
len = path_buf.len;
250261

251262
if (!check_path(path, len, &st, state->base_dir_len)) {
252263
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);

0 commit comments

Comments
 (0)