@@ -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+ */
237245int 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