tree.c: update read_tree_recursive callback to pass strbuf as base
This allows the callback to use 'base' as a temporary buffer to quickly assemble full path "without" extra allocation. The callback has to restore it afterwards of course. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b260d265e1
commit
6a0b0b6de9
16
tree.c
16
tree.c
@ -30,9 +30,12 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
|
||||
return add_cache_entry(ce, opt);
|
||||
}
|
||||
|
||||
static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
|
||||
static int read_one_entry(const unsigned char *sha1, struct strbuf *base,
|
||||
const char *pathname, unsigned mode, int stage,
|
||||
void *context)
|
||||
{
|
||||
return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
|
||||
return read_one_entry_opt(sha1, base->buf, base->len, pathname,
|
||||
mode, stage,
|
||||
ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
|
||||
}
|
||||
|
||||
@ -40,9 +43,12 @@ static int read_one_entry(const unsigned char *sha1, const char *base, int basel
|
||||
* This is used when the caller knows there is no existing entries at
|
||||
* the stage that will conflict with the entry being added.
|
||||
*/
|
||||
static int read_one_entry_quick(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
|
||||
static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base,
|
||||
const char *pathname, unsigned mode, int stage,
|
||||
void *context)
|
||||
{
|
||||
return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
|
||||
return read_one_entry_opt(sha1, base->buf, base->len, pathname,
|
||||
mode, stage,
|
||||
ADD_CACHE_JUST_APPEND);
|
||||
}
|
||||
|
||||
@ -70,7 +76,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (fn(entry.sha1, base->buf, base->len,
|
||||
switch (fn(entry.sha1, base,
|
||||
entry.path, entry.mode, stage, context)) {
|
||||
case 0:
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user