X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=entry.c;h=7b7aa8167adade20f38cfb2709e02b3ed31f11a4;hb=59f3e3f1e2b600f122e011b3d90309736799e25d;hp=acc892f9a62b5bc3d3442b044b29bf8d763bf3ba;hpb=77bc4302dc93ac33891c72df59d9426eb6d06d0b;p=~andy%2Fgit diff --git a/entry.c b/entry.c index acc892f9a..7b7aa8167 100644 --- a/entry.c +++ b/entry.c @@ -234,19 +234,30 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen) return lstat(path, st); } +/* + * Write the contents from ce out to the working tree. + * + * When topath[] is not NULL, instead of writing to the working tree + * file named by ce, a temporary file is created by this function and + * its name is returned in topath[], which must be able to hold at + * least TEMPORARY_FILENAME_LENGTH bytes long. + */ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath) { - static char path[PATH_MAX + 1]; + static struct strbuf path_buf = STRBUF_INIT; + char *path; struct stat st; - int len = state->base_dir_len; + int len; if (topath) return write_entry(ce, topath, state, 1); - memcpy(path, state->base_dir, len); - strcpy(path + len, ce->name); - len += ce_namelen(ce); + strbuf_reset(&path_buf); + strbuf_add(&path_buf, state->base_dir, state->base_dir_len); + strbuf_add(&path_buf, ce->name, ce_namelen(ce)); + path = path_buf.buf; + len = path_buf.len; if (!check_path(path, len, &st, state->base_dir_len)) { unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);