From patchwork Tue Sep 7 13:36:42 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: 12478717 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.7 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,URIBL_BLOCKED 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 2CC29C433F5 for ; Tue, 7 Sep 2021 13:37:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08A7A610E9 for ; Tue, 7 Sep 2021 13:37:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344600AbhIGNiF (ORCPT ); Tue, 7 Sep 2021 09:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344029AbhIGNiB (ORCPT ); Tue, 7 Sep 2021 09:38:01 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 783B8C061757 for ; Tue, 7 Sep 2021 06:36:51 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id u9so14477554wrg.8 for ; Tue, 07 Sep 2021 06:36:51 -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=WbsBZWVl4KvCj9IY03Gebo9jmW5xuo+m0X7mW1oG4Nk=; b=KxDpCA7hF+k4TeKQLTev6tZRapJAvTpESjTn1CGJjjckJh1RbJpoWlwSFRwYWVl7ii 6amt1KG33wX7NpNmX4+ot4Wricwo4KJ7rDU7oJ4yjRCmUPPZ5XsgI4gAl7MPUkqmocaW 6JvWyAg5PVXtlpq/B5l1WmnR/PyUXUt+jFUmOEpUzZdKW0T7lFyHGNvfL+1b/Y5cvbtd tDQ66uirKgtAtrjyqqnor882Ffk7R2bgrLqEihTR44dPNpGPWL7uSnhs2EiGArNlhDoq Dy/Y5nwbsCKWT52CLOH4De3JxcJIHX/Z4tc48vK/SPaleUnjvDli0+KWJnUjAH8b3ajP 5hgw== 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=WbsBZWVl4KvCj9IY03Gebo9jmW5xuo+m0X7mW1oG4Nk=; b=OUVq+S6T43vt2LKFd4FMMq8zfyEj8AeEhhPl2sLw6hjeRUFQe0JfEDOWVLtNObsiOE K8VOxBbseP3jIEiLqWnNzB5lnqRmqdNc8E2U/PSH2RQikjJhCf7y9Whkr5LkXD70ZxlD Jx6mMflMhtmT0Wxqe0taBJu3p01x1SAycrunVdm2IGd/RP8xoXojtPcd0M8s/wxvzXHv j45EUWjJzfT8jT6xng0m9vap5MgNZzfK1+GmX+ZpMPiROXRxf0bKCiPk8Zfky97Xnl8r TIJd6l59ruF21dr50P5I7DfSMNtu5k+a7m39y+AeHKlC2PL0Pa/nJWeskcAM59toz1bT eHJw== X-Gm-Message-State: AOAM5321XnPim4K3jIVkObmAo/WbIIZKVMe9ieVK7JnGmPrrjalqL8Rh 18knyXa65+Z1WlhjWMbB3u77S0FquAY= X-Google-Smtp-Source: ABdhPJxi4mgtVWGH740U2ZWdxV0lsGnHYuhO2L1ukovCf0nnTHPjM1S88IgtRmbUBscJQMWJbZGDaA== X-Received: by 2002:a5d:464c:: with SMTP id j12mr19374291wrs.27.1631021810137; Tue, 07 Sep 2021 06:36:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e3sm13896025wrv.18.2021.09.07.06.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:42 +0000 Subject: [PATCH v3 1/7] show-branch: show reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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, --reflog option would look for '\t' in the reflog message. As refs.c already parses the reflog line, the '\t' was never found, and show-branch --reflog would always say "(none)" as reflog message Add test. Signed-off-by: Han-Wen Nienhuys --- builtin/show-branch.c | 12 +++++++----- t/t3202-show-branch.sh | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/builtin/show-branch.c b/builtin/show-branch.c index d77ce7aeb38..902a0d99850 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -762,6 +762,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) char *logmsg; char *nth_desc; const char *msg; + char *end; timestamp_t timestamp; int tz; @@ -771,11 +772,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) reflog = i; break; } - msg = strchr(logmsg, '\t'); - if (!msg) - msg = "(none)"; - else - msg++; + + end = strchr(logmsg, '\n'); + if (end) + *end = '\0'; + + msg = (*logmsg == '\0') ? "(none)" : logmsg; reflog_msg[i] = xstrfmt("(%s) %s", show_date(timestamp, tz, DATE_MODE(RELATIVE)), diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh index ad9902a06b9..d4d64401e4b 100755 --- a/t/t3202-show-branch.sh +++ b/t/t3202-show-branch.sh @@ -4,6 +4,9 @@ test_description='test show-branch' . ./test-lib.sh +# arbitrary reference time: 2009-08-30 19:20:00 +GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW + test_expect_success 'setup' ' test_commit initial && for i in $(test_seq 1 10) @@ -146,4 +149,16 @@ test_expect_success 'show branch --merge-base with N arguments' ' test_cmp expect actual ' +test_expect_success 'show branch --reflog=2' ' + sed "s/^> //" >expect <<-\EOF && + > ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10 + > ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10 + > -- + > + [refs/heads/branch10@{0}] branch10 + > ++ [refs/heads/branch10@{1}] initial + EOF + git show-branch --reflog=2 >actual && + test_cmp actual expect +' + test_done From patchwork Tue Sep 7 13:36:43 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: 12478721 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.7 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,URIBL_BLOCKED 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 64C61C433F5 for ; Tue, 7 Sep 2021 13:37:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 431C5610E9 for ; Tue, 7 Sep 2021 13:37:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344617AbhIGNiI (ORCPT ); Tue, 7 Sep 2021 09:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344229AbhIGNiB (ORCPT ); Tue, 7 Sep 2021 09:38:01 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C555C06175F for ; Tue, 7 Sep 2021 06:36:52 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id n5so14483692wro.12 for ; Tue, 07 Sep 2021 06:36:52 -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=JpwBKzKGV5OZrreDmuvwGx82dF6Vy4fzhGZLhC9Pd5Q=; b=Lj0bPGeGfm+3DSnPQeX7LCCZblXuDwTaCzAyaViRe7Gxy7lTcZScsbufxoG5cmTJZt RJszE5ufC5yBMAEuyhsFLf39rvBfTFa512bnND6E4DpoVGDudZ1OWpVkVZOv210G/yFq ZDm55Hu7NElLaTGZ5256OpoP/Wo6tFak6PxRtNhT/zK4gaElWdx1A73uVXfk7J16t2GB rB/g7uuaCvwUZtPbVtjjymQ0nzUOfxMqtdYBPTzurX09guTx40KZUeCsA1+wC2u95qu9 tiHTWIEl5AfipzK0kxBHdbmka0H9RfnkKYxyCxfS80xGoHUDFCbcprThBTciM+B3YVmC rG8w== 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=JpwBKzKGV5OZrreDmuvwGx82dF6Vy4fzhGZLhC9Pd5Q=; b=XxcLuuWDZMleJJCsTupZ2hpEgTBMpkMe8wjDGrU8i6VX6S7AefY/xLGHOFkjPH996W fXocZxty/wJOm7W0TApC2UcDGXdBa+dtf6lS6JdmHrwmtwv0FoQ6w6UG7h4M/rHGF4qe etC02fBT3UIS9EVoGbgLPW7Y4dfoiqwyx2Lqegc/P+7+HlBk+r50pMVzlFfRpBqB/XQY s8PXJj3khAuDY2fvAEsyEU5zuPB/wG0BK18+0gkM/pfddh1ZWuE0WAEwPJOLRJXhw+B4 DF766+QCIRKHjagTmaoNqUPCIaCwO7uoTKFQzRLUU3nbWaavnRRMB+NJX9YywPer5JvI jVOA== X-Gm-Message-State: AOAM532HnaobZC9Jg44X4geQABHznSrgW0jJknlN+J7sgrCrQHB1xDHM AsAGO6oqar/H1jf02HVm825pXNs/GXg= X-Google-Smtp-Source: ABdhPJxs8xA5Ja0mBA2jXOI83iasz+OczNhkX5S1MnSMPwCVXfJnF0gkYJlXtjfbJE3MdYAd3RZBDQ== X-Received: by 2002:adf:eb4a:: with SMTP id u10mr18890893wrn.11.1631021810741; Tue, 07 Sep 2021 06:36:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r27sm1708078wrr.70.2021.09.07.06.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:50 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:43 +0000 Subject: [PATCH v3 2/7] refs: trim newline from reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 | 5 ----- 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, 21 insertions(+), 29 deletions(-) diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 902a0d99850..58a894e81e2 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -762,7 +762,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) char *logmsg; char *nth_desc; const char *msg; - char *end; timestamp_t timestamp; int tz; @@ -773,10 +772,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) break; } - end = strchr(logmsg, '\n'); - if (end) - *end = '\0'; - msg = (*logmsg == '\0') ? "(none)" : logmsg; reflog_msg[i] = xstrfmt("(%s) %s", show_date(timestamp, tz, 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 Tue Sep 7 13:36:44 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: 12478723 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.7 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,URIBL_BLOCKED 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 B5CBBC433FE for ; Tue, 7 Sep 2021 13:37:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CD2D610E9 for ; Tue, 7 Sep 2021 13:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344627AbhIGNiJ (ORCPT ); Tue, 7 Sep 2021 09:38:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344394AbhIGNiB (ORCPT ); Tue, 7 Sep 2021 09:38:01 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9E48C0613C1 for ; Tue, 7 Sep 2021 06:36:52 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id u26-20020a05600c441a00b002f66b2d8603so1850764wmn.4 for ; Tue, 07 Sep 2021 06:36:52 -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=pstwq/kc/H06DKL2hTe2ctJSHP9PkG4suDIuxZbTWMDSrnVFPsmh5HyNp+raGBnCjl DKELtPIQPg8B1WTwBAe+62GNsiMrb2LSCdoegabfWFn+vtIDCBiLOEnzOUksuqQbWBur Y65DxOktM+XFFSIq/c+RNRE+8iOKgxUXL+3s+JIy2fyue8UqA/w3KUaH+9DCXtSCkpz9 1+reIkk/DQ18MPFq/lJlKiZjSuz5mauQuMDWsr9W8LadK0nxgRMLJ82IQlz/zRp/lefd ZbQrLwYc5t2GWOmgUqgMfTKXku+mefwBhutznYHyXYqfUeU92fmgo7kEbcfX1OwQC3v5 36Iw== 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=nykciVH/QFjyjNvZiOMNP+59ZA4EoKU8rmtz92rdTcFHeD6Yl82AHXnD1qP7pPUg87 WF6Tmvk0sxJW45XhX5XIcKJKRyhcez0qp4AxgvRqDZ3NnlRDNPAHJQzTkcp4Kikx+yMw EjfVo3S8G6XULT9nXILpxvKycXsrd22UcgocfKuksaSBmrBHXVshtF3dv0y06LxssGPG 3w0JJAqxEaZjFj4+I6Ns74z+1DETg6W5/YBoY0Msa0n0o3H1Wfh/6Lz6IDlFsqeUxEjU XsoX2goo8LBu7erg21bbQ7WXPoXFHFjdHOnoCd0HRMXgdAk7v++T6GcI6ub+EpyECQyp srSw== X-Gm-Message-State: AOAM530/WQ4feJBeTs/ku9J1dx2eP0LJNqkFCBewtKyYxLjsvLycms02 eD5CxyJUstzgZ1HcCOwIV4L6xNVxzxQ= X-Google-Smtp-Source: ABdhPJy5U9etMozfTK67fI3ufy/+W5svvyy60atKRpwSibYiJt6VCeZ7rZn72adOKMiFw1IFgKbYow== X-Received: by 2002:a7b:c4cd:: with SMTP id g13mr3994987wmk.91.1631021811484; Tue, 07 Sep 2021 06:36:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s14sm2325564wmc.25.2021.09.07.06.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:51 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:44 +0000 Subject: [PATCH v3 3/7] test-ref-store: tweaks to for-each-reflog-ent format Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 Tue Sep 7 13:36:45 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: 12478727 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.7 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,URIBL_BLOCKED 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 7EBB5C433FE for ; Tue, 7 Sep 2021 13:37:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62566610C9 for ; Tue, 7 Sep 2021 13:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344699AbhIGNiP (ORCPT ); Tue, 7 Sep 2021 09:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344390AbhIGNiB (ORCPT ); Tue, 7 Sep 2021 09:38:01 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7394DC0613CF for ; Tue, 7 Sep 2021 06:36:53 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id e26so6882645wmk.2 for ; Tue, 07 Sep 2021 06:36:53 -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=RiPMVl/8BJ9BjqloJiw1H75atPXMEznihaobJpZExl3/h8NnZM/lYdtP3Mc7zLsCDh UUx+q/0GpyFLB/RvwJZFR7KbXMczOhnukpu6Cs+xCaOF717vKqy8uVzf3/JT37zSCZqs aVT0EmETxyWo8vjSzm8x8z3O0blZ0f87aRheEvFPbYYnZRmEVTdX6ZBPMEDZwrGpJyHp o1tz3XdWHoigihI9D/HRDuj/nVJVyg33p4JCH5WJQj2xE94StTff4t8wxqO63twOg54m maiqukd0oRSHKPFMk9x5gU8EFFe/tbgyH6SIo2Nm6s0yV3TZFUFwmb6f1wup9kW0npYr x2uQ== 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=XF5Z/TmjG5xXjWo/r9LWAnkiCVJsavBkxzarkBt38qLB86U87NesuPFdHpaGttPlqM 1YrgqYatR+K75e7XmxXClEa6u3ZPq7j564tL/dRgYc/TUPejMNHPfhX+BicHHkpKjPKN mdx8oFYGmQ9vypqkXp5VzdliUBBWcShA7NQsCKXhKA8Hqg4FuCDZ4LYdHHm1vHCDvw3Y miy+ohTdonWDnY/Z8UpwNT6TNK0Pxdpc8vsM0u2GBnShU9n1zPM56YYAfCzKf/26Tw// BVvVvf4IXJevZUFppr/fgYW+uRfsafZZp9dXL0+nUS9/W7JsulWR/wwddGU7K0HMx4+7 CDDg== X-Gm-Message-State: AOAM530ql4LY5zt8V1b6NoJ/lgZPszKCz5/ugQWaLbEmnTy3EuS9f6wj wcBRr9/JTDJsiP//y8OMzgWNtnFMCYY= X-Google-Smtp-Source: ABdhPJzD85Od1z2B7CmAsqNAN03w2oUnmUbDafb+N7B1Y9zJg7t0pH7N0wl4jai5MabmS7Hce/8HlQ== X-Received: by 2002:a1c:f314:: with SMTP id q20mr3952491wmq.154.1631021812136; Tue, 07 Sep 2021 06:36:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l10sm11841135wrg.50.2021.09.07.06.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:51 -0700 (PDT) Message-Id: <52093fce57c7ef91b6d730f50d6b7ffa6cadc03f.1631021808.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:45 +0000 Subject: [PATCH v3 4/7] t1400: use test-helper ref-store to inspect reflog contents Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 Tue Sep 7 13:36:46 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: 12478719 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.7 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,URIBL_BLOCKED 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 2E86BC433EF for ; Tue, 7 Sep 2021 13:37:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 125BA610E9 for ; Tue, 7 Sep 2021 13:37:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344615AbhIGNiH (ORCPT ); Tue, 7 Sep 2021 09:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344577AbhIGNiE (ORCPT ); Tue, 7 Sep 2021 09:38:04 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4B40C0613D9 for ; Tue, 7 Sep 2021 06:36:54 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id u15-20020a05600c19cf00b002f6445b8f55so2290362wmq.0 for ; Tue, 07 Sep 2021 06:36:54 -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=WH2k3KghbeMFoOFf3HcPFHf0urOrSVpn5v9rkcW20KE=; b=MGABPSdULOJgRwrrE90BfTF7FM0+ylahyMx3xtT/+qtI3aRSkxvHUqVaCDY/PJRjxf Jd9wEp7bExmznm9bY1ZrSqIJsg3iC1czZXXplTLqQFtUp7u+Oh9xQoL06RJDQpED4/S9 EhodKHqrwRXPSGyBCOjg3js9xQtifq79WH4m/noW9nQ0cSneewjsERJbmab/htty415F aA6AyUmm7IJS2p4cKvwP5wj7hKR6GXNVHKhJspHzempOYS726l1dqWMIcZtSt0EdZaMF p2VgANcpM7auFA9wjxD3eIS3+pwv7HAAezwRebIc9p8ZKIuU9uX9jhdR5+xmKzCWTMkJ B0Ow== 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=WH2k3KghbeMFoOFf3HcPFHf0urOrSVpn5v9rkcW20KE=; b=Sw+hZ0ZJq/g5NhV8G90rRPlj4T1uZ8fhrZxEaJTKtpgA27lkrml7kwu3cfsiDzLjG5 O90EEDK/WIAfWj5agMvBXcgE3zV5KxFEyWfHZUSEFTjgZ1hRJ9YEkYXovWOWK7kET5jw cYiqLTHBVEaVm/g1x37Q2U4L62giy06s1Z2N49dP19o73am/1TTMotC5v3VCHWZaDkfc 0gUdCCmm53qg0NERCET57hie8Kp3quaO169cQNZfuvTBLjpNo6Ejob0TeIJ6c2/ERy6B S3gMdj6DHJoi3Vryq7Gtl76FnFCn5CbqvDVU/FLM/+H+RE5GOSmgvuliJv7wnO6UUFMB QsFQ== X-Gm-Message-State: AOAM533nd/HcaIiU9txVcG6ZWZ9SfWlalAHogtmhUMgr5684yYmH9c68 d8EL8Kw6aYwOHJqguwPhrOgC3NXsvEI= X-Google-Smtp-Source: ABdhPJz46f+/JPXWWriJK4PK/hOTgQy//IZ4a7zdL/TYJ/pYnzfNOhe5w+kY9oKIuTSdqMH9jjyyyQ== X-Received: by 2002:a7b:cbc9:: with SMTP id n9mr4103143wmi.50.1631021812854; Tue, 07 Sep 2021 06:36:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 17sm2309584wmj.20.2021.09.07.06.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:52 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:46 +0000 Subject: [PATCH v3 5/7] refs: drop force_create argument of create_reflog API Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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. This argument was introduced in abd0cd3a301 (refs: new public ref function: safe_create_reflog, 2015-07-21), which promised to immediately use it in a follow-on commit, but that never happened. 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..04d73b89c9c 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, 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 Tue Sep 7 13:36:47 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: 12478725 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.7 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,URIBL_BLOCKED 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 EE321C433EF for ; Tue, 7 Sep 2021 13:37:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCB8861057 for ; Tue, 7 Sep 2021 13:37:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344671AbhIGNiM (ORCPT ); Tue, 7 Sep 2021 09:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344579AbhIGNiE (ORCPT ); Tue, 7 Sep 2021 09:38:04 -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 35930C061796 for ; Tue, 7 Sep 2021 06:36:55 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id j17-20020a05600c1c1100b002e754875260so2251051wms.4 for ; Tue, 07 Sep 2021 06:36:55 -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=O8TvS/RYI1/f14ABLT38ETUNLnRVHqlQFrNFSAh4SFE=; b=PpMJba0RrG4qbcwsgTKgAR3uquhhZGhRREoIh+sn7BAsciGsthE4ouA5LpBWBVYKpb 1h06iaf/ch8ZSDOIxlkAJEpDLRKNR1aBgtJIOzKJXfRh0zE7UKuCPAwCTXqjOXMDf7Me /K3iB0ODM3PXJRdxoSZpiibRf/CNwLv0pY6Nzx4X3TERgSW0JRRlQxGGEv9U87BSaQA8 ZAMN/FCToIqoYRgX5CkI+AwaRkib8K6HUgDTIY50SeBj23QFsR2eI6YXo7EqYEI6M5cM 7Pr5fEwRFpsoNSXmka8YSPWwjPXZ6XkdRnGeD1qI6r1+0rleRb7aWXiwOK3/DMjcsKSy UReg== 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=O8TvS/RYI1/f14ABLT38ETUNLnRVHqlQFrNFSAh4SFE=; b=fMRdL2VOB7kuCYNDnBh+pM9MGcOMDtVlq2tr22dfHxpYxGdVADjfdfbmpHxZTnnEk5 qGSH+BFwBS8v8iQKCnc3o5MewYs8X2sVPwvRZmkAnwxhwbEl/lYuaMYiMYexajyHa10/ OlaAbMJYu/edZs4QNSahfJQWLC1fzLErxR0PP3EhaRthkpC+33wv9LQSZDttpr7X4X5Z zGf1CU5KDSyRmwUO1h4iluBMWaAKiskZWnD/NHVDJ3K9g+4vg6CmuMMIhWRi4dNNrAWf jPmT8Hy5pi/PtmEpNgDe5iowxVE/z7tQY9ra6rXs3fytwMgBig7QNbFTeQhGEE2+Fskz jHqA== X-Gm-Message-State: AOAM531wYZq1vCvkIYxFUeRW1Nb+guRKWTAvNEaBcqE+DgSLofn8e8S7 ec2jVTrNFgXNswEFuAbvs69OTcgjIhA= X-Google-Smtp-Source: ABdhPJziQO8B/a/TMsuPAKzBoMI5PC+EGrW8a82ZMYDvrU23cFtZzWdecSXcZuTplLjK1XxAjPqgbA== X-Received: by 2002:a1c:2313:: with SMTP id j19mr3900066wmj.189.1631021813843; Tue, 07 Sep 2021 06:36:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g11sm10815929wrx.30.2021.09.07.06.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:53 -0700 (PDT) Message-Id: <7a030cfd3e2521f08562ff7ecc00743b786c0e32.1631021808.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:47 +0000 Subject: [PATCH v3 6/7] 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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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. With this feature, it is possible to mark only specific branches as subject to reflog updates. When introduced, it presumably served as a cheap substitute for introducing branch.$NAME.logRefUpdate configuration setting. Reflogs are small and don't impact the runtime of normal operations, so this flexibility is not very useful. Since it incurs complexity for alternate ref backends, we remove it. Further background to this change is in . 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 04d73b89c9c..4aa4d2bbba1 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 && From patchwork Tue Sep 7 13:36:48 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: 12478729 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 156C7C433F5 for ; Tue, 7 Sep 2021 13:37:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EECC161057 for ; Tue, 7 Sep 2021 13:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344745AbhIGNiR (ORCPT ); Tue, 7 Sep 2021 09:38:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343628AbhIGNiE (ORCPT ); Tue, 7 Sep 2021 09:38:04 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC96CC06179A for ; Tue, 7 Sep 2021 06:36:55 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id u26-20020a05600c441a00b002f66b2d8603so1850929wmn.4 for ; Tue, 07 Sep 2021 06:36:55 -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=l0MAmZmOyqa1wApQi9lyUCvdt02PjhsqsP/HLs7DN4E=; b=awxBYRq/nXERqDbkEoTvRCR3p43D9S3Dfobr2M4hv1u/O92SwVMrNUCmmgiz2y8xWT 0sV6ukXupTjzjI1VMQibpKPNCcgbEKXwq/WbezN78zEJYcmQnOK6NImrYsVLn3rywNSq iR2WbZZKxndCiI8nB5gZ5nNj+drpjbiicr7TjbNH7mtGittWQPNNzBGRrda2pTm4sCsD 8e73zG6hkh6IjWQPKgsRvvB/Vz1U9ojGQkO7Ky6rhMmXqHOikIHnOoDqyl7A2Us4Wrbg TmbmwnXcWZdSZZs1OrlJi2t9lXlatzEAJS0CKPiQTaqc9QoAYIYwC04knbkQPxeyZ+1v jBKA== 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=l0MAmZmOyqa1wApQi9lyUCvdt02PjhsqsP/HLs7DN4E=; b=qS2lWL/Na5R9K/tS9Z+oasXDAcF93Xlko8zD8GplLuU3MX0QesJd+7GvPfRM42Iouy 4UA8jZfGquSEiNQLsszs4X1cuxrHiJV23FnLzl92cvsPq8fuK5tmjGgfiDKlWUDuQSpZ Fx+KBuJ5J1u6ZqodrBhHBqWLy2BnH0tKk0iOBqulgRjymUo0u6X4x41pTW3V4XBP0Y4V rtscu3Lu5Jo3oKQTpXV4EOP/rv/OTXeaolYF3vHugVXDj8fbbp2diTb1bSokK2GrVRrU aF7H94LOSBbX9y+4n3i6BScBrVKXcmVUz9USv2CH2sBgd13TgoJhZiGvlwDwcpCZZGb9 zTig== X-Gm-Message-State: AOAM532lknz3F1cZpSgxBNuUJg2RJ1XMnYu1bI+Ib/bkYc3FTPJIDb7C MfaCLbUjqGCC08D+3azgm/s7gpcpFfA= X-Google-Smtp-Source: ABdhPJzdqIclqXUBmRQEK47DCvTV9w/bcOHQddIzsrl77Ze4giVuKdCKne3p2+OKwBDC/2ntfJsiAQ== X-Received: by 2002:a1c:2bc6:: with SMTP id r189mr4046257wmr.183.1631021814386; Tue, 07 Sep 2021 06:36:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c2sm11001994wrs.60.2021.09.07.06.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 06:36:54 -0700 (PDT) Message-Id: <1124dbad594ed24d4b20d5afc213b57c6f253603.1631021808.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Sep 2021 13:36:48 +0000 Subject: [PATCH v3 7/7] refs: change log_ref_setup calling convention Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , 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 --- refs/files-backend.c | 48 ++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 4aa4d2bbba1..114d01a9e3c 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1535,30 +1535,26 @@ static int open_or_create_logfile(const char *path, void *cb) } /* - * Create a reflog for a ref. If force_create = 0, only create the - * reflog for certain refs (those for which should_autocreate_reflog - * returns non-zero). Otherwise, create it regardless of the reference - * name. If the logfile already existed or was created, return 0 and - * set *logfd to the file descriptor opened for appending to the file. - * If no logfile exists and we decided not to create one, return 0 and - * set *logfd to -1. On failure, fill in *err, set *logfd to -1, and - * return -1. + * Create a reflog for a ref. If force_create = 0, only create the reflog for + * certain refs (those for which should_autocreate_reflog returns non-zero). + * Otherwise, create it regardless of the reference name. On success, return the + * filedescriptor. If the log should not be written, return 0 On error, return + * -1 and fill in *err. */ -static int log_ref_setup(struct files_ref_store *refs, - const char *refname, int force_create, - int *logfd, struct strbuf *err) +static int log_ref_setup(struct files_ref_store *refs, const char *refname, + int force_create, struct strbuf *err) { struct strbuf logfile_sb = STRBUF_INIT; char *logfile; - *logfd = -1; + int 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 (raceproof_create_file(logfile, open_or_create_logfile, logfd)) { + if (raceproof_create_file(logfile, open_or_create_logfile, &logfd)) { if (errno == ENOENT) strbuf_addf(err, "unable to create directory for '%s': " @@ -1572,11 +1568,11 @@ static int log_ref_setup(struct files_ref_store *refs, logfile, strerror(errno)); } - if (*logfd >= 0) + if (logfd > 0) adjust_shared_perm(logfile); free(logfile); - return (*logfd < 0) ? -1 : 0; + return logfd; } static int files_create_reflog(struct ref_store *ref_store, const char *refname, @@ -1584,15 +1580,14 @@ static int files_create_reflog(struct ref_store *ref_store, const char *refname, { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_WRITE, "create_reflog"); - int fd; - - if (log_ref_setup(refs, refname, 1, &fd, err)) - return -1; + int fd = log_ref_setup(refs, refname, 1, err); - if (fd >= 0) + if (fd > 0) { close(fd); + return 0; + } - return 0; + return fd; } static int log_ref_write_fd(int fd, const struct object_id *old_oid, @@ -1624,15 +1619,12 @@ static int files_log_ref_write(struct files_ref_store *refs, if (log_all_ref_updates == LOG_REFS_UNSET) log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; - result = log_ref_setup(refs, refname, - flags & REF_FORCE_CREATE_REFLOG, - &logfd, err); + logfd = log_ref_setup(refs, refname, flags & REF_FORCE_CREATE_REFLOG, + err); - if (result) - return result; + if (logfd <= 0) + return logfd; - if (logfd < 0) - return 0; result = log_ref_write_fd(logfd, old_oid, new_oid, git_committer_info(0), msg); if (result) {