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

Re: [PATCH 06/10] refs: skip collision checks in initial transactions

From
karthik nayak <karthik.188@gmail.com>
Date
Nov 11, 2024, 10:53 UTC
Message-ID
<CAOLa=ZRrPx2BMe+b3iOQMK9U+GiY6UVYpRJyqxrUamAG2b2EYg@mail.gmail.com>
In-Reply-To
<20241108-pks-refs-optimize-migrations-v1-6-7fd37fa80e35@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
[snip]
Show 28 quoted lines
> diff --git a/refs.c b/refs.c
> index 0f10c565bbb4e0d91210c52a3221a224e4264d28..d690eb19b3fd7083a5309deb98738547e4f48040 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -2324,6 +2324,7 @@ int refs_verify_refname_available(struct ref_store *refs,
>  				  const char *refname,
>  				  const struct string_list *extras,
>  				  const struct string_list *skip,
> +				  int initial_transaction,
>  				  struct strbuf *err)
>  {
>  	const char *slash;
> @@ -2332,8 +2333,6 @@ int refs_verify_refname_available(struct ref_store *refs,
>  	struct strbuf referent = STRBUF_INIT;
>  	struct object_id oid;
>  	unsigned int type;
> -	struct ref_iterator *iter;
> -	int ok;
>  	int ret = -1;
>
>  	/*
> @@ -2363,7 +2362,8 @@ int refs_verify_refname_available(struct ref_store *refs,
>  		if (skip && string_list_has_string(skip, dirname.buf))
>  			continue;
>
> -		if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
> +		if (!initial_transaction &&
> +		    !refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
Nit: It would be nice to have a comment here, perhaps something like:
     /* in initial transaction there are no refs in the ref store */
Show 54 quoted lines
>  				       &type, &ignore_errno)) {
>  			strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
>  				    dirname.buf, refname);
> @@ -2388,21 +2388,26 @@ int refs_verify_refname_available(struct ref_store *refs,
>  	strbuf_addstr(&dirname, refname + dirname.len);
>  	strbuf_addch(&dirname, '/');
>
> -	iter = refs_ref_iterator_begin(refs, dirname.buf, NULL, 0,
> -				       DO_FOR_EACH_INCLUDE_BROKEN);
> -	while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
> -		if (skip &&
> -		    string_list_has_string(skip, iter->refname))
> -			continue;
> +	if (!initial_transaction) {
> +		struct ref_iterator *iter;
> +		int ok;
>
> -		strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
> -			    iter->refname, refname);
> -		ref_iterator_abort(iter);
> -		goto cleanup;
> -	}
> +		iter = refs_ref_iterator_begin(refs, dirname.buf, NULL, 0,
> +					       DO_FOR_EACH_INCLUDE_BROKEN);
> +		while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
> +			if (skip &&
> +			    string_list_has_string(skip, iter->refname))
> +				continue;
>
> -	if (ok != ITER_DONE)
> -		BUG("error while iterating over references");
> +			strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
> +				    iter->refname, refname);
> +			ref_iterator_abort(iter);
> +			goto cleanup;
> +		}
> +
> +		if (ok != ITER_DONE)
> +			BUG("error while iterating over references");
> +	}
>
>  	extra_refname = find_descendant_ref(dirname.buf, extras, skip);
>  	if (extra_refname)
> diff --git a/refs.h b/refs.h
> index 024a370554e013d66febee635e4c0415ba061fe6..980bd20cf24e15144aeff991eeba8b27a936d386 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -101,13 +101,16 @@ int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname,
>   * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
>   * "foo/barbados".
>   *
> + * If `initial_transaction` is truish, then all collision checks with
> + * preexisting refs are skipped.
> + *
Okay we have it here, so this should do.
[snip]
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 of 42 in “refs: optimize ref format migrations”
  1. 00/10 refs: optimize ref format migrationsPatrick Steinhardt, Nov 8, 2024
  2. 01/10 refs: allow passing flags when setting up a transactionPatrick Steinhardt, Nov 8, 2024
  3. karthik nayakNov 11, 2024
  4. Patrick SteinhardtNov 11, 2024
  5. 02/10 refs/files: move logic to commit initial transactionPatrick Steinhardt, Nov 8, 2024
  6. 03/10 refs: introduce "initial" transaction flagPatrick Steinhardt, Nov 8, 2024
  7. 05/10 refs: use "initial" transaction semantics to migrate refsPatrick Steinhardt, Nov 8, 2024
  8. karthik nayakNov 11, 2024
  9. 06/10 refs: skip collision checks in initial transactionsPatrick Steinhardt, Nov 8, 2024
  10. karthik nayakNov 11, 2024
  11. 04/10 refs/files: support symbolic and root refs in initial transactionPatrick Steinhardt, Nov 8, 2024
  12. karthik nayakNov 11, 2024
  13. Patrick SteinhardtNov 11, 2024
  14. 09/10 reftable/block: rename `block_writer::buf` variablePatrick Steinhardt, Nov 8, 2024
  15. 08/10 reftable/writer: optimize allocations by using a scratch bufferPatrick Steinhardt, Nov 8, 2024
  16. 07/10 refs: don't normalize log messages with `REF_SKIP_CREATE_REFLOG`Patrick Steinhardt, Nov 8, 2024
  17. 10/10 reftable/block: optimize allocations by using scratch bufferPatrick Steinhardt, Nov 8, 2024
  18. karthik nayakNov 11, 2024
  19. Patrick SteinhardtNov 11, 2024
  20. Junio C HamanoNov 20, 2024
  21. Patrick SteinhardtNov 20, 2024
  22. Christian CouderNov 20, 2024
  23. Patrick SteinhardtNov 25, 2024
  24. 00/10 refs: optimize ref format migrationsPatrick Steinhardt, Nov 20, 2024
  25. 01/10 refs: allow passing flags when setting up a transactionPatrick Steinhardt, Nov 20, 2024
  26. Christian CouderNov 20, 2024
  27. 02/10 refs/files: move logic to commit initial transactionPatrick Steinhardt, Nov 20, 2024
  28. 03/10 refs: introduce "initial" transaction flagPatrick Steinhardt, Nov 20, 2024
  29. 04/10 refs/files: support symbolic and root refs in initial transactionPatrick Steinhardt, Nov 20, 2024
  30. 05/10 refs: use "initial" transaction semantics to migrate refsPatrick Steinhardt, Nov 20, 2024
  31. 06/10 refs: skip collision checks in initial transactionsPatrick Steinhardt, Nov 20, 2024
  32. Christian CouderNov 20, 2024
  33. Patrick SteinhardtNov 25, 2024
  34. Kristoffer HaugsbakkNov 20, 2024
  35. Patrick SteinhardtNov 25, 2024
  36. 07/10 refs: don't normalize log messages with `REF_SKIP_CREATE_REFLOG`Patrick Steinhardt, Nov 20, 2024
  37. 08/10 reftable/writer: optimize allocations by using a scratch bufferPatrick Steinhardt, Nov 20, 2024
  38. Christian CouderNov 20, 2024
  39. Patrick SteinhardtNov 25, 2024
  40. 09/10 reftable/block: rename `block_writer::buf` variablePatrick Steinhardt, Nov 20, 2024
  41. 10/10 reftable/block: optimize allocations by using scratch bufferPatrick Steinhardt, Nov 20, 2024
  42. Christian CouderNov 20, 2024

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.