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

Re: [PATCH v3 2/3] refs: add option core.logAllRefUpdates = always

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2017, 21:58 UTC
Message-ID
<xmqq37g0us5p.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170127100948.29408-2-cornelius.weig@tngtech.com>
cornelius.weig@tngtech.com writes:
Show 11 quoted lines
> Notes:
>     Changes wrt v2:
>     
>      - change wording in commit message s/do not typically/are not meant to/;
>      - in update_refs_for_switch move refname to the enclosing block, so that
>        should_autocreate_reflog has access. Thanks Junio for spotting this
>        potential bug early :)
>      - add test that asserts reflogs are created for tags if
>        logAllRefUpdates=always. The case with logAllRefUpdates=true is IMHO already
>        covered by the default case. To make that clearer, I explicitly added
>        logAllRefUpdates=true.

These look all sensible. Especially thanks for reordering the code to feed the real refname for the new branch in the "checkout" codepath.

Show 5 quoted lines
>     When writing the test for git-tag, I realized that the option
>     --no-create-reflog to git-tag does not take precedence over
>     logAllRefUpdate=always. IOW the setting cannot be overridden on the command
>     line. Do you think this is a defect or would it not be desirable to have this
>     feature anyway?

"--no-create-reflog" should override the configuration set to "true" or "always". Also "--create-reflog" should override the configuration set to "false".

If the problem was inherited from the original code before your change (e.g. you set logAllRefUpdates to true and then did "update-ref --no-create-reflog refs/heads/foo". Does the code before your change ignore the command lne option and create a reflog for the branch?), then it would be ideal to fix the bug before this series as a preparatory fix. If the problem was introduced by this patch set, then we would need a fix not to introduce it ;-)

Show 21 quoted lines
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index bfe685c..81ea2ed 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -612,14 +612,12 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
>  	const char *old_desc, *reflog_msg;
>  	if (opts->new_branch) {
>  		if (opts->new_orphan_branch) {
> -			if (opts->new_branch_log && !log_all_ref_updates) {
> +			const char *refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
> +			if (opts->new_branch_log && should_autocreate_reflog(refname)) {
>  				int ret;
> -				char *refname;
>  				struct strbuf err = STRBUF_INIT;
>  
> -				refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch);
>  				ret = safe_create_reflog(refname, 1, &err);
> -				free(refname);
>  				if (ret) {
>  					fprintf(stderr, _("Can not do reflog for '%s': %s\n"),
>  						opts->new_orphan_branch, err.buf);

Here you need to have another free(), as this block makes an early return and you end up leaking refname.

Show 12 quoted lines
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> index 1cfa8a2..1bf622d 100755
> --- a/t/t7004-tag.sh
> +++ b/t/t7004-tag.sh
> @@ -71,6 +71,7 @@ test_expect_success 'creating a tag for an unknown revision should fail' '
>  
>  # commit used in the tests, test_tick is also called here to freeze the date:
>  test_expect_success 'creating a tag using default HEAD should succeed' '
> +	test_config core.logAllRefUpdates true &&
>  	test_tick &&
>  	echo foo >foo &&
>  	git add foo &&

This change is to make sure that 'true' does not affect tags (but 'always' does as seen in the later new test)? I am just double checking, not objecting.

Thanks.
Previous: cornelius.weig@tngtech.comNext: Junio C Hamano
Message 24 of 33 in “tag: add tag.createReflog option”
  1. tag: add tag.createReflog optioncornelius.weig@tngtech.com, Jan 25, 2017
  2. Pranit BauvaJan 25, 2017
  3. Jeff KingJan 25, 2017
  4. Junio C HamanoJan 25, 2017
  5. Cornelius WeigJan 25, 2017
  6. Jeff KingJan 25, 2017
  7. Junio C HamanoJan 25, 2017
  8. Junio C HamanoJan 25, 2017
  9. Cornelius WeigJan 25, 2017
  10. refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 26, 2017
  11. refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 26, 2017
  12. Jeff KingJan 26, 2017
  13. Cornelius WeigJan 26, 2017
  14. Jeff KingJan 26, 2017
  15. 1/3 config: add markup to core.logAllRefUpdates doccornelius.weig@tngtech.com, Jan 26, 2017
  16. 2/3 refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 26, 2017
  17. Junio C HamanoJan 26, 2017
  18. 3/3 update-ref: add test cases for bare repositorycornelius.weig@tngtech.com, Jan 26, 2017
  19. Junio C HamanoJan 26, 2017
  20. Junio C HamanoJan 26, 2017
  21. 1/3 config: add markup to core.logAllRefUpdates doccornelius.weig@tngtech.com, Jan 27, 2017
  22. 3/3 update-ref: add test cases for bare repositorycornelius.weig@tngtech.com, Jan 27, 2017
  23. 2/3 refs: add option core.logAllRefUpdates = alwayscornelius.weig@tngtech.com, Jan 27, 2017
  24. Junio C HamanoJan 30, 2017
  25. Junio C HamanoJan 30, 2017
  26. Cornelius WeigJan 31, 2017
  27. Junio C HamanoJan 31, 2017
  28. Jeff KingJan 30, 2017
  29. Cornelius WeigJan 31, 2017
  30. Jeff KingJan 31, 2017
  31. Junio C HamanoJan 31, 2017
  32. Cornelius WeigJan 31, 2017
  33. Junio C HamanoJan 31, 2017

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.