summaryrefslogtreecommitdiff
path: root/tree-walk.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-07-31 04:38:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-07-31 20:34:25 (GMT)
commit9055384710dd8963b125f4f87c24d8f67d9fa24f (patch)
tree927c9d4670548c932c3b13e1bfcee33ca431943c /tree-walk.c
parent947208b725188eb499625ebc5c6e43d54c97e4fc (diff)
downloadgit-9055384710dd8963b125f4f87c24d8f67d9fa24f.zip
git-9055384710dd8963b125f4f87c24d8f67d9fa24f.tar.gz
git-9055384710dd8963b125f4f87c24d8f67d9fa24f.tar.bz2
tree-walk: drop oid from traverse_info
As the previous commit shows, the presence of an oid in each level of the traverse_info is confusing and ultimately not necessary. Let's drop it to make it clear that it will not always be set (as well as convince us that it's unused, and let the compiler catch any merges with other branches that do add new uses). Since the oid is part of name_entry, we'll actually stop embedding a name_entry entirely, and instead just separately hold the pathname, its length, and the mode. This makes the resulting code slightly more verbose as we have to pass those elements around individually. But it also makes it more clear what each code path is going to use (and in most of the paths, we really only care about the pathname itself). A few of these conversions are noisier than they need to be, as they also take the opportunity to rename "len" to "namelen" for clarity (especially where we also have "pathlen" or "ce_len" alongside). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tree-walk.c')
-rw-r--r--tree-walk.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/tree-walk.c b/tree-walk.c
index ba10615..4610f77 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -175,27 +175,27 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
if (pathlen && base[pathlen-1] == '/')
pathlen--;
info->pathlen = pathlen ? pathlen + 1 : 0;
- info->name.path = base;
- info->name.pathlen = pathlen;
+ info->name = base;
+ info->namelen = pathlen;
if (pathlen)
info->prev = &dummy;
}
-char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n)
+char *make_traverse_path(char *path, const struct traverse_info *info,
+ const char *name, size_t namelen)
{
- int len = tree_entry_len(n);
int pathlen = info->pathlen;
- path[pathlen + len] = 0;
+ path[pathlen + namelen] = 0;
for (;;) {
- memcpy(path + pathlen, n->path, len);
+ memcpy(path + pathlen, name, namelen);
if (!pathlen)
break;
path[--pathlen] = '/';
- n = &info->name;
- len = tree_entry_len(n);
+ name = info->name;
+ namelen = info->namelen;
info = info->prev;
- pathlen -= len;
+ pathlen -= namelen;
}
return path;
}
@@ -397,12 +397,13 @@ int traverse_trees(struct index_state *istate,
if (info->prev) {
strbuf_grow(&base, info->pathlen);
- make_traverse_path(base.buf, info->prev, &info->name);
+ make_traverse_path(base.buf, info->prev, info->name,
+ info->namelen);
base.buf[info->pathlen-1] = '/';
strbuf_setlen(&base, info->pathlen);
traverse_path = xstrndup(base.buf, info->pathlen);
} else {
- traverse_path = xstrndup(info->name.path, info->pathlen);
+ traverse_path = xstrndup(info->name, info->pathlen);
}
info->traverse_path = traverse_path;
for (;;) {