From patchwork Thu Mar 10 13:56:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776372 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 EB872C433FE for ; Thu, 10 Mar 2022 13:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242593AbiCJN6M (ORCPT ); Thu, 10 Mar 2022 08:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242589AbiCJN6L (ORCPT ); Thu, 10 Mar 2022 08:58:11 -0500 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 A13A0141FF6 for ; Thu, 10 Mar 2022 05:57:10 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id i66so3281532wma.5 for ; Thu, 10 Mar 2022 05:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OV/oEB8EmP/cEtCwmJ2WBG66N1H/py1ld3DUjHPv6sI=; b=G50xftEhYsah9HeEsDQ9OkVjTZ6KzxBFlrpaUzq62pW3s6sCrfw4Jn2D7fWnXjLf9M vm/1xoui4AKVMz9ITJ95HeZvCcX6XNCBS75YOi0cXKnhetvrJ+483zbQNJH4Jl+c1hIk fJUeWqA0qUJLJTrv7rU+wrzUB09R54aMoHHYmY2OMBra+Pzs8knNxdnB5oZBNX63jmY9 Kf5y2VRdmQoTl63XSEhrlkkbrm89/CafiEbMZFnyB51Y9NK2fTqmalPxPMuT1v0KcNkU iyxqWrvqOzDeGHdxmUdEi7ihYdQqD4n1G7Of6RxaZrgr+OXQWl6QiLZOq6FIiaH5l/LC pFRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OV/oEB8EmP/cEtCwmJ2WBG66N1H/py1ld3DUjHPv6sI=; b=eotQ13X5LVuuxrErHTYBbaLWLHN5sgdQw0vj4OHrixdsfR5pLpLFrFda9P5Wj1tWCZ sVvnM7x/nUZwtybCKmL47j3hcld1hrTG5PolHymGwLvrsztka8EZ2OVHegi+PDzpgjZj 6iMttSPR82EJobejE8iaJcaGA1gS6bRldKaT87YPWRbwXWwVloOtmSNofY2ch1Koy2Ve sT5Dwz8GVQs8jmMEM9ELj8cUNTH8kZcn00AZC9be7LKyzFqe1TOb3TA1sOmJFixgXU5f Mt5hO/d9yFUJwaQB+KjFN8SXThrIvyHSVHIBsMlI5x+RZeEiXJaZJ1benaLucPKHMUf+ 9I0A== X-Gm-Message-State: AOAM530+1C2s8IJAgQoJjVGiMBz45M/i0zB9wSNqjGDfTLcLZ7GwAMwB dmssnAit26AgRWxDGFL27WhYefNhxkx/Sw== X-Google-Smtp-Source: ABdhPJyItrBOP+VMScSWkWFwLrHNnygLfM0R81qFxB75OWMjP51J4ne0iMH0Xm/nRWpeyacZclJ85A== X-Received: by 2002:a05:600c:1d18:b0:389:cda6:f39f with SMTP id l24-20020a05600c1d1800b00389cda6f39fmr8535696wms.69.1646920628749; Thu, 10 Mar 2022 05:57:08 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:08 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 1/7] ls-tree tests: add tests for --name-status Date: Thu, 10 Mar 2022 14:56:57 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The --name-status synonym for --name-only added in c639a5548a5 (ls-tree: --name-only, 2005-12-01) had no tests, let's make sure it works the same way as its sibling. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3101-ls-tree-dirname.sh | 55 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh index 05fde642259..217006d1bfb 100755 --- a/t/t3101-ls-tree-dirname.sh +++ b/t/t3101-ls-tree-dirname.sh @@ -201,31 +201,34 @@ EOF test_cmp expected check ' -test_expect_success 'ls-tree --name-only' ' - git ls-tree --name-only $tree >current && - cat >expected <<\EOF && -1.txt -2.txt -path0 -path1 -path2 -path3 -EOF - test_output -' - -test_expect_success 'ls-tree --name-only -r' ' - git ls-tree --name-only -r $tree >current && - cat >expected <<\EOF && -1.txt -2.txt -path0/a/b/c/1.txt -path1/b/c/1.txt -path2/1.txt -path3/1.txt -path3/2.txt -EOF - test_output -' +for opt in --name-only --name-status +do + test_expect_success "ls-tree $opt" ' + git ls-tree $opt $tree >current && + cat >expected <<-\EOF && + 1.txt + 2.txt + path0 + path1 + path2 + path3 + EOF + test_output + ' + + test_expect_success "ls-tree $opt -r" ' + git ls-tree $opt -r $tree >current && + cat >expected <<-\EOF && + 1.txt + 2.txt + path0/a/b/c/1.txt + path1/b/c/1.txt + path2/1.txt + path3/1.txt + path3/2.txt + EOF + test_output + ' +done test_done From patchwork Thu Mar 10 13:56:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776373 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 9A262C433F5 for ; Thu, 10 Mar 2022 13:57:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242601AbiCJN6R (ORCPT ); Thu, 10 Mar 2022 08:58:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242589AbiCJN6M (ORCPT ); Thu, 10 Mar 2022 08:58:12 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D024141FF7 for ; Thu, 10 Mar 2022 05:57:11 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id bg31-20020a05600c3c9f00b00381590dbb33so3435372wmb.3 for ; Thu, 10 Mar 2022 05:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qo0XRDn9CWFxeoswMkxUtUpU2NAJRZIfnj/z5vohKz8=; b=gOLxJksW4V1NCY8M97k9wTsNvpMALMkBR8KAoH/zMVOvSHIk2ALGoOLmj48JTQvA8Q H+FbZ1pq/W2UO6Q325kGRA4OylZsYYtmy1CD0EtNYRyIxNGdBy4T7A5pDCtPTdBvuaKV DV6OC4DVIGN8wHpBgPNQ8VOnyobGE8XSembGkM0tL1OkchxlPFZekevKAL7Gsw8Abe48 zqf5S18YDYFQ3NDxPAxitC9+TVshRK1oT9ZXxZcADWg3kYNlIsNALIsGun9t/batNjjB q3jEWuY+0cieUQdESGjCrgljZ4C7pxZ1ZQkJniSLs7AbW3KNk/SFy9UlAJrdLqKZYlj+ QXWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qo0XRDn9CWFxeoswMkxUtUpU2NAJRZIfnj/z5vohKz8=; b=P+bCUSax2GZAmizcEqzE1ynEikSQjRMWbG3Ebj71EtbyaORUukcRdehcakOvVb10wb fN+XTOHWx/4Y/EW6GPGOac4I6W88tQ3/j58DpFiOp25tmwi7HOqD21cGht3HoSIPO2dq 6f2/113jkB7+7mOouZYM4lSvqHMy08IJ2R+8z8+MgYqpGIkDhDHpO2dO8eRY0qV2GmF+ YS4kO1MKBgn1RTBN3gTDR30BWlIqtDUkpIG7OAaYOfKvlKOmuueXR2DpZ3YaTz3H+21i PHuUYCyyRiDgUUvsgefaS39O32pSwJQGFNFKDaL4habLiANI8RbY/7BOBDzTCd7yieoh hPnQ== X-Gm-Message-State: AOAM530atcDvqaWeIZKVO9xGcwp73EwmZyRX1SynZUHuH89f+LWyt/0q dYtGxsLJyZJQRwxN4OPLqW1tC4v1JusUqA== X-Google-Smtp-Source: ABdhPJwizK0TE1kseq0/n9FiPuJMaIRSqJfSr8/VS4q6bqDn1OTynFcOHS2qKiVtAIpC4dqSUmVfAg== X-Received: by 2002:a7b:c5d1:0:b0:37f:a8a3:9e17 with SMTP id n17-20020a7bc5d1000000b0037fa8a39e17mr11634176wmk.109.1646920629798; Thu, 10 Mar 2022 05:57:09 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:09 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 2/7] ls-tree tests: exhaustively test fast & slow path for --format Date: Thu, 10 Mar 2022 14:56:58 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change these tests adapted from my initial version in [1] to exhaustively test both the fast and slow paths of --format. In [1] there was a "GIT_TEST_LS_TREE_FORMAT_BACKEND" variable to ensure that we had test coverage for passing tests that would otherwise use show_tree() through show_tree_fmt(), and thus that the formatting mechanism could handle all the same cases as the non-formatting options. Somewhere in subsequent re-rolls of that we seem to have drifted away from what the goal of these tests should be. We're trying to ensure correctness of show_tree_fmt(). We can't tell if we "hit [the] fast-path" here, and instead of having an explicit test for that, we can just add it to something our "test_ls_tree_format" tests for. 1. https://lore.kernel.org/git/RFC-patch-6.7-eac299f06ff-20211217T131635Z-avarab@gmail.com/ 2. https://lore.kernel.org/git/cb717d08be87e3239117c6c667cb32caabaad33d.1646390152.git.dyroneteng@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3104-ls-tree-format.sh | 89 +++++++++++++++------------------------ 1 file changed, 33 insertions(+), 56 deletions(-) diff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh index b86941c2024..12105115eaf 100755 --- a/t/t3104-ls-tree-format.sh +++ b/t/t3104-ls-tree-format.sh @@ -22,79 +22,56 @@ test_ls_tree_format () { opts=$2 && fmtopts=$3 && shift 2 && - git ls-tree $opts -r HEAD >expect.raw && - sed "s/^/> /" >expect actual && - test_cmp expect actual + + test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" ' + git ls-tree $opts -r HEAD >expect && + git ls-tree --format="$format" -r $fmtopts HEAD >actual && + test_cmp expect actual + ' + + test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" ' + git ls-tree --format="$format" -r $fmtopts HEAD >expect && + git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw && + sed "s/^> //" >actual ' ' - test_ls_tree_format \ - "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ - "" -' +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ + "" -test_expect_success 'ls-tree --format=' ' - test_ls_tree_format \ - "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \ - "--long" -' +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \ + "--long" -test_expect_success 'ls-tree --format=' ' - test_ls_tree_format \ - "%(path)" \ - "--name-only" -' +test_ls_tree_format \ + "%(path)" \ + "--name-only" -test_expect_success 'ls-tree --format=' ' - test_ls_tree_format \ - "%(objectname)" \ - "--object-only" -' +test_ls_tree_format \ + "%(objectname)" \ + "--object-only" + +test_ls_tree_format \ + "%(objectname)" \ + "--object-only --abbrev" \ + "--abbrev" -test_expect_success 'ls-tree --format= --abbrev' ' - test_ls_tree_format \ - "%(objectname)" \ - "--object-only --abbrev" \ - "--abbrev" -' -test_expect_success 'ls-tree combine --format= and -t' ' - test_ls_tree_format \ +test_ls_tree_format \ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ "-t" \ "-t" -' -test_expect_success 'ls-tree combine --format= and --full-name' ' - test_ls_tree_format \ +test_ls_tree_format \ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ "--full-name" \ "--full-name" -' -test_expect_success 'ls-tree combine --format= and --full-tree' ' - test_ls_tree_format \ +test_ls_tree_format \ "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ "--full-tree" \ "--full-tree" -' - -test_expect_success 'ls-tree hit fast-path with --format=' ' - git ls-tree -r HEAD >expect && - git ls-tree --format="%(objectmode) %(objecttype) %(objectname)%x09%(path)" -r HEAD >actual && - test_cmp expect actual -' - -test_expect_success 'ls-tree hit fast-path with --format=' ' - git ls-tree -r --name-only HEAD >expect && - git ls-tree --format="%(path)" -r HEAD >actual && - test_cmp expect actual -' -test_expect_success 'ls-tree hit fast-path with --format=' ' - git ls-tree -r --object-only HEAD >expect && - git ls-tree --format="%(objectname)" -r HEAD >actual && - test_cmp expect actual -' test_done From patchwork Thu Mar 10 13:56:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776376 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 5E12FC433F5 for ; Thu, 10 Mar 2022 13:57:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242622AbiCJN6W (ORCPT ); Thu, 10 Mar 2022 08:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242595AbiCJN6O (ORCPT ); Thu, 10 Mar 2022 08:58:14 -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 5B02A14F9AD for ; Thu, 10 Mar 2022 05:57:12 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so3430213wmp.5 for ; Thu, 10 Mar 2022 05:57:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V4ew7zgCX4z8EWaq1qfRudy0Qjw8oVj39a6DG47R86Y=; b=oOWKEOq9VrpN8/xwXFRNEjQyPpXm3TToGlc5/kYlM3doDUUmBL3kXsT7Zz9PdrJwGy h/DtSa2NfauFY2x8DWl3uWInyw0yvcqi4oH4xE3JOAM+jeZ35DP4/x5SAwG4qKcdIbTN jYu9o0yx603o8j1MfxyjKlR51GMKPtmSzepekkhYvbrQdFitcaTZ3B6FE+eM3+WcHg4q Nhg/cXi7tHDiH5ExD9zMG8uzN1eguISepo4NFSy5xLY6/5DblvkXuz9MdOIbu+Q5zxx9 TSwA5DtDv5y6ZRh4cOp4XUAMPYQa3QiOhd1VfHAgOWSUSYH8StK27FgkF4rj31s2Weet WgHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V4ew7zgCX4z8EWaq1qfRudy0Qjw8oVj39a6DG47R86Y=; b=2ZJNDfU22rDURNsIAPGV5dMQx9RItfrlrongfpZJ+WHCT1CN/+6MdZl5iIcJYY51A3 Q4JP6uTB5ynlhWDcsMrJRCUUDT2zRmt+nzeMBO7fDr3JNAUPeDeNWeqDtk9u4885bC3Z NC0nVSin2+jmhcajPB1h9NqQ2wCjwwk61R5An9DRWihWf9wlajRInXKusr0U8oR0MQCv XHm2GHieRIgQbTXhgzkpJG5SK1RidJRSP9Ag6ks8M7EjuM937PBIiSu9KrF3GUYfVH4Y EWh6zfLohEGNYp+CescXjED9nOQe6s+4NMUZvQHlhO4RQcWTtUOc1zynh/X7mripDR3X IzkQ== X-Gm-Message-State: AOAM531tOJy04UcaxWDiAgs8MTBdpVdcEMcnNfpvlZbcxn0kFu25jkcG GV59iMfY/VKIx46Bpcj1yJdJuYAf7ke+hg== X-Google-Smtp-Source: ABdhPJwcuI0d3OjIFO38/UTES3uxJ5hOWPKNBTO95m//oS73l1Y15x+yvDyFPp4up+N7StFWGIcphw== X-Received: by 2002:a7b:c841:0:b0:389:864c:e715 with SMTP id c1-20020a7bc841000000b00389864ce715mr3695778wml.72.1646920630586; Thu, 10 Mar 2022 05:57:10 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:10 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 3/7] ls-tree: remove dead labels Date: Thu, 10 Mar 2022 14:56:59 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org These have not been used since a preceding "ls-tree: slightly refactor `show_tree()`" commit, and should be squashed into that. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-tree.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 23ec2f0fe76..f04733a9be1 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -18,9 +18,6 @@ static int line_termination = '\n'; #define LS_RECURSIVE 1 #define LS_TREE_ONLY (1 << 1) #define LS_SHOW_TREES (1 << 2) -#define LS_NAME_ONLY (1 << 3) -#define LS_SHOW_SIZE (1 << 4) -#define LS_OBJECT_ONLY (1 << 5) static int abbrev; static int ls_options; static struct pathspec pathspec; From patchwork Thu Mar 10 13:57:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776375 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 7CDBBC433F5 for ; Thu, 10 Mar 2022 13:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242620AbiCJN6U (ORCPT ); Thu, 10 Mar 2022 08:58:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242596AbiCJN6O (ORCPT ); Thu, 10 Mar 2022 08:58:14 -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 7F5C714FFD5 for ; Thu, 10 Mar 2022 05:57:13 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id e24so8078325wrc.10 for ; Thu, 10 Mar 2022 05:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qgzhy2ku0o3GoDlMBMdtPBxvUe5eGsJ7sFFXGcRiBd8=; b=Kn6ae0aPZe4ZXTIMInVUtD8zVO4JcT5GfEW+dF4rqzL64tTmQRPqkXjVnmqFVB9K0w qLYR4BtrVcuSus2gHuEvmzRtboBJyHFucV8D9gcU+WXXkhR8W7bKXIbUDudsFJ7ZkWNQ ES4B5CPA2kzYJOJaG2/9FFX+nsYMk7JS0GsCKFYtCiidKfXtOJfaZHGGRdEsdEupWnOI hhFxL1LxSyzpuYPp1tTxdEpyoa/K2Cui/3rI4l8rGky4hPQvy32GH5GMhhNFyhPvZ4l9 1ifpyu/W1E2yWM/ThsSEWNfg91bi6y28KuMtzxX2nkzQsCGCAhoU0jvDLROg+art5F+p +M1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qgzhy2ku0o3GoDlMBMdtPBxvUe5eGsJ7sFFXGcRiBd8=; b=0b3aJlOaiSed35W4VHol6I1BNz7Wb2mbdtpen7iBPrDJFate3/gpitBMe8Q7hgn3uc zbXHRKmfyw4KoTCAFqD0ML0QiBLPuqL0qK/KLoFUkSpt+wuBXeZJxqsYiFvkV7p3LwhQ Wa/FDYwUrfW4Z7POgJ+YyjtvAv1azJZEsaheXeh96iFWVyoD8gB94CFJYahC6nh3XPbH aydb1M17Ars9SIhuIQP7ey2C31DbYuoCyM3rfRXvC496OJmDU4XIHUYUF1Y9xBlHDWAK bg0whBzPMeWb+/OVLzcUox/rbwnwLuiO7yXm92VohO/uk6lZ1DVsEgQSEgLjtjyqJ3j7 5jUQ== X-Gm-Message-State: AOAM5339T6Ll7qhz873dNNu3DgwK3pz5PwvJ0tHOjaGshiZzYM3c2VGQ fRK1ZhMIbcExdeotIgP5OQPnS89Ip8+o9w== X-Google-Smtp-Source: ABdhPJx1d0RcIqHZbViXFkNw32rtsdC1RpJ4V7heUzZivPkLbDB33Q883r438KL/x0h2mmEaBMFhaw== X-Received: by 2002:adf:c5ca:0:b0:1f0:aa2:494b with SMTP id v10-20020adfc5ca000000b001f00aa2494bmr3730899wrg.275.1646920631618; Thu, 10 Mar 2022 05:57:11 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:10 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 4/7] ls-tree: remove unused "MODE_UNSPECIFIED" Date: Thu, 10 Mar 2022 14:57:00 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the "MODE_UNSPECIFIED" added in a preceding commit. We don't need it, instead let's start the "command mode" enum at 1, as e.g. builtin/help.c does for its similar pattern. In addition let's change this from "mutx_option" to a more obvious "ls-tree_cmdmode", even if the type name isn't used anywhere else. The previous name sounded as though it had something to do with a (thread?) mutex. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-tree.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index f04733a9be1..95816709d38 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -49,11 +49,10 @@ static const char * const ls_tree_usage[] = { NULL }; -static enum mutx_option { - MODE_UNSPECIFIED = 0, +static enum ls_tree_cmdmode { + MODE_LONG = 1, MODE_NAME_ONLY, MODE_OBJECT_ONLY, - MODE_LONG, } cmdmode; static void expand_objectsize(struct strbuf *line, const struct object_id *oid, From patchwork Thu Mar 10 13:57:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776374 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 7D4BBC433EF for ; Thu, 10 Mar 2022 13:57:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242611AbiCJN6S (ORCPT ); Thu, 10 Mar 2022 08:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242598AbiCJN6P (ORCPT ); Thu, 10 Mar 2022 08:58:15 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D3CF14FFE1 for ; Thu, 10 Mar 2022 05:57:14 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id j26so8141760wrb.1 for ; Thu, 10 Mar 2022 05:57:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zccgqm5NQ33F8V57r3tVB2s+DDzPw+xehfma7K1UOic=; b=M+KhgrGKc0LStb44UOpvDg91AiJgilFsl6WCElTRTppxN2NTvMyfGAdexpDMARkRYs XzuiJgUteQoOrlN53VxoKHauQK9/8Zf+cywK6Z1LFhFdRpBEOq9/5+YN0Mpzl4wYhd4B 6hIdBds9snNIK0LYw9ReQm9gZVc4/1vi0m6CZ8EENl7Fdbl8WVEmZ/GKtMu7EGLNIGUJ VOs8qZlIqR0lBEZX5DCMm3skX3iYJsMoUykaGom+hZL4ANnQaFp6yp3K960TLAB39dhn M+iX/j9RXxQfhVnDmBfhW79YiQgLQoOvGVmdGp1lN3ddn1a/sZxXyOwYb1d4BXkpwt4s Liog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zccgqm5NQ33F8V57r3tVB2s+DDzPw+xehfma7K1UOic=; b=eHTNgZTc/OUUKOQSq/NWdqgbx9vlki5eDIJAyb3vCoPMNqNTigePkcZfk9zmqPBvo1 N7qdxuL9O/AGkLgAjWdRWmidFWlb4pKpj8ZRjJpsuAYSFJt5RzVi2keTN+DtlSMyxc3J 4afQqN4+2wQYutCK/1ttnPvgBjIGWhWIPMHyHt/EyQIEDFt7YUeRVK7v0psOSfqkQQAj /5qLDxkqcYqRH2179zx4qhdqC1vX8Lo8dAiv7s1q+ypbde6elbbHht0zLkNnZUV4Lx9D tSLZzcKIcMQPLcIP4dLiw3vxVGNKNBoHMXeNYFIRULW360eqv9f2xpuMHB4QJFuBQNZq qYwg== X-Gm-Message-State: AOAM5334sUK68riXJArQCIRFVJ0lzmWC/qEUXiQNXHnkem/lTyArl5rd nT9+PjjOTpWBYjRRRAoN4zYkiWQGwmYUbw== X-Google-Smtp-Source: ABdhPJz3/vCBTKu9ETsz4CkWuIisW+a5kN0uBR2n1XFzgCML10JQcFgwJC6TfvN0lFrbUeywycLwow== X-Received: by 2002:a5d:6d0f:0:b0:203:9157:1c48 with SMTP id e15-20020a5d6d0f000000b0020391571c48mr865315wrq.192.1646920632707; Thu, 10 Mar 2022 05:57:12 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:11 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 5/7] ls-tree: detect and error on --name-only --name-status Date: Thu, 10 Mar 2022 14:57:01 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The --name-only and --name-status options are synonyms, but let's detect and error if both are provided. In addition let's add explicit --format tests for the combination of these various options. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-tree.c | 11 ++++++++++- t/t3103-ls-tree-misc.sh | 15 +++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 95816709d38..528b4e5b5f6 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -52,6 +52,7 @@ static const char * const ls_tree_usage[] = { static enum ls_tree_cmdmode { MODE_LONG = 1, MODE_NAME_ONLY, + MODE_NAME_STATUS, MODE_OBJECT_ONLY, } cmdmode; @@ -301,7 +302,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) OPT_CMDMODE(0, "name-only", &cmdmode, N_("list only filenames"), MODE_NAME_ONLY), OPT_CMDMODE(0, "name-status", &cmdmode, N_("list only filenames"), - MODE_NAME_ONLY), + MODE_NAME_STATUS), OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"), MODE_OBJECT_ONLY), OPT_SET_INT(0, "full-name", &chomp_prefix, @@ -327,6 +328,14 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) ls_tree_prefix = prefix = NULL; chomp_prefix = 0; } + /* + * We wanted to detect conflicts between --name-only and + * --name-status, but once we're done with that subsequent + * code should only need to check the primary name. + */ + if (cmdmode == MODE_NAME_STATUS) + cmdmode = MODE_NAME_ONLY; + /* -d -r should imply -t, but -d by itself should not have to. */ if ( (LS_TREE_ONLY|LS_RECURSIVE) == ((LS_TREE_ONLY|LS_RECURSIVE) & ls_options)) diff --git a/t/t3103-ls-tree-misc.sh b/t/t3103-ls-tree-misc.sh index ce39158338a..81c63439623 100755 --- a/t/t3103-ls-tree-misc.sh +++ b/t/t3103-ls-tree-misc.sh @@ -24,15 +24,18 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' ' ' for opts in \ - "--name-only --long" \ - "--name-status --long" \ - "--name-only --object-only" \ + "--long --name-only" \ + "--name-only --name-status" \ "--name-status --object-only" \ - "--object-only --long" \ - " --object-only --format" + "--object-only --long" do test_expect_success "usage: incompatible options: $opts" ' test_expect_code 129 git ls-tree $opts $tree - ' + ' + + one_opt=$(echo "$opts" | cut -d' ' -f1) + test_expect_success "usage: incompatible options: $one_opt and --format" ' + test_expect_code 129 git ls-tree $one_opt --format=fmt $tree + ' done test_done From patchwork Thu Mar 10 13:57:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776377 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 75C15C433FE for ; Thu, 10 Mar 2022 13:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242625AbiCJN6X (ORCPT ); Thu, 10 Mar 2022 08:58:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242605AbiCJN6R (ORCPT ); Thu, 10 Mar 2022 08:58:17 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A36F14E976 for ; Thu, 10 Mar 2022 05:57:15 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id x15so8047403wru.13 for ; Thu, 10 Mar 2022 05:57:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BruHHzvqYJfbKEeBZjzxdi06DKTnvSoOL5hUMm4Cglw=; b=Rur8soX/SkUIGefcCHzxjhRWILOOfmgasV5dJTh1CJUepy3N2xVz62cjwXn1PUUx7j 99nPxChB4fELXOGUqauWHG1TyyZGYIBb5Vo+OLlZr6PCf6JsxuGyGW3KfYj6n632C4Jy +Qv4WTf7wJtnZw6G2Yr6KXiTiInS6Io39YPDosx4+Ag3IQwdIvYlp6wHo8zO+/j3tB5W ZPvfwxNRg69N89F5YMplpDk3ItncZJ9Hy45jLYaQ7XtNQVQt4a4TARNdgGAHZKXLgCbc wUFQMKh5dXaDh/2ahkVXWTNobivOKFwR/gJqsLmZpdiRkOdUtpL1bc5pkaNK7UXqs/B4 hkjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BruHHzvqYJfbKEeBZjzxdi06DKTnvSoOL5hUMm4Cglw=; b=5cd+KQfB/QTnEuPOMp+8nlA/krK/cHIGayt47ODsD4CQwK2UY9nnyV9a3RV3R1xRS/ gEQIaIcoG3t+hnuRD5azNnwhxvfFO8eYTXtgealiU0HmtT6KhLzNEEDqC8kBept2SgnD i/amo/6Hg5DIi4sCBQJCgD9F37XLBVaycCzu3PNHZYE4cqj/0OyQoezoOZPHxSSxKETx vUJHGW8kerlBNvKOOIUUY5PFndo4N311nfIdMhKBP9YeBxYVACqche7Au4IIumllKspB 0uDoWtcyORajUoXJt0t3+glMizLKFpc0osveZDHBC7pf5NyYGSzl3sqZg6POus5wUVzq qUoQ== X-Gm-Message-State: AOAM530zfgz7VnLDjPwAtuf1n5yRrjjHQTmB1wAKsvPe3MLcDGmFH3tv 8VFGaDOjawj3ontnu6I5LqlPH4ENptIKQg== X-Google-Smtp-Source: ABdhPJz8+ogSKJ3k7vYrt+olyGjps2EIy0TmCxdLlwTFjlk40K3Tv0puD2uqWK8mXTY2u9ZqZxYVuw== X-Received: by 2002:a5d:64c1:0:b0:203:7aa5:9390 with SMTP id f1-20020a5d64c1000000b002037aa59390mr3726339wri.328.1646920633574; Thu, 10 Mar 2022 05:57:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:12 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 6/7] ls-tree: remove FIELD_*, just use MODE_* Date: Thu, 10 Mar 2022 14:57:02 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we're picking where we should go in the optimized "show_tree" path there's no reason for why we need to convert our "cmdmode" of e.g. MODE_LONG into a FIELD_LONG_DEFAULT. Instead we can simply do those checks in the show_tree() function itself. Let's also make this code more future-proof by unrolling the hardcoded strmp() if/else if chain into something that checks a new "static struct" providing a bidirectional mapping between optimized formats and the ls_tree_cmdmode. A preceding commit removed "MODE_UNSPECIFIED", now there is a use for such a thing, as we'll need to add this to our mapping so we'll choose the "show_tree" fast-path here. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-tree.c | 98 ++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 528b4e5b5f6..820baddf9a9 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -23,25 +23,13 @@ static int ls_options; static struct pathspec pathspec; static int chomp_prefix; static const char *ls_tree_prefix; -#define FIELD_PATH_NAME 1 -#define FIELD_SIZE (1 << 1) -#define FIELD_OBJECT_NAME (1 << 2) -#define FIELD_TYPE (1 << 3) -#define FIELD_MODE (1 << 4) -#define FIELD_DEFAULT 29 /* 11101 size is not shown to output by default */ -#define FIELD_LONG_DEFAULT (FIELD_DEFAULT | FIELD_SIZE) static const char *format; -static const char *default_format = "%(objectmode) %(objecttype) %(objectname)%x09%(path)"; -static const char *long_format = "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)"; -static const char *name_only_format = "%(path)"; -static const char *object_only_format = "%(objectname)"; struct show_tree_data { unsigned mode; enum object_type type; const struct object_id *oid; const char *pathname; struct strbuf *base; - unsigned int shown_fields; }; static const char * const ls_tree_usage[] = { @@ -50,7 +38,8 @@ static const char * const ls_tree_usage[] = { }; static enum ls_tree_cmdmode { - MODE_LONG = 1, + MODE_DEFAULT = 0, + MODE_LONG, MODE_NAME_ONLY, MODE_NAME_STATUS, MODE_OBJECT_ONLY, @@ -122,25 +111,6 @@ static size_t expand_show_tree(struct strbuf *sb, const char *start, return len; } -static int parse_shown_fields(unsigned int *shown_fields) -{ - if (cmdmode == MODE_NAME_ONLY) { - *shown_fields = FIELD_PATH_NAME; - return 0; - } - if (cmdmode == MODE_OBJECT_ONLY) { - *shown_fields = FIELD_OBJECT_NAME; - return 0; - } - if (!ls_options || (ls_options & LS_RECURSIVE) - || (ls_options & LS_SHOW_TREES) - || (ls_options & LS_TREE_ONLY)) - *shown_fields = FIELD_DEFAULT; - if (cmdmode == MODE_LONG) - *shown_fields = FIELD_LONG_DEFAULT; - return 1; -} - static int show_recursive(const char *base, size_t baselen, const char *pathname) { int i; @@ -207,7 +177,7 @@ static int show_default(struct show_tree_data *data) { size_t baselen = data->base->len; - if (data->shown_fields & FIELD_SIZE) { + if (cmdmode == MODE_LONG) { char size_text[24]; if (data->type == OBJ_BLOB) { unsigned long size; @@ -240,14 +210,12 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, int recurse = 0; size_t baselen; enum object_type type = object_type(mode); - unsigned int shown_fields = *(unsigned int *)context; struct show_tree_data data = { .mode = mode, .type = type, .oid = oid, .pathname = pathname, .base = base, - .shown_fields = shown_fields, }; if (type == OBJ_BLOB) { @@ -260,12 +228,12 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, return recurse; } - if (shown_fields == FIELD_OBJECT_NAME) { + if (cmdmode == MODE_OBJECT_ONLY) { printf("%s%c", find_unique_abbrev(oid, abbrev), line_termination); return recurse; } - if (shown_fields == FIELD_PATH_NAME) { + if (cmdmode == MODE_NAME_ONLY) { baselen = base->len; strbuf_addstr(base, pathname); write_name_quoted_relative(base->buf, @@ -275,12 +243,40 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, return recurse; } - if (shown_fields>= FIELD_DEFAULT) + if (cmdmode == MODE_LONG || + (!ls_options || (ls_options & LS_RECURSIVE) + || (ls_options & LS_SHOW_TREES) + || (ls_options & LS_TREE_ONLY))) show_default(&data); return recurse; } +struct ls_tree_cmdmode_to_fmt { + enum ls_tree_cmdmode mode; + const char *const fmt; +}; + +static struct ls_tree_cmdmode_to_fmt ls_tree_cmdmode_format[] = { + { + .mode = MODE_DEFAULT, + .fmt = "%(objectmode) %(objecttype) %(objectname)%x09%(path)", + }, + { + .mode = MODE_LONG, + .fmt = "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)", + }, + { + .mode = MODE_NAME_ONLY, /* And MODE_NAME_STATUS */ + .fmt = "%(path)", + }, + { + .mode = MODE_OBJECT_ONLY, + .fmt = "%(objectname)", + }, + { 0 }, +}; + int cmd_ls_tree(int argc, const char **argv, const char *prefix) { struct object_id oid; @@ -367,25 +363,23 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) if (!tree) die("not a tree object"); - parse_shown_fields(&shown_fields); - /* * The generic show_tree_fmt() is slower than show_tree(), so * take the fast path if possible. */ - if (format && (!strcmp(format, default_format))) { - fn = show_tree; - } else if (format && (!strcmp(format, long_format))) { - shown_fields = shown_fields | FIELD_SIZE; - fn = show_tree; - } else if (format && (!strcmp(format, name_only_format))) { - shown_fields = FIELD_PATH_NAME; - fn = show_tree; - } else if (format && (!strcmp(format, object_only_format))) { - shown_fields = FIELD_OBJECT_NAME; - fn = show_tree; - } else if (format) + if (format) { + struct ls_tree_cmdmode_to_fmt *m2f; + fn = show_tree_fmt; + for (m2f = ls_tree_cmdmode_format; m2f->fmt; m2f++) { + if (strcmp(format, m2f->fmt)) + continue; + + cmdmode = m2f->mode; + fn = show_tree; + break; + } + } return !!read_tree(the_repository, tree, &pathspec, fn, &shown_fields); } From patchwork Thu Mar 10 13:57:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12776378 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 EC810C433F5 for ; Thu, 10 Mar 2022 13:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242628AbiCJN6Y (ORCPT ); Thu, 10 Mar 2022 08:58:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242613AbiCJN6R (ORCPT ); Thu, 10 Mar 2022 08:58:17 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E6014FFE8 for ; Thu, 10 Mar 2022 05:57:16 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id k24so8100804wrd.7 for ; Thu, 10 Mar 2022 05:57:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G7bL6ceVt6iAEb99wmEoga3LhCUbEOglmpmv1Xai/FA=; b=Jl9HOWGKfCRsSnPe1GRKKETGAjCELinDQq0wOVBvsSw4a/RvkAqtMDSTSQnuw1M+DP IJA1nM3sHXByQVBb3IDMdhslOBJWB3n5Gax0hR+ZtaXvfX5Eh3EBwYMsUJmxmAFWh3nA GKgRB0wl42RO2C88djcNezAwVb/A+vJD+8h4TVNZiD/zwncm0dhLco9eVsxaoSFntapX mc+/uEk08RQWNbx/8ImnhIhlpBGy97WNBALGbkRjFgVvegZw2nDwVtmXiwk9Vhy+FAyO 8JfANpIGw9D8MxkoLRvOct+avgLrQ/WYJumcN9Gcj2vEvDrdPykw9ypsYbFiHCHxSNLu PtLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G7bL6ceVt6iAEb99wmEoga3LhCUbEOglmpmv1Xai/FA=; b=qsb8eeIhF/FLcp7hz6R7f1MO2/VEPTu49fAkQMW5UsmYVj81JItZ4XRukB19P/KUUK LH0mTJ/05VW6xvNEaw9IoAqEO+NyxVhTPqletoH9ueTfx72+gJ3LuMd4rPVzuzvGdmX+ QA0HWOj3wkbMPc0/HcVBR2MNcla+2UN6XZ+XXc1hhV/Ims80XNpbYQQR1A3vrR2SaLHV Gffm8Sia1ffPRGqRoYuUp8ei7dg77wPwA/2R+QZTGHqZgg47DhsI7Vs2GEypKqN1zb01 9BIVQqTWtE6OQvrVygWUUfAhc5pxVmbC57xc6zb24bzThR9kYaLyVXe9UVjeDpINNbN6 vUkg== X-Gm-Message-State: AOAM533TcpJc+OuqsmgFkn2MKva5u4Y5YcAQrzfa6Ad8knlo/qtczbER k5Zi0WqH3Of1wFCnq5vCRzO845qRx8RsUg== X-Google-Smtp-Source: ABdhPJxcfl9fpA3lFe6lZHtGQ1ivqeLDWOXHExZ9Dxz0wjY0hrQfzOjIPQoZNq2n7OHm5ddFWKNjmA== X-Received: by 2002:adf:fcd0:0:b0:1ef:31fe:d08e with SMTP id f16-20020adffcd0000000b001ef31fed08emr3559490wrs.667.1646920634517; Thu, 10 Mar 2022 05:57:14 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p2-20020a1c7402000000b0038159076d30sm7737162wmc.22.2022.03.10.05.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 05:57:13 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Teng Long , Johannes.Schindelin@gmx.de, congdanhqx@gmail.com, tenglong.tl@alibaba-inc.com, =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC/REVIEW 7/7] ls-tree: split up "fast path" callbacks Date: Thu, 10 Mar 2022 14:57:03 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1295.g6b025d3e231 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make the various if/else in the callbacks for the "fast path" a lot easier to read by just using common functions for the parts that are common, and have per-format callbacks for those parts that are different. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-tree.c | 198 +++++++++++++++++++++++++++++----------------- 1 file changed, 124 insertions(+), 74 deletions(-) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 820baddf9a9..ee69b8c2702 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -173,108 +173,157 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base, return recurse; } -static int show_default(struct show_tree_data *data) +static int show_tree_common(struct show_tree_data *data, int *recurse, + const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode) { - size_t baselen = data->base->len; - - if (cmdmode == MODE_LONG) { - char size_text[24]; - if (data->type == OBJ_BLOB) { - unsigned long size; - if (oid_object_info(the_repository, data->oid, &size) == OBJ_BAD) - xsnprintf(size_text, sizeof(size_text), "BAD"); - else - xsnprintf(size_text, sizeof(size_text), - "%" PRIuMAX, (uintmax_t)size); - } else { - xsnprintf(size_text, sizeof(size_text), "-"); - } - printf("%06o %s %s %7s\t", data->mode, type_name(data->type), - find_unique_abbrev(data->oid, abbrev), size_text); - } else { - printf("%06o %s %s\t", data->mode, type_name(data->type), - find_unique_abbrev(data->oid, abbrev)); - } - baselen = data->base->len; - strbuf_addstr(data->base, data->pathname); - write_name_quoted_relative(data->base->buf, - chomp_prefix ? ls_tree_prefix : NULL, stdout, - line_termination); - strbuf_setlen(data->base, baselen); - return 1; -} - -static int show_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, void *context) -{ - int recurse = 0; - size_t baselen; enum object_type type = object_type(mode); - struct show_tree_data data = { - .mode = mode, - .type = type, - .oid = oid, - .pathname = pathname, - .base = base, - }; + int ret = -1; + + *recurse = 0; + data->mode = mode; + data->type = type; + data->oid = oid; + data->pathname = pathname; + data->base = base; if (type == OBJ_BLOB) { if (ls_options & LS_TREE_ONLY) - return 0; + ret = 0; } else if (type == OBJ_TREE && show_recursive(base->buf, base->len, pathname)) { - recurse = READ_TREE_RECURSIVE; + *recurse = READ_TREE_RECURSIVE; if (!(ls_options & LS_SHOW_TREES)) - return recurse; + ret = *recurse; } - if (cmdmode == MODE_OBJECT_ONLY) { - printf("%s%c", find_unique_abbrev(oid, abbrev), line_termination); - return recurse; - } + return ret; +} - if (cmdmode == MODE_NAME_ONLY) { - baselen = base->len; - strbuf_addstr(base, pathname); - write_name_quoted_relative(base->buf, - chomp_prefix ? ls_tree_prefix : NULL, - stdout, line_termination); - strbuf_setlen(base, baselen); - return recurse; +static void show_tree_common_default_long(struct strbuf *base, + const char *pathname, + const size_t baselen) +{ + strbuf_addstr(base, pathname); + write_name_quoted_relative(base->buf, + chomp_prefix ? ls_tree_prefix : NULL, stdout, + line_termination); + strbuf_setlen(base, baselen); +} + +static int show_tree_default(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, + void *context) +{ + int early; + int recurse; + struct show_tree_data data = { 0 }; + + early = show_tree_common(&data, &recurse, oid, base, pathname, mode); + if (early >= 0) + return early; + + printf("%06o %s %s\t", data.mode, type_name(data.type), + find_unique_abbrev(data.oid, abbrev)); + show_tree_common_default_long(base, pathname, data.base->len); + return recurse; +} + +static int show_tree_long(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, void *context) +{ + int early; + int recurse; + struct show_tree_data data = { 0 }; + char size_text[24]; + + early = show_tree_common(&data, &recurse, oid, base, pathname, mode); + if (early >= 0) + return early; + + if (data.type == OBJ_BLOB) { + unsigned long size; + if (oid_object_info(the_repository, data.oid, &size) == OBJ_BAD) + xsnprintf(size_text, sizeof(size_text), "BAD"); + else + xsnprintf(size_text, sizeof(size_text), + "%" PRIuMAX, (uintmax_t)size); + } else { + xsnprintf(size_text, sizeof(size_text), "-"); } - if (cmdmode == MODE_LONG || - (!ls_options || (ls_options & LS_RECURSIVE) - || (ls_options & LS_SHOW_TREES) - || (ls_options & LS_TREE_ONLY))) - show_default(&data); + printf("%06o %s %s %7s\t", data.mode, type_name(data.type), + find_unique_abbrev(data.oid, abbrev), size_text); + show_tree_common_default_long(base, pathname, data.base->len); + return 1; +} +static int show_tree_name_only(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, void *context) +{ + int early; + int recurse; + const size_t baselen = base->len; + struct show_tree_data data = { 0 }; + + early = show_tree_common(&data, &recurse, oid, base, pathname, mode); + if (early >= 0) + return early; + + strbuf_addstr(base, pathname); + write_name_quoted_relative(base->buf, + chomp_prefix ? ls_tree_prefix : NULL, + stdout, line_termination); + strbuf_setlen(base, baselen); + return recurse; +} + +static int show_tree_object(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, void *context) +{ + int early; + int recurse; + struct show_tree_data data = { 0 }; + + early = show_tree_common(&data, &recurse, oid, base, pathname, mode); + if (early >= 0) + return early; + + printf("%s%c", find_unique_abbrev(oid, abbrev), line_termination); return recurse; } struct ls_tree_cmdmode_to_fmt { enum ls_tree_cmdmode mode; const char *const fmt; + read_tree_fn_t fn; }; static struct ls_tree_cmdmode_to_fmt ls_tree_cmdmode_format[] = { { .mode = MODE_DEFAULT, .fmt = "%(objectmode) %(objecttype) %(objectname)%x09%(path)", + .fn = show_tree_default, }, { .mode = MODE_LONG, .fmt = "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)", + .fn = show_tree_long, }, { .mode = MODE_NAME_ONLY, /* And MODE_NAME_STATUS */ .fmt = "%(path)", + .fn = show_tree_name_only, }, { .mode = MODE_OBJECT_ONLY, .fmt = "%(objectname)", + .fn = show_tree_object + }, + { + /* fallback */ + .fn = show_tree_default, }, - { 0 }, }; int cmd_ls_tree(int argc, const char **argv, const char *prefix) @@ -283,7 +332,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) struct tree *tree; int i, full_tree = 0; unsigned int shown_fields = 0; - read_tree_fn_t fn = show_tree; + read_tree_fn_t fn = NULL; const struct option ls_tree_options[] = { OPT_BIT('d', NULL, &ls_options, N_("only show trees"), LS_TREE_ONLY), @@ -312,6 +361,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) OPT__ABBREV(&abbrev), OPT_END() }; + struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format; git_config(git_default_config, NULL); ls_tree_prefix = prefix; @@ -367,18 +417,18 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) * The generic show_tree_fmt() is slower than show_tree(), so * take the fast path if possible. */ - if (format) { - struct ls_tree_cmdmode_to_fmt *m2f; - - fn = show_tree_fmt; - for (m2f = ls_tree_cmdmode_format; m2f->fmt; m2f++) { - if (strcmp(format, m2f->fmt)) - continue; - + while (m2f++) { + if (!m2f->fmt) { + fn = format ? show_tree_fmt : show_tree_default; + } else if (format && !strcmp(format, m2f->fmt)) { cmdmode = m2f->mode; - fn = show_tree; - break; + fn = m2f->fn; + } else if (!format && cmdmode == m2f->mode) { + fn = m2f->fn; + } else { + continue; } + break; } return !!read_tree(the_repository, tree, &pathspec, fn, &shown_fields);