From patchwork Fri Jul 29 19:29:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932782 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 C4985C00144 for ; Fri, 29 Jul 2022 19:29:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238692AbiG2T3q (ORCPT ); Fri, 29 Jul 2022 15:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238602AbiG2T3p (ORCPT ); Fri, 29 Jul 2022 15:29:45 -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 A97455FACB for ; Fri, 29 Jul 2022 12:29:43 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id id17so3023641wmb.1 for ; Fri, 29 Jul 2022 12:29:43 -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=Fjy29URKj3Un18HszCKExbcLlsxvb1I2+KYxkv7oJvo=; b=QtLC1caupuqHOtsspy7OVwzsBaW2uMAzoklI0gpDb7qM08EAVRqpUmcd75YWcpaDfr Xj/yAANF2KqWnVme1uSD4UY6F/lNR7YPuIY4xyBPzn0W6o2MkvbX0de2q1vWNay8A2nv KOx436ZZj4NQ8xA4DvBCW463WdooA7OKIJzw188Iug5fvHgVtPNGCzbHGRP44RRYaZUR 582knrz5nsQCcpv9L4fphGKWTyvaiZ86FublgYbOANU5nQhRHKUbLF1UyJ6z9bLrD8dh KEDP+AuzVybmulI+HRCIP+GUs3U2gIM/pXZiyeKDQCtIaIVIqDFhIsn1pXGAWSEJglOj 8/1g== 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=Fjy29URKj3Un18HszCKExbcLlsxvb1I2+KYxkv7oJvo=; b=xUIUrjegGA9uNVUhyFgHNBFrXtDFWyJBZ8f9Fl9vBcLt6aJp7lYBdu730up3/lmUcV YQ/fS8x0jNTtjoia7/7jPbSHRvBo8rnhJ19Wf20FQFvLHOjV2xy5PPGwpH/alUbi07/8 2CLCHPLqDOhkrmbjUAZrrKwLxYFY0qbqRfTMlXSIDhM5OGLKBkn55zWwoPENWGy6Bqh7 ave32sCxEy9ybLEXnVA/OTNT6mUsODSK5u53bAMxs7j0gq/F6HV8JDlwgoT5i66MjwvA XaqQrklpyEjzbmOUulEXd7VAU3m1RhKXBCBTRhWN43foDD1SZDpQoIdj2wgeX0JO4rUZ zJGQ== X-Gm-Message-State: AJIora97QVA2S7dTbu+eVdR1rUTdjcxPrelhCbN1VEXvDTDccUEFy6cO B9p/Dy+eA+kwTombtd0V/nzgNFiEQOs= X-Google-Smtp-Source: AGRyM1ttUmroLNQcwdH/dLR5npzphqePicsMaJgzGUZaoB6xEfF6NRiIyl1vSM+ss1P3D2ZuWVXlBQ== X-Received: by 2002:a05:600c:a146:b0:3a3:1e79:4446 with SMTP id ib6-20020a05600ca14600b003a31e794446mr3631504wmb.158.1659122981703; Fri, 29 Jul 2022 12:29:41 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f12-20020a05600c154c00b003a31169a7f4sm11095015wmg.12.2022.07.29.12.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:41 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:30 +0000 Subject: [PATCH v2 01/10] refs: allow "HEAD" as decoration filter Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The normalize_glob_ref() method was introduced in 65516f586b693 (log: add option to choose which refs to decorate, 2017-11-21) to help with decoration filters such as --decorate-refs= and --decorate-refs-exclude=. The method has not been used anywhere else. At the moment, it is impossible to specify HEAD as a decoration filter since normalize_glob_ref() prepends "refs/" to the filter if it isn't already there. Allow adding HEAD as a decoration filter by allowing the exact string "HEAD" to not be prepended with "refs/". Add a test in t4202-log.sh that would previously fail since the HEAD decoration would exist in the output. It is sufficient to only cover "HEAD" here and not include other special refs like REBASE_HEAD. This is because HEAD is the only ref outside of refs/* that is added to the list of decorations. Signed-off-by: Derrick Stolee --- refs.c | 4 ++-- t/t4202-log.sh | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/refs.c b/refs.c index 90bcb271687..ec3134e4842 100644 --- a/refs.c +++ b/refs.c @@ -457,8 +457,8 @@ void normalize_glob_ref(struct string_list_item *item, const char *prefix, if (prefix) { strbuf_addstr(&normalized_pattern, prefix); - } - else if (!starts_with(pattern, "refs/")) + } else if (!starts_with(pattern, "refs/") && + strcmp(pattern, "HEAD")) strbuf_addstr(&normalized_pattern, "refs/"); strbuf_addstr(&normalized_pattern, pattern); strbuf_strip_suffix(&normalized_pattern, "/"); diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 6e663525582..6b7d8e269f7 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1025,6 +1025,12 @@ test_expect_success 'decorate-refs and simplify-by-decoration without output' ' test_cmp expect actual ' +test_expect_success 'decorate-refs-exclude HEAD' ' + git log --decorate=full --oneline \ + --decorate-refs-exclude="HEAD" >actual && + ! grep HEAD actual +' + test_expect_success 'log.decorate config parsing' ' git log --oneline --decorate=full >expect.full && git log --oneline --decorate=short >expect.short && From patchwork Fri Jul 29 19:29:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932784 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 C486DC00144 for ; Fri, 29 Jul 2022 19:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238750AbiG2T3t (ORCPT ); Fri, 29 Jul 2022 15:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238636AbiG2T3p (ORCPT ); Fri, 29 Jul 2022 15:29:45 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD17D606BE for ; Fri, 29 Jul 2022 12:29:44 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id i10-20020a1c3b0a000000b003a2fa488efdso2364186wma.4 for ; Fri, 29 Jul 2022 12:29:44 -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=Evi/S2XBMDmcNt2aElcJYPive8tSadhed7YNYWDiBDQ=; b=ojOWk9OAS0Vv2/dDndpyY/zi7bnnTb9NSqyRfmf6ReEFKxMMT6iIz7OIUy03hKCYvV lujO2uPWKp+Jild7ISqu8j/6f+CPgn9d15f/1IBgAvSnwJdGR7WQUVilD8LyhkJNx1G0 P8yLWiVEVn1mSrkRjrqXZHtSKq4SajR4uGvbF2DU0BX9if97vtSajMCKYTqFxLkTf4b5 oclEx8yKZFphc3St0KIhm7lfuyKWoMSHiA9g4sKFV0Djey7BRpbWMJi/WusVuqgzxrXF IE7BfY/z9YthtGGGmG/jxmRMQ+xPHQtzu1Euc2QWS0z0Zc8nymV6wrCWEJoqMxjGFlgT OW8w== 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=Evi/S2XBMDmcNt2aElcJYPive8tSadhed7YNYWDiBDQ=; b=AtoxMgjR7fkTGDvn7EKIt8xWho4A97CubpYN4ryZ/CsPeIMxrQXWVXcM0l6PP+J+6S pqo3EabbYl1wuw8A/4HZNMF3I6qql3wg6kjB/caITr7J8eQ3K9ZljqbnCGww25SvXz+Z CbIl8RnvlV08QtkhaQ55UScHZP/mmOPkqgUriLpqphcT10fMnQaBatZkNKJLiTC37Yuw Goa/ZlH5KB3WkvhImBH3p03xiFChzaIdBk0g2Dw2jXu5BAUk3YvDBfBxYGXKX5oDslwY PELMD8o3dBqNwsIMN3wC2s9JIKEdihuCmwOTfEaWr8268+0qSudEJ3H+Jsfdon2ZWV/R EzbA== X-Gm-Message-State: AJIora+JWBsngH7Z306G0zSmr0D2Hiuj4lmNiFHvR5Oncc86J2O8Hd/o sAcznnIh7B2B5qlaX30ZkJQRMVcEp/c= X-Google-Smtp-Source: AGRyM1v40juCDYWt631TReB3ZNhVz0CmSQj3+5Lib0smWV42whaK7IwUJo4QD7Gv+IgScJ8GfDi6eg== X-Received: by 2002:a05:600c:19d2:b0:3a3:3aca:a83d with SMTP id u18-20020a05600c19d200b003a33acaa83dmr3622805wmq.88.1659122982796; Fri, 29 Jul 2022 12:29:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 18-20020a05600c029200b003a2fdde48d1sm4993786wmk.25.2022.07.29.12.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:42 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:31 +0000 Subject: [PATCH v2 02/10] t4207: test coloring of grafted decorations Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The color.decorate. config option added the 'grafted' slot in 09c4ba410b0f (log-tree: allow to customize 'grafted' color, 2018-05-26) but included no tests for this behavior. When modifying some logic around decorations, this ref namespace was ignored and could have been lost as a default namespace for 'git log' decorations by default. Add two tests to t4207 that check that the replaced objects are correctly decorated. Use "black" as the color since it is distinct from the other colors already in the test. The first test uses regular replace-objects while the second creates a commit graft. Be sure to test both modes with GIT_REPLACE_REF_BASE unset and set to an alternative base. Signed-off-by: Derrick Stolee --- t/t4207-log-decoration-colors.sh | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index 36ac6aff1e4..69f8ac602d6 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -18,6 +18,7 @@ test_expect_success setup ' git config color.decorate.tag "reverse bold yellow" && git config color.decorate.stash magenta && git config color.decorate.HEAD cyan && + git config color.decorate.grafted black && c_reset="" && @@ -27,6 +28,7 @@ test_expect_success setup ' c_tag="" && c_stash="" && c_HEAD="" && + c_grafted="" && test_commit A && git clone . other && @@ -63,4 +65,61 @@ test_expect_success 'Commit Decorations Colored Correctly' ' test_cmp expected out ' +cat >expected <\ + ${c_reset}${c_branch}main${c_reset}${c_commit},\ + ${c_reset}${c_tag}tag: D${c_reset}${c_commit})${c_reset} D +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: C${c_reset}${c_commit},\ + ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} B +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A +EOF + +test_expect_success 'test coloring with replace-objects' ' + test_when_finished rm -rf .git/refs/replace* && + test_commit C && + test_commit D && + + git replace HEAD~1 HEAD~2 && + git log --first-parent --abbrev=10 --decorate --oneline --color=always HEAD | + sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" | + test_decode_color >out && + test_cmp expected out && + git replace -d HEAD~1 && + + GIT_REPLACE_REF_BASE=refs/replace2/ git replace HEAD~1 HEAD~2 && + GIT_REPLACE_REF_BASE=refs/replace2/ git log --first-parent --abbrev=10 \ + --decorate --oneline --color=always HEAD | + sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" | + test_decode_color >out && + test_cmp expected out +' + +cat >expected <\ + ${c_reset}${c_branch}main${c_reset}${c_commit},\ + ${c_reset}${c_tag}tag: D${c_reset}${c_commit},\ + ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit},\ + ${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A +EOF + +test_expect_success 'test coloring with grafted commit' ' + test_when_finished rm -rf .git/refs/replace* && + + git replace --graft HEAD HEAD~2 && + git log --first-parent --abbrev=10 --decorate --oneline --color=always HEAD | + sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" | + test_decode_color >out && + test_cmp expected out && + git replace -d HEAD && + + GIT_REPLACE_REF_BASE=refs/replace2/ git replace --graft HEAD HEAD~2 && + GIT_REPLACE_REF_BASE=refs/replace2/ git log --first-parent --abbrev=10 \ + --decorate --oneline --color=always HEAD | + sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" | + test_decode_color >out && + test_cmp expected out +' + test_done From patchwork Fri Jul 29 19:29:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932785 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 F20D5C00144 for ; Fri, 29 Jul 2022 19:29:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238812AbiG2T3v (ORCPT ); Fri, 29 Jul 2022 15:29:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238602AbiG2T3r (ORCPT ); Fri, 29 Jul 2022 15:29:47 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1464A5F11C for ; Fri, 29 Jul 2022 12:29:46 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id m13so3183448wrq.6 for ; Fri, 29 Jul 2022 12:29:46 -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=Oa8F6UISOftTCgWXDlHBf7u9PgQ9MG6BPAoOJ3khpvw=; b=PCQzi4McDKcrS0MIdpLkencxUsj1ILOwW70hxqWQxFbw6xwU0bp69FkMGp+3hI6uJc +BxF5Lh2ubrksy3RbupiSb7CR9xhm+8yeHpBn8BZeBGnr1eKngXkTSlGLTkkHyFU05IO 954gwpPJTFF0DCD0xhUbjfqkzEVPfpRo5vLb8aVV/AZAcMzV8KrLoN4cc5gDIKflpOSJ WRawO+rUaPgCrcsBvbVyiA2F53/W5GGT7l5DB+MOZlNA2dAZc6DebGdhQBHq+qvu8Brg dojfnKMQiP66uZUH2U3DwW6hjqf06WMaQ9vPOfrGJAbNqg3bbAIYkbypdGnn4HIfEqpZ Nzmg== 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=Oa8F6UISOftTCgWXDlHBf7u9PgQ9MG6BPAoOJ3khpvw=; b=s97IHnPorj3j5pcuvFhD9Vte4wC6kZNUlfYy8Z1wih1hcstNXmPJVDduXrYxQg1vYr qxXZCEWMGNxomJSDllksklY5tU02hndivRp1ZhDU/X6PbsPjrvaMuh6nC0bfkPNmZbuI dpJAdPE8QrAjXMH24UUu1xDjlc6Gd9W7w5ymzJcpv3uPm1GqmiwacLvinS+xP58IrDy6 /oqAoejVA7j0X5DfQ8fIYntQkwIVNC48PR7rS/TKJ2I1Linwg/daivlPuz9N8BB2VU5Q WTc7pzalC96UeEkbCTELa71Lyu+lXghEzU0YaGVIhF0uEXfJcNo2vHft/CaYvkdHs+jq FvMw== X-Gm-Message-State: ACgBeo3CLvX3DRbaSQcGGkVkNc0TIDjXEkLph/uGMmhTKug6axrO2bMW I9WN/7TIzya8F/e0NNVTLUbmDx8JddQ= X-Google-Smtp-Source: AA6agR60za6uZfYboRFSchEV+QofxRIFqKb2jk9IXWdpkrMZMu/7obKI32iwyX0e2dkCsXwVETKEng== X-Received: by 2002:a05:6000:692:b0:21f:d91:f154 with SMTP id bo18-20020a056000069200b0021f0d91f154mr3146585wrb.668.1659122984120; Fri, 29 Jul 2022 12:29:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q186-20020a1c43c3000000b003a302fb9df7sm9753513wma.21.2022.07.29.12.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:43 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:32 +0000 Subject: [PATCH v2 03/10] refs: add array of ref namespaces Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Git interprets different meanings to different refs based on their names. Some meanings are cosmetic, like how refs in 'refs/remotes/*' are colored differently from refs in 'refs/heads/*'. Others are more critical, such as how replace refs are interpreted. Before making behavior changes based on ref namespaces, collect all known ref namespaces into a array of ref_namespace_info structs. This array is indexed by the new ref_namespace enum for quick access. As of this change, this array is purely documentation. Future changes will add dependencies on this array. Signed-off-by: Derrick Stolee --- environment.c | 2 ++ notes.c | 1 + refs.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ refs.h | 46 ++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) diff --git a/environment.c b/environment.c index b3296ce7d15..9eb22f975c7 100644 --- a/environment.c +++ b/environment.c @@ -185,6 +185,8 @@ void setup_git_env(const char *git_dir) free(git_replace_ref_base); git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base : "refs/replace/"); + update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); + free(git_namespace); git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); diff --git a/notes.c b/notes.c index 7452e71cc8d..7bade6d8f69 100644 --- a/notes.c +++ b/notes.c @@ -1005,6 +1005,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, if (!notes_ref) notes_ref = default_notes_ref(); + update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref)); if (!combine_notes) combine_notes = combine_notes_concatenate; diff --git a/refs.c b/refs.c index ec3134e4842..8e87cc7efb0 100644 --- a/refs.c +++ b/refs.c @@ -20,6 +20,7 @@ #include "repository.h" #include "sigchain.h" #include "date.h" +#include "commit.h" /* * List of all available backends @@ -56,6 +57,88 @@ static unsigned char refname_disposition[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 4, 4 }; +struct ref_namespace_info ref_namespaces[] = { + [NAMESPACE_HEAD] = { + .ref = "HEAD", + .decoration = DECORATION_REF_HEAD, + .exact = 1, + }, + [NAMESPACE_BRANCHES] = { + .ref = "refs/heads/", + .decoration = DECORATION_REF_LOCAL, + }, + [NAMESPACE_TAGS] = { + .ref = "refs/tags/", + .decoration = DECORATION_REF_TAG, + }, + [NAMESPACE_REMOTE_REFS] = { + /* + * The default refspec for new remotes copies refs from + * refs/heads/ on the remote into refs/remotes//. + * As such, "refs/remotes/" has special handling. + */ + .ref = "refs/remotes/", + .decoration = DECORATION_REF_REMOTE, + }, + [NAMESPACE_STASH] = { + /* + * The single ref "refs/stash" stores the latest stash. + * Older stashes can be found in the reflog. + */ + .ref = "refs/stash", + .exact = 1, + .decoration = DECORATION_REF_STASH, + }, + [NAMESPACE_REPLACE] = { + /* + * This namespace allows Git to act as if one object ID + * points to the content of another. Unlike the other + * ref namespaces, this one can be changed by the + * GIT_REPLACE_REF_BASE environment variable. This + * .namespace value will be overwritten in setup_git_env(). + */ + .ref = "refs/replace/", + .decoration = DECORATION_GRAFTED, + }, + [NAMESPACE_NOTES] = { + /* + * The refs/notes/commit ref points to the tip of a + * parallel commit history that adds metadata to commits + * in the normal history. This branch can be overwritten + * by the core.notesRef config variable or the + * GIT_NOTES_REFS environment variable. + */ + .ref = "refs/notes/commit", + .exact = 1, + }, + [NAMESPACE_PREFETCH] = { + /* + * Prefetch refs are written by the background 'fetch' + * maintenance task. It allows faster foreground fetches + * by advertising these previously-downloaded tips without + * updating refs/remotes/ without user intervention. + */ + .ref = "refs/prefetch/", + }, + [NAMESPACE_REWRITTEN] = { + /* + * Rewritten refs are used by the 'label' command in the + * sequencer. These are particularly useful during an + * interactive rebase that uses the 'merge' command. + */ + .ref = "refs/rewritten/", + }, +}; + +void update_ref_namespace(enum ref_namespace namespace, char *ref) +{ + struct ref_namespace_info *info = &ref_namespaces[namespace]; + if (info->ref_updated) + free(info->ref); + info->ref = ref; + info->ref_updated = 1; +} + /* * Try to read one refname component from the front of refname. * Return the length of the component found, or -1 if the component is diff --git a/refs.h b/refs.h index 47cb9edbaa8..94e8dedf939 100644 --- a/refs.h +++ b/refs.h @@ -2,6 +2,7 @@ #define REFS_H #include "cache.h" +#include "commit.h" struct object_id; struct ref_store; @@ -930,4 +931,49 @@ struct ref_store *get_main_ref_store(struct repository *r); struct ref_store *get_submodule_ref_store(const char *submodule); struct ref_store *get_worktree_ref_store(const struct worktree *wt); +/* + * Some of the names specified by refs have special meaning to Git. + * Organize these namespaces in a comon 'ref_namespaces' array for + * reference from multiple places in the codebase. + */ + +struct ref_namespace_info { + char *ref; + enum decoration_type decoration; + + /* + * If 'exact' is true, then we must match the 'ref' exactly. + * Otherwise, use a prefix match. + * + * 'orig_ref' is for internal use. It represents whether the + * 'ref' value was replaced from its original literal version. + */ + unsigned exact:1, + ref_updated:1; +}; + +enum ref_namespace { + NAMESPACE_HEAD, + NAMESPACE_BRANCHES, + NAMESPACE_TAGS, + NAMESPACE_REMOTE_REFS, + NAMESPACE_STASH, + NAMESPACE_REPLACE, + NAMESPACE_NOTES, + NAMESPACE_PREFETCH, + NAMESPACE_REWRITTEN, + + /* Must be last */ + NAMESPACE__COUNT +}; + +/* See refs.c for the contents of this array. */ +extern struct ref_namespace_info ref_namespaces[]; + +/* + * Some ref namespaces can be modified by config values or environment + * variables. Modify a namespace as specified by its ref_namespace key. + */ +void update_ref_namespace(enum ref_namespace namespace, char *ref); + #endif /* REFS_H */ From patchwork Fri Jul 29 19:29:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932786 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 B5B60C19F2A for ; Fri, 29 Jul 2022 19:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238824AbiG2T3z (ORCPT ); Fri, 29 Jul 2022 15:29:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238715AbiG2T3t (ORCPT ); Fri, 29 Jul 2022 15:29:49 -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 4ADE25FACB for ; Fri, 29 Jul 2022 12:29:47 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id x23-20020a05600c179700b003a30e3e7989so2933678wmo.0 for ; Fri, 29 Jul 2022 12:29:47 -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=SaPL8Oci9QgOPfLUSeQl8NMVH0gyPAwGHimYdcNV2Ng=; b=aD9LksJUOGbi3XqKnr3A0qzvk3klCs4J8gZbnsJ2+BijWOgiWrvNRv9avWMnYsX0kI NydG1HKDAvZfytH2E1nFOHFE2Xx5RvU48WMy09Qm/k0W+81LdoFsxiOpt573FxhSKIxx 4hNcfijqic2mSzjoyLzAZptW8pomm5USXj3IzJephx0CWJab+xmNJNOd1A9VcjFFlzZ1 0x1E+SfaLvNflqG8GHVDzwpkR4GQcUkC/2D3MWtxAHVnqpEyKcTFdOvyeiYNIxHQvppb Ztl67PBrJdMUN9bhqhd+CJWULfZjPGsQQ2qtIkLmX5ycZq5stWsgMEsvrLg7oi0Vbp++ tGng== 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=SaPL8Oci9QgOPfLUSeQl8NMVH0gyPAwGHimYdcNV2Ng=; b=2Gu8L8zjFTP8u3AJSprzVxCi6LB94Kfcw/igbOvdyU7Q4IGoystLf+Zmw6sdUmmc0U sPDsJlSO8s02bO5L7qoXSn4dMRmG1/ezerdXbDHtAgqgbugwO0SDg0eKQBCevqyDtr6y OkU3UzTAxbwjzxN9V8keFfqKX6fwP70BwBiPuXV8D7XxiyX6QgL8CpKVxd6V4VW2MCki IRdTL5wpVgIyWe+I1y61vjd3UtttQVJ4bePAoAG6YbrNwJ9DNMIGTYXu7ZSGuY8rRn5J tRArpKhCRY5Xh+xlijRTqML0IIB0uyV4nn8mv5BqVDgzlDEW51Pc00qjZVISw9EkfWNC VcHQ== X-Gm-Message-State: AJIora9C6ikEZ73CgtfgZZFwZa6QFOrM6MlzmMdT63h+FahB7oDW7GHK M9DRt6CyML440B1k6zWgGxTvdgx6z14= X-Google-Smtp-Source: AGRyM1suE94Caj5Nh77h9CKYc1Cav8w2yxFn1pPNZiFeiihyRCjXzQr6nk09zY+jGKUco3qcS7o/1A== X-Received: by 2002:a05:600c:358d:b0:3a3:3819:c07 with SMTP id p13-20020a05600c358d00b003a338190c07mr4010425wmq.76.1659122985334; Fri, 29 Jul 2022 12:29:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g9-20020a05600c4ec900b003a3199c243bsm12331942wmq.0.2022.07.29.12.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:44 -0700 (PDT) Message-Id: <8da0b0a31810c8221ad3ab13b8c41cf1a266c2c0.1659122979.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:33 +0000 Subject: [PATCH v2 04/10] refs: use ref_namespaces for replace refs base Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The git_replace_ref_base global is used to store the value of the GIT_REPLACE_REF_BASE environment variable or the default of "refs/replace/". This is initialized within setup_git_env(). The ref_namespaces array is a new centralized location for information such as the ref namespace used for replace refs. Instead of having this namespace stored in two places, use the ref_namespaces array instead. For simplicity, create a local git_replace_ref_base variable wherever the global was previously used. Signed-off-by: Derrick Stolee --- builtin/replace.c | 3 +++ cache.h | 1 - environment.c | 3 +-- log-tree.c | 2 ++ refs.c | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 583702a0980..6b97ef2348b 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -106,6 +106,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn) size_t base_len; int had_error = 0; struct object_id oid; + const char *git_replace_ref_base = ref_namespaces[NAMESPACE_REPLACE].ref; strbuf_addstr(&ref, git_replace_ref_base); base_len = ref.len; @@ -147,6 +148,8 @@ static int check_ref_valid(struct object_id *object, struct strbuf *ref, int force) { + const char *git_replace_ref_base = ref_namespaces[NAMESPACE_REPLACE].ref; + strbuf_reset(ref); strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object)); if (check_refname_format(ref->buf, 0)) diff --git a/cache.h b/cache.h index ac5ab4ef9d3..631a4f388d6 100644 --- a/cache.h +++ b/cache.h @@ -1008,7 +1008,6 @@ void reset_shared_repository(void); * commands that do not want replace references to be active. */ extern int read_replace_refs; -extern char *git_replace_ref_base; /* * These values are used to help identify parts of a repository to fsync. diff --git a/environment.c b/environment.c index 9eb22f975c7..b2004437dce 100644 --- a/environment.c +++ b/environment.c @@ -56,7 +56,6 @@ const char *askpass_program; const char *excludes_file; enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; int read_replace_refs = 1; -char *git_replace_ref_base; enum eol core_eol = EOL_UNSET; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; char *check_roundtrip_encoding = "SHIFT-JIS"; @@ -162,6 +161,7 @@ const char *getenv_safe(struct strvec *argv, const char *name) void setup_git_env(const char *git_dir) { + char *git_replace_ref_base; const char *shallow_file; const char *replace_ref_base; struct set_gitdir_args args = { NULL }; @@ -182,7 +182,6 @@ void setup_git_env(const char *git_dir) if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) read_replace_refs = 0; replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); - free(git_replace_ref_base); git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base : "refs/replace/"); update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); diff --git a/log-tree.c b/log-tree.c index d0ac0a6327a..bb80f1a94d2 100644 --- a/log-tree.c +++ b/log-tree.c @@ -141,10 +141,12 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, enum object_type objtype; enum decoration_type deco_type = DECORATION_NONE; struct decoration_filter *filter = (struct decoration_filter *)cb_data; + const char *git_replace_ref_base; if (filter && !ref_filter_match(refname, filter)) return 0; + git_replace_ref_base = ref_namespaces[NAMESPACE_REPLACE].ref; if (starts_with(refname, git_replace_ref_base)) { struct object_id original_oid; if (!read_replace_refs) diff --git a/refs.c b/refs.c index 8e87cc7efb0..0da089d760b 100644 --- a/refs.c +++ b/refs.c @@ -1607,6 +1607,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix, int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data) { + const char *git_replace_ref_base = ref_namespaces[NAMESPACE_REPLACE].ref; return do_for_each_repo_ref(r, git_replace_ref_base, fn, strlen(git_replace_ref_base), DO_FOR_EACH_INCLUDE_BROKEN, cb_data); From patchwork Fri Jul 29 19:29:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932787 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 63994C00144 for ; Fri, 29 Jul 2022 19:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238852AbiG2TaC (ORCPT ); Fri, 29 Jul 2022 15:30:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238751AbiG2T3t (ORCPT ); Fri, 29 Jul 2022 15:29:49 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529B562A65 for ; Fri, 29 Jul 2022 12:29:48 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id v3so6199551wrp.0 for ; Fri, 29 Jul 2022 12:29:48 -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=mnPtNgySTa7llJBb+s/lASeY/w+3Iuv0kFohfWZv/IA=; b=lW+FWjxtqOUV3eKFb9mBRH6Tg+tOxdOaq/bJqdGCd0QuGCOJCeJrHsutGJhdWjcyIp TVxP3l1oA+yIBiQ1cKhaFllCIm1XvSmdoCf7tb24anU/IbNDm0eO5iyls+mQNCJWfFpW 3RZTJg6/AjifX12WqoyOpJ1/eEEWL2GDKqgrQUt3s1+cgE++VG90z7Q6sielM1Vj/m41 LIP53xN8YDgm5bk2APjTXtcW8MyYzvQESp7HNSpp+AAyhoDHbgnUiSTk1glCCzFxPAGP YKxtbSY0zxsWbGnu3/rnFRzzCox2VmMeXATWceVKhS/3fAbIhTvVuFIV/RNfli8OSdMr 9r5Q== 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=mnPtNgySTa7llJBb+s/lASeY/w+3Iuv0kFohfWZv/IA=; b=U1HKKPGhroWF5RvcMrlhxPb0xSmieNn3dhKZKMvtfatW33j7LFg0x/4sb81rpSw0gE yQMtrCUz60vYSPcGrd6dpXdjuqlMlaKJyteT5KKmH7OEJyjRL2wjjIFmMAGRSvXSZYuD yS2qlxiFH33jiC1iv7FPnZrk20EWWg5jWv912MzTqt2vXM16q1/VpuR8gA5jopFW+Y6K EeR2fgSQhq3QAzjfn4oi26oST/4VLxoR4rHmUewvQDB82AycaJbBYj45jrt2AAWGXC5C 6Z/20CixtY7178D4nr4KTHvOknuemKiV+8ASOeUTN0UB1juLiyxVHmULTacI5xD2ZSU9 BHmQ== X-Gm-Message-State: ACgBeo0mg3GYltfwFTsMLOHMIcyUAPfT7eNfOUMPANX6rutjV1Faj9nu 9bAtqT7v9MFW13t1t1tek+WWwO643Co= X-Google-Smtp-Source: AA6agR7xOk1U57661RxVkATfpzvbZarTrHXHBxQT/3kId1MmkjNpheMK4wiuQn534ked32z2roPorg== X-Received: by 2002:a5d:5c0c:0:b0:21e:7098:1903 with SMTP id cc12-20020a5d5c0c000000b0021e70981903mr3229391wrb.623.1659122986415; Fri, 29 Jul 2022 12:29:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a5-20020adffb85000000b0021e5cc26dd0sm4399161wrr.62.2022.07.29.12.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:45 -0700 (PDT) Message-Id: <53b15a0b7932f892505d07a509909b62c473037e.1659122979.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:34 +0000 Subject: [PATCH v2 05/10] log-tree: use ref_namespaces instead of if/else-if Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The add_ref_decoration() method uses an if/else-if chain to determine if a ref matches a known ref namespace that has a special decoration category. That decoration type is later used to assign a color when writing to stdout. The newly-added ref_namespaces array contains all namespaces, along with information about their decoration type. Check this array instead of this if/else-if chain. This reduces our dependency on string literals being embedded in the decoration logic. Signed-off-by: Derrick Stolee --- log-tree.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/log-tree.c b/log-tree.c index bb80f1a94d2..6075bdd334e 100644 --- a/log-tree.c +++ b/log-tree.c @@ -137,6 +137,7 @@ static int ref_filter_match(const char *refname, static int add_ref_decoration(const char *refname, const struct object_id *oid, int flags, void *cb_data) { + int i; struct object *obj; enum object_type objtype; enum decoration_type deco_type = DECORATION_NONE; @@ -167,16 +168,21 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, return 0; obj = lookup_object_by_type(the_repository, oid, objtype); - if (starts_with(refname, "refs/heads/")) - deco_type = DECORATION_REF_LOCAL; - else if (starts_with(refname, "refs/remotes/")) - deco_type = DECORATION_REF_REMOTE; - else if (starts_with(refname, "refs/tags/")) - deco_type = DECORATION_REF_TAG; - else if (!strcmp(refname, "refs/stash")) - deco_type = DECORATION_REF_STASH; - else if (!strcmp(refname, "HEAD")) - deco_type = DECORATION_REF_HEAD; + for (i = 0; i < NAMESPACE__COUNT; i++) { + struct ref_namespace_info *info = &ref_namespaces[i]; + + if (!info->decoration) + continue; + if (info->exact) { + if (!strcmp(refname, info->ref)) { + deco_type = info->decoration; + break; + } + } else if (starts_with(refname, info->ref)) { + deco_type = info->decoration; + break; + } + } add_name_decoration(deco_type, refname, obj); while (obj->type == OBJ_TAG) { From patchwork Fri Jul 29 19:29:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932788 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 D5D76C00144 for ; Fri, 29 Jul 2022 19:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238825AbiG2TaJ (ORCPT ); Fri, 29 Jul 2022 15:30:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238813AbiG2T3v (ORCPT ); Fri, 29 Jul 2022 15:29:51 -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 CAEE87AB2E for ; Fri, 29 Jul 2022 12:29:49 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so4576219wmb.5 for ; Fri, 29 Jul 2022 12:29:49 -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=dyhp7QpKAZesUxp8Eg1oJuLJ7RasqexTwL2exERL+QI=; b=EQ2ak1OzTNnJNWNWEYzBXM6kT8X2dtHt0BiWmuoL/bAtj+CZxEg+eNh1wWPP3+Bb9O +FIeoYs6GRl+aLAl9qCLKmyLGwgUiJVD3IoUdOT1kUR6aGXsaB2r02hJvrXOX12jYfOZ 1q/q5S0eRAZw6nszBSlrdVpqdRdv05vqgjCUoCn9DRQwwu1ZlyuTruIpU9syJ0u/9Qrc zzlgpi1j3T2TuL2nGO2OAyPJrOq5m7410Z/ZC0aQ/MSxC/QOySHAyhJl+7czGi7V0yOw /P4pEduseJdiO3ZuxTnU+jI+LpvXIyYdZHCM8YJSwVJpp46oX3huitc6F7pfJlhcXDS+ nyCQ== 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=dyhp7QpKAZesUxp8Eg1oJuLJ7RasqexTwL2exERL+QI=; b=CtV+CyQvrFyb7yDwYVO5TIobIb2TF8KgTZKF3x05zIiJ38d3er5pafNr4hfk4TnwFx dwiqYIWXgQYpRYUdChvYBCEi7hwW0FpmFRZj2TteXIkOqzXwRkhYAvnAFtWiplrR0/rJ My55vI9rBRBUrIElRJ12Obz6K3bIT90lQUj8NeJtrywR0C1bd7exitaMEFFmEpFiIyCb JM0lKEVX5TfsaT78sD9mSbqYs0nJ7jxFIrignZip/iqFtIQTT9m7GWEfqGjOx3pwqN6W /m/vphm4uwBcG7H2ttw1ugI2HChusmjxOGdFwx8e0GIcTGlKDEsXRxznSGpVOO5Dl7iX xMBA== X-Gm-Message-State: AJIora/JScGkO5WPDYgcgDm053rMfNOoyH2TPkghGHd59/CXE+wvth8f rQ4cy+1qTySPlEJnQhSF2G+ZtfPPjkA= X-Google-Smtp-Source: AGRyM1vgNPiIVYjoSFKdAfZXK9J9dgFhCMyEIKBsvzSL4f0CtSxOB6XMRZIrl6js0pmPFVfHV1H8Qg== X-Received: by 2002:a05:600c:a18e:b0:3a3:4068:d845 with SMTP id id14-20020a05600ca18e00b003a34068d845mr3333198wmb.15.1659122987594; Fri, 29 Jul 2022 12:29:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a4-20020adffb84000000b0021e51c039c5sm4462694wrr.80.2022.07.29.12.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:47 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:35 +0000 Subject: [PATCH v2 06/10] log: add default decoration filter Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When a user runs 'git log', they expect a certain set of helpful decorations. This includes: * The HEAD ref * Branches (refs/heads/) * Stashes (refs/stash) * Tags (refs/tags/) * Remote branches (refs/remotes/) * Replace refs (refs/replace/ or $GIT_REPLACE_REF_BASE) Each of these namespaces was selected due to existing test cases that verify these namespaces appear in the decorations. In particular, stashes and replace refs can have custom colors from the color.decorate. config option. While one test checks for a decoration from notes, it only applies to the tip of refs/notes/commit (or its configured ref name). Notes form their own kind of decoration instead. Modify the expected output for the tests in t4013 that expect this note decoration. There are several tests throughout the codebase that verify that --decorate-refs, --decorate-refs-exclude, and log.excludeDecoration work as designed and the tests continue to pass without intervention. However, there are other refs that are less helpful to show as decoration: * Prefetch refs (refs/prefetch/) * Rebase refs (refs/rebase-merge/ and refs/rebase-apply/) * Bundle refs (refs/bundle/) [!] [!] The bundle refs are part of a parallel series that bootstraps a repo from a bundle file, storing the bundle's refs into the repo's refs/bundle/ namespace. In the case of prefetch refs, 96eaffebbf3d0 (maintenance: set log.excludeDecoration durin prefetch, 2021-01-19) added logic to add refs/prefetch/ to the log.excludeDecoration config option. Additional feedback pointed out that having such a side-effect can be confusing and perhaps not helpful to users. Instead, we should hide these ref namespaces that are being used by Git for internal reasons but are not helpful for the users to see. The way to provide a seamless user experience without setting the config is to modify the default decoration filters to match our expectation of what refs the user actually wants to see. In builtin/log.c, after parsing the --decorate-refs and --decorate-refs-exclude options from the command-line, call set_default_decoration_filter(). This method populates the exclusions from log.excludeDecoration, then checks if the list of pattern modifications are empty. If none are specified, then the default set is restricted to the set of inclusions mentioned earlier (HEAD, branches, etc.). A previous change introduced the ref_namespaces array, which includes all of these currently-used namespaces. The 'decoration' value is non-zero when that namespace is associated with a special coloring and fits into the list of "expected" decorations as described above, which makes the implementation of this filter very simple. Note that the logic in ref_filter_match() in log-tree.c follows this matching pattern: 1. If there are exclusion patterns and the ref matches one, then ignore the decoration. 2. If there are inclusion patterns and the ref matches one, then definitely include the decoration. 3. If there are config-based exclusions from log.excludeDecoration and the ref matches one, then ignore the decoration. With this logic in mind, we need to ensure that we do not populate our new defaults if any of these filters are manually set. Specifically, if a user runs git -c log.excludeDecoration=HEAD log then we expect the HEAD decoration to not appear. If we left the default inclusions in the set, then HEAD would match that inclusion before reaching the config-based exclusions. A potential alternative would be to check the list of default inclusions at the end, after the config-based exclusions. This would still create a behavior change for some uses of --decorate-refs-exclude=, and could be overwritten somewhat with --decorate-refs=refs/ and --decorate-refs=HEAD. However, it no longer becomes possible to include refs outside of the defaults while also excluding some using log.excludeDecoration. Another alternative would be to exclude the known namespaces that are not intended to be shown. This would reduce the visible effect of the change for expert users who use their own custom ref namespaces. The implementation change would be very simple to swap due to our use of ref_namespaces: int i; struct string_list *exclude = decoration_filter->exclude_ref_pattern; /* * No command-line or config options were given, so * populate with sensible defaults. */ for (i = 0; i < NAMESPACE__COUNT; i++) { if (ref_namespaces[i].decoration) continue; string_list_append(exclude, ref_namespaces[i].ref); } The main downside of this approach is that we expect to add new hidden namespaces in the future, and that means that Git versions will be less stable in how they behave as those namespaces are added. It is critical that we provide ways for expert users to disable this behavior change via command-line options and config keys. These changes will be implemented in a future change. Add a test that checks that the defaults are not added when --decorate-refs is specified. We verify this by showing that HEAD is not included as it normally would. Also add a test that shows that the default filter avoids the unwanted decorations from refs/prefetch, refs/rebase-merge, and refs/bundle. Signed-off-by: Derrick Stolee --- Documentation/git-log.txt | 7 ++-- builtin/log.c | 50 +++++++++++++++++++------- t/t4013/diff.log_--decorate=full_--all | 2 +- t/t4013/diff.log_--decorate_--all | 2 +- t/t4202-log.sh | 22 ++++++++++++ 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 20e87cecf49..b2ac89dfafc 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -45,13 +45,16 @@ OPTIONS --decorate-refs=:: --decorate-refs-exclude=:: - If no `--decorate-refs` is given, pretend as if all refs were - included. For each candidate, do not use it for decoration if it + For each candidate reference, do not use it for decoration if it matches any patterns given to `--decorate-refs-exclude` or if it doesn't match any of the patterns given to `--decorate-refs`. The `log.excludeDecoration` config option allows excluding refs from the decorations, but an explicit `--decorate-refs` pattern will override a match in `log.excludeDecoration`. ++ +If none of these options or config settings are given, then references are +used as decoration if they match `HEAD`, `refs/heads/`, `refs/remotes/`, +`refs/stash/`, or `refs/tags/`. --source:: Print out the ref name given on the command line by which each diff --git a/builtin/log.c b/builtin/log.c index 88a5e98875a..0b5efc9434c 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -162,6 +162,37 @@ static void cmd_log_init_defaults(struct rev_info *rev) parse_date_format(default_date_mode, &rev->date_mode); } +static void set_default_decoration_filter(struct decoration_filter *decoration_filter) +{ + int i; + struct string_list *include = decoration_filter->include_ref_pattern; + const struct string_list *config_exclude = + git_config_get_value_multi("log.excludeDecoration"); + + if (config_exclude) { + struct string_list_item *item; + for_each_string_list_item(item, config_exclude) + string_list_append(decoration_filter->exclude_ref_config_pattern, + item->string); + } + + if (decoration_filter->exclude_ref_pattern->nr || + decoration_filter->include_ref_pattern->nr || + decoration_filter->exclude_ref_config_pattern->nr) + return; + + /* + * No command-line or config options were given, so + * populate with sensible defaults. + */ + for (i = 0; i < NAMESPACE__COUNT; i++) { + if (!ref_namespaces[i].decoration) + continue; + + string_list_append(include, ref_namespaces[i].ref); + } +} + static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, struct rev_info *rev, struct setup_revision_opt *opt) { @@ -171,9 +202,11 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP; static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP; static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP; - struct decoration_filter decoration_filter = {&decorate_refs_include, - &decorate_refs_exclude, - &decorate_refs_exclude_config}; + struct decoration_filter decoration_filter = { + .exclude_ref_pattern = &decorate_refs_exclude, + .include_ref_pattern = &decorate_refs_include, + .exclude_ref_config_pattern = &decorate_refs_exclude_config, + }; static struct revision_sources revision_sources; const struct option builtin_log_options[] = { @@ -265,16 +298,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, } if (decoration_style || rev->simplify_by_decoration) { - const struct string_list *config_exclude = - repo_config_get_value_multi(the_repository, - "log.excludeDecoration"); - - if (config_exclude) { - struct string_list_item *item; - for_each_string_list_item(item, config_exclude) - string_list_append(&decorate_refs_exclude_config, - item->string); - } + set_default_decoration_filter(&decoration_filter); if (decoration_style) rev->show_decorations = 1; diff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all index 3f9b872eceb..6b0b334a5d6 100644 --- a/t/t4013/diff.log_--decorate=full_--all +++ b/t/t4013/diff.log_--decorate=full_--all @@ -20,7 +20,7 @@ Date: Mon Jun 26 00:06:00 2006 +0000 Rearranged lines in dir/sub -commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits) +commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 Author: A U Thor Date: Mon Jun 26 00:06:00 2006 +0000 diff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all index f5e20e1e14a..c7df1f58141 100644 --- a/t/t4013/diff.log_--decorate_--all +++ b/t/t4013/diff.log_--decorate_--all @@ -20,7 +20,7 @@ Date: Mon Jun 26 00:06:00 2006 +0000 Rearranged lines in dir/sub -commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits) +commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 Author: A U Thor Date: Mon Jun 26 00:06:00 2006 +0000 diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 6b7d8e269f7..9ea9e835d43 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1031,6 +1031,12 @@ test_expect_success 'decorate-refs-exclude HEAD' ' ! grep HEAD actual ' +test_expect_success 'decorate-refs focus from default' ' + git log --decorate=full --oneline \ + --decorate-refs="refs/heads" >actual && + ! grep HEAD actual +' + test_expect_success 'log.decorate config parsing' ' git log --oneline --decorate=full >expect.full && git log --oneline --decorate=short >expect.short && @@ -2198,6 +2204,22 @@ test_expect_success 'log --decorate includes all levels of tag annotated tags' ' test_cmp expect actual ' +test_expect_success 'log --decorate does not include things outside filter' ' + reflist="refs/prefetch refs/rebase-merge refs/bundle" && + + for ref in $reflist + do + git update-ref $ref/fake HEAD || return 1 + done && + + git log --decorate=full --oneline >actual && + + for ref in $reflist + do + ! grep $ref/fake actual || return 1 + done +' + test_expect_success 'log --end-of-options' ' git update-ref refs/heads/--source HEAD && git log --end-of-options --source >actual && From patchwork Fri Jul 29 19:29:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932791 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 DA487C00144 for ; Fri, 29 Jul 2022 19:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238930AbiG2TaR (ORCPT ); Fri, 29 Jul 2022 15:30:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238869AbiG2TaJ (ORCPT ); Fri, 29 Jul 2022 15:30:09 -0400 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 006838722B for ; Fri, 29 Jul 2022 12:29:50 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id r83-20020a1c4456000000b003a3a22178beso1097754wma.3 for ; Fri, 29 Jul 2022 12:29:50 -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=bwsJMCUaNnaQVcBetUJjAkWYzd3maTfFPvF0ly6ZmQ8=; b=Icje1K9kIi0tQzDMEK0N4HkDq3kTO/+Jz68QvFig3kd1JGqvE1G608mo0erZFSrf5K GnzAfWyH9zwa+gPxtRUsoal2C1lqEpQZVquxbPIK1vbXQgm9yAgNzbaKfY+T3jMRCoX0 xzT4xLPIPR2tggkpYMLUcUg54dsh4DqGBplyIOent6EAnHxmuVgEkSupoP1On2NZaWEK 2gm/lWZNnAyBo841U2knYJnFc98nwf63xg/PdWksxXa8jl+jdsMRF2nRHJmXngousqNe tYRYF4mOaAoQL3Zmujmd/JinZ2n/9gW8kfa4eitUGt5eW7iVUr4phXohMASShQEc/3iU EwEg== 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=bwsJMCUaNnaQVcBetUJjAkWYzd3maTfFPvF0ly6ZmQ8=; b=DelFO6qoHPoSqA3+HAaV0adLjJBa5gonn0EbbdgI24Gv0qyVEWkeAU4WhrnjsoeNAs 7GS810dQJU1+LD9RZfLadZTJ74zz4vPlv29RY/kV1A7+swaeAbzVb+BsrvUPBo4kl3CE 83EnZRCbg85irffSJ6cRvchWoBSJ6SGPFsc2qojiiXrIrHaFYpF8CQ8FGkAoES/hE2Y8 rzoN5pmcBfxyxrU64rmouJuiBfOEjyTdty+IDJSDyuENY/78MqaYciGL/ZpguWXrbL3J KveZGeX6ZCuEvExnpxXjiOJoiH+9yTyVL6QQi+QZ9Hm2TvJ51l5mx9gJd61JhJ8dYxXy kiKQ== X-Gm-Message-State: AJIora9AWA5nEUJ04/RBOjKckeBRQIo5KA+evV5Lz68wP/Zj0nq5K3XX Q8xGOQsLQTjg2KQU/KTMvd0Fwfyh724= X-Google-Smtp-Source: AGRyM1u9SabcDKe79lD7J68b/M9HryCDqLuJhdiJVYvjQ8J6GalrO/ByYtQfZFqZ54dLMwgOMjt86w== X-Received: by 2002:a05:600c:19cf:b0:3a3:1df6:af0c with SMTP id u15-20020a05600c19cf00b003a31df6af0cmr3764254wmq.37.1659122988949; Fri, 29 Jul 2022 12:29:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i3-20020a1c5403000000b003a02f957245sm9336147wmb.26.2022.07.29.12.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:48 -0700 (PDT) Message-Id: <64ee889369dd4044a4acd967876476ea6cfff1c3.1659122979.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:36 +0000 Subject: [PATCH v2 07/10] log: add --decorate-all option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Signed-off-by: Derrick Stolee --- Documentation/git-log.txt | 5 + builtin/log.c | 27 ++++- t/t4013-diff-various.sh | 2 + ...f.log_--decorate=full_--decorate-all_--all | 61 +++++++++++ .../diff.log_--decorate_--decorate-all_--all | 61 +++++++++++ t/t4202-log.sh | 103 +++++++++++++++++- 6 files changed, 252 insertions(+), 7 deletions(-) create mode 100644 t/t4013/diff.log_--decorate=full_--decorate-all_--all create mode 100644 t/t4013/diff.log_--decorate_--decorate-all_--all diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index b2ac89dfafc..633705bde90 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -56,6 +56,11 @@ If none of these options or config settings are given, then references are used as decoration if they match `HEAD`, `refs/heads/`, `refs/remotes/`, `refs/stash/`, or `refs/tags/`. +--decorate-all:: + When specified, this option clears all previous `--decorate-refs` + or `--decorate-refs-exclude` options and relaxes the default + decoration filter to include all possible decoration refs. + --source:: Print out the ref name given on the command line by which each commit was reached. diff --git a/builtin/log.c b/builtin/log.c index 0b5efc9434c..b7fc4946c35 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -101,6 +101,25 @@ static int parse_decoration_style(const char *value) return -1; } +static int decorate_all; +static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP; +static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP; +static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP; + +static int decorate_all_callback(const struct option *opt, + const char *arg, int unset) +{ + if (unset) { + decorate_all = 0; + return 0; + } + + string_list_clear(&decorate_refs_include, 0); + string_list_clear(&decorate_refs_exclude, 0); + decorate_all = 1; + return 0; +} + static int decorate_callback(const struct option *opt, const char *arg, int unset) { if (unset) @@ -176,7 +195,8 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f item->string); } - if (decoration_filter->exclude_ref_pattern->nr || + if (decorate_all || + decoration_filter->exclude_ref_pattern->nr || decoration_filter->include_ref_pattern->nr || decoration_filter->exclude_ref_config_pattern->nr) return; @@ -199,9 +219,6 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, struct userformat_want w; int quiet = 0, source = 0, mailmap; static struct line_opt_callback_data line_cb = {NULL, NULL, STRING_LIST_INIT_DUP}; - static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP; - static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP; - static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP; struct decoration_filter decoration_filter = { .exclude_ref_pattern = &decorate_refs_exclude, .include_ref_pattern = &decorate_refs_include, @@ -214,6 +231,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, OPT_BOOL(0, "source", &source, N_("show source")), OPT_BOOL(0, "use-mailmap", &mailmap, N_("use mail map file")), OPT_ALIAS(0, "mailmap", "use-mailmap"), + OPT_CALLBACK_F(0, "decorate-all", NULL, NULL, N_("how all ref decorations"), + PARSE_OPT_NOARG, decorate_all_callback), OPT_STRING_LIST(0, "decorate-refs", &decorate_refs_include, N_("pattern"), N_("only decorate refs that match ")), OPT_STRING_LIST(0, "decorate-refs-exclude", &decorate_refs_exclude, diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 056e922164d..577221c71ed 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -352,6 +352,8 @@ log -GF -p --pickaxe-all master log -IA -IB -I1 -I2 -p master log --decorate --all log --decorate=full --all +log --decorate --decorate-all --all +log --decorate=full --decorate-all --all rev-list --parents HEAD rev-list --children HEAD diff --git a/t/t4013/diff.log_--decorate=full_--decorate-all_--all b/t/t4013/diff.log_--decorate=full_--decorate-all_--all new file mode 100644 index 00000000000..d6e79287846 --- /dev/null +++ b/t/t4013/diff.log_--decorate=full_--decorate-all_--all @@ -0,0 +1,61 @@ +$ git log --decorate=full --decorate-all --all +commit b7e0bc69303b488b47deca799a7d723971dfa6cd (refs/heads/mode) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + update mode + +commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (refs/heads/note) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + update mode (file2) + +Notes: + note + +commit cd4e72fd96faed3f0ba949dc42967430374e2290 (refs/heads/rearrange) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + Rearranged lines in dir/sub + +commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + Notes added by 'git notes add' + +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master) +Merge: 9a6d494 c7a2ab9 +Author: A U Thor +Date: Mon Jun 26 00:04:00 2006 +0000 + + Merge branch 'side' + +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side) +Author: A U Thor +Date: Mon Jun 26 00:03:00 2006 +0000 + + Side + +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third + +commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 +Author: A U Thor +Date: Mon Jun 26 00:01:00 2006 +0000 + + Second + + This is the second commit. + +commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial) +Author: A U Thor +Date: Mon Jun 26 00:00:00 2006 +0000 + + Initial +$ diff --git a/t/t4013/diff.log_--decorate_--decorate-all_--all b/t/t4013/diff.log_--decorate_--decorate-all_--all new file mode 100644 index 00000000000..5d22618bb60 --- /dev/null +++ b/t/t4013/diff.log_--decorate_--decorate-all_--all @@ -0,0 +1,61 @@ +$ git log --decorate --decorate-all --all +commit b7e0bc69303b488b47deca799a7d723971dfa6cd (mode) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + update mode + +commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (note) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + update mode (file2) + +Notes: + note + +commit cd4e72fd96faed3f0ba949dc42967430374e2290 (rearrange) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + Rearranged lines in dir/sub + +commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits) +Author: A U Thor +Date: Mon Jun 26 00:06:00 2006 +0000 + + Notes added by 'git notes add' + +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> master) +Merge: 9a6d494 c7a2ab9 +Author: A U Thor +Date: Mon Jun 26 00:04:00 2006 +0000 + + Merge branch 'side' + +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side) +Author: A U Thor +Date: Mon Jun 26 00:03:00 2006 +0000 + + Side + +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third + +commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 +Author: A U Thor +Date: Mon Jun 26 00:01:00 2006 +0000 + + Second + + This is the second commit. + +commit 444ac553ac7612cc88969031b02b3767fb8a353a (initial) +Author: A U Thor +Date: Mon Jun 26 00:00:00 2006 +0000 + + Initial +$ diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 9ea9e835d43..e939ed34ff7 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -704,9 +704,12 @@ test_expect_success 'set up more tangled history' ' git checkout -b tangle HEAD~6 && test_commit tangle-a tangle-a a && git merge main~3 && + git update-ref refs/prefetch/merge HEAD && git merge side~1 && + git update-ref refs/rewritten/merge HEAD && git checkout main && git merge tangle && + git update-ref refs/hidden/tangle HEAD && git checkout -b reach && test_commit reach && git checkout main && @@ -974,9 +977,9 @@ test_expect_success 'decorate-refs-exclude and simplify-by-decoration' ' Merge-tag-reach (HEAD -> main) reach (tag: reach, reach) seventh (tag: seventh) - Merge-branch-tangle - Merge-branch-side-early-part-into-tangle (tangle) - tangle-a (tag: tangle-a) + Merge-branch-tangle (refs/hidden/tangle) + Merge-branch-side-early-part-into-tangle (refs/rewritten/merge, tangle) + Merge-branch-main-early-part-into-tangle (refs/prefetch/merge) EOF git log -n6 --decorate=short --pretty="tformat:%f%d" \ --decorate-refs-exclude="*octopus*" \ @@ -1037,6 +1040,100 @@ test_expect_success 'decorate-refs focus from default' ' ! grep HEAD actual ' +test_expect_success '--decorate-all overrides defaults' ' + cat >expect.default <<-\EOF && + Merge-tag-reach (HEAD -> refs/heads/main) + Merge-tags-octopus-a-and-octopus-b + seventh (tag: refs/tags/seventh) + octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b) + octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a) + reach (tag: refs/tags/reach, refs/heads/reach) + Merge-branch-tangle + Merge-branch-side-early-part-into-tangle (refs/heads/tangle) + Merge-branch-main-early-part-into-tangle + tangle-a (tag: refs/tags/tangle-a) + Merge-branch-side + side-2 (tag: refs/tags/side-2, refs/heads/side) + side-1 (tag: refs/tags/side-1) + Second + sixth + fifth + fourth + third + second + initial + EOF + git log --decorate=full --pretty="tformat:%f%d" >actual && + test_cmp expect.default actual && + + cat >expect.all <<-\EOF && + Merge-tag-reach (HEAD -> refs/heads/main) + Merge-tags-octopus-a-and-octopus-b + seventh (tag: refs/tags/seventh) + octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b) + octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a) + reach (tag: refs/tags/reach, refs/heads/reach) + Merge-branch-tangle (refs/hidden/tangle) + Merge-branch-side-early-part-into-tangle (refs/rewritten/merge, refs/heads/tangle) + Merge-branch-main-early-part-into-tangle (refs/prefetch/merge) + tangle-a (tag: refs/tags/tangle-a) + Merge-branch-side + side-2 (tag: refs/tags/side-2, refs/heads/side) + side-1 (tag: refs/tags/side-1) + Second + sixth + fifth + fourth + third + second + initial + EOF + git log --decorate=full --pretty="tformat:%f%d" \ + --decorate-all >actual && + test_cmp expect.all actual +' + +test_expect_success '--decorate-all clears previous exclusions' ' + cat >expect.all <<-\EOF && + Merge-tag-reach (HEAD -> refs/heads/main) + reach (tag: refs/tags/reach, refs/heads/reach) + Merge-tags-octopus-a-and-octopus-b + octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b) + octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a) + seventh (tag: refs/tags/seventh) + Merge-branch-tangle (refs/hidden/tangle) + Merge-branch-side-early-part-into-tangle (refs/rewritten/merge, refs/heads/tangle) + Merge-branch-main-early-part-into-tangle (refs/prefetch/merge) + tangle-a (tag: refs/tags/tangle-a) + side-2 (tag: refs/tags/side-2, refs/heads/side) + side-1 (tag: refs/tags/side-1) + initial + EOF + + git log --decorate=full --pretty="tformat:%f%d" \ + --simplify-by-decoration \ + --decorate-refs-exclude="heads/octopus*" \ + --decorate-refs="heads" \ + --decorate-all >actual && + test_cmp expect.all actual && + + cat >expect.filtered <<-\EOF && + Merge-tags-octopus-a-and-octopus-b + octopus-b (refs/heads/octopus-b) + octopus-a (refs/heads/octopus-a) + initial + EOF + + git log --decorate=full --pretty="tformat:%f%d" \ + --simplify-by-decoration \ + --decorate-refs-exclude="heads/octopus" \ + --decorate-refs="heads" \ + --decorate-all \ + --decorate-refs-exclude="tags/" \ + --decorate-refs="heads/octopus*" >actual && + test_cmp expect.filtered actual +' + test_expect_success 'log.decorate config parsing' ' git log --oneline --decorate=full >expect.full && git log --oneline --decorate=short >expect.short && From patchwork Fri Jul 29 19:29:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932789 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 5AEDEC00144 for ; Fri, 29 Jul 2022 19:30:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238874AbiG2TaM (ORCPT ); Fri, 29 Jul 2022 15:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238871AbiG2TaJ (ORCPT ); Fri, 29 Jul 2022 15:30:09 -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 3BE8787358 for ; Fri, 29 Jul 2022 12:29:52 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id a18-20020a05600c349200b003a30de68697so4774616wmq.0 for ; Fri, 29 Jul 2022 12:29: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=oJoq1uXDl143NTF1u/dd6KyDPbbovo9RQ9+2oLr18xo=; b=bC8cY95X1DWvCBGys2THk9LbMX6Hhx5L00ZuR2ZcfdfnOEtEPafscMCwuhfz/vyxH/ g2QLtYFjIlXoEE0937W5SHQDp7AETFQJp9NXOQRD5KKcVjiWlNz5qdmAp7yLJwckAvNA 2jbb+jOuuopji8/deAWTaQVVsCwRhF9gJ190xGfaZTme94LduKUU9A2uJ4m5iuCuchXU m0dDDEUcfe0CvdgHJRJW0dTswOjTYwzUNtJH2e7g7eROZaINj6tf9UgxtGfY9hR/I5kX huxjL8ARN1AYBN58vdN1ZEvuFvLqGI6TZhNpWk5ASZDDG9tBQBtsMZ3IV+GoNq1Se/kb gwHA== 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=oJoq1uXDl143NTF1u/dd6KyDPbbovo9RQ9+2oLr18xo=; b=0Nu/9eq3TeOEbdyB7omrrdzdkzIm3k2Qhs3Zi3aQVpYm1jcwWjC1H/NUmseGHE699z SA1E1hYagSsiPaIYtPEtPTNl+66VMGB8CCAITBXE+jS5V3R0DFTOyMKb5hGbGW6DU/SC nZ4eGNEd0oNEknX/uhNopjVCkzHaSZ9joK748KTVblmKzrJOshis7WqAMDW8GuQBmHMi t9oKtSm8vmujI04ojPp1WWLDN2vIWa8ZZnsptIV9HDvpeVEWF3K0RT7YSqY01GFrxcpo tYfawWbE3ARZ2CbgiY8EflG6E8reYBdlFDinZhERLRZNDC/Yr1FvxkdPMqg63F/raZjo nmlQ== X-Gm-Message-State: AJIora9S6ODAMkLV4h0LxAGWBBaAHuHJmfv5/zIyHOQuoQV6+TZS17oB eBcQa5mBqKFUUdW9PAYfcqWfhImNF2U= X-Google-Smtp-Source: AGRyM1uYnv1C1JBYOxvlB/VO6BIqjjxEYlkx0ep04fdVciUALUUleTsbcTXLxpTIEoDl2gjcIgXsQg== X-Received: by 2002:a05:600c:4e86:b0:3a3:2edc:bcb4 with SMTP id f6-20020a05600c4e8600b003a32edcbcb4mr3920966wmq.85.1659122990157; Fri, 29 Jul 2022 12:29:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j17-20020a05600c191100b003a342933727sm12086430wmq.3.2022.07.29.12.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:49 -0700 (PDT) Message-Id: <8142b32f023685c78936a618d7b93aaf86ba77fb.1659122979.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:37 +0000 Subject: [PATCH v2 08/10] log: create log.decorateFilter=all Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The previous change introduced the --decorate-all option for users who do not want their decorations limited to a narrow set of ref namespaces. Add a config option that is equivalent to specifying --decorate-all by default. Signed-off-by: Derrick Stolee --- Documentation/config/log.txt | 5 +++++ Documentation/git-log.txt | 4 +++- builtin/log.c | 12 ++++++++++++ t/t4202-log.sh | 3 +++ t/t9902-completion.sh | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Documentation/config/log.txt b/Documentation/config/log.txt index 456eb07800c..615cb26e5c9 100644 --- a/Documentation/config/log.txt +++ b/Documentation/config/log.txt @@ -18,6 +18,11 @@ log.decorate:: names are shown. This is the same as the `--decorate` option of the `git log`. +log.decorateFilter:: + By default, `git log` only shows decorations for certain known ref + namespaces. If 'all' is specified, then show all possible ref + decorations. Default value is 'default'. + log.excludeDecoration:: Exclude the specified patterns from the log decorations. This is similar to the `--decorate-refs-exclude` command-line option, but diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 633705bde90..c35f9b8ad9e 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -59,7 +59,9 @@ used as decoration if they match `HEAD`, `refs/heads/`, `refs/remotes/`, --decorate-all:: When specified, this option clears all previous `--decorate-refs` or `--decorate-refs-exclude` options and relaxes the default - decoration filter to include all possible decoration refs. + decoration filter to include all possible decoration refs. This + option is assumed if the config value `log.decorateFilter` is set + to `all`. --source:: Print out the ref name given on the command line by which each diff --git a/builtin/log.c b/builtin/log.c index b7fc4946c35..961fe3ae45b 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -184,6 +184,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) static void set_default_decoration_filter(struct decoration_filter *decoration_filter) { int i; + char *value = NULL; struct string_list *include = decoration_filter->include_ref_pattern; const struct string_list *config_exclude = git_config_get_value_multi("log.excludeDecoration"); @@ -195,6 +196,17 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f item->string); } + /* + * By default, decorate_all is disabled. Enable it if + * log.decorateMode=all. Don't ever disable it by config, since + * the command-line takes precedent. + */ + if (!decorate_all && + !git_config_get_string("log.decoratefilter", &value) && + !strcmp("all", value)) + decorate_all = 1; + free(value); + if (decorate_all || decoration_filter->exclude_ref_pattern->nr || decoration_filter->include_ref_pattern->nr || diff --git a/t/t4202-log.sh b/t/t4202-log.sh index e939ed34ff7..6d96710fdfa 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1090,6 +1090,9 @@ test_expect_success '--decorate-all overrides defaults' ' EOF git log --decorate=full --pretty="tformat:%f%d" \ --decorate-all >actual && + test_cmp expect.all actual && + git -c log.decorateFilter=all log \ + --decorate=full --pretty="tformat:%f%d" >actual && test_cmp expect.all actual ' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 31526e6b641..7a0c7b3c372 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2489,6 +2489,7 @@ test_expect_success 'git config - variable name' ' test_completion "git config log.d" <<-\EOF log.date Z log.decorate Z + log.decorateFilter Z log.diffMerges Z EOF ' @@ -2511,6 +2512,7 @@ test_expect_success 'git -c - variable name' ' test_completion "git -c log.d" <<-\EOF log.date=Z log.decorate=Z + log.decorateFilter=Z log.diffMerges=Z EOF ' @@ -2533,6 +2535,7 @@ test_expect_success 'git clone --config= - variable name' ' test_completion "git clone --config=log.d" <<-\EOF log.date=Z log.decorate=Z + log.decorateFilter=Z log.diffMerges=Z EOF ' From patchwork Fri Jul 29 19:29:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932792 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 D6570C00144 for ; Fri, 29 Jul 2022 19:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238952AbiG2TaV (ORCPT ); Fri, 29 Jul 2022 15:30:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238876AbiG2TaK (ORCPT ); Fri, 29 Jul 2022 15:30:10 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEA8D8736A for ; Fri, 29 Jul 2022 12:29:52 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id bn9so7144477wrb.9 for ; Fri, 29 Jul 2022 12:29: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=flNOUpFpQNk5mfo8GE8lZF5pNYZBrO+OeLGye5bTl1g=; b=gx+nBeJMGeA9joe77Uh/rDo4OX7gqj6pOEsPktStZ9uFb/cP3jY05VH+UWdaHxDo34 DbNIS2/m1N7NpfPMdP84soe9YgkxgIJJCTpDzmqfu32im2wWyy4x3VZPCFAas8A0TNH0 65xS7qmYzyTpNQ1kI5q2D2pLEcWnn57B2QQKIBz9KrrO9eiCOAKHNXCCTxebsHz9qve2 k4EGMlmCSL9KBNB0sM4UI4L9KC7/3qOlfsH9pvnvzzJmJ/Rhr1mxxNfWtq+06jgY1Zvq pnACWZQHOxDre86KTbQAwdaGRKmEbeXqVFsy1IxN3kwlZ2gIT5jLceDjnjHX1VxilnHw LHrA== 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=flNOUpFpQNk5mfo8GE8lZF5pNYZBrO+OeLGye5bTl1g=; b=ETjp4jxIFAkuGc24Ui25O/RLNBqJXjvhOX/uQXOfuD09AzPfCLQehhK78so83N1eEp kQv568hA7OOkA1ewWmwWxvyRgcdXEq7aHIYjGBb+VxuvcgkDADP9J/V0ADXkUSkWWncu v9WF66gP56SQRU4le50r1q6iwqw+RN5ArMee3TnZLzxT8kmguKcjX7inrLDhS+6x8HOB RvgcuQDBvN1EttiQKRPyqEq36PKuCSyAEY5qWVggxTFSCHUdwXPpL/OWCFop43xRPdn9 o4l0kpbYDTEvpjwu2tIZFL7QaAvd81dp+EH3w/MFKBQjLGuSDMZldaR0GRI56C29AYmp cXHQ== X-Gm-Message-State: ACgBeo1dfW3Eau09u0AwmoAUiJLszDzJIN/++oEfWQoMuoVlJ7iV9IjU haWtWcOzbEeVV91b87A11wyaiioTJ50= X-Google-Smtp-Source: AA6agR4jX1MkTxte+lNC8535FY1Z5jJxgktrEhuHx3iVV125FeRqRLXZhKMpkvPoEPTDZR1cb0mjsQ== X-Received: by 2002:a05:6000:168e:b0:21d:b9bf:5e39 with SMTP id y14-20020a056000168e00b0021db9bf5e39mr3461212wrd.71.1659122991172; Fri, 29 Jul 2022 12:29:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x12-20020a05600c21cc00b0039747cf8354sm4998025wmj.39.2022.07.29.12.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:50 -0700 (PDT) Message-Id: <318269dfe27a56d4c85b8723fbd9853159e9d096.1659122979.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:38 +0000 Subject: [PATCH v2 09/10] maintenance: stop writing log.excludeDecoration Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This reverts commit 96eaffebbf3d0 (maintenance: set log.excludeDecoration durin prefetch, 2021-01-19). The previous change created a default decoration filter that does not include refs/prefetch/, so this modification of the config is no longer needed. One issue that can happen from this point on is that users who ran the prefetch task on previous versions of Git will still have a log.excludeDecoration value and that will prevent the new default decoration filter from being active. Thus, when we add the refs/bundle/ namespace as part of the bundle URI feature, those users will see refs/bundle/ decorations. Signed-off-by: Derrick Stolee --- builtin/gc.c | 6 ------ t/t7900-maintenance.sh | 21 --------------------- 2 files changed, 27 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index eeff2b760e0..6c222052177 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -910,12 +910,6 @@ static int fetch_remote(struct remote *remote, void *cbdata) static int maintenance_task_prefetch(struct maintenance_run_opts *opts) { - git_config_set_multivar_gently("log.excludedecoration", - "refs/prefetch/", - "refs/prefetch/", - CONFIG_FLAGS_FIXED_VALUE | - CONFIG_FLAGS_MULTI_REPLACE); - if (for_each_remote(fetch_remote, opts)) { error(_("failed to prefetch remotes")); return 1; diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 74aa6384755..62ed694a404 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -162,7 +162,6 @@ test_expect_success 'prefetch multiple remotes' ' test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one && test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two && - test_cmp_config refs/prefetch/ log.excludedecoration && git log --oneline --decorate --all >log && ! grep "prefetch" log && @@ -173,26 +172,6 @@ test_expect_success 'prefetch multiple remotes' ' test_subcommand git fetch remote2 $fetchargs out && - grep refs/remotes/remote1/ out && - grep refs/prefetch/ out && - - git log --oneline --decorate --all >log && - ! grep "prefetch" log && - ! grep "remote1" log && - grep "remote2" log && - - # a second run does not change the config - git maintenance run --task=prefetch && - git log --oneline --decorate --all >log2 && - test_cmp log log2 -' - test_expect_success 'loose-objects task' ' # Repack everything so we know the state of the object dir git repack -adk && From patchwork Fri Jul 29 19:29:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12932790 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 0D3C2C19F2A for ; Fri, 29 Jul 2022 19:30:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238061AbiG2TaP (ORCPT ); Fri, 29 Jul 2022 15:30:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238873AbiG2TaJ (ORCPT ); Fri, 29 Jul 2022 15:30:09 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E17C287367 for ; Fri, 29 Jul 2022 12:29:52 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id m13so3183756wrq.6 for ; Fri, 29 Jul 2022 12:29: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=UoY7mpk7Qo5GFKFqkKwE93tV0XG246YR3UoNXkoYwAU=; b=azt1GvXMai9fysHfNUblThRb5I2A9kxgbnqxOHzLQJ9gLn4Gp2QjqdZ+mvHGalr/C5 R85rzegLetItZnL7BALSwxb2GzpMOyyQYqyiBtSsCJdqM8wCw5RUrzmzX27/gMNXTIa7 4NKQW2Hn/qexkp+an/1Vwh3hKH3vEig+6X4Yj9Jm2mMBfR6A6k2t3TTl7LmzPjT1Kzje y33JTjmDrn8l3oS6VlDuaxbKI2z6sY1hAEwIayJKvkHCe7EWIgohSYzJN/4/WrumqWeM 99oiGGNsgylZ2CWtyaTsXdKoHwzxQHbIMIJa7WEzjGIlNh83rjh9jMwZ8ZmHiI0e2FzZ c2mg== 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=UoY7mpk7Qo5GFKFqkKwE93tV0XG246YR3UoNXkoYwAU=; b=4YoQqVCB1RiJh0yxvmQSO0PiN4Ct2SWO0dWq+YEPymTCXKTG/sdKf4uiwxI5NQcbaA 0AkPBDIyzh8U+krDWf8lSAZSk2ti4mdsYqyZ5w+Wu9Eb6puI9P/wIRKrL5iZ6xlFMNXg 87o680uqyDVwgx4uKer28cw6/ucvYQ0e8dhQHyQN++TmxIZDlfXPq25IbIEMkXxPwQZd b6i1nhrero6eQNb6MjQftJOl61CM8kUO/HdkPJXUWAZfhHs7dqgBa6/vicZ2T0RPv12+ yYHJxPDTVRrkCNWADUymr6vpGKixjamrRaH3rg2PH0j0zi7GFh+dEK2rE7NGrZ+PUyr9 O27w== X-Gm-Message-State: ACgBeo0VSuLOW1NZSre1ibpecIPOaqoIGnmKYypf+pjgmJArSb5Y3z5+ ZX9MnBRD+8oPO7tse5CgdVNHe9kIUdQ= X-Google-Smtp-Source: AA6agR61O5SCkvzxiMkxsQz/cJLy+FFTOZWCnPdYUk9hssx5ncc8WXdF8krbGTt5RLbimdVpKnDGtA== X-Received: by 2002:adf:efc3:0:b0:21f:15aa:1b40 with SMTP id i3-20020adfefc3000000b0021f15aa1b40mr1691260wrp.159.1659122992228; Fri, 29 Jul 2022 12:29:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b003a2ed2a40e4sm10007619wms.17.2022.07.29.12.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 12:29:51 -0700 (PDT) Message-Id: <8599bb550457ea0edb3c412e84ee688061883e7f.1659122979.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Jul 2022 19:29:39 +0000 Subject: [PATCH v2 10/10] fetch: use ref_namespaces during prefetch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, me@ttaylorr.com, vdye@github.com, steadmon@google.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The "refs/prefetch/" namespace is used by 'git fetch --prefetch' as a replacement of the destination of the refpsec for a remote. Git also removes refspecs that include tags. Instead of using string literals for the 'refs/tags/ and 'refs/prefetch/' namespaces, use the entries in the ref_namespaces array. This kind of change could be done in many places around the codebase, but we are isolating only to this change because of the way the refs/prefetch/ namespace somewhat motivated the creation of the ref_namespaces array. Signed-off-by: Derrick Stolee --- builtin/fetch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index fc5cecb4835..004d92b3554 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -490,7 +490,9 @@ static void filter_prefetch_refspec(struct refspec *rs) continue; if (!rs->items[i].dst || (rs->items[i].src && - !strncmp(rs->items[i].src, "refs/tags/", 10))) { + !strncmp(rs->items[i].src, + ref_namespaces[NAMESPACE_TAGS].ref, + strlen(ref_namespaces[NAMESPACE_TAGS].ref)))) { int j; free(rs->items[i].src); @@ -506,7 +508,7 @@ static void filter_prefetch_refspec(struct refspec *rs) } old_dst = rs->items[i].dst; - strbuf_addstr(&new_dst, "refs/prefetch/"); + strbuf_addstr(&new_dst, ref_namespaces[NAMESPACE_PREFETCH].ref); /* * If old_dst starts with "refs/", then place