From patchwork Mon Sep 6 16:52:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12477129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA149C433FE for ; Mon, 6 Sep 2021 16:52:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1C5261051 for ; Mon, 6 Sep 2021 16:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238567AbhIFQxc (ORCPT ); Mon, 6 Sep 2021 12:53:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234037AbhIFQxb (ORCPT ); Mon, 6 Sep 2021 12:53:31 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D33C061757 for ; Mon, 6 Sep 2021 09:52:26 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id b6so10693466wrh.10 for ; Mon, 06 Sep 2021 09:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=M8cMkenOYpSJIzJ7GJmSZTU5BOuiS7mxgTz003EpiVg=; b=D6geH1bMqFxPWcgakemthqUj61nG/0Th+wd58auxXS+tFnwZQNrRTkY4C/lvu70S1h ESme2jpa3djAHILp9hqlcdaGQwXaX2soTrRokce/LS8qgmb9uj5SYVJswQ6scet6PvFr s3Rex0IZ2Z7o62yui8SsE+cJ+zMxe87nU35Pm+O+NOuQC0WcItw9K16R0pHD86bCXvDM GckSxSI5P9kHoPTU0YQhC4rc5luytEnZNkVFkIYOaPpfmhovsqvS0WOygEanQurRdJRD IIvBYHkXbGMzIFu/mNk1bo7gmC55f3SZTSNGZ+STrfh1OeKVq8S/O9ddLdAxNbHYHggf twOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=M8cMkenOYpSJIzJ7GJmSZTU5BOuiS7mxgTz003EpiVg=; b=gUK/yxWqZj4Hpq/NoM/euVTemcKTr436I3j/HeRKDEUBJssuNK9/yR5Cva2bwX4Q// ZbLwNTsxc2ETWzXMHJqy9mH9KTeKervJh6FJC7mLadhwA4a9F+6rbRLPgo5Gf+dgpYzZ /8BerQjplWYWzTrAsg30/A6QkAPtVp8++eqjqXcFnemAw07dkpYj/TkhIDLLj2wyqC5s ThiQupVhOlLFUrC4U6OmK+JoD3MOp593dJ7i2zMi8aaYPZ8lCzodD6LOK0leuysatHd1 Zr9/EJFSzQm9mqq2ZigJe2MZLR+NlMMDku0S8WXVmbwu6ha/c1IhIDLLIuwDPva3kzhI Nf+w== X-Gm-Message-State: AOAM531gI+XBq+jusjEkxXN2VLC6c6N4Qg73MLwwbuG+XZCRcTAddwxD xo2YmPTmfVpcPHoty2KW2W7gsMAnSZ8= X-Google-Smtp-Source: ABdhPJz7rxQ+pIfKDZLgoTeMLt4NR1WAVxHiV6+x33LuuaKbQfRzxmU/PryP5czN0DtPWfEQo7nqcA== X-Received: by 2002:adf:d193:: with SMTP id v19mr14493525wrc.377.1630947144925; Mon, 06 Sep 2021 09:52:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f17sm9793378wrt.63.2021.09.06.09.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 09:52:24 -0700 (PDT) Message-Id: <995d450da42f35b4cecdd699fa1b1a74518f481e.1630947142.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Sep 2021 16:52:18 +0000 Subject: [PATCH v2 1/5] refs: trim newline from reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Commit 523fa69c ("reflog: cleanse messages in the refs.c layer") standardizes how write entries into the reflog. This commit standardizes how we get messages out of the reflog. Before, the files backend implicitly added '\n' to the end of reflog message on reading, which creates a subtle incompatibility with alternate ref storage backends, such as reftable. We address this by stripping LF from the message before we pass it to the user-provided callback. Signed-off-by: Han-Wen Nienhuys --- builtin/show-branch.c | 4 +++- reflog-walk.c | 6 ++---- refs/files-backend.c | 30 +++++++++++++++--------------- t/t1405-main-ref-store.sh | 5 ++--- t/t1406-submodule-ref-store.sh | 4 ++-- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/builtin/show-branch.c b/builtin/show-branch.c index d77ce7aeb38..acf710313a0 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -888,7 +888,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) show_one_commit(rev[i], 1); } else - puts(reflog_msg[i]); + puts(reflog_msg[i]); /* XXX - this puts a + newline. Did we put two + newlines beforehand? */ if (is_head) head_at = i; diff --git a/reflog-walk.c b/reflog-walk.c index e9cd3283694..944cce929c8 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -245,8 +245,6 @@ void get_reflog_message(struct strbuf *sb, info = &commit_reflog->reflogs->items[commit_reflog->recno+1]; len = strlen(info->message); - if (len > 0) - len--; /* strip away trailing newline */ strbuf_add(sb, info->message, len); } @@ -285,10 +283,10 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline, info = &commit_reflog->reflogs->items[commit_reflog->recno+1]; get_reflog_selector(&selector, reflog_info, dmode, force_date, 0); if (oneline) { - printf("%s: %s", selector.buf, info->message); + printf("%s: %s\n", selector.buf, info->message); } else { - printf("Reflog: %s (%s)\nReflog message: %s", + printf("Reflog: %s (%s)\nReflog message: %s\n", selector.buf, info->email, info->message); } diff --git a/refs/files-backend.c b/refs/files-backend.c index 677b7e4cdd2..206c9f8b932 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1897,17 +1897,15 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c int tz; const char *p = sb->buf; - /* old SP new SP name SP time TAB msg LF */ - if (!sb->len || sb->buf[sb->len - 1] != '\n' || - parse_oid_hex(p, &ooid, &p) || *p++ != ' ' || + /* old SP new SP name SP time TAB msg */ + if (!sb->len || parse_oid_hex(p, &ooid, &p) || *p++ != ' ' || parse_oid_hex(p, &noid, &p) || *p++ != ' ' || - !(email_end = strchr(p, '>')) || - email_end[1] != ' ' || + !(email_end = strchr(p, '>')) || email_end[1] != ' ' || !(timestamp = parse_timestamp(email_end + 2, &message, 10)) || !message || message[0] != ' ' || - (message[1] != '+' && message[1] != '-') || - !isdigit(message[2]) || !isdigit(message[3]) || - !isdigit(message[4]) || !isdigit(message[5])) + (message[1] != '+' && message[1] != '-') || !isdigit(message[2]) || + !isdigit(message[3]) || !isdigit(message[4]) || + !isdigit(message[5])) return 0; /* corrupt? */ email_end[1] = '\0'; tz = strtol(message + 1, NULL, 10); @@ -1999,6 +1997,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store, strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1)); scanp = bp; endp = bp + 1; + strbuf_trim_trailing_newline(&sb); ret = show_one_reflog_ent(&sb, fn, cb_data); strbuf_reset(&sb); if (ret) @@ -2011,6 +2010,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store, * Process it, and we can end the loop. */ strbuf_splice(&sb, 0, 0, buf, endp - buf); + strbuf_trim_trailing_newline(&sb); ret = show_one_reflog_ent(&sb, fn, cb_data); strbuf_reset(&sb); break; @@ -2060,7 +2060,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store, if (!logfp) return -1; - while (!ret && !strbuf_getwholeline(&sb, logfp, '\n')) + while (!ret && !strbuf_getline(&sb, logfp)) ret = show_one_reflog_ent(&sb, fn, cb_data); fclose(logfp); strbuf_release(&sb); @@ -3020,18 +3020,18 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid, if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz, message, policy_cb)) { if (!cb->newlog) - printf("would prune %s", message); + printf("would prune %s\n", message); else if (cb->flags & EXPIRE_REFLOGS_VERBOSE) - printf("prune %s", message); + printf("prune %s\n", message); } else { if (cb->newlog) { - fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s", - oid_to_hex(ooid), oid_to_hex(noid), - email, timestamp, tz, message); + fprintf(cb->newlog, "%s %s %s %" PRItime " %+05d\t%s\n", + oid_to_hex(ooid), oid_to_hex(noid), email, + timestamp, tz, message); oidcpy(&cb->last_kept_oid, noid); } if (cb->flags & EXPIRE_REFLOGS_VERBOSE) - printf("keep %s", message); + printf("keep %s\n", message); } return 0; } diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index 49718b7ea7f..a600bedf2cd 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -89,13 +89,12 @@ test_expect_success 'for_each_reflog()' ' test_expect_success 'for_each_reflog_ent()' ' $RUN for-each-reflog-ent HEAD >actual && head -n1 actual | grep one && - tail -n2 actual | head -n1 | grep recreate-main + tail -n1 actual | grep recreate-main ' test_expect_success 'for_each_reflog_ent_reverse()' ' $RUN for-each-reflog-ent-reverse HEAD >actual && - head -n1 actual | grep recreate-main && - tail -n2 actual | head -n1 | grep one + tail -n1 actual | grep one ' test_expect_success 'reflog_exists(HEAD)' ' diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh index 0a87058971e..b0365c1fee0 100755 --- a/t/t1406-submodule-ref-store.sh +++ b/t/t1406-submodule-ref-store.sh @@ -74,13 +74,13 @@ test_expect_success 'for_each_reflog()' ' test_expect_success 'for_each_reflog_ent()' ' $RUN for-each-reflog-ent HEAD >actual && head -n1 actual | grep first && - tail -n2 actual | head -n1 | grep main.to.new + tail -n1 actual | grep main.to.new ' test_expect_success 'for_each_reflog_ent_reverse()' ' $RUN for-each-reflog-ent-reverse HEAD >actual && head -n1 actual | grep main.to.new && - tail -n2 actual | head -n1 | grep first + tail -n1 actual | grep first ' test_expect_success 'reflog_exists(HEAD)' ' From patchwork Mon Sep 6 16:52:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12477131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18D71C433EF for ; Mon, 6 Sep 2021 16:52:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE60461051 for ; Mon, 6 Sep 2021 16:52:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238871AbhIFQxd (ORCPT ); Mon, 6 Sep 2021 12:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230491AbhIFQxb (ORCPT ); Mon, 6 Sep 2021 12:53:31 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9BA4C061575 for ; Mon, 6 Sep 2021 09:52:26 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id i6so10708131wrv.2 for ; Mon, 06 Sep 2021 09:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2bnCoDymTUy35GY0pnGuwLVLYsI77eGdhk8l9/1MYn0=; b=MX6wJ79i7ej7gqyLshlXz4v1uKfdQaSG3n1somUl0oT5Qd9QJx64S5cFz33toTBAsk GqktwajJFpwfNvGGvDQhAnA4G3UqCHnYTQdulEFw/IJtvQhVPI9eu70cN+2TimydnhZH yhUn5sZ58kCXY+o4riD/xiIj5caQc48mL+54c71k5JW8uoHdRs4N13CV5EX15jOK6jGv QuBj5WpyZWeXExjXtIwqOLEHdBmPcUuW1QaEvZZROZEDDPIPPEoqXoO9ggPSV2ZNkJhL k8k8v3M9pHM54aDiYLBTqUjbqtcx9GVj343LJCPn4vFEsLzNkggQw1w65crd6O6snK1A 2VZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2bnCoDymTUy35GY0pnGuwLVLYsI77eGdhk8l9/1MYn0=; b=DJ3/eVC/QGHAovOnTTMiqM29byvgY9Cp1QSbQqZHwxm0lZstogxjuen3WO4zwCpCCl GYWwIrefyJjLKzAkg3RcnziHjhZ4mN1RGrU2ZPkCtSLAKum1Cv0jGTWp1juGPUGNhkuo KFCamke3ttczJ8why5viwyZdget6aDeBBsp2tkFf/dJ5EpHFzVViex9BIb4WKum4iXWP siPCw2ClJbNlDseOte9ZKZ/yoaWsj1f9zwZN8fF1FHHDAZRg1jBbaR7BLBg3WO4xdpF3 NsdPj+BYTYAFXmIiGcXRQjINOup69qk2WG+WoCk6/5taTk7BLM6USfw0Ptgls+SEma+c I9dA== X-Gm-Message-State: AOAM530UQ0kQUPsaHBxXe0jn77lAGLcfWVeBo8RNam3nbPooubCGopJs KXOAjHdCaZxB0FThX5nDz2Hxe/i1ZMs= X-Google-Smtp-Source: ABdhPJyLNPfa9E2XXyvpQlK5ChMF+Taq4oFMNH3MG/gLAYg0Qz2uS5yp+ML40sW6/En7RjBbvmS54g== X-Received: by 2002:adf:d1c3:: with SMTP id b3mr14421114wrd.286.1630947145508; Mon, 06 Sep 2021 09:52:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l10sm8906723wrg.50.2021.09.06.09.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 09:52:25 -0700 (PDT) Message-Id: <11b296a55e9e450575c64ade1a2cb93a1886b9da.1630947142.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Sep 2021 16:52:19 +0000 Subject: [PATCH v2 2/5] test-ref-store: tweaks to for-each-reflog-ent format Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Follow the reflog format more closely, so it can be used for comparing reflogs in tests without using inspecting files under .git/logs/ Signed-off-by: Han-Wen Nienhuys --- t/helper/test-ref-store.c | 5 ++--- t/t1405-main-ref-store.sh | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index b314b81a45b..0fcad9b3812 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -151,9 +151,8 @@ static int each_reflog(struct object_id *old_oid, struct object_id *new_oid, const char *committer, timestamp_t timestamp, int tz, const char *msg, void *cb_data) { - printf("%s %s %s %"PRItime" %d %s\n", - oid_to_hex(old_oid), oid_to_hex(new_oid), - committer, timestamp, tz, msg); + printf("%s %s %s %" PRItime " %+05d\t%s\n", oid_to_hex(old_oid), + oid_to_hex(new_oid), committer, timestamp, tz, msg); return 0; } diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index a600bedf2cd..76b15458409 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -94,6 +94,7 @@ test_expect_success 'for_each_reflog_ent()' ' test_expect_success 'for_each_reflog_ent_reverse()' ' $RUN for-each-reflog-ent-reverse HEAD >actual && + head -n1 actual | grep recreate-main && tail -n1 actual | grep one ' From patchwork Mon Sep 6 16:52:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12477133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA76C433F5 for ; Mon, 6 Sep 2021 16:52:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7691360FBF for ; Mon, 6 Sep 2021 16:52:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238998AbhIFQxf (ORCPT ); Mon, 6 Sep 2021 12:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234037AbhIFQxc (ORCPT ); Mon, 6 Sep 2021 12:53:32 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DDB0C061757 for ; Mon, 6 Sep 2021 09:52:27 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso5457824wmb.2 for ; Mon, 06 Sep 2021 09:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=VbH/83jrdvsUB3nQiP13PUf4tK2Z3NCD9+NJRlFhS2Y=; b=KUooObF74j2MVrlrFId8YwBni+lFXpSXQPik+6HmkmQViIK1NHV0TlYfvgULsbgVJK T+Yn0wjc4EVyIxTvrNLYWv8VuPS6jPv6IouKEO+XbPv5wyeTStPHBt+vAhsqAqgPkfHD /mkExAjiDEQWz3Q/0k1Z/x/LHN7ABQMluA0KEyY7ShGPgFM4MBO98M9PwHy2VtUS0F/Y fmWjbyKADYUr+YfhPVka6ElV1K5yPUdsYZpg8iwMGI3u4rdmJWdoX9S7v5A/QU7WufYa DHLD71fUHP13FLzHCTmRSjsryq7UrNtRooArycBx1u7kSKOe+XQ0dzVkVRWW8Tkv5j+R LE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=VbH/83jrdvsUB3nQiP13PUf4tK2Z3NCD9+NJRlFhS2Y=; b=AXnkclCwKLYynax0u4J+r8s+fVtxtYetJSVSEbCWkQY7xTJ/bgcM8B9Qyr0HAOoVE3 GXEP2+RzNnRSHDdtUxuoQlJ2I7W1fuD7yEbBNNiZJmMQI89mjsyKRs6mwfhIXkH5UaW9 0gfry2DiloEH3UIBvpPDo4VsuGjB0IJARedCZVj9i+5Gg+2ZdrsMkdCOPBGN3Ngx0Np2 kfZ6w1dpqo4s2LSfBDMRdXwi7wBGX5uMC7hR/E08nfo8wL8Bq90bphYfm6Yb8iE2Y7z5 4O0j03zdopVW7GbKvmXDSZiQe4ziE+RqQw2MQz43ZCoKHlpyBKh4GH5dFrMiWCT110nZ VY/A== X-Gm-Message-State: AOAM532MQwCshDhze+53YUfGrZvqyE7yTjOQBbm3Pm/KtP4GSbIxRQI4 HYgxwejtqm1KYYXG7rX5jwrFkl3cVFY= X-Google-Smtp-Source: ABdhPJxoJ95m0T8P1y73KLj5HR0t9tC1TkMkd9PUHp0QmIOM8cJgemDeDFBNH6HxrfbrQQPaX5RtqQ== X-Received: by 2002:a7b:c148:: with SMTP id z8mr36993wmi.147.1630947146039; Mon, 06 Sep 2021 09:52:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x11sm8454773wro.83.2021.09.06.09.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 09:52:25 -0700 (PDT) Message-Id: <9ec09cc64cd6f227e96fb9752c23ce3e54e5dd2f.1630947142.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 06 Sep 2021 16:52:20 +0000 Subject: [PATCH v2 3/5] t1400: use test-helper ref-store to inspect reflog contents Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- t/t1400-update-ref.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 4506cd435b0..8ced98e0fe8 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -10,6 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh Z=$ZERO_OID +TAB=' ' m=refs/heads/main n_dir=refs/heads/gu @@ -318,11 +319,12 @@ test_expect_success 'symref empty directory removal' ' cat >expect < 1117150200 +0000 Initial Creation $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch -$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 +$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000$TAB EOF test_expect_success "verifying $m's log (logged by touch)" ' - test_when_finished "rm -rf .git/$m .git/logs expect" && - test_cmp expect .git/logs/$m + test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" && + test-tool ref-store main for-each-reflog-ent $m > actual && + test_cmp actual expect ' test_expect_success "create $m (logged by config)" ' @@ -347,11 +349,12 @@ test_expect_success "set $m (logged by config)" ' cat >expect < 1117150320 +0000 Initial Creation $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch -$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000 +$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000$TAB EOF test_expect_success "verifying $m's log (logged by config)" ' - test_when_finished "rm -f .git/$m .git/logs/$m expect" && - test_cmp expect .git/logs/$m + test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" && + test-tool ref-store main for-each-reflog-ent $m > actual && + test_cmp actual expect ' test_expect_success 'set up for querying the reflog' ' @@ -467,7 +470,8 @@ $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 co $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit. EOF test_expect_success 'git commit logged updates' ' - test_cmp expect .git/logs/$m + test-tool ref-store main for-each-reflog-ent $m >actual && + test_cmp expect actual ' unset h_TEST h_OTHER h_FIXED h_MERGED From patchwork Mon Sep 6 16:52:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12477135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE02FC433EF for ; Mon, 6 Sep 2021 16:52:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D427A61051 for ; Mon, 6 Sep 2021 16:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234037AbhIFQxh (ORCPT ); Mon, 6 Sep 2021 12:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238800AbhIFQxd (ORCPT ); Mon, 6 Sep 2021 12:53:33 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B772C061575 for ; Mon, 6 Sep 2021 09:52:28 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 79-20020a1c0452000000b002e6cf79e572so5460321wme.1 for ; Mon, 06 Sep 2021 09:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=kKKFpVfYPxKKzWYMV/lhWUYC/2Q29tOtbs82LkkaFFQ=; b=K+7Tp3YqN6M9tY3NA4i694QjEFQgk7kHbVZN3C6zqQEtOmm9VjYSlEnghzE22Q65lZ Y3vIxriCsPP07ZBGfaT1Z3MecPVeAPkv19dZ0nzEqj34i4NEIQPW5RKIEFe7KnlQbK6n 0Ax/AVwDcj2l3jR5Bt4kHn3/lsNEG63KjsLq5+qnY3v3fwj0p7mfYSx7oE1w6+OCPOct ix7JKuqOA2YW9yfi/EBU/y12MlkcNwxrWkSaS7V6lFTHMX82NCRJrcAy+9apjstWhusJ vLhzZ4cQSN9L99rGaHz2qD9sVaquiqEI4Qdsy3hVxkFsHCEF6CqNJe3YOZ5q5OW/Y33x 03EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=kKKFpVfYPxKKzWYMV/lhWUYC/2Q29tOtbs82LkkaFFQ=; b=m5BtOe5YnxHslSDbuCp69XlX2DhfLI47KTSV/ss2PIlf4AXb7sA6Jx/HsN4FBJPUPi Vh3dPwpME9j8czDSU0B30Y0HRMHYRb8UZNmmSV3SXv29MfOwAHxw2DcLmjybf8XoKjEd 9+2sew50XcEXzGVI/qb4g3u0ySZRSYNr4cU/Bp+MMoF5gRMZilbGHL0uiW68ijmdLlfh mTYiqB7oU0ObwmBYatoZYqFbMDiFmn4nkcJL+UNdXaULcDDh0/IbIS3ANZVBSyom0DbO sd44RG0lSloQPCRJBknLtRZgI2Gkx/dTvDK1k26igCNm6gQXuwoAVTwF3FVbeDFJJvzX ufDQ== X-Gm-Message-State: AOAM5303Xks4gOZLQ1DIpddQhdXTKz6mXfEOuHxORWP8QsTcIu1RaT7g jwAgIGE3twkODk7dI8v1ljm9tONMDAY= X-Google-Smtp-Source: ABdhPJxKvLCK20sCPJGkgEHWOGNpZN6hRYzHA6cV+BptTOb5FI6mae7dgP8a9B3Hh9FL6rpzzg5P2w== X-Received: by 2002:a05:600c:3b0e:: with SMTP id m14mr69354wms.118.1630947146705; Mon, 06 Sep 2021 09:52:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a133sm53801wme.5.2021.09.06.09.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 09:52:26 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 06 Sep 2021 16:52:21 +0000 Subject: [PATCH v2 4/5] refs: drop force_create argument of create_reflog API Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys There is only one caller, builtin/checkout.c, and it hardcodes force_create=1. Signed-off-by: Han-Wen Nienhuys --- builtin/checkout.c | 2 +- refs.c | 9 ++++----- refs.h | 4 ++-- refs/debug.c | 5 ++--- refs/files-backend.c | 5 ++--- refs/packed-backend.c | 3 +-- refs/refs-internal.h | 2 +- t/helper/test-ref-store.c | 3 +-- t/t1405-main-ref-store.sh | 2 +- t/t1406-submodule-ref-store.sh | 2 +- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index b5d477919a7..3c6506e0595 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -876,7 +876,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, int ret; struct strbuf err = STRBUF_INIT; - ret = safe_create_reflog(refname, 1, &err); + ret = safe_create_reflog(refname, &err); if (ret) { fprintf(stderr, _("Can not do reflog for '%s': %s\n"), opts->new_orphan_branch, err.buf); diff --git a/refs.c b/refs.c index 8b9f7c3a80a..ca59a7cc652 100644 --- a/refs.c +++ b/refs.c @@ -2347,16 +2347,15 @@ int reflog_exists(const char *refname) } int refs_create_reflog(struct ref_store *refs, const char *refname, - int force_create, struct strbuf *err) + struct strbuf *err) { - return refs->be->create_reflog(refs, refname, force_create, err); + return refs->be->create_reflog(refs, refname, err); } -int safe_create_reflog(const char *refname, int force_create, - struct strbuf *err) +int safe_create_reflog(const char *refname, struct strbuf *err) { return refs_create_reflog(get_main_ref_store(the_repository), refname, - force_create, err); + err); } int refs_delete_reflog(struct ref_store *refs, const char *refname) diff --git a/refs.h b/refs.h index 48970dfc7e0..3c457bc19c8 100644 --- a/refs.h +++ b/refs.h @@ -416,8 +416,8 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags); * Setup reflog before using. Fill in err and return -1 on failure. */ int refs_create_reflog(struct ref_store *refs, const char *refname, - int force_create, struct strbuf *err); -int safe_create_reflog(const char *refname, int force_create, struct strbuf *err); + struct strbuf *err); +int safe_create_reflog(const char *refname, struct strbuf *err); /** Reads log for the value of ref during at_time. **/ int read_ref_at(struct ref_store *refs, diff --git a/refs/debug.c b/refs/debug.c index 1a7a9e11cfa..f6b01b1eba0 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -340,11 +340,10 @@ static int debug_reflog_exists(struct ref_store *ref_store, const char *refname) } static int debug_create_reflog(struct ref_store *ref_store, const char *refname, - int force_create, struct strbuf *err) + struct strbuf *err) { struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; - int res = drefs->refs->be->create_reflog(drefs->refs, refname, - force_create, err); + int res = drefs->refs->be->create_reflog(drefs->refs, refname, err); trace_printf_key(&trace_refs, "create_reflog: %s: %d\n", refname, res); return res; } diff --git a/refs/files-backend.c b/refs/files-backend.c index 206c9f8b932..b710d43be16 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1598,15 +1598,14 @@ error: return -1; } -static int files_create_reflog(struct ref_store *ref_store, - const char *refname, int force_create, +static int files_create_reflog(struct ref_store *ref_store, const char *refname, struct strbuf *err) { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_WRITE, "create_reflog"); int fd; - if (log_ref_setup(refs, refname, force_create, &fd, err)) + if (log_ref_setup(refs, refname, /*force_create=*/1, &fd, err)) return -1; if (fd >= 0) diff --git a/refs/packed-backend.c b/refs/packed-backend.c index f8aa97d7998..af7038de42d 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1618,8 +1618,7 @@ static int packed_reflog_exists(struct ref_store *ref_store, } static int packed_create_reflog(struct ref_store *ref_store, - const char *refname, int force_create, - struct strbuf *err) + const char *refname, struct strbuf *err) { BUG("packed reference store does not support reflogs"); } diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 3155708345f..cc0e56e8c82 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -590,7 +590,7 @@ typedef int for_each_reflog_ent_reverse_fn(struct ref_store *ref_store, void *cb_data); typedef int reflog_exists_fn(struct ref_store *ref_store, const char *refname); typedef int create_reflog_fn(struct ref_store *ref_store, const char *refname, - int force_create, struct strbuf *err); + struct strbuf *err); typedef int delete_reflog_fn(struct ref_store *ref_store, const char *refname); typedef int reflog_expire_fn(struct ref_store *ref_store, const char *refname, const struct object_id *oid, diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 0fcad9b3812..a65fda66ddc 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -180,11 +180,10 @@ static int cmd_reflog_exists(struct ref_store *refs, const char **argv) static int cmd_create_reflog(struct ref_store *refs, const char **argv) { const char *refname = notnull(*argv++, "refname"); - int force_create = arg_flags(*argv++, "force-create"); struct strbuf err = STRBUF_INIT; int ret; - ret = refs_create_reflog(refs, refname, force_create, &err); + ret = refs_create_reflog(refs, refname, &err); if (err.len) puts(err.buf); return ret; diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index 76b15458409..3cb5e23d6db 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -108,7 +108,7 @@ test_expect_success 'delete_reflog(HEAD)' ' ' test_expect_success 'create-reflog(HEAD)' ' - $RUN create-reflog HEAD 1 && + $RUN create-reflog HEAD && git reflog exists HEAD ' diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh index b0365c1fee0..78d40bdcd8b 100755 --- a/t/t1406-submodule-ref-store.sh +++ b/t/t1406-submodule-ref-store.sh @@ -92,7 +92,7 @@ test_expect_success 'delete_reflog() not allowed' ' ' test_expect_success 'create-reflog() not allowed' ' - test_must_fail $RUN create-reflog HEAD 1 + test_must_fail $RUN create-reflog HEAD ' test_done From patchwork Mon Sep 6 16:52:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12477137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79E4BC433FE for ; Mon, 6 Sep 2021 16:52:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C71261051 for ; Mon, 6 Sep 2021 16:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239581AbhIFQxi (ORCPT ); Mon, 6 Sep 2021 12:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230491AbhIFQxd (ORCPT ); Mon, 6 Sep 2021 12:53:33 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91072C061757 for ; Mon, 6 Sep 2021 09:52:28 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so265509wmh.1 for ; Mon, 06 Sep 2021 09:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Q+Op4PTH28MvR0erQ9QO3PJo2ZFM6SERxS6JFjsgTR4=; b=bLpXIjwF07Oa518jEfnSuRTtq8U0L4Zmbd8Jxit38sX8T0ntvjf6OxieCj+fkfmC6W R2uwHQlXWyt2lXB7mV+hYBa7wMgziK1nXTaZiaAyLjLsFYWKpBlnzYXdeVWXgRuMZSNJ qfZtJeGYo5Y6Xvz2Hh8PMvaLNgvpPRLWU+48SIpMRUjUHOmHrfxZftSUliz5dAZCCd59 o44d/8CfSb9ylWTo7bjEbGmoZbUiGrDIZXfqAjQ5L+0YDI+VLjQLbiBZYyZ2kZN3VEwn mYqpuZpQmZJ0vItAprQf1oay62tYtjFadSNXS2ZG9U0H3rGsuJmyYBj3Ew2oJMxQgv8o a3CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Q+Op4PTH28MvR0erQ9QO3PJo2ZFM6SERxS6JFjsgTR4=; b=oDrkQAJBedZXyEpo3ay7K2oS2FBiGyV5hVSPhtv5i5suANpvBkAL4VYG7r0U2+TSOf yfnWpMhkaEdYv4ROwCEsw77xCFLVytE9dgGl5mTy1tI7bhYPppGEN0S3NpQDaxa6VhGF nrLFJS5KhHEDRRK6xP3sA54qXKziU28/2dS0dp6lZawPKeAF4tyeDMaR5NJn7Op9orru XasrT+q2eALT1dZKdzQfn8nWyMrzdw8krg3vQ9iB7cn/u8287uX/WaTLuabMVgBWM1c3 S3u1gu5fSa1aLgfFHJw5SsgDYk3dxzMb+qlMieSoPfEkgK4APtmwOJkucpju6ONweL4B smNQ== X-Gm-Message-State: AOAM531YBJXkX4OAR07phBlyWCAJONJRxj/FrMkP4dxSP/nOGmgu+mGi H3Aq8XGcAPoYOTbyJCO+M8mq0PrMAg0= X-Google-Smtp-Source: ABdhPJzsvUhikDGknoYOwB4pnQuBpNFI/kEYMNgcDgajZ5eM6H7smeMUV+rEm2GLPtndrTZq3Addew== X-Received: by 2002:a05:600c:3556:: with SMTP id i22mr69587wmq.104.1630947147247; Mon, 06 Sep 2021 09:52:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b4sm8282255wrp.33.2021.09.06.09.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 09:52:26 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 06 Sep 2021 16:52:22 +0000 Subject: [PATCH v2 5/5] RFC: refs: reflog entries aren't written based on reflog existence. Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Before, if we aren't supposed to update reflogs (eg. core.logallrefupdates=NONE), we would still write reflog entries if the reflog file (.git/logs/REFNAME) existed. The reftable storage backend cannot distinguish between a non-existing reflog, and an empty one. Therefore it cannot mimick this functionality. In CAFQ2z_Ps3YxycA+NJ9VKt_PEXb+m83JdNB7ujzWw1fTPKyZ=fg@mail.gmail.com, we came to the conclusion that this feature is probably a remnant from the time that reflogs weren't enabled by default, and it does not need to be kept. Signed-off-by: Han-Wen Nienhuys --- refs/files-backend.c | 53 ++++++++++++++----------------------------- t/t1400-update-ref.sh | 5 ++-- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index b710d43be16..5ba68584aba 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1551,51 +1551,32 @@ static int log_ref_setup(struct files_ref_store *refs, struct strbuf logfile_sb = STRBUF_INIT; char *logfile; + *logfd = -1; + if (!force_create && !should_autocreate_reflog(refname)) + return 0; + files_reflog_path(refs, &logfile_sb, refname); logfile = strbuf_detach(&logfile_sb, NULL); - if (force_create || should_autocreate_reflog(refname)) { - if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) { - if (errno == ENOENT) - strbuf_addf(err, "unable to create directory for '%s': " - "%s", logfile, strerror(errno)); - else if (errno == EISDIR) - strbuf_addf(err, "there are still logs under '%s'", - logfile); - else - strbuf_addf(err, "unable to append to '%s': %s", - logfile, strerror(errno)); - - goto error; - } - } else { - *logfd = open(logfile, O_APPEND | O_WRONLY, 0666); - if (*logfd < 0) { - if (errno == ENOENT || errno == EISDIR) { - /* - * The logfile doesn't already exist, - * but that is not an error; it only - * means that we won't write log - * entries to it. - */ - ; - } else { - strbuf_addf(err, "unable to append to '%s': %s", - logfile, strerror(errno)); - goto error; - } - } + if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) { + if (errno == ENOENT) + strbuf_addf(err, + "unable to create directory for '%s': " + "%s", + logfile, strerror(errno)); + else if (errno == EISDIR) + strbuf_addf(err, "there are still logs under '%s'", + logfile); + else + strbuf_addf(err, "unable to append to '%s': %s", + logfile, strerror(errno)); } if (*logfd >= 0) adjust_shared_perm(logfile); free(logfile); - return 0; - -error: - free(logfile); - return -1; + return (*logfd < 0) ? -1 : 0; } static int files_create_reflog(struct ref_store *ref_store, const char *refname, diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 8ced98e0fe8..446b568cef3 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -270,7 +270,7 @@ test_expect_success "(not) changed .git/$m" ' ' rm -f .git/logs/refs/heads/main -test_expect_success "create $m (logged by touch)" ' +test_expect_success "create $m" ' test_config core.logAllRefUpdates false && GIT_COMMITTER_DATE="2005-05-26 23:30" \ git update-ref --create-reflog HEAD $A -m "Initial Creation" && @@ -318,9 +318,8 @@ test_expect_success 'symref empty directory removal' ' cat >expect < 1117150200 +0000 Initial Creation -$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch -$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000$TAB EOF + test_expect_success "verifying $m's log (logged by touch)" ' test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" && test-tool ref-store main for-each-reflog-ent $m > actual &&