Re: [PATCH v5 09/18] notes & match-trees: use name_entry's "pathlen" member
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 31, 2021, 23:32 UTC
- Message-ID
- <xmqqsg4a527l.fsf@gitster.g>
- In-Reply-To
- <patch-09.19-749be26bf8e-20210331T190531Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 8 quoted lines
> 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.
Show 8 quoted lines
> @@ -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.
Show 13 quoted lines
> 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.
Show 8 quoted lines
> 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.