[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git
Subject:    Re: [PATCH v5 09/18] notes & match-trees: use name_entry's "pathlen" member
From:       Junio C Hamano <gitster () pobox ! com>
Date:       2021-03-31 23:32:30
Message-ID: xmqqsg4a527l.fsf () gitster ! g
[Download RAW message or body]

Æ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.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic