From patchwork Mon Nov 22 14:20:52 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: 12632019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70E99C433FE for ; Mon, 22 Nov 2021 14:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239346AbhKVOYF (ORCPT ); Mon, 22 Nov 2021 09:24:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232494AbhKVOYF (ORCPT ); Mon, 22 Nov 2021 09:24:05 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F46AC061574 for ; Mon, 22 Nov 2021 06:20:58 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id o29so15559182wms.2 for ; Mon, 22 Nov 2021 06:20:58 -0800 (PST) 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=OuCqtHRK/vK4Q099RfeF3vUiPh0kfiXb7vMkw7ScbpY=; b=VrXHLUAe0wHTu4+qT8VQXkuBX/yUhDJ2dLojBs8CNXKSx01SYQ0bUciiH//2f/0/kH ISUYSKLEzR+E3APWwApeJtLRoVvc8FLNtflTwav+hY1d6VfKAClsTx6Y9wtyxRY+47GA E+jWC5fSccZq4hwHBjjbIXVwSEd1rzXus2FJuohjo4Jx1hhN32naiUEseqsI03E8plkx pI++lryhJanBTEWPThvOnZ0st0N7i48p+N6rHvGBhCHjntQdr62mg5PAUKA54I5cBsde mZSrM6+i1MSBGAuSIRYgOyVD+e3HnXFNXpwKlqqeUoU4oSOCaFLvZz9h4gUK6qgsjGbs +2ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=OuCqtHRK/vK4Q099RfeF3vUiPh0kfiXb7vMkw7ScbpY=; b=IcVDN2vgAygo2/9JjorBjAKgvZVfSvmuwJAhCBIbTTmAU6lP6dw9CSgsh2ogO1wVoz L3afJ3fVBiTUauVT+Dg031e9el+h2xx4YJPra7yOWOy3vBF+XS6V/oLpFwUVp705jkh/ HOZ6nPYkh2KEXKWOZFKwHjVr/HzoJQzKbI1cA1nowsEmh0IhJzzth2DfJVXrjK9SkxtX MNaehyUoVRi9xbUEiEmlr1C5RqKi6x8LkerX4rIHxNQJV6vwd7X9FmL2jigCeEcXrj06 hWpdJSGxjyUTP3mLwhVBV2cepxUbEiaoAxAliKzNxVLc3CyKRzxEbnLgmCT9yMimtjHV /oZQ== X-Gm-Message-State: AOAM531vpQ8vNf+gzNIytQn1HiTKCj3tF/unny0pvX0G28Cpv0/3Gjcs vZzvHhJ1RzjKR0zK86g+AFV+MT5SA80= X-Google-Smtp-Source: ABdhPJxwJ8+M+R79DhdbJOPob4CJ3XyirEf2ZEmiHlneSWXWd+9rtB9/g35D+A0n1TBhW2FhA3eOeg== X-Received: by 2002:a1c:9851:: with SMTP id a78mr29410987wme.116.1637590856647; Mon, 22 Nov 2021 06:20:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p12sm10666078wrr.10.2021.11.22.06.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 06:20:56 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 22 Nov 2021 14:20:52 +0000 Subject: [PATCH 1/4] show-branch: show reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 082449293b5..f1e8318592c 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -761,6 +761,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; @@ -770,11 +771,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 Mon Nov 22 14:20:53 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: 12632021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 605A2C4332F for ; Mon, 22 Nov 2021 14:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239485AbhKVOYG (ORCPT ); Mon, 22 Nov 2021 09:24:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239307AbhKVOYF (ORCPT ); Mon, 22 Nov 2021 09:24:05 -0500 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 3F7C0C061574 for ; Mon, 22 Nov 2021 06:20:59 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so9056881wmj.5 for ; Mon, 22 Nov 2021 06:20:59 -0800 (PST) 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=LdW0rXJSsGpMHVFEoQSE2K69zFkANfrkuBMdPDlqoa8=; b=OxpWqSH4JMD9gBH3VBl0ViSV9Doaz1V8dVGw4DM5BCWU3UJ7OfnMViFOEUnGy9RMom RrBGzIDTAdpfFk2aw8Zz07SmIeidDTowcqzv0qd9Guh3ze+s3rjpeYdiLwDFAznJcy33 XBcEsKplvvKQVZDQrYFJuoR1fjp9rXpQ2iKUg6lCF2t51/0u6BaCnEQsK94dYowZVS+x m/ZB0hGLRPUjq1z3HKsbPrJppsqAPjy3sKVyfon61ysoDq1QUp96vYOYrLRR1ozGzoce 52P2T0JHO8S5Y59m/4Hg6k+qTdUB/ely/HsmQAZG6Iqg10f5Ov1S3Mf6R1zZ+UA/dhcR 3BFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=LdW0rXJSsGpMHVFEoQSE2K69zFkANfrkuBMdPDlqoa8=; b=qGA1mUwOUhWl+p70f1qg7iWvoQjWby3/EksEzntaKWTFICuEW7QuDQcnRb0C9ippop WrrX5vrxJm7yBxafdgQkD6BEQ0EwGg0AxiHhnIo7USDNI4leVd43Folqjlh4Rbvn7muA bppBFsu3h5OOUFNP/aLjvlQ7UAqy9BbLwXA70I8p4BmdGUFBjyXVzy2iFdlIWpHeo9X6 HdWVMZ2lOyV14eT6j+RrD462D0gsH4iFlNqRABbf0MZA1SYJboGIH9xVwabRzufQxiJ1 QnvQd2QJSVBmvV4GOE+w7lRg0Cv9xWeBQx+WJ5VWiGDur/zMwnBfUqUqB7Nv9SR01eXy Xqag== X-Gm-Message-State: AOAM532NrCemzv+St4EpRSamKvd90/jXuRjQNPsZ3Obz3NHSN0SDjntH BY3gz1v0JdceoIBqFwlvom3J92oBWDs= X-Google-Smtp-Source: ABdhPJxWT1dlikMZgycP2oebrDdj6a1odl6fBbKX0O2cujq8MASLv4St9UBhBWql0a30Fb+28JZW6g== X-Received: by 2002:a1c:7201:: with SMTP id n1mr29864986wmc.176.1637590857611; Mon, 22 Nov 2021 06:20:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h15sm26120507wmq.32.2021.11.22.06.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 06:20:57 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 22 Nov 2021 14:20:53 +0000 Subject: [PATCH 2/4] refs: trim newline from reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 f1e8318592c..016ccdafd0f 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -761,7 +761,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; @@ -772,10 +771,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 8ac4b284b6b..3ee59a98d2f 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -244,8 +244,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); } @@ -284,10 +282,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 151b0056fe5..583bbc5f8b9 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1936,17 +1936,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); @@ -2038,6 +2036,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) @@ -2050,6 +2049,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; @@ -2099,7 +2099,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); @@ -3059,18 +3059,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 Nov 22 14:20:54 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: 12632023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43B81C433F5 for ; Mon, 22 Nov 2021 14:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239540AbhKVOYI (ORCPT ); Mon, 22 Nov 2021 09:24:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239349AbhKVOYG (ORCPT ); Mon, 22 Nov 2021 09:24:06 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF189C061574 for ; Mon, 22 Nov 2021 06:20:59 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 133so15603482wme.0 for ; Mon, 22 Nov 2021 06:20:59 -0800 (PST) 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=TbHTd0Nsgh/BZgNAI3BnjF+HJqYjHPMxEhmA0RxOgN8ZK1p1FwL8xCUfflwscBAMYM kHXevm/2HRqHFVEoRl3vmgGeEtF7yPn9UT00MvPSsDWPc6BjNiP5ON8rhh49u/4a4D2G R1ON3kzJj+Sb981EKh4XTrEPM8jGavYRZXrvsPJH2h5XAUUxzytz7PeFkFbTLLu2ja2F CqsFteTT25KqjV8GuVWfZtJcxU4KsyqnbxtRa3jmNl4VVWxW3TCjNxuP+ISFvDCBtdH+ MOaWBXi3NG9HymMw+WXdObkkUjEdoSPmWmqUFi6z4rjhaWnjFIqy4ULXmYjeY+ucLVm0 xvgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=kKfozFUvJCkFqXiqOo19FxWpJzvhkwQtckd1737U+q+FoVzHLSJjoSmQ/x+7CUkbPC jUto5pnO7TcbOABDQ/ZVN+kVklKFFXrV5Qxv5scFswsMJcrFF7RwcDYpCqvm5u5QqsVt 2BjKbh9LmCHhpKG4FaFaXkYSOY86oEJA8JbZGe87T/eMPWtTVw7AK/Y8RF8v3Av5sDLA JgE/Xw3Tl1EXLfL7zIO33zI2fsezSsYysBWn+PEeBG0vIp426nKH+DO4JrIrpP38iPyU 9huL7iQGUjG1wktELZGjzjLQkvoqwLTF15PocrIt8QD9gcBoVY/Enad7bP4FMcu/qxJb Y0tA== X-Gm-Message-State: AOAM532yXD69FUcN2867/TlWuHBD83I7m+jYPcdFbhuVMVwCEvp1z6Fp b0eHV9Ig9vOmmQG1Rtmm6WnAVFdHBdo= X-Google-Smtp-Source: ABdhPJwvyrAh3jLkvT/8PsGkhAb63OEvxj+hZz8YaJRa/dfXtvBtfdC9msrNNy4ngp6Ngr0beiW/Dw== X-Received: by 2002:a05:600c:1e26:: with SMTP id ay38mr30388993wmb.14.1637590858314; Mon, 22 Nov 2021 06:20:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f7sm10789182wri.74.2021.11.22.06.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 06:20:57 -0800 (PST) Message-Id: <8a1b094d54732b8b60eacb9892ab460a411bcec3.1637590855.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 22 Nov 2021 14:20:54 +0000 Subject: [PATCH 3/4] test-ref-store: tweaks to for-each-reflog-ent format Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 Nov 22 14:20:55 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: 12632025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC20DC433EF for ; Mon, 22 Nov 2021 14:21:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239589AbhKVOYL (ORCPT ); Mon, 22 Nov 2021 09:24:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239307AbhKVOYH (ORCPT ); Mon, 22 Nov 2021 09:24:07 -0500 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 7E0A8C061714 for ; Mon, 22 Nov 2021 06:21:00 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id u1so32990495wru.13 for ; Mon, 22 Nov 2021 06:21:00 -0800 (PST) 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=4XVZAMqIqOH16y6McU/uuX4Y21yjewme90u7J9fesnI=; b=JNi2QWIfMZ7IszFSfiS6QCpg2fOGycEy3cnZGfuK8wUa/+xn4B1BtSpiTy2A7LmZtl CTtMYv1LAnwRP6RyoN+tQh+ZA+0NDa8scoke0agBCB1g1fl6cBS6eNneRBXHJqevAAal xVsLydLDE4LOiwqP2gYVKMEz08F9bv5Jur5xrwly7SZRcUx+4Rq44NuyGtkWcuz0nL8P +wlMd5eqtJuf8ioyQwOWgG8OY9D+fTjbMZQzvjl/B0lZsjBIQuv5hnjeZNdrnvk+p4ov gT99sW7xIhOIQbhLyOTmLRi1tqRQNBQrpFSQw9yiQcT6gcA2SAG87PNWyK729N1y+W9c 0PWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=4XVZAMqIqOH16y6McU/uuX4Y21yjewme90u7J9fesnI=; b=YSTt3kybDNSql0sVM5raYn84TTu55IMnysn11L89EXWmK3xwtIt05J5bp1xaDSx6nQ TQyVuXklCP7iaTc2GO+AohgNW01RY/KZyCU1uH0dorSrCb7aq0lL3vzZWBvylh52NwQI 4ToE2fF5YFe4/glVR2FX5PblDmuVQ/pLvkAS9WqEZVxFNqjcs7pufnK9Uw/ykcTmUCXU tBXWxKg/rHcEUuLC4WHF2NTsCxin/ESY8sS/0/LrleQQHEYs65bkK0Me4UggdDMtojs+ y3ywOAGvHdqpJz1Ab71eWKrebmOmkoSilNqhiZbhlWqjwjUZJHM/ssnIbBBz5UJn3IHz 1qxQ== X-Gm-Message-State: AOAM530ukY7jChe0BfaPsXjGNiNAbfDs9ar2f+yJEizFiHlfwWDpII9Q kM4ApkXWOInYXGPRkU16YAWu8f4T5Ws= X-Google-Smtp-Source: ABdhPJx8X5xjNonEixKvdILl43IN3RsnuSAuE15MnPfzO7tGBqWp/KD5DFZRHXg4Qfhmsdwsfq4cOw== X-Received: by 2002:adf:fd90:: with SMTP id d16mr38068781wrr.385.1637590858992; Mon, 22 Nov 2021 06:20:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q24sm11729444wmj.21.2021.11.22.06.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 06:20:58 -0800 (PST) Message-Id: <4ba97a4e70aa437f9f710746fa7a8abad0732996.1637590855.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 22 Nov 2021 14:20:55 +0000 Subject: [PATCH 4/4] t1400: use test-helper ref-store to inspect reflog contents Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 This avoids inspecting the file system, which only works with the files ref backend. 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 0d4f73acaa8..f91432e7a25 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