Message ID | patch-09.19-749be26bf8e-20210331T190531Z-avarab@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | tree-walk.h: slimmed down | expand |
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > while (desc.size) { > const char *name; > unsigned short mode; > + int len = tree_entry_len(&desc.entry); > > tree_entry_extract(&desc, &name, &mode); > - if (strlen(name) == toplen && > + if (len == toplen && Makes sense. > @@ -216,9 +217,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, > * - to discard the "const"; this is OK because we > * know it points into our non-const "buf" > */ > - rewrite_here = (unsigned char *)(desc.entry.path + > - strlen(desc.entry.path) + > - 1); > + rewrite_here = (unsigned char *)(name + len + 1); So does this. The original using desc.entry.path even though it called extract to learn the name does not make much sense. > break; > } > update_tree_entry(&desc); > diff --git a/notes.c b/notes.c > index a19e4ad7943..e2fec12a39e 100644 > --- a/notes.c > +++ b/notes.c > @@ -413,7 +413,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, > while (tree_entry(&desc, &entry)) { > unsigned char type; > struct leaf_node *l; > - size_t path_len = strlen(entry.path); > + int path_len = entry.pathlen; OK. > if (path_len == 2 * (hashsz - prefix_len)) { > /* This is potentially the remainder of the SHA-1 */ > @@ -483,7 +483,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, > strbuf_addch(&non_note_path, *q++); > strbuf_addch(&non_note_path, '/'); > } > - strbuf_addstr(&non_note_path, entry.path); > + strbuf_add(&non_note_path, entry.path, path_len); OK. > add_non_note(t, strbuf_detach(&non_note_path, NULL), > entry.mode, entry.oid.hash); > } Looking good. Thanks.
diff --git a/match-trees.c b/match-trees.c index 48f3e0ed526..4ad0ca18256 100644 --- a/match-trees.c +++ b/match-trees.c @@ -199,9 +199,10 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, while (desc.size) { const char *name; unsigned short mode; + int len = tree_entry_len(&desc.entry); tree_entry_extract(&desc, &name, &mode); - if (strlen(name) == toplen && + if (len == toplen && !memcmp(name, prefix, toplen)) { if (!S_ISDIR(mode)) die("entry %s in tree %s is not a tree", name, @@ -216,9 +217,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, * - to discard the "const"; this is OK because we * know it points into our non-const "buf" */ - rewrite_here = (unsigned char *)(desc.entry.path + - strlen(desc.entry.path) + - 1); + rewrite_here = (unsigned char *)(name + len + 1); break; } update_tree_entry(&desc); diff --git a/notes.c b/notes.c index a19e4ad7943..e2fec12a39e 100644 --- a/notes.c +++ b/notes.c @@ -413,7 +413,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, while (tree_entry(&desc, &entry)) { unsigned char type; struct leaf_node *l; - size_t path_len = strlen(entry.path); + int path_len = entry.pathlen; if (path_len == 2 * (hashsz - prefix_len)) { /* This is potentially the remainder of the SHA-1 */ @@ -483,7 +483,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, strbuf_addch(&non_note_path, *q++); strbuf_addch(&non_note_path, '/'); } - strbuf_addstr(&non_note_path, entry.path); + strbuf_add(&non_note_path, entry.path, path_len); add_non_note(t, strbuf_detach(&non_note_path, NULL), entry.mode, entry.oid.hash); }
Change code that was doing a strlen() on the "path" from a name_entry struct to instead use the pathlen given to us by decode_tree_entry(). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- match-trees.c | 7 +++---- notes.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-)