tree-walk: accept a raw length for traverse_path_len()
authorJeff King <peff@peff.net>
Wed, 31 Jul 2019 04:38:20 +0000 (00:38 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2019 20:06:52 +0000 (13:06 -0700)
We take a "struct name_entry", but only care about the length of the
path name. Let's just take that length directly, making it easier to use
the function from callers that sometimes do not have a name_entry at
all.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge-tree.c
tree-walk.h
unpack-trees.c
index f0e4cfefaaf5c450f70b0afc5f1eda5636ec405e..0629c87b19d59d7003f50fa9524953515b409909 100644 (file)
@@ -180,7 +180,7 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const stru
 
 static char *traverse_path(const struct traverse_info *info, const struct name_entry *n)
 {
 
 static char *traverse_path(const struct traverse_info *info, const struct name_entry *n)
 {
-       char *path = xmallocz(traverse_path_len(info, n));
+       char *path = xmallocz(traverse_path_len(info, tree_entry_len(n)));
        return make_traverse_path(path, info, n->path, n->pathlen);
 }
 
        return make_traverse_path(path, info, n->path, n->pathlen);
 }
 
index 47bf85d28287d231362461b39cc1a07568e1303d..a25c751c1eae6fbd8c41c399571f9d350e8b1c7d 100644 (file)
@@ -74,9 +74,10 @@ char *make_traverse_path(char *path, const struct traverse_info *info,
                         const char *name, size_t namelen);
 void setup_traverse_info(struct traverse_info *info, const char *base);
 
                         const char *name, size_t namelen);
 void setup_traverse_info(struct traverse_info *info, const char *base);
 
-static inline size_t traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
+static inline size_t traverse_path_len(const struct traverse_info *info,
+                                      size_t namelen)
 {
 {
-       return st_add(info->pathlen, tree_entry_len(n));
+       return st_add(info->pathlen, namelen);
 }
 
 /* in general, positive means "kind of interesting" */
 }
 
 /* in general, positive means "kind of interesting" */
index 8dbfb22770df155c734103872e91becf1777bd3c..492eff666a7979568202247c4306578223fe7eab 100644 (file)
@@ -686,7 +686,7 @@ static int index_pos_by_traverse_info(struct name_entry *names,
                                      struct traverse_info *info)
 {
        struct unpack_trees_options *o = info->data;
                                      struct traverse_info *info)
 {
        struct unpack_trees_options *o = info->data;
-       size_t len = traverse_path_len(info, names);
+       size_t len = traverse_path_len(info, tree_entry_len(names));
        char *name = xmalloc(len + 1 /* slash */ + 1 /* NUL */);
        int pos;
 
        char *name = xmalloc(len + 1 /* slash */ + 1 /* NUL */);
        int pos;
 
@@ -936,7 +936,7 @@ static int compare_entry(const struct cache_entry *ce, const struct traverse_inf
         * Even if the beginning compared identically, the ce should
         * compare as bigger than a directory leading up to it!
         */
         * Even if the beginning compared identically, the ce should
         * compare as bigger than a directory leading up to it!
         */
-       return ce_namelen(ce) > traverse_path_len(info, n);
+       return ce_namelen(ce) > traverse_path_len(info, tree_entry_len(n));
 }
 
 static int ce_in_traverse_path(const struct cache_entry *ce,
 }
 
 static int ce_in_traverse_path(const struct cache_entry *ce,
@@ -960,7 +960,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info,
        struct index_state *istate,
        int is_transient)
 {
        struct index_state *istate,
        int is_transient)
 {
-       size_t len = traverse_path_len(info, n);
+       size_t len = traverse_path_len(info, tree_entry_len(n));
        struct cache_entry *ce =
                is_transient ?
                make_empty_transient_cache_entry(len) :
        struct cache_entry *ce =
                is_transient ?
                make_empty_transient_cache_entry(len) :