From patchwork Wed Nov 4 17:47:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2A70C2D0A3 for ; Wed, 4 Nov 2020 17:47:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FC7B2067B for ; Wed, 4 Nov 2020 17:47:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cVmHlpai" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730859AbgKDRrW (ORCPT ); Wed, 4 Nov 2020 12:47:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730773AbgKDRrV (ORCPT ); Wed, 4 Nov 2020 12:47:21 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52901C0613D3 for ; Wed, 4 Nov 2020 09:47:21 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id l36so12097849ota.4 for ; Wed, 04 Nov 2020 09:47:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jX1I/11xj2Js1SC6Xf3WAOTlZscFqgixgujNsZTgEKU=; b=cVmHlpaiBPGX5rj4v1m78GDcUQWX3N6ZpGmZFMlxfn3bwqbFDNbVaWtdvnVrURsT+y gSaET/E3bhqKkBJgk2O78w+o13tm0ansktoAD0ANs/YRPUHizfeq3/M1qF7Mm53bRgDY 8n6BxsRFFwqThoVVccVJPJnrDSNZ3gOHez3Dw9MDefEWhNcuesHsU4EYklGObaXgRq7F 9MVOMm/dI3wZo/xWbxfbSJCOGJT30sxymbM7q4om4zx3IT2lDGL41amiUTL7OFpim+mi EMygMa9v+arjSXZC3zR6cFsbpOYNZcRlb6hU89dBGo7pXiyBuqmUCOa66QpzK+sKGUCr LARA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jX1I/11xj2Js1SC6Xf3WAOTlZscFqgixgujNsZTgEKU=; b=D0aLI6L0slJAfbRKy8EFl3ENXwrmbLOU8avePQgPFz0drA1la3OyDwik1ikpNAk6K9 qhvlCUKyVMJ1URG1konFuotm04OiOGiAvLhRINIyBCPy5IAig9ftoAsiVW30ALr3FVWX V6fripKbEh0BC7NvPCwYq1tMNF0eCDaF5O+NMm3hcw6pZ9hvUbG0o40Wbb9uHeXnSVT5 KaQ2hClZYaBCS+AWRXI4/e1krfc0UMhZBKHbx+pTofxjoIWjoBysAvIEN05sHL5iVBR0 GMNBC+8JXqSI4ijtrngM59acEzF5KWHgi6YDMSkhYghSlB3xBd2lYO/JzXH+Mv39RuY2 c3pg== X-Gm-Message-State: AOAM533pm8iFYDAlmCQagyxrrWdUP1sJlvuQXuuAXTFmXkh4vUT8FG9d tu6rECWmwRIJr+FBAsm9SD8QCo+WIOfwPQ== X-Google-Smtp-Source: ABdhPJxm8eFzCvUyX1GwHbdSSlxlkv/t0uL86p6btXfla+FXhugCEfZyaVE6pub9OubgEIvefXmvwQ== X-Received: by 2002:a9d:d73:: with SMTP id 106mr3152901oti.36.1604512040478; Wed, 04 Nov 2020 09:47:20 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id 8sm607872oii.45.2020.11.04.09.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:19 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 01/10] test: completion: add run_func() helper Date: Wed, 4 Nov 2020 11:47:07 -0600 Message-Id: <20201104174716.783348-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Pretty straightforward: runs functions. Signed-off-by: Felipe Contreras --- t/t9902-completion.sh | 58 ++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 7b7bc6e4bd..ab5134cdcc 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -75,6 +75,12 @@ run_completion () __git_wrap__git_main && print_comp } +run_func () +{ + local -a COMPREPLY && + "$@" && print_comp +} + # Test high-level completion # Arguments are: # 1: typed text so far (cur) @@ -452,8 +458,7 @@ test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' ' EOF ( cur=should_be_ignored && - __gitcomp_direct "$(cat expected)" && - print_comp + run_func __gitcomp_direct "$(cat expected)" ) && test_cmp expected out ' @@ -538,7 +543,7 @@ test_expect_success '__gitcomp - expand/narrow all negative options' ' ' test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' - __gitcomp "$invalid_variable_name" + run_func __gitcomp "$invalid_variable_name" ' read -r -d "" refs <<-\EOF @@ -577,7 +582,7 @@ test_expect_success '__gitcomp_nl - no suffix' ' ' test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' ' - __gitcomp_nl "$invalid_variable_name" + run_func __gitcomp_nl "$invalid_variable_name" ' test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' ' @@ -1077,8 +1082,7 @@ test_expect_success '__git_complete_refs - simple' ' EOF ( cur= && - __git_complete_refs && - print_comp + run_func __git_complete_refs ) && test_cmp expected out ' @@ -1090,8 +1094,7 @@ test_expect_success '__git_complete_refs - matching' ' EOF ( cur=mat && - __git_complete_refs && - print_comp + run_func __git_complete_refs ) && test_cmp expected out ' @@ -1104,8 +1107,7 @@ test_expect_success '__git_complete_refs - remote' ' EOF ( cur= && - __git_complete_refs --remote=other && - print_comp + run_func __git_complete_refs --remote=other ) && test_cmp expected out ' @@ -1123,8 +1125,7 @@ test_expect_success '__git_complete_refs - track' ' EOF ( cur= && - __git_complete_refs --track && - print_comp + run_func __git_complete_refs --track ) && test_cmp expected out ' @@ -1136,8 +1137,7 @@ test_expect_success '__git_complete_refs - current word' ' EOF ( cur="--option=mat" && - __git_complete_refs --cur="${cur#*=}" && - print_comp + run_func __git_complete_refs --cur="${cur#*=}" ) && test_cmp expected out ' @@ -1149,8 +1149,7 @@ test_expect_success '__git_complete_refs - prefix' ' EOF ( cur=v1.0..mat && - __git_complete_refs --pfx=v1.0.. --cur=mat && - print_comp + run_func __git_complete_refs --pfx=v1.0.. --cur=mat ) && test_cmp expected out ' @@ -1166,8 +1165,7 @@ test_expect_success '__git_complete_refs - suffix' ' EOF ( cur= && - __git_complete_refs --sfx=. && - print_comp + run_func __git_complete_refs --sfx=. ) && test_cmp expected out ' @@ -1180,8 +1178,7 @@ test_expect_success '__git_complete_fetch_refspecs - simple' ' EOF ( cur= && - __git_complete_fetch_refspecs other && - print_comp + run_func __git_complete_fetch_refspecs other ) && test_cmp expected out ' @@ -1192,8 +1189,7 @@ test_expect_success '__git_complete_fetch_refspecs - matching' ' EOF ( cur=br && - __git_complete_fetch_refspecs other "" br && - print_comp + run_func __git_complete_fetch_refspecs other "" br ) && test_cmp expected out ' @@ -1206,8 +1202,7 @@ test_expect_success '__git_complete_fetch_refspecs - prefix' ' EOF ( cur="+" && - __git_complete_fetch_refspecs other "+" "" && - print_comp + run_func __git_complete_fetch_refspecs other "+" "" ) && test_cmp expected out ' @@ -1220,8 +1215,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' EOF ( cur=refs/ && - __git_complete_fetch_refspecs other "" refs/ && - print_comp + run_func __git_complete_fetch_refspecs other "" refs/ ) && test_cmp expected out ' @@ -1234,8 +1228,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' EOF ( cur=+refs/ && - __git_complete_fetch_refspecs other + refs/ && - print_comp + run_func __git_complete_fetch_refspecs other + refs/ ) && test_cmp expected out ' @@ -1714,8 +1707,7 @@ test_path_completion () # unusual characters in path names. By requesting only # untracked files we do not have to bother adding any # paths to the index in those tests. - __git_complete_index_file --others && - print_comp + run_func __git_complete_index_file --others ) && test_cmp expected out } @@ -2200,8 +2192,7 @@ do ( words=(git push '$flag' other ma) && cword=${#words[@]} cur=${words[cword-1]} && - __git_complete_remote_or_refspec && - print_comp + run_func __git_complete_remote_or_refspec ) && test_cmp expected out ' @@ -2213,8 +2204,7 @@ do ( words=(git push other '$flag' ma) && cword=${#words[@]} cur=${words[cword-1]} && - __git_complete_remote_or_refspec && - print_comp + run_func __git_complete_remote_or_refspec ) && test_cmp expected out ' From patchwork Wed Nov 4 17:47:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EA11C4742C for ; Wed, 4 Nov 2020 17:47:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7E6C206B7 for ; Wed, 4 Nov 2020 17:47:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i/5YWRhx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730879AbgKDRrY (ORCPT ); Wed, 4 Nov 2020 12:47:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbgKDRrX (ORCPT ); Wed, 4 Nov 2020 12:47:23 -0500 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30B7EC0613D3 for ; Wed, 4 Nov 2020 09:47:23 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id u127so23009370oib.6 for ; Wed, 04 Nov 2020 09:47:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gICJVCMqfDrg885NseUjxrp8f2rqBBXCJDy5po/R+oA=; b=i/5YWRhxRYqWKuYYQ6lTaSFdBVw+0xnJ2Y2I+GYCKmXGLcb/ekMqJLA37A4v+MS92k za3ff5y1JbASmGZxFj/JG+NKGB37v5THg2t10Tutk71oe4NoQz2RI0vuLCo/8d/+7f4A XBF+Wmd1Rge8BW8KXTj2Jnz5eRCwGU6WHxgfrTW8QtPBP2sRyckyjEiXnt/ATkr7sY9h UL+FaBRy5b9eSA48TNIM5Ei/A0jZRvKSqeabF/9IVZfE2TR05f7MUxs6UmtQJp/9aikS bIXEk2mdFEhZ7oacuHaxZWa5cxE2B/zXYyI2u6DUPXMprmVtiMpesYA8jaIwtfJAW37r UGmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gICJVCMqfDrg885NseUjxrp8f2rqBBXCJDy5po/R+oA=; b=q8xK72vsScOirhaUd+X1TEnTKcKjp9gPAO9N8DdE6h+oUlxeFi8MBBimBA5yxw+XMZ MI72HRY7Elp24O6IoNUZ+311Wlqp1TPkaPdsQs/k9d/8X5Y1bnYjkDkDlJqEfpS8OzE6 r6ztjrr4kK/UGkKlWeBHIL9p2cs2XHFrYqV7iI/ckZQJ5JayrIcrxW6A9OkbehvVQLFO 6EXvxU98JR47EWfL1wgsjeLhuCiZfZ9VoJCTvEFynmuGe4yGyhO4Ob4nzPMcqDz2fOt7 JDWL86z2k2Mx7DvCaTbk01feOy7EVGeCtuLwhDyCUK0ZLa8PBnKWOnIvAG4H4r8P+q2d Sncg== X-Gm-Message-State: AOAM530U5BfMHmXYjphRZvGVKlIpKQRFGmSUJnP0nZwbL6f6YGj1u7BS y/Ak52HSxxnrqoGMTvHnP/PZ2h5kkZneew== X-Google-Smtp-Source: ABdhPJwW3VjsPc52/A9lKocN5f0zfew9xoUC4DhNslNO75JR6YRl5P19oLTsGKBDvXbuf30XY8wIDw== X-Received: by 2002:aca:1e09:: with SMTP id m9mr3376876oic.60.1604512042302; Wed, 04 Nov 2020 09:47:22 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id 76sm628962oty.15.2020.11.04.09.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:21 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 02/10] completion: bash: remove non-append functionality Date: Wed, 4 Nov 2020 11:47:08 -0600 Message-Id: <20201104174716.783348-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no point in setting COMPREPLY only to override it later, and in fact; we don't do that. Therefore there's no functional difference between __gitcomp_direct() and __gitcomp_direct_append(), since __gitcomp_direct() *always* operates on empty COMPREPLY. The same goes for __gitcomp_nl(). This patch makes the functionality of append and non-append functions the same. There should be no functional changes. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a96ad87e7..87762dc33e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -303,7 +303,7 @@ __gitcomp_direct () { local IFS=$'\n' - COMPREPLY=($1) + COMPREPLY+=($1) } # Similar to __gitcomp_direct, but appends to COMPREPLY instead. @@ -456,7 +456,6 @@ __gitcomp_nl_append () # appended. __gitcomp_nl () { - COMPREPLY=() __gitcomp_nl_append "$@" } From patchwork Wed Nov 4 17:47:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE2CEC4741F for ; Wed, 4 Nov 2020 17:47:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FCBA206B7 for ; Wed, 4 Nov 2020 17:47:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LY0FIi24" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730883AbgKDRr0 (ORCPT ); Wed, 4 Nov 2020 12:47:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731194AbgKDRrY (ORCPT ); Wed, 4 Nov 2020 12:47:24 -0500 Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B66D5C0613D3 for ; Wed, 4 Nov 2020 09:47:24 -0800 (PST) Received: by mail-oo1-xc2e.google.com with SMTP id q1so827189oot.4 for ; Wed, 04 Nov 2020 09:47:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hND/JECgqF1QaVlTxCzjJX+h0Q4eNFhd8tsBiwEFwZ4=; b=LY0FIi24OgYdUTwuR64OANMVaYrNAoyvmlE8k9nYDjB86GyQZv24uiC04II3ZT/OeQ QCU5vw48VKmqYaYaArVe/KMmd7Mbvilqzv8ZUjnjLf0GwwipKJPbS2jGYSzWBF4GrmrB kYqtQppYWlrgJt38gJmrCPS4b2eYBYle/h/sLOszRdbbB7Ev+C40SgxcqYzXo590XV73 KyKjK7/BRY6GcMRJN+ImYovrFULAp3pcJ7wX9NOVAQ3vZbhY9sqKkTyE5nZ2ahHQTANo ZTBQivuuFQoh+eRM+5ZaoYdKZDca9QEkeAbLHzl/G57s4UNUoTbLLI0KY+pNItdHhyrh fwdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hND/JECgqF1QaVlTxCzjJX+h0Q4eNFhd8tsBiwEFwZ4=; b=bvcvPhTVu2tQePKdXx2XGAEKZglBrdB1dOyXsf4JrNOE5hCJTTdG8MF3XiI2+gmYrw CnKoh1Hd2Mtcmeam0AfBZnHsgUyCA/L+oxphGOFHdCDgi9pSLVERxTqiFrGFYwzFkdiA wZYpnfsvo4TvBiewfhxX9JAMpotGNYUbiv0DG4wST/adFhsFuQAw5aq3x+Q6HfwB8+5a 7e8GrxdnDavbPQvxXHJ2VQ86aZNOSAe1eKsf3AvbX8SELhamK2ayEii514XWW5+ISBvw dvPVSJxgO/m9vijSG7uHo+PrSI9A1xYqqymHY+91Sw6675rCi9q08SpNVTa1T1NJRMV5 tUqg== X-Gm-Message-State: AOAM532laHMEBKZ4a9UDEqB3EzJz3LI+x1sduUmLpchMO8lf2lXTMM0b /kmBlW/bVqiCtmYbLepvdy27aBv142BAfA== X-Google-Smtp-Source: ABdhPJwRprhXEDWTx6hhszJd9uPj2Zx9pw8IfNkMWEiJI4CHlHsKJE4vWBlBW8wNh7Lr5GHmMuUESg== X-Received: by 2002:a05:6820:345:: with SMTP id m5mr19752244ooe.59.1604512043908; Wed, 04 Nov 2020 09:47:23 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id l204sm589848oia.32.2020.11.04.09.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:23 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 03/10] completion: bash: get rid of _append() functions Date: Wed, 4 Nov 2020 11:47:09 -0600 Message-Id: <20201104174716.783348-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no need to have duplicated functionality. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 35 ++++++-------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 87762dc33e..80701749fa 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -292,8 +292,7 @@ _get_comp_words_by_ref () } fi -# Fills the COMPREPLY array with prefiltered words without any additional -# processing. +# Appends prefiltered words to COMPREPLY without any additional processing. # Callers must take care of providing only words that match the current word # to be completed and adding any prefix and/or suffix (trailing space!), if # necessary. @@ -306,19 +305,6 @@ __gitcomp_direct () COMPREPLY+=($1) } -# Similar to __gitcomp_direct, but appends to COMPREPLY instead. -# Callers must take care of providing only words that match the current word -# to be completed and adding any prefix and/or suffix (trailing space!), if -# necessary. -# 1: List of newline-separated matching completion words, complete with -# prefix and suffix. -__gitcomp_direct_append () -{ - local IFS=$'\n' - - COMPREPLY+=($1) -} - __gitcompappend () { local x i=${#COMPREPLY[@]} @@ -437,16 +423,8 @@ __gitcomp_builtin () __gitcomp "$options" } -# Variation of __gitcomp_nl () that appends to the existing list of -# completion candidates, COMPREPLY. -__gitcomp_nl_append () -{ - local IFS=$'\n' - __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" -} - # Generates completion reply from newline-separated possible completion words -# by appending a space to all of them. +# by appending a space to all of them. The result is appended to COMPREPLY. # It accepts 1 to 4 arguments: # 1: List of possible completion words, separated by a single newline. # 2: A prefix to be added to each possible completion word (optional). @@ -456,7 +434,8 @@ __gitcomp_nl_append () # appended. __gitcomp_nl () { - __gitcomp_nl_append "$@" + local IFS=$'\n' + __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" } # Fills the COMPREPLY array with prefiltered paths without any additional @@ -843,7 +822,7 @@ __git_complete_refs () # Append DWIM remote branch names if requested if [ "$dwim" = "yes" ]; then - __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")" + __gitcomp_direct "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")" fi } @@ -2615,7 +2594,7 @@ __git_complete_config_variable_name () local pfx="${cur%.*}." cur_="${cur#*.}" __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")" - __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx" + __gitcomp_nl $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx" return ;; guitool.*.*) @@ -2665,7 +2644,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." - __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx" + __gitcomp_nl "pushDefault" "$pfx" "$cur_" "$sfx" return ;; url.*.*) From patchwork Wed Nov 4 17:47:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69BA3C4742C for ; Wed, 4 Nov 2020 17:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16907206B7 for ; Wed, 4 Nov 2020 17:47:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aV8Az+uq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731333AbgKDRr2 (ORCPT ); Wed, 4 Nov 2020 12:47:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730775AbgKDRr0 (ORCPT ); Wed, 4 Nov 2020 12:47:26 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BCF8C0613D4 for ; Wed, 4 Nov 2020 09:47:26 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id l36so12098074ota.4 for ; Wed, 04 Nov 2020 09:47:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=83PgvcvU7eSvLs78eT0hKzmYz6NLov2wKU8Q35kGPHY=; b=aV8Az+uqlt2ahm3ISYDpn4x5Mkf1miRHjr+qEez0N0W1/1QLC8AG/gafLRk3hqS+KP jYEIuIXFANRSl45YOkBsaYx59X84t1VK2IaalQpRZ3pfNLz+3OYz9AEBBx8aOJIqdN68 9EgfR1RsqbzPGRzVcfqObbTFm9qtkA+sy6f7Xr579yLjTyR1CK60mdE96y/RrFOrW+Pr +uDT7B6AXdiKofEN8+8Q8COPO8emdDXJc38tRjbC541sqn9tYzQ9NYxppdaByeFQkeXB rEu+NTYViJpk2sd7Q/RvaPjFzjSI14oAitX5DaGcMLADFqYuu3HT6WbLDccqx5gJiy3s 8jHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=83PgvcvU7eSvLs78eT0hKzmYz6NLov2wKU8Q35kGPHY=; b=pxuoyIXFvaki7Ljnl1IeRObk5xoF8o2/GHJIf+jt1wzk5F8cJCCNr2aKe5CuKiS5ZV cmnlzlN/F7nky6DbwbAQYwIQz9H8soyMm2tldX6Sz/7Id87ZQ3M/c8B/jRc4ZSDzPyy/ l3EP9roSzpSzu2NQdVtvQMYAJcHuhhLfSdsxlqdjMzKQsuDq+uxzr+hRhxfzLO0xFRfH 87djXvwhGMXpWa829MdojpmGaX+phBvQv5K7rRjDkaV5C3pYP1PDtfl0+Lpr/vTUCD9Y tTlGCs6zHYmZtqKb0pf2V5a1uz7xgS7vALkKexsoegkTWA/p8T6GBg0XbGoZUCIHlMY+ 7Z7g== X-Gm-Message-State: AOAM532GkSQLO7VZFqMXAk7NunuYF8Rgf7/1hhlXve76h1jxH3BjKi5R nbv50QKst9TCUT0umyvAu/VJ1Ph04FRSng== X-Google-Smtp-Source: ABdhPJw0ES0ATcSI2gNBKsvEIl7+x4H6IlKn/1Y98g3WSacELWvhCGGhOS55Wh/t3jAiKyLISl8gmQ== X-Received: by 2002:a9d:73cb:: with SMTP id m11mr20285956otk.128.1604512045643; Wed, 04 Nov 2020 09:47:25 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id l9sm621583otn.53.2020.11.04.09.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:25 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 04/10] completion: bash: get rid of any non-append code Date: Wed, 4 Nov 2020 11:47:10 -0600 Message-Id: <20201104174716.783348-5-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 80701749fa..9f384698f2 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -315,12 +315,6 @@ __gitcompappend () done } -__gitcompadd () -{ - COMPREPLY=() - __gitcompappend "$@" -} - # Generates completion reply, appending a space to possible completion words, # if necessary. # It accepts 1 to 4 arguments: @@ -448,7 +442,7 @@ __gitcomp_file_direct () { local IFS=$'\n' - COMPREPLY=($1) + COMPREPLY+=($1) # use a hack to enable file mode in bash < 4 compopt -o filenames +o nospace 2>/dev/null || @@ -471,7 +465,7 @@ __gitcomp_file () # since tilde expansion is not applied. # This means that COMPREPLY will be empty and Bash default # completion will be used. - __gitcompadd "$1" "${2-}" "${3-$cur}" "" + __gitcompappend "$1" "${2-}" "${3-$cur}" "" # use a hack to enable file mode in bash < 4 compopt -o filenames +o nospace 2>/dev/null || From patchwork Wed Nov 4 17:47:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9943FC2D0A3 for ; Wed, 4 Nov 2020 17:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 536492067B for ; Wed, 4 Nov 2020 17:47:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PowITBqf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732109AbgKDRr3 (ORCPT ); Wed, 4 Nov 2020 12:47:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732066AbgKDRr2 (ORCPT ); Wed, 4 Nov 2020 12:47:28 -0500 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A7D6C0613D3 for ; Wed, 4 Nov 2020 09:47:28 -0800 (PST) Received: by mail-ot1-x341.google.com with SMTP id g19so10646580otp.13 for ; Wed, 04 Nov 2020 09:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Wu893TP6PVjXtaNUZYYu4R2pJ7LfNrKwBcdWIwyccw=; b=PowITBqfMARr+pxGd8W0/q/WIU8a2P6drl4EY65UbuJCq9eNbI/jeAJD0iAd4TSrtI Q8t+002oefIYsDHhpwNVJvbzYV/6QyDwcX2eAY6uAxFfS5YeF1pTnHjJ+IYAXrBJZ3my 2PtJB4v7uxtW/+Wixiprjnc9snXj+RwOaTumUsh0CCEt17SRzblvnLxw23um/Us0gCZr AqJM9ZaPWfNkLCMgBl8HwTPtnjYss8BQJMayRfZDLJkaBZ0CmWEDPf7MZ5U7SQ+r/GlE sS+ZGavfGY34YzVYRtHlWIFODABQ7by7sSbA83UY//gDAGreu1gCjW/lZ6l6W4OLuEtB Pfyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Wu893TP6PVjXtaNUZYYu4R2pJ7LfNrKwBcdWIwyccw=; b=Qbtm8+gpSh9orgiCIQeC0YFoVZ+6hbOAbNv2AJGLLJ5z1/69xSWJSNpPyQIjymp6FZ DfdkFOzQju+Up+3vqLAU/EyFtLw7OHmc9ku6F6tTFGEBa0t0yY9h7Y2HfKvJtdFW3i8y waBsD7offsmcF0gD+wZ7m1YV26NofnI3jJv+q6Mf9YVzn+h6pL37se8aAepdkOGP8Cqd dg51nDqb65xgey9PkdwcgBFK4s1fJcHHcqeBWgXMv+igblv4tbyhVu0RvRSL5VAQkqb7 o8tnKmT1nHToonWHo/lQvxEce/3ztXDV634fAC0XPM0/2vSM6EvBIN+ZyRuoEuTzrMCB CfwQ== X-Gm-Message-State: AOAM533Qe4XkkhQKcEQ7px01gUzM8y44Hjn5aZkWeZmSXYp2t79+sZoS NdvSYBsqToANm7REkR7iJY1GRGAg97zlUw== X-Google-Smtp-Source: ABdhPJxaNh/n6I9CcidfErXkd1vwaCTquWj7oMFnS98ipKPjhKRELDODX8XDbcnN+cHVoMSp78US8g== X-Received: by 2002:a9d:3d3:: with SMTP id f77mr4164846otf.125.1604512047477; Wed, 04 Nov 2020 09:47:27 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t6sm687955ooo.22.2020.11.04.09.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:26 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 05/10] completion: bash: do not modify COMP_WORDBREAKS Date: Wed, 4 Nov 2020 11:47:11 -0600 Message-Id: <20201104174716.783348-6-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There was no need for this once __git_reassemble_comp_words_by_ref() was introduced. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 5 ----- 1 file changed, 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 9f384698f2..90202e11a4 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -45,11 +45,6 @@ # When set to "1" suggest all options, including options which are # typically hidden (e.g. '--allow-empty' for 'git commit'). -case "$COMP_WORDBREAKS" in -*:*) : great ;; -*) COMP_WORDBREAKS="$COMP_WORDBREAKS:" -esac - # Discovers the path to the git repository taking any '--git-dir=' and # '-C ' options into account and stores it in the $__git_repo_path # variable. From patchwork Wed Nov 4 17:47:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 468A5C388F9 for ; Wed, 4 Nov 2020 17:47:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2CF42067B for ; Wed, 4 Nov 2020 17:47:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U4f81O0x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732113AbgKDRrb (ORCPT ); Wed, 4 Nov 2020 12:47:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730685AbgKDRra (ORCPT ); Wed, 4 Nov 2020 12:47:30 -0500 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B829C0613D3 for ; Wed, 4 Nov 2020 09:47:30 -0800 (PST) Received: by mail-oi1-x22a.google.com with SMTP id s21so23071143oij.0 for ; Wed, 04 Nov 2020 09:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N7CI/ZykoKzaO59Xhwn/2SBndJ4CIFMdgttXarqFQHk=; b=U4f81O0x62WLfE1ZWbJXdd7X/rL8LWz7MGTqKoJs/jieB7SmGd80+MC/iQzMXQPzkz oQZuRcRtaLj8NxVzk/ytgzjkDQP4+5d9Vx9+UzWRlOwOUYKSgAKeXqUWy1VKl71OqAVY ykzFjNrhxxTDFstrXtfNoqaorgh4XGUiZOmIQbLlqyPQpem7/QF0mP54xlgvxDyCu6r7 PwtffOxOX2ktY9AC1798G7K1loh9yov69LpLuwkMWykDDY98xZTBCxw+U9Nb3ktlZm3f cW1a0zaHdSnyxyyDeCwtoJ83uQvB4EpAwSBEf9/SyAF3iszHxCREHG8thvqPpi+Ckiti 6eSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N7CI/ZykoKzaO59Xhwn/2SBndJ4CIFMdgttXarqFQHk=; b=YwyfBcGYlipEeGP6Zrmzqg89ROebxyjkkjfzdiUXY7TG3AAVIsY9txidsyPmHeVvFc 4zs4T6ODRMNN5DxqW/gtIk7yZJSffkNp8TEzXNQS5YKGKFQrK/vFMXxVPrY/kZ7xXoR8 pIOG3ATNdkAuU1JgTjEKlO5m39kRLy+++uLBTAfwgmUWRy1ixtskjAfjDB669BuyHwLu B/TLV5a4lC3UWiOIiCrIJH6SydmOR2e8nmQFDcFU0w+UhY1dxA9IouC5ndX3Dy66RROf 3mbg1zDDVtv81x6HlPbCY3N6Ff6Vqp+XXHjNDMJQAFKOPAnZjLlR8CHQJGUlsTM8Gi2w sHMw== X-Gm-Message-State: AOAM532lIbwBa7AJ14Mu08Pvf3YpNklxz+LcuM8wo8JKs/eq3oyRhDju KWfrSjfHyuKoO7mTuqDKA0ghdBQId+uRzg== X-Google-Smtp-Source: ABdhPJwofygNpbz6+iUGEglcAwy4CR9dZHWd0o9efREiT7wAYlYP3s4lhVqDdEMq2VQCY6CXdCPZbg== X-Received: by 2002:aca:88b:: with SMTP id 133mr3109018oii.143.1604512049169; Wed, 04 Nov 2020 09:47:29 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id k13sm677557ooi.41.2020.11.04.09.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:28 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 06/10] completion: bash: simplify _get_comp_words_by_ref() Date: Wed, 4 Nov 2020 11:47:12 -0600 Message-Id: <20201104174716.783348-7-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We don't need the whole functionality of _get_comp_words_by_ref(), we know exactly what we need from that function, so only do that. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 30 ++++++-------------------- t/t9902-completion.sh | 21 ++++-------------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 90202e11a4..1bd81dcc9c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -260,30 +260,12 @@ __git_reassemble_comp_words_by_ref() if ! type _get_comp_words_by_ref >/dev/null 2>&1; then _get_comp_words_by_ref () { - local exclude cur_ words_ cword_ - if [ "$1" = "-n" ]; then - exclude=$2 - shift 2 - fi - __git_reassemble_comp_words_by_ref "$exclude" - cur_=${words_[cword_]} - while [ $# -gt 0 ]; do - case "$1" in - cur) - cur=$cur_ - ;; - prev) - prev=${words_[$cword_-1]} - ;; - words) - words=("${words_[@]}") - ;; - cword) - cword=$cword_ - ;; - esac - shift - done + local words_ cword_ + __git_reassemble_comp_words_by_ref "=:" + cword=$cword_ + cur=${words_[cword]} + prev=${words_[cword-1]} + words=("${words_[@]}") } fi diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index ab5134cdcc..bc18bd4b68 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -40,23 +40,10 @@ GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase' # So let's override it with a minimal version for testing purposes. _get_comp_words_by_ref () { - while [ $# -gt 0 ]; do - case "$1" in - cur) - cur=${_words[_cword]} - ;; - prev) - prev=${_words[_cword-1]} - ;; - words) - words=("${_words[@]}") - ;; - cword) - cword=$_cword - ;; - esac - shift - done + cword=$_cword + cur=${_words[cword]} + prev=${_words[cword-1]} + words=("${_words[@]}") } print_comp () From patchwork Wed Nov 4 17:47:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4582EC2D0A3 for ; Wed, 4 Nov 2020 17:47:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BBE42087D for ; Wed, 4 Nov 2020 17:47:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V+lXX3jl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732110AbgKDRrf (ORCPT ); Wed, 4 Nov 2020 12:47:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728679AbgKDRrc (ORCPT ); Wed, 4 Nov 2020 12:47:32 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A0CC0613D3 for ; Wed, 4 Nov 2020 09:47:31 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id i18so15371148ots.0 for ; Wed, 04 Nov 2020 09:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UEW6E9+N/jkXvYi9lr0+pv6BPwfmU/Gz88cwmAxLmJc=; b=V+lXX3jljFicx27GPPZLilYojui4XL/Opb4pFhGDYux/SpVF48KGkCHe2eRGcf4zwH /93l6UWzzjej5HVomAzHcETkyzZSpuVH67l4IdctuFxK2ozvcXUKXTgfQX8XKZ4wmsqU TZMFO0ahfBSgugV3KxNvWF39Zjz0UKCxMGBX6t59zqzqLMU2Fw+1wlYGUtu8vcJlyuWN EKPee9gYHoTCgjEpqDnpiUBAiogBu4Ra5y8kIkVBGSn/H2HlQHbuMqZLZrEuuYObLcLD JobHfuG4O8iAAACI/avjnECWeNDLUmFhvS5M0KGPnwZ4ZRidH5jEp7Qtx9OSXOVXynDj TcmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UEW6E9+N/jkXvYi9lr0+pv6BPwfmU/Gz88cwmAxLmJc=; b=mqd1P5AKprYL2/7kfvx2PzirxABWJk3vUUnTIPEJ8gs9sI7VGfwppZ8HVegCooOmqK 86akjSIJPZh2iPRKrMv6kV0sQKgnQphKTZzduHkzHpaCfYM3riEH8cf2E/Blxd5mlFFe DIdU9JGaQ0od/ZXaODkFxNvbqVV30FI0DHCpKkZHiPnbK7NLWeWPnU6kqnOIUI5CNOvH pPZwBpJf2wxl/HxdcVR4TVlD1nDTl8fMg/uxbZE5LTXMbOX74LKWWVNjnvIDMlfjmuX7 lE167H6vQyXlm7p/voCQtusaun6knSlRB+EG6Z+ln+ch3JWASeBxSvSSHnIs0DHfcHCu nrIw== X-Gm-Message-State: AOAM530VI2zk4a3yxJniW1c6/oT4KlTeV3JviOFcnVaZMi42GEeqE0BW 587kzpsZlFOlg1LDq0DNIVy0ok8CkzKVqw== X-Google-Smtp-Source: ABdhPJwpdB79p7vOsEIM+iH91FW22B1e1E729NzrsVdHjImmzHZflVTlJ2ib8vLX3qbWqIEyUU4sVA== X-Received: by 2002:a9d:f67:: with SMTP id 94mr5643187ott.282.1604512050905; Wed, 04 Nov 2020 09:47:30 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id b1sm652277oof.43.2020.11.04.09.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:30 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 07/10] completion: bash: refactor _get_comp_words_by_ref() Date: Wed, 4 Nov 2020 11:47:13 -0600 Message-Id: <20201104174716.783348-8-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We don't need a separate function to do what we already know we want to do. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 93 +++++++++++--------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1bd81dcc9c..f856db148b 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -186,21 +186,11 @@ __git_dequote () # # RELEASE: 2.x -# This function can be used to access a tokenized list of words -# on the command line: -# -# __git_reassemble_comp_words_by_ref '=:' -# if test "${words_[cword_-1]}" = -w -# then -# ... -# fi -# -# The argument should be a collection of characters from the list of -# word completion separators (COMP_WORDBREAKS) to treat as ordinary -# characters. +# This function reorganizes the words on the command line to be processed by +# the rest of the script. # # This is roughly equivalent to going back in time and setting -# COMP_WORDBREAKS to exclude those characters. The intent is to +# COMP_WORDBREAKS to exclude '=' and ':'. The intent is to # make option types like --date= and : easy to # recognize by treating each shell word as a single token. # @@ -208,60 +198,55 @@ __git_dequote () # shared with other completion scripts. By the time the completion # function gets called, COMP_WORDS has already been populated so local # changes to COMP_WORDBREAKS have no effect. -# -# Output: words_, cword_, cur_. -__git_reassemble_comp_words_by_ref() +if ! type _get_comp_words_by_ref >/dev/null 2>&1; then +_get_comp_words_by_ref () { + local words_ cword_ local exclude i j first + # Which word separators to exclude? - exclude="${1//[^$COMP_WORDBREAKS]}" + exclude="${COMP_WORDBREAKS//[^=:]}" cword_=$COMP_CWORD if [ -z "$exclude" ]; then words_=("${COMP_WORDS[@]}") - return - fi - # List of word completion separators has shrunk; - # re-assemble words to complete. - for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do - # Append each nonempty word consisting of just - # word separator characters to the current word. - first=t - while - [ $i -gt 0 ] && - [ -n "${COMP_WORDS[$i]}" ] && - # word consists of excluded word separators - [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] - do - # Attach to the previous token, - # unless the previous token is the command name. - if [ $j -ge 2 ] && [ -n "$first" ]; then - ((j--)) - fi - first= + else + # List of word completion separators has shrunk; + # re-assemble words to complete. + for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + # Append each nonempty word consisting of just + # word separator characters to the current word. + first=t + while + [ $i -gt 0 ] && + [ -n "${COMP_WORDS[$i]}" ] && + # word consists of excluded word separators + [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] + do + # Attach to the previous token, + # unless the previous token is the command name. + if [ $j -ge 2 ] && [ -n "$first" ]; then + ((j--)) + fi + first= + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + if (($i < ${#COMP_WORDS[@]} - 1)); then + ((i++)) + else + # Done. + break 2 + fi + done words_[$j]=${words_[j]}${COMP_WORDS[i]} if [ $i = $COMP_CWORD ]; then cword_=$j fi - if (($i < ${#COMP_WORDS[@]} - 1)); then - ((i++)) - else - # Done. - return - fi done - words_[$j]=${words_[j]}${COMP_WORDS[i]} - if [ $i = $COMP_CWORD ]; then - cword_=$j - fi - done -} + fi -if ! type _get_comp_words_by_ref >/dev/null 2>&1; then -_get_comp_words_by_ref () -{ - local words_ cword_ - __git_reassemble_comp_words_by_ref "=:" cword=$cword_ cur=${words_[cword]} prev=${words_[cword-1]} From patchwork Wed Nov 4 17:47:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C10A4C4741F for ; Wed, 4 Nov 2020 17:47:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DF92208C7 for ; Wed, 4 Nov 2020 17:47:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GVH0bI6i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730842AbgKDRrf (ORCPT ); Wed, 4 Nov 2020 12:47:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730685AbgKDRrd (ORCPT ); Wed, 4 Nov 2020 12:47:33 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77353C0613D4 for ; Wed, 4 Nov 2020 09:47:33 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id n11so20108309ota.2 for ; Wed, 04 Nov 2020 09:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AwsMYNgb0G5mnwFqNs/rWgQfqxDQJuNrB9U+MKHVaG4=; b=GVH0bI6ipWKasC4dYIkcLq4sVcuw3x2Koa9H+x7Y78ClNKgRTu7mznsi4UD63NQs22 VOMJNXujGewNJUhhywvl7rNU8ZvFZNSr8suMLEXwTZehx6Jx2cyHF66YK19p4qXYG9h5 lNfnX9CDKUP1aFlzqgqClcCDxibBI7d/X+tGJFqMo6gp1V5AdpUW/ksHFXUesUIUjBzp M66lNVqQkZcxGdP9NFwejdSoytDVdQxcvAoeLkZadShQv6N+ffd+m86Xu4aoyNNb3knQ sfCoLv8PelbHqDANaKO2OPUYmeKWCOC13VJk3r81ZwlYuD9uSDXxMdORmZyb0kOtwZiU HkdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AwsMYNgb0G5mnwFqNs/rWgQfqxDQJuNrB9U+MKHVaG4=; b=W0VfMBDsbisUUY/c4C2WimbMHesiltVTLuTBAJvVs6XCctrwCuH/XcqIZLyO02tI52 /Z0CfQb1s74PuVr4RKOg2UXNG9avDQPl/Ar0+V1btsNwhWjqhnLj2DFXnsbNV5qwrvlP BWHFGqSh/f8IRHjQT2bHGa7OOcfAAIY3gR1B2wGUnhfd4GH9EsxuJF3+dlA/h1mnOS99 9SvsuYVP2Lkp/q5X2rrUPi9v7P2Mc9et6m4kZxMdStM0oyEMBUOk1qgTjxpC7TJzAg0q PGO5fdVqdjWR6dVwpkK283mQXkfJCPh+2kGJBR70lMMJy/NTSqBQZCFwGxVsRGw9RrFj ighQ== X-Gm-Message-State: AOAM533m6z7hCpje6KoLSWYJMGxYVIJ+7i064L91bdRbxieomDKVOCPr kk/EA11luFBgLwcFr0V3LMjAUo7ZZHsosw== X-Google-Smtp-Source: ABdhPJyTCEHuIPm55x0//EGwa40o2ZoLTSqqTSF+TzYevmEKm1FuXR4r3tyJx2A/cpWvWdAWg/tFmQ== X-Received: by 2002:a9d:46f:: with SMTP id 102mr3203894otc.293.1604512052650; Wed, 04 Nov 2020 09:47:32 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id v17sm616550ote.40.2020.11.04.09.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:32 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 08/10] completion: bash: cleanup _get_comp_words_by_ref() Date: Wed, 4 Nov 2020 11:47:14 -0600 Message-Id: <20201104174716.783348-9-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove temporary variables. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index f856db148b..3666fba8ca 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -202,14 +202,13 @@ __git_dequote () if ! type _get_comp_words_by_ref >/dev/null 2>&1; then _get_comp_words_by_ref () { - local words_ cword_ local exclude i j first # Which word separators to exclude? exclude="${COMP_WORDBREAKS//[^=:]}" - cword_=$COMP_CWORD + cword=$COMP_CWORD if [ -z "$exclude" ]; then - words_=("${COMP_WORDS[@]}") + words=("${COMP_WORDS[@]}") else # List of word completion separators has shrunk; # re-assemble words to complete. @@ -229,9 +228,9 @@ _get_comp_words_by_ref () ((j--)) fi first= - words_[$j]=${words_[j]}${COMP_WORDS[i]} + words[$j]=${words[j]}${COMP_WORDS[i]} if [ $i = $COMP_CWORD ]; then - cword_=$j + cword=$j fi if (($i < ${#COMP_WORDS[@]} - 1)); then ((i++)) @@ -240,17 +239,15 @@ _get_comp_words_by_ref () break 2 fi done - words_[$j]=${words_[j]}${COMP_WORDS[i]} + words[$j]=${words[j]}${COMP_WORDS[i]} if [ $i = $COMP_CWORD ]; then - cword_=$j + cword=$j fi done fi - cword=$cword_ - cur=${words_[cword]} - prev=${words_[cword-1]} - words=("${words_[@]}") + cur=${words[cword]} + prev=${words[cword-1]} } fi From patchwork Wed Nov 4 17:47:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80AEDC388F9 for ; Wed, 4 Nov 2020 17:47:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2591820825 for ; Wed, 4 Nov 2020 17:47:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZnCnKJ0+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732116AbgKDRrh (ORCPT ); Wed, 4 Nov 2020 12:47:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728679AbgKDRrf (ORCPT ); Wed, 4 Nov 2020 12:47:35 -0500 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EB43C0613D3 for ; Wed, 4 Nov 2020 09:47:35 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id 9so23020787oir.5 for ; Wed, 04 Nov 2020 09:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7kFlxMX4hnUVT4xhtEwHBGmNeSzM50Kbqe2ph0xHk4I=; b=ZnCnKJ0+IVGnW3OSjIjLWhbwcPXgdZqEqAHUApy0eJ0pAWlJpxjyeATBZjkgz6hNtJ OgROMvFXFJbLmmyJrl510TEBH5QtmWf6QUH9XyeVyopURQ8MSEVKsLyntuQxyily6n5x FfMHvvlYPRLRrsnIY1qs/IxiZm1eaX5h5Y6aKqALYJDXh4Ed39e/189T1SSvh3zr/jsq HFhMMx14kUvnSAqsDMblO3UhYtcd0bBQhN27zN+DC6EaX4smLVpQVM0kYwDjM1gDYVeZ C7EppvMT6IVI9+gwZG21U2YwNSNNGfEry2yqUNQohOWeUAkcFowcPZ0bee7ONkZmJlOC UmKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7kFlxMX4hnUVT4xhtEwHBGmNeSzM50Kbqe2ph0xHk4I=; b=F7DoOyRpbAHfClNCPYvNS+SYeQOWKEUlcA9T35ey5Yht9nq9xB/J+3XFYQJN61GVZK qhoVgwucZbTHsiOBj70l9NOGSPpQABmgHef0r4prB3iOnK3f1z3GKpEc5EY40IisYAeT LXOX3LmoXKLOvPRUhi8TX1xQJXvoO4+trRe0Q6Nvxl1dcYbl9nx8GUnzh3JigsMqrJJG rvaogg8ITqNNyjzf/xNXP0epzb3mLnKplhJVHlsojtQ/LGvFZ7guNvv6ODBeuqjNORL5 50z/whbF+r86cl7xJeWf9yUxtGXvmGCtt8UX2/e6ZPmANbe42AbCKoFKQcKj2YvhK2af 4jbA== X-Gm-Message-State: AOAM531wTG52RULakIcUyV9KeYOIjcNEjhwrEBGEXF9NNpDGZ9hZjyjm lkdhRaplhh4yC7MD3yp9ZpTesJZinQBQWg== X-Google-Smtp-Source: ABdhPJzKsNgAK06EaaVgWO2M+3mxR7Q91FfX09yUlQqGuDoUp4Q8GerYqXuJup08FIG9zio6cInstg== X-Received: by 2002:aca:b588:: with SMTP id e130mr3481354oif.56.1604512054291; Wed, 04 Nov 2020 09:47:34 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t27sm607210otc.14.2020.11.04.09.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:33 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 09/10] completion: bash: trivial cleanup Date: Wed, 4 Nov 2020 11:47:15 -0600 Message-Id: <20201104174716.783348-10-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The most typical case first (COMP_WORDBREAKS contains our wanted words). Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 3666fba8ca..b4e6f82c66 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -207,9 +207,7 @@ _get_comp_words_by_ref () # Which word separators to exclude? exclude="${COMP_WORDBREAKS//[^=:]}" cword=$COMP_CWORD - if [ -z "$exclude" ]; then - words=("${COMP_WORDS[@]}") - else + if [ -n "$exclude" ]; then # List of word completion separators has shrunk; # re-assemble words to complete. for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do @@ -244,6 +242,8 @@ _get_comp_words_by_ref () cword=$j fi done + else + words=("${COMP_WORDS[@]}") fi cur=${words[cword]} From patchwork Wed Nov 4 17:47:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11881825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC5A7C4742C for ; Wed, 4 Nov 2020 17:47:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3C2620825 for ; Wed, 4 Nov 2020 17:47:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cs5p5F5J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730796AbgKDRrj (ORCPT ); Wed, 4 Nov 2020 12:47:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730805AbgKDRrh (ORCPT ); Wed, 4 Nov 2020 12:47:37 -0500 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC68EC0613D3 for ; Wed, 4 Nov 2020 09:47:36 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id m143so13695728oig.7 for ; Wed, 04 Nov 2020 09:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kZSEo5aeV0sJZOZP2IvzEgVHSf/5Q3duWx5U/yZ1p6g=; b=Cs5p5F5J6Ai4oxoGEVs1bwpc0dl86h9vcP50X5MVI/qj2zgA7AjKMcjXngdXfZbEly jKJwv5UH+2/S76J3T9bqwLYVySyRmYJbnx3pPQc+BT0vTJpKZoy//as4Bg/8oqAu4Biu lUIqoWlFMohE93aOJR0v3jgwgCIiSRZKTW8VWDvVwYWYzDYPUFltf1DECTvIvxVSsM1g 3OJhQUjsMVteQT1AIb3aH/s9TbPq3KzOUqGb0wJ+kL9uzlGqTokfZ4k/CM0DA9Yc/7CG PEg0d2Ijl6rr0UOKXvHHJX6CakkfEbOHyatUe0vorOcWR85VK5lQNUYsmSgkYgiE/qPO JBBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kZSEo5aeV0sJZOZP2IvzEgVHSf/5Q3duWx5U/yZ1p6g=; b=Cczu9DvIVwsrQanAQX9Tiyc0VRMCgJoR4ObXNKvIRHnIvX2lXTo4Xe2yXsqNpIQwb4 hdHoFc8gzE6fUTiMZMuUqYDPCqcS7E3Ay9qfnkpB7WrLbEkKMgU0mv985DzslZjCPqMV RY0FwkZm0CEu+/ArreHWIPADkmbdiX4W7mx7Y9ab9F/H8W7NYSoHTMMr3+Fvws7pPcq1 r/tjMMFq1oNmJpgb9ohXGk/R+Jq5tOcXoEOfVYBsr52hVSqkYhUeOfpq27p/eUjG2oJT VihmMf80VuQNa/vZj2Ns4n/CFtySanxMVKnN6Xj3Yz6nY4f8u+3rPkbkmg3ZJv6hTCun wDnQ== X-Gm-Message-State: AOAM533RN7EvzDL254ciH6B/BY4VuZDcR4DdRikAY76jFpKAbIpHUjJw dMsgdgNn4PndkK+FOuo5Q6258OGDpTbmGg== X-Google-Smtp-Source: ABdhPJw1HCMxn9YjEtREnZtfDx0gl3GJUcpagZSW6TiKbmqmXefIfjuAN8D9HMUY4/uc90GnCU0tpw== X-Received: by 2002:aca:4b82:: with SMTP id y124mr3124258oia.35.1604512055841; Wed, 04 Nov 2020 09:47:35 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id u16sm453045ooj.8.2020.11.04.09.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 09:47:35 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , Felipe Contreras Subject: [PATCH 10/10] completion: bash: move _get_comp_words_by_ref() Date: Wed, 4 Nov 2020 11:47:16 -0600 Message-Id: <20201104174716.783348-11-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201104174716.783348-1-felipe.contreras@gmail.com> References: <20201104174716.783348-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's only used in one place, rename it, and use it even if bash-completion's inefficient and buggy _get_comp_words_by_ref() is available. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 184 ++++++++++++------------- t/t9902-completion.sh | 2 +- 2 files changed, 92 insertions(+), 94 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b4e6f82c66..e0e44bdf75 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -159,98 +159,6 @@ __git_dequote () done } -# The following function is based on code from: -# -# bash_completion - programmable completion functions for bash 3.2+ -# -# Copyright © 2006-2008, Ian Macdonald -# © 2009-2010, Bash Completion Maintainers -# -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see . -# -# The latest version of this software can be obtained here: -# -# http://bash-completion.alioth.debian.org/ -# -# RELEASE: 2.x - -# This function reorganizes the words on the command line to be processed by -# the rest of the script. -# -# This is roughly equivalent to going back in time and setting -# COMP_WORDBREAKS to exclude '=' and ':'. The intent is to -# make option types like --date= and : easy to -# recognize by treating each shell word as a single token. -# -# It is best not to set COMP_WORDBREAKS directly because the value is -# shared with other completion scripts. By the time the completion -# function gets called, COMP_WORDS has already been populated so local -# changes to COMP_WORDBREAKS have no effect. - -if ! type _get_comp_words_by_ref >/dev/null 2>&1; then -_get_comp_words_by_ref () -{ - local exclude i j first - - # Which word separators to exclude? - exclude="${COMP_WORDBREAKS//[^=:]}" - cword=$COMP_CWORD - if [ -n "$exclude" ]; then - # List of word completion separators has shrunk; - # re-assemble words to complete. - for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do - # Append each nonempty word consisting of just - # word separator characters to the current word. - first=t - while - [ $i -gt 0 ] && - [ -n "${COMP_WORDS[$i]}" ] && - # word consists of excluded word separators - [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] - do - # Attach to the previous token, - # unless the previous token is the command name. - if [ $j -ge 2 ] && [ -n "$first" ]; then - ((j--)) - fi - first= - words[$j]=${words[j]}${COMP_WORDS[i]} - if [ $i = $COMP_CWORD ]; then - cword=$j - fi - if (($i < ${#COMP_WORDS[@]} - 1)); then - ((i++)) - else - # Done. - break 2 - fi - done - words[$j]=${words[j]}${COMP_WORDS[i]} - if [ $i = $COMP_CWORD ]; then - cword=$j - fi - done - else - words=("${COMP_WORDS[@]}") - fi - - cur=${words[cword]} - prev=${words[cword-1]} -} -fi - # Appends prefiltered words to COMPREPLY without any additional processing. # Callers must take care of providing only words that match the current word # to be completed and adding any prefix and/or suffix (trailing space!), if @@ -3474,10 +3382,100 @@ if [[ -n ${ZSH_VERSION-} ]] && return fi +# The following function is based on code from: +# +# bash_completion - programmable completion functions for bash 3.2+ +# +# Copyright © 2006-2008, Ian Macdonald +# © 2009-2010, Bash Completion Maintainers +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# The latest version of this software can be obtained here: +# +# http://bash-completion.alioth.debian.org/ +# +# RELEASE: 2.x + +# This function reorganizes the words on the command line to be processed by +# the rest of the script. +# +# This is roughly equivalent to going back in time and setting +# COMP_WORDBREAKS to exclude '=' and ':'. The intent is to +# make option types like --date= and : easy to +# recognize by treating each shell word as a single token. +# +# It is best not to set COMP_WORDBREAKS directly because the value is +# shared with other completion scripts. By the time the completion +# function gets called, COMP_WORDS has already been populated so local +# changes to COMP_WORDBREAKS have no effect. + +__git_get_comp_words_by_ref () +{ + local exclude i j first + + # Which word separators to exclude? + exclude="${COMP_WORDBREAKS//[^=:]}" + cword=$COMP_CWORD + if [ -n "$exclude" ]; then + # List of word completion separators has shrunk; + # re-assemble words to complete. + for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + # Append each nonempty word consisting of just + # word separator characters to the current word. + first=t + while + [ $i -gt 0 ] && + [ -n "${COMP_WORDS[$i]}" ] && + # word consists of excluded word separators + [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] + do + # Attach to the previous token, + # unless the previous token is the command name. + if [ $j -ge 2 ] && [ -n "$first" ]; then + ((j--)) + fi + first= + words[$j]=${words[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword=$j + fi + if (($i < ${#COMP_WORDS[@]} - 1)); then + ((i++)) + else + # Done. + break 2 + fi + done + words[$j]=${words[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword=$j + fi + done + else + words=("${COMP_WORDS[@]}") + fi + + cur=${words[cword]} + prev=${words[cword-1]} +} + __git_func_wrap () { local cur words cword prev - _get_comp_words_by_ref -n =: cur words cword prev + __git_get_comp_words_by_ref $1 } diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index bc18bd4b68..b8dfeb82bf 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -38,7 +38,7 @@ GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase' # We don't need this function to actually join words or do anything special. # Also, it's cleaner to avoid touching bash's internal completion variables. # So let's override it with a minimal version for testing purposes. -_get_comp_words_by_ref () +__git_get_comp_words_by_ref () { cword=$_cword cur=${_words[cword]}