git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What's cooking (draft for #4's issue this month)

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 14, 2021, 21:31 UTC
Message-ID
<xmqq7dl4y2lu.fsf@gitster.g>
In-Reply-To
<YHa5NE3tj/R5kF8N@ncase>
Patrick Steinhardt <ps@pks.im> writes:
> The other breakages I see are caused by hn/reftable, where all tests in
> t0031-reftables.sh cause segfaults. The root cause seems to be that
> reading refs via the reftable backend doesn't initialize the `algo`
> field of the OID, which is fixed via the following patch.

OK. On 'master' without bc/hash-transition-interop-part-1, hashcpy() and oidread() both use the size from the_hash_algo but with the topic, oidread() becomes the way to declare that the given oid uses the_hash_algo.

static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
{
	memcpy(sha_dst, sha_src, the_hash_algo->rawsz);
}
static inline void oidread(struct object_id *oid, const unsigned char *hash)
{
	size_t rawsz = the_hash_algo->rawsz;
	memcpy(oid->hash, hash, rawsz);
	memset(oid->hash + rawsz, 0, GIT_MAX_RAWSZ - rawsz);
	oid->algo = hash_algo_by_ptr(the_hash_algo);
}

So the patch makes sense to directly squashed into hn/reftable topic to (1) be a benign no-op in the master and to (2) fix an expected semantic conflict with bc/hash-transition-interop-part-1 topic.

Thanks.
Show 80 quoted lines
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 130fd90e45..35fb7dd0a2 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -251,10 +251,10 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
>  		ri->base.flags = 0;
>  		switch (ri->ref.value_type) {
>  		case REFTABLE_REF_VAL1:
> -			hashcpy(ri->oid.hash, ri->ref.value.val1);
> +			oidread(&ri->oid, ri->ref.value.val1);
>  			break;
>  		case REFTABLE_REF_VAL2:
> -			hashcpy(ri->oid.hash, ri->ref.value.val2.value);
> +			oidread(&ri->oid, ri->ref.value.val2.value);
>  			break;
>  		case REFTABLE_REF_SYMREF: {
>  			int out_flags = 0;
> @@ -299,7 +299,7 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
>  	struct git_reftable_iterator *ri =
>  		(struct git_reftable_iterator *)ref_iterator;
>  	if (ri->ref.value_type == REFTABLE_REF_VAL2) {
> -		hashcpy(peeled->hash, ri->ref.value.val2.target_value);
> +		oidread(peeled, ri->ref.value.val2.target_value);
>  		return 0;
>  	}
>
> @@ -977,7 +977,7 @@ git_reftable_reflog_ref_iterator_advance(struct ref_iterator *ref_iterator)
>
>  		free(ri->last_name);
>  		ri->last_name = xstrdup(ri->log.refname);
> -		hashcpy(ri->oid.hash, ri->log.update.new_hash);
> +		oidread(&ri->oid, ri->log.update.new_hash);
>  		return ITER_OK;
>  	}
>  }
> @@ -1090,8 +1090,8 @@ static int git_reftable_for_each_reflog_ent_newest_first(
>  			break;
>  		}
>
> -		hashcpy(old_oid.hash, log.update.old_hash);
> -		hashcpy(new_oid.hash, log.update.new_hash);
> +		oidread(&old_oid, log.update.old_hash);
> +		oidread(&new_oid, log.update.new_hash);
>
>  		full_committer = fmt_ident(log.update.name, log.update.email,
>  					   WANT_COMMITTER_IDENT,
> @@ -1157,8 +1157,8 @@ static int git_reftable_for_each_reflog_ent_oldest_first(
>  		struct object_id new_oid;
>  		const char *full_committer = "";
>
> -		hashcpy(old_oid.hash, log->update.old_hash);
> -		hashcpy(new_oid.hash, log->update.new_hash);
> +		oidread(&old_oid, log->update.old_hash);
> +		oidread(&new_oid, log->update.new_hash);
>
>  		full_committer = fmt_ident(log->update.name, log->update.email,
>  					   WANT_COMMITTER_IDENT, NULL,
> @@ -1330,8 +1330,8 @@ git_reftable_reflog_expire(struct ref_store *ref_store, const char *refname,
>  		if (err > 0 || strcmp(log.refname, refname)) {
>  			break;
>  		}
> -		hashcpy(ooid.hash, log.update.old_hash);
> -		hashcpy(noid.hash, log.update.new_hash);
> +		oidread(&ooid, log.update.old_hash);
> +		oidread(&noid, log.update.new_hash);
>
>  		if (should_prune_fn(&ooid, &noid, log.update.email,
>  				    (timestamp_t)log.update.time,
> @@ -1410,7 +1410,7 @@ static int git_reftable_read_raw_ref(struct ref_store *ref_store,
>  		strbuf_addstr(referent, ref.value.symref);
>  		*type |= REF_ISSYMREF;
>  	} else if (reftable_ref_record_val1(&ref) != NULL) {
> -		hashcpy(oid->hash, reftable_ref_record_val1(&ref));
> +		oidread(oid, reftable_ref_record_val1(&ref));
>  	} else {
>  		*type |= REF_ISBROKEN;
>  		errno = EINVAL;
>
>
> Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 14 in “What's cooking (draft for #4's issue this month)”
  1. Junio C HamanoApr 14, 2021
  2. Patrick SteinhardtApr 14, 2021
  3. Junio C HamanoApr 14, 2021
  4. Junio C HamanoApr 14, 2021
  5. Jeff KingApr 15, 2021
  6. Junio C HamanoApr 15, 2021
  7. Junio C HamanoApr 14, 2021
  8. Junio C HamanoApr 14, 2021
  9. Junio C HamanoApr 14, 2021
  10. brian m. carlsonApr 15, 2021
  11. Junio C HamanoApr 15, 2021
  12. brian m. carlsonApr 19, 2021
  13. Junio C HamanoApr 19, 2021
  14. Han-Wen NienhuysApr 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.