diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2014-11-30 16:05:00 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-12-01 11:32:29 -0800 |
commit | 6a0b0b6de996e2ac7eeb951e3d08f577c11c7e54 (patch) | |
tree | b5ce77337d93903b5363e20694397efcb73daf25 /builtin | |
parent | Git 2.2 (diff) | |
download | tgif-6a0b0b6de996e2ac7eeb951e3d08f577c11c7e54.tar.xz |
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>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/checkout.c | 8 | ||||
-rw-r--r-- | builtin/log.c | 2 | ||||
-rw-r--r-- | builtin/ls-tree.c | 9 |
3 files changed, 10 insertions, 9 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 5410dacea0..8adf48de74 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -62,7 +62,7 @@ static int post_checkout_hook(struct commit *old, struct commit *new, } -static int update_some(const unsigned char *sha1, const char *base, int baselen, +static int update_some(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { int len; @@ -71,11 +71,11 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen, if (S_ISDIR(mode)) return READ_TREE_RECURSIVE; - len = baselen + strlen(pathname); + len = base->len + strlen(pathname); ce = xcalloc(1, cache_entry_size(len)); hashcpy(ce->sha1, sha1); - memcpy(ce->name, base, baselen); - memcpy(ce->name + baselen, pathname, len - baselen); + memcpy(ce->name, base->buf, base->len); + memcpy(ce->name + base->len, pathname, len - base->len); ce->ce_flags = create_ce_flags(0) | CE_UPDATE; ce->ce_namelen = len; ce->ce_mode = create_ce_mode(mode); diff --git a/builtin/log.c b/builtin/log.c index 734aab3a73..f2a9f0156d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -489,7 +489,7 @@ static int show_tag_object(const unsigned char *sha1, struct rev_info *rev) } static int show_tree_object(const unsigned char *sha1, - const char *base, int baselen, + struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 51184dfa2e..1ab0381245 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -61,7 +61,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname) } } -static int show_tree(const unsigned char *sha1, const char *base, int baselen, +static int show_tree(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { int retval = 0; @@ -79,7 +79,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen, */ type = commit_type; } else if (S_ISDIR(mode)) { - if (show_recursive(base, baselen, pathname)) { + if (show_recursive(base->buf, base->len, pathname)) { retval = READ_TREE_RECURSIVE; if (!(ls_options & LS_SHOW_TREES)) return retval; @@ -90,7 +90,8 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen, return 0; if (chomp_prefix && - (baselen < chomp_prefix || memcmp(ls_tree_prefix, base, chomp_prefix))) + (base->len < chomp_prefix || + memcmp(ls_tree_prefix, base->buf, chomp_prefix))) return 0; if (!(ls_options & LS_NAME_ONLY)) { @@ -112,7 +113,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen, printf("%06o %s %s\t", mode, type, find_unique_abbrev(sha1, abbrev)); } - write_name_quotedpfx(base + chomp_prefix, baselen - chomp_prefix, + write_name_quotedpfx(base->buf + chomp_prefix, base->len - chomp_prefix, pathname, stdout, line_termination); return retval; } |