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
This commit is contained in:
Junio C Hamano
2013-10-30 12:10:56 -07:00
3 changed files with 18 additions and 6 deletions

View File

@ -14,7 +14,7 @@
static int line_termination = '\n'; static int line_termination = '\n';
static int checkout_stage; /* default to checkout stage0 */ static int checkout_stage; /* default to checkout stage0 */
static int to_tempfile; static int to_tempfile;
static char topath[4][PATH_MAX + 1]; static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
static struct checkout state; static struct checkout state;

View File

@ -976,6 +976,7 @@ struct checkout {
refresh_cache:1; refresh_cache:1;
}; };
#define TEMPORARY_FILENAME_LENGTH 25
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
struct cache_def { struct cache_def {

21
entry.c
View File

@ -234,19 +234,30 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
return lstat(path, st); 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, int checkout_entry(struct cache_entry *ce,
const struct checkout *state, char *topath) const struct checkout *state, char *topath)
{ {
static char path[PATH_MAX + 1]; static struct strbuf path_buf = STRBUF_INIT;
char *path;
struct stat st; struct stat st;
int len = state->base_dir_len; int len;
if (topath) if (topath)
return write_entry(ce, topath, state, 1); return write_entry(ce, topath, state, 1);
memcpy(path, state->base_dir, len); strbuf_reset(&path_buf);
strcpy(path + len, ce->name); strbuf_add(&path_buf, state->base_dir, state->base_dir_len);
len += ce_namelen(ce); 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)) { 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); unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);