Re: [PATCH v3 2/3] refs: add option core.logAllRefUpdates = always
From: Junio C Hamano <hidden>
Date: 2017-01-30 21:58:54
cornelius.weig@tngtech.com writes:
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.
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 ;-)
quoted hunk
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.
quoted hunk
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.