From patchwork Tue Nov 10 21:21: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: 11895325 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 1F88DC55ABD for ; Tue, 10 Nov 2020 21:21:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF50D20781 for ; Tue, 10 Nov 2020 21:21:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iLbrNtLk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731711AbgKJVVn (ORCPT ); Tue, 10 Nov 2020 16:21:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbgKJVVn (ORCPT ); Tue, 10 Nov 2020 16:21:43 -0500 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14243C0613D1 for ; Tue, 10 Nov 2020 13:21:43 -0800 (PST) Received: by mail-oo1-xc30.google.com with SMTP id y3so3314346ooq.2 for ; Tue, 10 Nov 2020 13:21:43 -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=xDjeYERVmZBgLAnqXkqNSn+x8uE0/N1xNl0tBZNq1xk=; b=iLbrNtLkqI+wgB763M4/J4FCaHtC+i1M52eV30El1bVh46BHhsiKEY/TUUXpMNLwin ufarD8ptHkG6SesRJ6ThhXXUGRmwu6BtZizy89TV1SFyfwi/3Prlp1Wy7baD5ZUP1/uc 3Ds3AB3n4rHJPnlgqzqPN8xKkHKLxkIZXsxOvS5JveMiQDL0cJLVEP8N4OLUesAS44lm jZm2YnOHu/ys4WPeFXM9kp1uU46asqKDtKhnnRnX8Xf84WVWtoo0hVLTnIhOusYtLJ0A dEz4OIHpDmMPw0JaEjRoLCJmDZaGRX7yIfkIWyMumxD3OS8mFxy589ECb8Cqwf+N/tCt 38xA== 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=xDjeYERVmZBgLAnqXkqNSn+x8uE0/N1xNl0tBZNq1xk=; b=c6sO3RyaczDz5Ck40s1yqvrjcs1cM5UwpE75yn+Pjf5RNofRf6+f8NW0riOEMhBNjK Rn+OcJGjeTbTmqdy1pr7LxeBF83tujHWk9YAhUkRPJ9DK479woYin6SUmqC1rFpIeis/ 6Xal6A47+uCbsB4LVh3bLV/FaSj0T6Ms+WOCIUixm8TMG+YZZIRJ0rn/pdsTLVwmJM0U D8PqWtHkdGISxzLTfsqwI3F3Q/aFxGIqg+OqQiJRzTY/QU68TmX9tX9/efWQiq2HB7og im+14UupXs5dNn4VsgkJDYLFvTSdzeQK/5tkPjft78m/PfaczScopvoanDrs4NQgOfIT LPAA== X-Gm-Message-State: AOAM533PP+jSJ5+jp/7sNq1dcfNhVPXb94Qo3XL77Vbe5nj2LKNkGG8s SpjU+rMUTIUxUhEpepg2DolPjhvof/fXHg== X-Google-Smtp-Source: ABdhPJyTnZ1nV2QgSDE+rFLjAUeHXiHhvaT5CsXX1OE8mI0NJ0lgsfl3aecg65Ae5ajXYpU9DPiCcg== X-Received: by 2002:a4a:c4c7:: with SMTP id g7mr14494844ooq.50.1605043302192; Tue, 10 Nov 2020 13:21:42 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id 32sm27636otw.21.2020.11.10.13.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:41 -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 v2 01/26] completion: bash: fix prefix detection in branch.* Date: Tue, 10 Nov 2020 15:21:11 -0600 Message-Id: <20201110212136.870769-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Otherwise we are completely ignoring the --cur argument. The issue can be tested with: git clone --config=branch. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7c81e4ba49..b866b68b3c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2615,8 +2615,8 @@ __git_complete_config_variable_name () return ;; branch.*) - local pfx="${cur%.*}." - cur_="${cur#*.}" + local pfx="${cur_%.*}." + cur_="${cur_#*.}" __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")" __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx" return From patchwork Tue Nov 10 21:21: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: 11895331 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 2E049C55ABD for ; Tue, 10 Nov 2020 21:21:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E312E20781 for ; Tue, 10 Nov 2020 21:21:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PIay9Vyf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731735AbgKJVVq (ORCPT ); Tue, 10 Nov 2020 16:21:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbgKJVVp (ORCPT ); Tue, 10 Nov 2020 16:21:45 -0500 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DA58C0613D1 for ; Tue, 10 Nov 2020 13:21:45 -0800 (PST) Received: by mail-ot1-x32c.google.com with SMTP id l36so129360ota.4 for ; Tue, 10 Nov 2020 13:21:45 -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=udwQE863MDU6iSYqiBMkmiS+h620h7PqpG/YqrVBlnM=; b=PIay9VyfVnDgLwdzry2HrGgyp/GXVqkfbfbv5TKxIcl2SCCZvPm8646I1RGFi2mA/v XSrC+h+VACwT/VU5un092aGG/Jwzk6S4JlW+E3i7vCmKFeu/KZZmHoR7KDZxyx/GT+H4 Dim9GND89BYm4pjfa/hfIDxuaxmkNQExU2Q2FwrT/KWcEDanJa/G4+WfjsegaTor0cme 2PgEJOIFTKsaqKenjpbSfQ6PuUUY424tUgLz8TKiLiKMD7XO6nELcM81u4M9Hzm1qNCR v9KfsYbC3iZWggjvEYbDLWM6ruk6BsN1eneSmaE00KZlalpeCRjAnwMyCT2FVnlRBVg9 7eRw== 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=udwQE863MDU6iSYqiBMkmiS+h620h7PqpG/YqrVBlnM=; b=YBf1O63kRrWJL0IjbnTyBeY9ZWMTwA20N+B9w0RHSLzYldzC0aCNcisGQuBvh6WgXr VmwgFCKxXcpKdX91vRXhe/HMZnMVCh8LXoAk/yDGwWPHO3l/0rxNyR5cbQOUPl+8XLOz IZWhGADhqh4MKlDWBln300xZNFL+m0SyE0gOkHzApRH0txX8BQNLw0ADgqU+brp7Vve3 +5kx7HxGaDtFGc8ED57yGeo3iwfasGyo2Bk9zzTApcwd+WoQJQqkP5KCFRpNpR6Lk7X6 FbTfNHbjrmdgtThhidUNDVhzdQgth2opxL0LNR8Wruopvcmmdhr8HjcKa1P7qmzpqkPX GQXA== X-Gm-Message-State: AOAM5314NnXN65q663QOxkn8eTuH2ADiASMYQUyoUNNxDcFMmpoUExYv BdXKZsF+PFiS0UMb08xgg6xhEIqHGAlF9g== X-Google-Smtp-Source: ABdhPJxnc2ZliqIDt3yX1tExq64tcpCCZKPYhF9I+D2ne6hZLx79zR22ZwPzLjiE5y0+Ba6Nh/F+eQ== X-Received: by 2002:a05:6830:441:: with SMTP id d1mr5807984otc.337.1605043304509; Tue, 10 Nov 2020 13:21:44 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id g8sm3391850oia.16.2020.11.10.13.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:44 -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 v2 02/26] completion: bash: add correct suffix in variables Date: Tue, 10 Nov 2020 15:21:12 -0600 Message-Id: <20201110212136.870769-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org __gitcomp automatically adds a suffix, but __gitcomp_nl and others don't, we need to specify a space by default. Can be tested with: git config branch.autoSetupMe Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 6 +++--- t/t9902-completion.sh | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b866b68b3c..bbdb46d87e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2618,7 +2618,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_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }" return ;; guitool.*.*) @@ -2652,7 +2652,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __git_compute_all_commands - __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx" + __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }" return ;; remote.*.*) @@ -2668,7 +2668,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_append "pushDefault" "$pfx" "$cur_" "${sfx- }" return ;; url.*.*) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 2be9190425..4a3d3d1597 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2293,6 +2293,13 @@ test_expect_success 'git config - value' ' EOF ' +test_expect_success 'git config - direct completions' ' + test_completion "git config branch.autoSetup" <<-\EOF + branch.autoSetupMerge Z + branch.autoSetupRebase Z + EOF +' + test_expect_success 'git -c - section' ' test_completion "git -c br" <<-\EOF branch.Z From patchwork Tue Nov 10 21:21: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: 11895327 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 B4FD6C388F7 for ; Tue, 10 Nov 2020 21:21:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6393020781 for ; Tue, 10 Nov 2020 21:21:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="higok09V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731750AbgKJVVs (ORCPT ); Tue, 10 Nov 2020 16:21:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbgKJVVr (ORCPT ); Tue, 10 Nov 2020 16:21:47 -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 92CA3C0613D1 for ; Tue, 10 Nov 2020 13:21:47 -0800 (PST) Received: by mail-oo1-xc2e.google.com with SMTP id l10so2007972oom.6 for ; Tue, 10 Nov 2020 13:21:47 -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=iUt7GQutxz3mgHglSFcvh2I2ipKDO2u3MjWJhgdu43M=; b=higok09VteI4FVBvpYQR3M7mHML/sLtMCjR+80zIKF5fnblILYsDRKJ9eILbNJ/FgI shD87VgWQQrMlGp3he/bvRg1FJu+mJxWk6O5OcdGIXHbKmb4//d/bGGml7+8p69SaTZf KGUwGhgey3omrS+lGTTk+ZAx/CB3dFLQCIC0w+mFNS9ChipFHZQwte5+xKdTcXIzuum+ LEVjt6H010Ly+O4Glr16oktXNX2h7S0Dzi3ry70cKjjNi3bkWHV4EOOg4lH2yL8/fDFI QtuJRgIBd3wVo258ygAW3hKbL73rAG7SFbU6mKGwmGzfZKfumwaKPqkr+DxXApVY7Omi btWg== 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=iUt7GQutxz3mgHglSFcvh2I2ipKDO2u3MjWJhgdu43M=; b=OfaV8niovnday8IMvY5xk2b3Oc0q9I3MvAnr2su+JiOiOrrCB/f1rVCUvlo9Fs8zfn quqGt+wQXambi3NbUsBGLLTfPLxHtYSF2Dy4WfGQ1LH3AVP55q4vZGvXEq80qKgexq34 OLR59xjOzhmmQQt3C+UXgBrFg6hHSSdA9TzHdTYsmU4G+yxVhQGpTCaVS6hzWZkc7qLA dWiZDOPSSLZICyMJ9YySecu4OQO0tQPwsWKbx9gAZzZ+jwIbBH06QHJz6FMGd1Si+l5W dtirRLvmcwOF9J56hzG1xBNDI4imkWlFJ9V8KNa91WhUM+T+Gz0+EbNz3bqxblC6sdtF HfoA== X-Gm-Message-State: AOAM531H7b9EYDnvxbXku/xW6coJr9eJM4WUEx8B7UTBjBmi8BBeJAWY MH+AfOUDsWt1eSxOogmT9kVDNfwMQYUmXA== X-Google-Smtp-Source: ABdhPJycCigZS5Uqh0YafARgKl3lLUdf6P/SE4WVn05ROgfFPuyW+0gwKn9V4fXw7ad6E53ObtfS+Q== X-Received: by 2002:a4a:96b1:: with SMTP id s46mr5581966ooi.39.1605043306751; Tue, 10 Nov 2020 13:21:46 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id x8sm36207ooc.44.2020.11.10.13.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:46 -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 v2 03/26] completion: bash: fix for suboptions with value Date: Tue, 10 Nov 2020 15:21:13 -0600 Message-Id: <20201110212136.870769-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We need to ignore options that don't start with -- as well. Depending on the value of COMP_WORDBREAKS the last word could be duplicated otherwise. Can be tested with: git merge -X diff-algorithm= Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 2 +- t/t9902-completion.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index bbdb46d87e..5b2dff150d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -347,7 +347,7 @@ __gitcomp () local cur_="${3-$cur}" case "$cur_" in - --*=) + *=) ;; --no-*) local c i=0 IFS=$' \t\n' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 4a3d3d1597..4deda01153 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -537,6 +537,15 @@ test_expect_success '__gitcomp - expand/narrow all negative options' ' EOF ' +test_expect_success '__gitcomp - equal skip' ' + test_gitcomp "--option=" "--option=" <<-\EOF && + + EOF + test_gitcomp "option=" "option=" <<-\EOF + + EOF +' + test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' __gitcomp "$invalid_variable_name" ' @@ -2342,6 +2351,12 @@ test_expect_success 'git clone --config= - value' ' EOF ' +test_expect_success 'options with value' ' + test_completion "git merge -X diff-algorithm=" <<-\EOF + + EOF +' + test_expect_success 'sourcing the completion script clears cached commands' ' __git_compute_all_commands && verbose test -n "$__git_all_commands" && From patchwork Tue Nov 10 21:21: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: 11895339 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 36AFCC55ABD for ; Tue, 10 Nov 2020 21:21:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD3B5206F1 for ; Tue, 10 Nov 2020 21:21:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qlKQxCOO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731772AbgKJVVw (ORCPT ); Tue, 10 Nov 2020 16:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731759AbgKJVVt (ORCPT ); Tue, 10 Nov 2020 16:21:49 -0500 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B84FC0613D3 for ; Tue, 10 Nov 2020 13:21:49 -0800 (PST) Received: by mail-oo1-xc30.google.com with SMTP id g4so1607151oom.9 for ; Tue, 10 Nov 2020 13:21:49 -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=NX/DLewIinm9wuQBVdPcQG+miDz8MXllUkcbopJ+4SU=; b=qlKQxCOOI1spy3jmIOgnJsX39QsEgSnaTBgZE2KuQesB4oQj5PNfwd/ykCBa7JILjO jCaDdHqQzUhhC6Qp6+8XczIZWWIIBOdcN+gd0zryr3aeMp1bDJV4wIsboVWFs8EfAzOo YmTd60GqlKe1Kw+6P6Jl/7rVNPgzUi6QT+pAkcuKUgauAnt7dp3j90THspu8BLT+f535 oJjLjGH1WwEuo5+I6d6THfeqgAnuSJ5kQwgaqrQzfjFUG6yzCHqqQZgXSgnyL6ze21uS 2nxuFVA5qZVT9VjfHVRcMmkQZlb6Fu3jgqqtSwewN+NqVvg+k0eED0buLcUEJqONLhCZ rN4A== 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=NX/DLewIinm9wuQBVdPcQG+miDz8MXllUkcbopJ+4SU=; b=ZpK2xcrnCIbmoVWMw6wOgK7UrJnW4KFf9nmKAoep2TaJVlQ8Ps2V2GwzSitceW5oWH Rc78IOH60n80ZJdCE+2ihxGqhyiQv5Imu2UrAG7Ctmd+oYD1T69nzWFhvlMGOfUxcgFU cf5c5/BUpC0BeXlg1qyy4TcPOSfvxa3OstuYAgLkxnIgu2WssXFScOjcjVK4Lkg5tTHZ aBZUIETZNRtgu/0+WwAETboFt9GsBl4LM/tqPEHFa9oIQHC/X3Dz3oOwk9ayTzvV/nVQ wTPvcLFS7EgfnXWL4u1u2sYBq3cHN8MC4uWtHwuonaHfbj0LfvYIzPSF6m1VmhJcBDnc U2+g== X-Gm-Message-State: AOAM530dWTgS3AAfH6JNBfuEaKdjbPB7MgoWwJSdMy2O4dSDwfA30ZcO mAXEnbqZ4VakZaK49r7aSnmbaFOPyqsX6A== X-Google-Smtp-Source: ABdhPJxFPWdEjAvbTXtEHZmEf6ZfzLpQWpaZkco3t3hdhDIQglT4xxaxNr68zzVw6MZ4vh3B4PmvmA== X-Received: by 2002:a4a:ddd7:: with SMTP id i23mr4180451oov.73.1605043308596; Tue, 10 Nov 2020 13:21:48 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id y8sm20220ota.64.2020.11.10.13.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:48 -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 v2 04/26] completion: bash: do not modify COMP_WORDBREAKS Date: Tue, 10 Nov 2020 15:21:14 -0600 Message-Id: <20201110212136.870769-5-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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. Now irrespective of the value of COMP_WORDBREAKS, words are always joined together. By default COMP_WORDBREAKS does contain a colon, and if it doesn't somebody probably has a reason for it. Completions are not supposed to modify COMP_WORDBREAKS and none of the completions in the bash-completion project do. We manually set it in Zsh so the Bash script is not confused. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 5 ----- contrib/completion/git-completion.zsh | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 5b2dff150d..12275a3558 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. diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index e0fda27f4c..fa7f88bbb3 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -45,6 +45,7 @@ fi local old_complete="$functions[complete]" functions[complete]=: +COMP_WORDBREAKS=':' GIT_SOURCING_ZSH_COMPLETION=y . "$script" functions[complete]="$old_complete" From patchwork Tue Nov 10 21:21: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: 11895343 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 8470CC388F7 for ; Tue, 10 Nov 2020 21:21:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44DF720781 for ; Tue, 10 Nov 2020 21:21:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vd4uPI3r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731799AbgKJVVx (ORCPT ); Tue, 10 Nov 2020 16:21:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731759AbgKJVVw (ORCPT ); Tue, 10 Nov 2020 16:21:52 -0500 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 211F6C0613D4 for ; Tue, 10 Nov 2020 13:21:51 -0800 (PST) Received: by mail-ot1-x335.google.com with SMTP id 79so111026otc.7 for ; Tue, 10 Nov 2020 13:21:51 -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=l6cBJZ7n75P2T0lJKrk+2Tr6lfmT2bdrYr6QjHYYFOc=; b=vd4uPI3rpaCQjrUKNiOJsFGT1iAWLNXF7JQp9D4H+asdUNZCwrvUt2YYPrKVqW4fIR o85eVojpcABmcSZPPM9XA2shKZKCCrMXZ50kJuhnYLSOEFal4miGumt2EV4prI8bJZ2M /aoCNsTaYIJjte+uwESOVP5elhE6jERD5AXNZVBEvgA60Gic65UGdyI/NV4WbxX7nO2+ E9X03SGNWxfLhvTQWKiu9eP64mIj2xTD1iAHv90aXHbnNjTDIlFVvdSCXCdotW4royxo y+pvPMIX2Xv1QWGFWyeDTHqnGV3ttcRG2Dh9nRcqSqiYL3YaXdrpEAFL5LufkIAxsdLS 8Ntw== 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=l6cBJZ7n75P2T0lJKrk+2Tr6lfmT2bdrYr6QjHYYFOc=; b=HGx38G3vCzjsp+1SBN/lFfH6t6JYv0NQDK3M1vmWq5JtYmVGUz+tTAKkjjIw+GvNaY FzrrJU0FKIhuSSnh5+QaTyf9+BvrPBPi+kWATkAQRe+cC1aa6sb2rvDcaG8uaY3HQubG wfLWjgM1GcK3MC1PRlAUfzbWrd9fiSUJY6aCrLrhTsNSrvwYoXEFZvcrGfeCacKsOHRt rSKt1eQOKrIonytPYzWcFJ3t9QWRSZqKGujO+jxoiLhDNWAbMAF3Lm02XiKnY+g1XW5w 71Z2BNFqSIABet46V+Dbz6zZTne778PICI6bW/4yTkj17r3TghVts7zcQJrPgTSAmJ3j 2m3Q== X-Gm-Message-State: AOAM5332eqZO0/HQmsdVJsfqtvLNa7ElNmH3Y3nMGiQqSMy75Vp+x7ns uSahgCES98ouOdvJQuOlKOPe/u/cbGFeug== X-Google-Smtp-Source: ABdhPJwB7p60ElW+V7KckrkCX0Q5zkUErxiayurCHTzuADOrGm41rxf1fNxlN7MklX29CmIRNBfRjg== X-Received: by 2002:a9d:371:: with SMTP id 104mr15898193otv.266.1605043310321; Tue, 10 Nov 2020 13:21:50 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id m109sm26102otc.30.2020.11.10.13.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:49 -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 v2 05/26] test: completion: fix currently typed words Date: Tue, 10 Nov 2020 15:21:15 -0600 Message-Id: <20201110212136.870769-6-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org They don't match what we are supposed to be completing. No functional change. Signed-off-by: Felipe Contreras --- t/t9902-completion.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 4deda01153..2e04462bb0 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -486,7 +486,7 @@ test_expect_success '__gitcomp - option parameter' ' ' test_expect_success '__gitcomp - prefix' ' - test_gitcomp "branch.me" "remote merge mergeoptions rebase" \ + test_gitcomp "branch.maint.me" "remote merge mergeoptions rebase" \ "branch.maint." "me" <<-\EOF branch.maint.merge Z branch.maint.mergeoptions Z @@ -494,7 +494,7 @@ test_expect_success '__gitcomp - prefix' ' ' test_expect_success '__gitcomp - suffix' ' - test_gitcomp "branch.me" "master maint next seen" "branch." \ + test_gitcomp "branch.ma" "master maint next seen" "branch." \ "ma" "." <<-\EOF branch.master.Z branch.maint.Z From patchwork Tue Nov 10 21:21:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895333 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 E5270C56201 for ; Tue, 10 Nov 2020 21:21:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8106F207D3 for ; Tue, 10 Nov 2020 21:21:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g/bsO9FW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731808AbgKJVVy (ORCPT ); Tue, 10 Nov 2020 16:21:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731795AbgKJVVx (ORCPT ); Tue, 10 Nov 2020 16:21:53 -0500 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21448C0613D1 for ; Tue, 10 Nov 2020 13:21:53 -0800 (PST) Received: by mail-oi1-x244.google.com with SMTP id t143so16076716oif.10 for ; Tue, 10 Nov 2020 13:21:53 -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=TP8hFuNZwvhb15fuULec84AQreFA8VrMqmu9cUuUJ0U=; b=g/bsO9FWlIPw5GKWvY/hfkpBMMaQgBVBjnCN5T08Uw7KHvHT34S8QZYntflJLIu0mA Nrk0ldluJo6Qy2nszCU37dSGXyY7jSp/hxzwkOhnXRf/HxuWc2u/Uneu/QpFKNf/RLxS F5Ym/NfwvWQAbvCPdWPyUCuglYoFE4XdJhLeLjYbsZOKsKhHkVxU31yiOT4hDeL3fiCO 6/8OZXinoFSYP7Dn9PY0dAS9kxdtQ7huPsey8uoE4oOjWKsV9rdYRC8Ats/X6iaEBr2a LEMNcYS0qS2XYwB+b79P1WvyhatGDYHMnGKhOLgaNPHUop2YFCNrWxcKOHQtovAjC2Oq 3sIg== 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=TP8hFuNZwvhb15fuULec84AQreFA8VrMqmu9cUuUJ0U=; b=M01DSbv2EDq8nfYllKia48eXnYBDkThhEtLXtmUspMmyBmF8msBzn50nWKKiAy/elT k8FN0JN7ifIczdrkmz0rCdaJbBqqkX/O9eCH2bR0YRPTABetB3HVd5cnqMHu8fNL32ai 9TQdpXofZdhoG4wixqOSaxcGLjZwIljuA+3uPDXgiHDuf+moUd0bWLMMwWjgnvOab0c7 tQ2ElUeY9U0ND+4rmwefsI0wgRvzVoHYHIK8V+3ZYchdjAxUXvnkrNMGpvqa/xhd3x0y HcTrNBU47JmeA2ME6ArLBOQdWiWTDG6IuqXKE2vOAWDVYDa/CpT1+H4kSOPOW3aLFDKV SxOg== X-Gm-Message-State: AOAM532X8HLTA1EEecIUJmXD3GSCjJwf8rnSsjIOcXhDck1GdmisA5wa a49R1MwzIEb3WcZX2rsEgx0+Blik4ES9EA== X-Google-Smtp-Source: ABdhPJxvtL+eic0IEEbN7IzPfOaT+x4Jo9/cNjoZWvwPvnEskQ/3rlD6r2jU8qnbO1VNi8tk4MiBzw== X-Received: by 2002:aca:ed82:: with SMTP id l124mr41779oih.67.1605043312256; Tue, 10 Nov 2020 13:21:52 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id x24sm19568otq.68.2020.11.10.13.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:51 -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 v2 06/26] test: completion: add run_func() helper Date: Tue, 10 Nov 2020 15:21:16 -0600 Message-Id: <20201110212136.870769-7-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 2e04462bb0..3ec9ff9308 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 ' @@ -547,7 +552,7 @@ test_expect_success '__gitcomp - equal skip' ' ' 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 @@ -586,7 +591,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' ' @@ -1086,8 +1091,7 @@ test_expect_success '__git_complete_refs - simple' ' EOF ( cur= && - __git_complete_refs && - print_comp + run_func __git_complete_refs ) && test_cmp expected out ' @@ -1099,8 +1103,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 ' @@ -1113,8 +1116,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 ' @@ -1132,8 +1134,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 ' @@ -1145,8 +1146,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 ' @@ -1158,8 +1158,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 ' @@ -1175,8 +1174,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 ' @@ -1189,8 +1187,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 ' @@ -1201,8 +1198,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 ' @@ -1215,8 +1211,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 ' @@ -1229,8 +1224,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 ' @@ -1243,8 +1237,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 ' @@ -1775,8 +1768,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 } @@ -2261,8 +2253,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 ' @@ -2274,8 +2265,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 Tue Nov 10 21:21:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895341 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 D8A09C55ABD for ; Tue, 10 Nov 2020 21:21:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80C6D20781 for ; Tue, 10 Nov 2020 21:21:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ujfM+LYI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731837AbgKJVV6 (ORCPT ); Tue, 10 Nov 2020 16:21:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731795AbgKJVVy (ORCPT ); Tue, 10 Nov 2020 16:21:54 -0500 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C01C0613D1 for ; Tue, 10 Nov 2020 13:21:54 -0800 (PST) Received: by mail-ot1-x333.google.com with SMTP id n89so136174otn.3 for ; Tue, 10 Nov 2020 13:21:54 -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=Cl9UjcXzREbT04f32XAC5DBY8wYEr5MR8dw3hXmoPzs=; b=ujfM+LYIuiBkyRNWaH3hUZhkqkGYha2+nByjqv/qmESzCa0NvTEbFdBvmcOn171L6n IM1RJjUvRebdTs4SU9UGBIRrpRsEF9I5duhm6g0uT+VnITHcgOMSk1Xfl5tltjbGJOuX vDKjQXhp35D74Cim+jzMwIOcJ/XRWmcsJ4aSRV/hk8mj+VG4quX8O9u3BORtCeyAlPzb IsjR1+5O7I+oQuDja6dGect5DJbHA1890AumLJi+KE43XD4vjLChbzzRUBVKcVRtnqGM C3w9YzjS/7INzepNCJS8wNQwR6LcT2NfSVwosvcu+MoTiSvtRau1a/Ee8Jl22Cms07J+ U6RQ== 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=Cl9UjcXzREbT04f32XAC5DBY8wYEr5MR8dw3hXmoPzs=; b=TuJwNlE79K4A0Z0yiGxKgd788xW0xRFgWmOLXVE+B7MLvMEU7s/QT0GfW/5jjPG8si zryzqcayNJAuy2l1FqU4Y23KVMaVzu+geUfxpQ25Mh9t30bLFA2TJ/6onsEOnztF5NU8 tZTAk/JC6K99BN0ilXmCcZu4VT3wg8svGJEMWQ81lQSKI4cYNXwMLiU8b6t41iPO6qf9 I9ZB4mhjXlv1ij8I8zvD6wi4fFgbvaaMvN5EKnS/HcCyQta+Eu6tRu4Y/yR25euijoYM U6AkXOtdzmh8ga7j8uCi8VSijId39r5qymsj6WRw9o8I3Gqj+VW170j7mXNqnu3yeaSD 2cWg== X-Gm-Message-State: AOAM532fcfO7ETTLLTlDq6m/bCaE6plDoeYWGMf4vFcUd2SrKb0fQsKq 4o5R53uzOtR0CMX8zJhEkcebuCtJWa5Vqw== X-Google-Smtp-Source: ABdhPJxUo/5/2aWjlWjYwn61TF0DSwdsNBIq4yM0JbzHEd8mb1SJJvYXEpaccFXZmNF4K8WFqqNRYg== X-Received: by 2002:a9d:2cc:: with SMTP id 70mr16284391otl.346.1605043314006; Tue, 10 Nov 2020 13:21:54 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id n26sm43932oop.18.2020.11.10.13.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:53 -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 v2 07/26] completion: bash: remove non-append functionality Date: Tue, 10 Nov 2020 15:21:17 -0600 Message-Id: <20201110212136.870769-8-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 12275a3558..6a1106f17d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -298,7 +298,7 @@ __gitcomp_direct () { local IFS=$'\n' - COMPREPLY=($1) + COMPREPLY+=($1) } # Similar to __gitcomp_direct, but appends to COMPREPLY instead. @@ -450,7 +450,6 @@ __gitcomp_nl_append () # appended. __gitcomp_nl () { - COMPREPLY=() __gitcomp_nl_append "$@" } From patchwork Tue Nov 10 21:21:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895335 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 61B53C388F7 for ; Tue, 10 Nov 2020 21:22:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1984220781 for ; Tue, 10 Nov 2020 21:22:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nsSA7z4y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731862AbgKJVWA (ORCPT ); Tue, 10 Nov 2020 16:22:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731818AbgKJVV4 (ORCPT ); Tue, 10 Nov 2020 16:21:56 -0500 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 721DDC0613D1 for ; Tue, 10 Nov 2020 13:21:56 -0800 (PST) Received: by mail-ot1-x336.google.com with SMTP id z16so118000otq.6 for ; Tue, 10 Nov 2020 13:21:56 -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=t0td7i0rPVUi9PRW9OzwO6saxJyhmAoaYR/VCmaNn9c=; b=nsSA7z4yu9ODvJLVJJqK16CEN86LZGoTBs9pYlAYyDnQZvtYIMzT6iotxK9SDXOWLa ZGmtX6piCPwk5ALCd6HpvYt7/FoMH71LQ0u5yx2MHPBqh1SduFsNC1JA43m0DJn+3f3H zSGpf6XTeOFznVUR+Bms22s1B7Q7tkNP0vBrIktiH+6TQaGORn766E8Ul5xNPYWMnJ6o SIscrLk5jzlngm8ct2qCHdRFHNA+ud89tzrnMVHIl030IiDIreuoLrfbedoAvFkvKgKD ZWhdC698DYvN2wioQK9O4U8rdx8c45HEzYXBtTboYJI04rSArXWQNLwR9s1DTwPv0TmZ zsqw== 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=t0td7i0rPVUi9PRW9OzwO6saxJyhmAoaYR/VCmaNn9c=; b=sOrHCaDUAQJqYAdw3V3hor/0yOuD9/M/R5UcDgf0O6evS4OQopQmiPmyxIuf6P20hr KSb/efJnxyzXjNAcIpUxv/cE84Y/6chiz28w3AfeNrP0J0kYefVpuksOpubZCgDDJfFA +zvNc7NJzX5JWIj0BBmyub7N6/NXNpKKhLelAJC2HdNvDTuXNEDm1xUmKFMxyPLr/vmy +UBGl+3yJK578pvqcNaqfAQ6x8PJF2md8pUJ+9tzk3T0yeYjppl0paJnzh3e+R5Twwdk ecgx6qi4hU46P7Og5bnc8xcaX9g27ZG4i+ukUpuak/tRv/UWJMXJc3k5Oj4Olf4p+7a7 rjUw== X-Gm-Message-State: AOAM5337NohHilVoEbzu+md4bPXOFcTr5PnOlOZw+Fx2c3Bd+j8s49G+ fseichKknYvVsc3CLDcSQv4Wu5Nb4VVvKA== X-Google-Smtp-Source: ABdhPJw2Jd0LjoqCgSx0OSsfGmFK4sDwcy6lfZQAMho8Ht+qA/gMlqe3oGZ8TXtDNgA8BmlgLeRW9g== X-Received: by 2002:a05:6830:1210:: with SMTP id r16mr14473794otp.57.1605043315578; Tue, 10 Nov 2020 13:21:55 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id j8sm1915468oif.55.2020.11.10.13.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:55 -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 v2 08/26] completion: bash: get rid of _append() functions Date: Tue, 10 Nov 2020 15:21:18 -0600 Message-Id: <20201110212136.870769-9-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 ++++++-------------------- contrib/completion/git-completion.zsh | 10 -------- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 6a1106f17d..7ecec00624 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -287,8 +287,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. @@ -301,19 +300,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[@]} @@ -431,16 +417,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). @@ -450,7 +428,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 @@ -837,7 +816,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 } @@ -2612,7 +2591,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.*.*) @@ -2662,7 +2641,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.*.*) diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index fa7f88bbb3..1781401f5d 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -120,16 +120,6 @@ __gitcomp_file () compadd -f -p "${2-}" -- ${(f)1} && _ret=0 } -__gitcomp_direct_append () -{ - __gitcomp_direct "$@" -} - -__gitcomp_nl_append () -{ - __gitcomp_nl "$@" -} - __gitcomp_file_direct () { __gitcomp_file "$1" "" From patchwork Tue Nov 10 21:21:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895347 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 5D3CDC56202 for ; Tue, 10 Nov 2020 21:22:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 102BF20781 for ; Tue, 10 Nov 2020 21:22:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gDO4fPbY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731847AbgKJVWA (ORCPT ); Tue, 10 Nov 2020 16:22:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731835AbgKJVV6 (ORCPT ); Tue, 10 Nov 2020 16:21:58 -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 D8270C0613D3 for ; Tue, 10 Nov 2020 13:21:57 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id n11so142729ota.2 for ; Tue, 10 Nov 2020 13:21:57 -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=PzJCSLWW82V5OOHIX+VN205dxl4K03BLnTUqqJG+yrk=; b=gDO4fPbYJ1pGX6GVxcWnTqdPBY+jyTwqiDzzg2KVSlPA9LrL1Yc/hpNo8wp66fWIW1 CeMygdHJlQbmyD00MKSQ9zCxajbft3smDCJ9Mlv9N6TdHmGhii3YX314mcnDVkY4t77O wldLcHOG+GOTzd2nBekI0MqdtLJ+cP8YjM6lu6C7yLqJcX/l4GuWzftX0pyJpgm6BFYu yffWYS7tLweR81v9VepbaX5//vkxKpisbhyw1Kqu2bUaUGVZri1ykLjGaJusSlrcbz+q ywmxb86UDtcmCv7+yMQsZpPZhc+GzdCIzw5dgbAOLhqQUYazMYbOR8TXV5W6MTzH8POp 9bRQ== 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=PzJCSLWW82V5OOHIX+VN205dxl4K03BLnTUqqJG+yrk=; b=RyQulWVJHZf3bEL1KSLKkeJ2FRssNZcWPAy56VTOcGhmm98ndRx/ifOI36Afzy6Ujz KLBm6Bx36CeRWvIGuyje1o6GRF5KmE/l2recbKhSfLLiU5zXJ1hvPsXJYurxI7oZdg6B yyz+5AqmbfJ6gEFmV3hNhxTst2m00CjBHuglzlfW6270xaKlVHHO62ZMl65lbQToRytC ZT893/cWEbNerBcypBnqpRgd9jdglJQb24RXFjKU44zY1YSVDIBchjzEKlTUkx/yo6kb iLIUA/fHtf/9CWwg+kCSgy2ZecxQL1BiBLVPUTZWO/a8ScbezDUaZloAbLdKWV7kvJPc ZmVA== X-Gm-Message-State: AOAM531qrDTMLXLPPFiUDKbPZLW17VQ9+8V1BB01MmRDs7guPacx+eID E0nrYvgGtknjw94NVpqNh189kDayd1++eA== X-Google-Smtp-Source: ABdhPJy7F5cxsNSC2zFjFurhYIxZC0j2XQmIH8dA3IwVcne9nUcWnhm1XWeoyES7FqsQ3JhOcoFd2A== X-Received: by 2002:a9d:2c68:: with SMTP id f95mr16025014otb.300.1605043317011; Tue, 10 Nov 2020 13:21:57 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id 66sm26257otp.33.2020.11.10.13.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:56 -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 v2 09/26] completion: bash: get rid of any non-append code Date: Tue, 10 Nov 2020 15:21:19 -0600 Message-Id: <20201110212136.870769-10-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7ecec00624..15d7490cfd 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -300,7 +300,7 @@ __gitcomp_direct () COMPREPLY+=($1) } -__gitcompappend () +__gitcompadd () { local x i=${#COMPREPLY[@]} for x in $1; do @@ -310,12 +310,6 @@ __gitcompappend () done } -__gitcompadd () -{ - COMPREPLY=() - __gitcompappend "$@" -} - # Generates completion reply, appending a space to possible completion words, # if necessary. # It accepts 1 to 4 arguments: @@ -429,7 +423,7 @@ __gitcomp_builtin () __gitcomp_nl () { local IFS=$'\n' - __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" + __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" } # Fills the COMPREPLY array with prefiltered paths without any additional @@ -442,7 +436,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 || From patchwork Tue Nov 10 21:21:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895345 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 853A5C56201 for ; Tue, 10 Nov 2020 21:22:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24B1820781 for ; Tue, 10 Nov 2020 21:22:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M/Gf4O1A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731871AbgKJVWB (ORCPT ); Tue, 10 Nov 2020 16:22:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731795AbgKJVV7 (ORCPT ); Tue, 10 Nov 2020 16:21:59 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F7E1C0613D1 for ; Tue, 10 Nov 2020 13:21:59 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id j14so148363ots.1 for ; Tue, 10 Nov 2020 13:21:59 -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=c80GcgqRsU46vOjDm/wQpmL7rkTgHbBp13e34/gMSPE=; b=M/Gf4O1AygGAP5eSVUol7uBvheHLeuRiBvTfiT8Xp88PNdygFptV3rX9LcYJOGHXS0 SjijPra/M54BCMpfCKjVYxyE9dvogYM+aE6Pf3H4Ho3MkbMqLI7P00JkEatk8ZgiR2Hg HJcndFOEiLgqwjJWqNMw4pRbkJW8eVhVTtBrf3GTkDQot7dSD5IuAiW1sQTdKwPFuySy Q/c4rDDQmhP+Qy1a6UzwAQG9arrScdpJ9s7Af1tEFvdaACLSs/IKWkx9x52CuuMhx1a0 WmFDxltkeSaLVGuo7M7I3AM5ibTWyhXdrr8BTxXMm3kmIiQOhUHL1C8sjMRQXEl3HzLm mJFA== 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=c80GcgqRsU46vOjDm/wQpmL7rkTgHbBp13e34/gMSPE=; b=NFSnepANS7LLcEzfXlKhMiUxO7ckT0kslg8iqmRQeTWosK4M/e61gqaViD/Q7w6duD 6Cge/0552bfP8XRNYccWB9ONYNQ7AGC/S/t1XlTuSr7oPq66umQZvP/owOvlKf3Og6IK OAXIcqDw5vFHMV4IVf7ZUnrWxzlE1Z9x3dRr70aAr4zutGHtyGWNgae+7ofONOunz9s9 n6w0U6X5kMXlZW5iRhbaXA+OznO68bLRDJ9U1G/+81i/7e5dpT6a52KRLWG2zUo1LARk d/eYpZcII+m563308cJotVzi1sZFGNFVdA2j5FM/ywZG4W79BAb+dC6K8guocu7aPiMf wTxA== X-Gm-Message-State: AOAM533qnsjo1DH644naxN5YuHgYvGK0HSnsO3iZHpt114zBw09nT3dB 3y1m1I6jM29Cuuzkfpycp+aOVHl6M2sgIw== X-Google-Smtp-Source: ABdhPJy3tVV2WfFOjqFIT1rkZK9xubRs8iODeBqtpo3rfa34r2hZ5MbfTs+wQp91nIeRRDLsWqA5lw== X-Received: by 2002:a9d:39b4:: with SMTP id y49mr14756404otb.20.1605043318678; Tue, 10 Nov 2020 13:21:58 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id h28sm36111ooc.42.2020.11.10.13.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:58 -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 v2 10/26] completion: bash: factor out check in __gitcomp Date: Tue, 10 Nov 2020 15:21:20 -0600 Message-Id: <20201110212136.870769-11-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This way we can reorganize the rest of the function. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 15d7490cfd..bb1250f10c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -321,9 +321,11 @@ __gitcomp () { local cur_="${3-$cur}" + if [[ "$cur_" == *= ]]; then + return + fi + case "$cur_" in - *=) - ;; --no-*) local c i=0 IFS=$' \t\n' for c in $1; do From patchwork Tue Nov 10 21:21:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895349 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 9F927C388F7 for ; Tue, 10 Nov 2020 21:22:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66111206F1 for ; Tue, 10 Nov 2020 21:22:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="toiYWovb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731876AbgKJVWE (ORCPT ); Tue, 10 Nov 2020 16:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731795AbgKJVWC (ORCPT ); Tue, 10 Nov 2020 16:22:02 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03415C0613D1 for ; Tue, 10 Nov 2020 13:22:01 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id 79so111470otc.7 for ; Tue, 10 Nov 2020 13:22:00 -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=DYKOgf1LrApHyUZ/n7r52EOKugri1nEYLVh0uX8lvxo=; b=toiYWovb6OVtPKDdy8zP8xlcpVIGXKLDmIkN+En+Wd80WzGI8vHOW+ZlhegYYjFjgg QwFYhwvP/4h5HXHMZ1W7ImjY4psLWDFKmGwZQDTqgDR5OjZ+koI/H0oSgk6fUsCA7xlj AQgQG8GvMRJ+U+Zm847/na/dTAiCGVa/gSknwyqW91HqxOPIiZ7lWJylbVaIiTzBsFEy ZhFJKBYBYNdFImJOZcNEt+/HPkaZm0ZmodJcmNISq1MPUVno7YKMh38vX2iOmCHOzUnE P/p6I363ZfvYa6+ctBaoY18QmgeW/Dsh2+20RPi8CX5XZd52VvbDVY1ovgQwKvKz5twH OXmg== 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=DYKOgf1LrApHyUZ/n7r52EOKugri1nEYLVh0uX8lvxo=; b=mNvaBKR9uPqR1p/fwa2zA0cMPrxORtY8Pm07G1+HTX8Eskc5bGI0xWZ5wetjvPX/Ic +Eh0crqRUyq4uCiiOBXswAMVN6BQ1ZWlW6ZsPTVfrevLRZNn/JbPVbQmzOS5EBUtOsU+ F5ZWD3bVmVZVvskyktf0s62GBuWk4mB6xizxm+an7xTwsNO7m5sxU6DhAG0shUepJ7NS lWYHqBb0NUpdLYGXkxolID+87MWrGm6/GWTW+fHcbJQUuDKCU6P/jTk3FaG5BHPTQRdq IiRqeo1y2VqGddVIxwgwvhHOxabE6erD3hUCzC7eRHJvkUTR5EYjH5TNT5ONDIeMhAne bglw== X-Gm-Message-State: AOAM532IYDjI8nLz4wmrn7CJ5oTIOkFor4adoYjEN4tJ6Dnh5fkU9qUn lShGQWeGfAVz5SSY+ykrVYobWUQL/B7Tww== X-Google-Smtp-Source: ABdhPJwg60REk4kU879nnVz3pmaPwm1KevnBL9qKHE/RV3+q1+kyBxKXtYrUu4J/r2KEqFGoXys/Gg== X-Received: by 2002:a05:6830:84:: with SMTP id a4mr11938155oto.341.1605043320231; Tue, 10 Nov 2020 13:22:00 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id j23sm47116oos.4.2020.11.10.13.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:21:59 -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 v2 11/26] completion: bash: simplify equal suffix check Date: Tue, 10 Nov 2020 15:21:21 -0600 Message-Id: <20201110212136.870769-12-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We know the prefix is already '--no-', there's no need to check for the first '--'. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index bb1250f10c..3f684cfe59 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -335,7 +335,7 @@ __gitcomp () c="$c${4-}" if [[ $c == "$cur_"* ]]; then case $c in - --*=|*.) ;; + *=|*.) ;; *) c="$c " ;; esac COMPREPLY[i++]="${2-}$c" From patchwork Tue Nov 10 21:21:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895337 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 2E69DC56201 for ; Tue, 10 Nov 2020 21:22:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7C3720781 for ; Tue, 10 Nov 2020 21:22:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cVF5unyf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731900AbgKJVWF (ORCPT ); Tue, 10 Nov 2020 16:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731880AbgKJVWE (ORCPT ); Tue, 10 Nov 2020 16:22:04 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FCD6C0613D1 for ; Tue, 10 Nov 2020 13:22:03 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id 30so104377otx.9 for ; Tue, 10 Nov 2020 13:22:03 -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=dgROHsOqiiHds70f46AQaTOFp80zriEFNciFNyN8yaU=; b=cVF5unyfDL+o1w6/nWNVDgZPGmcpdKgmtjM84NaguqvsDNudSr9RFg7Kul8Za2flud 5BjrmgnV5sSDBaFkpqVumG2cwe0GnqaSDAfPfiIafSLiCiHFR9Q4jtK92f4E8H7P9Td7 p8sC8/UeuJ6n2APy8PnuX3pO/jV5w2ynzgsDTITHyPtuWMXLJu4fBHT+4uiYokNCsyRx kRS9udfXZNFZRWowj2HaP9gFg5ny9oeRWOjWDgJEXnPrMtNjnyIqGyAST9hFtxJnQR2T d3w8jYUcIkLJ+ap2DeJTOw+hLmMkYH49EqxM3Wo+vKqFQMnKH6DgjA1ql/rDeIPayqPu 9XQg== 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=dgROHsOqiiHds70f46AQaTOFp80zriEFNciFNyN8yaU=; b=ErBDvz5AouyxKep4hXDp6Uuly9hPopPzuZUpST1AgZzAqLZtdVKuXOPUXEwDjV6DtX LvaGhxNxwXGZU1OoFVsAfju6zjCaDVxYpnl8duTWV2VJ/clyNAKp9OEwJCl1kC3L7tVd R9p3A0I7cY8Tqnixcdxy9bXt9cHDZ8JDUzcbxttWqHU2SkM+4sucSLG+9UmGKdKtXC6h gBbX6aZYwXeIqVOv8+O3SCTa5TbqAM8iklJX0iKDBO4XpeGbN60hX3YJydlhlwWP5gHz c1qbh+FviOZc6Ctw9oZU0sk5p/LobbZiRY0Jlb1G8ylUX43uui/KBHGnR8A/fbmXM/dE Ir4Q== X-Gm-Message-State: AOAM533HENu7CyT35SCUcc+vF7vTtkcrOv/gD1WWtSikfPShn08EwNeP quJ72AtJMYlxjtLhCMgYCKbdUFvsDcNPiA== X-Google-Smtp-Source: ABdhPJxKs5G9pSynJNEqJdaye/MH4woRJiPtoXF/GPcaAXnP4s4y3Y9xtNDY/MiVx9QVTE2lywxkMQ== X-Received: by 2002:a9d:46f:: with SMTP id 102mr15815937otc.293.1605043322237; Tue, 10 Nov 2020 13:22:02 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id j23sm47135oos.4.2020.11.10.13.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:01 -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 v2 12/26] completion: bash: refactor __gitcomp Date: Tue, 10 Nov 2020 15:21:22 -0600 Message-Id: <20201110212136.870769-13-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We have to chunks of code doing exactly the same. There's no need for that. No functional changes. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 52 +++++++++----------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 3f684cfe59..8b4308fc99 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -325,44 +325,28 @@ __gitcomp () return fi - case "$cur_" in - --no-*) - local c i=0 IFS=$' \t\n' - for c in $1; do - if [[ $c == "--" ]]; then + local c i=0 IFS=$' \t\n' + for c in $1; do + if [[ $c == "--" ]]; then + if [[ "$cur_" == --no-* ]]; then continue fi - c="$c${4-}" + + c="--no-...${4-}" if [[ $c == "$cur_"* ]]; then - case $c in - *=|*.) ;; - *) c="$c " ;; - esac - COMPREPLY[i++]="${2-}$c" - fi - done - ;; - *) - local c i=0 IFS=$' \t\n' - for c in $1; do - if [[ $c == "--" ]]; then - c="--no-...${4-}" - if [[ $c == "$cur_"* ]]; then - COMPREPLY[i++]="${2-}$c " - fi - break + COMPREPLY[i++]="${2-}$c " fi - c="$c${4-}" - if [[ $c == "$cur_"* ]]; then - case $c in - *=|*.) ;; - *) c="$c " ;; - esac - COMPREPLY[i++]="${2-}$c" - fi - done - ;; - esac + break + fi + c="$c${4-}" + if [[ $c == "$cur_"* ]]; then + case $c in + *=|*.) ;; + *) c="$c " ;; + esac + COMPREPLY[i++]="${2-}$c" + fi + done } # Clear the variables caching builtins' options when (re-)sourcing From patchwork Tue Nov 10 21:21:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895351 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 3A5F6C388F7 for ; Tue, 10 Nov 2020 21:22:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F012D20781 for ; Tue, 10 Nov 2020 21:22:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bn97dguM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731910AbgKJVWG (ORCPT ); Tue, 10 Nov 2020 16:22:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731880AbgKJVWF (ORCPT ); Tue, 10 Nov 2020 16:22:05 -0500 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D237BC0613D1 for ; Tue, 10 Nov 2020 13:22:05 -0800 (PST) Received: by mail-oi1-x242.google.com with SMTP id t16so16078524oie.11 for ; Tue, 10 Nov 2020 13:22:05 -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=KBs0yqmkj6oreqJAIV5pz6IDRsi60l3I+52qceKH+7o=; b=Bn97dguM4EQWbEU/X8bjS4jluDpGnIYcPpokyXDWoodhFhWyldS16tP8NFn8y4oGxt THvFC/8bnpvcUJeA256aZjc2TeBhQ0hPJcDRYqu1AqqVDEg0464yEl29Bx3sUqV3p63R cke9+e2eYH5rS4TjTQdLB/qLPJwjqIEw52ostdS4zDD3++bw6ZRIIEK3W8VCkvfb+xS9 Nk0os5p0qyiwHso7RikaXgWOI7LuW8q3iIr4VM8yRzILsK0GUXshZH8EpZhdrW0PIBmh YsR4OqwlPIjR7abTXU86HbprncG5+/aCBnmsv1BIozoveC+45yryo1DPsC7qBMJ1JDYw C71A== 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=KBs0yqmkj6oreqJAIV5pz6IDRsi60l3I+52qceKH+7o=; b=o1k6PD/qmBFlpLSyz1TyQRuMdqOTvh/ftl5IM07oF6d6GUtTaVFn1lxNe1Sj9uixfP WUxkNy3tws5as+ruSbS2WQEtlQxc4F9PzXHW/9CAZL7oKJwhULHnu4f/pM5ursMNlBWN ekzzgU6G4L8sCCBrPDRIgHlrx7r3YgV8EgICK7zTvGOHOo+tNqKG7ae5woqS5YslaPX5 Whxe3vhUJbZqd4ur6mB36d3Sfk8VkNAbNqqVmxVlR7a5M7rQhXR02oj0GbMYJVeEFoD+ 5CgqrpXymu7WOly+kL93YAQVyjL/1N5RABkETTSA3V+GzOEfYZahq3wtJF6t4lcVzkDf 3UbA== X-Gm-Message-State: AOAM532OPjP7s/+VxH6CI6FlHPoHUCfaKdRzzY8rkVbg+KUKM2RPAbTj vvut0+3mbkmFzwvkVW1CI1UNddzeUPwm/A== X-Google-Smtp-Source: ABdhPJwuE7H1HD90kx8iGfRQiebENkwHjELIzBXgvK7WS0Zq6viQPVUrjbKw3G2sD2CVELw8JDGoLQ== X-Received: by 2002:aca:bc03:: with SMTP id m3mr47469oif.35.1605043325053; Tue, 10 Nov 2020 13:22:05 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id v13sm308838oic.17.2020.11.10.13.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:04 -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 v2 13/26] completion: bash: simplify __gitcomp Date: Tue, 10 Nov 2020 15:21:23 -0600 Message-Id: <20201110212136.870769-14-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's not possible for $cur_ to have anything more than --no- at this point, so there's no need to add a suffix, nor check anything else. All we are doing is checking that $cur_ matches --no, and adding a completion if so. This way the code reflects what we are doing. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8b4308fc99..9f5dd4e3e7 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -332,9 +332,8 @@ __gitcomp () continue fi - c="--no-...${4-}" - if [[ $c == "$cur_"* ]]; then - COMPREPLY[i++]="${2-}$c " + if [[ --no == "$cur_"* ]]; then + COMPREPLY[i++]="--no-... " fi break fi From patchwork Tue Nov 10 21:21:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895359 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 4CC49C388F7 for ; Tue, 10 Nov 2020 21:22:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B55220781 for ; Tue, 10 Nov 2020 21:22:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xnv74KQ7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731946AbgKJVWK (ORCPT ); Tue, 10 Nov 2020 16:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731880AbgKJVWH (ORCPT ); Tue, 10 Nov 2020 16:22:07 -0500 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA9D4C0613D1 for ; Tue, 10 Nov 2020 13:22:07 -0800 (PST) Received: by mail-ot1-x335.google.com with SMTP id l36so130369ota.4 for ; Tue, 10 Nov 2020 13:22:07 -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=PNb4m+fcbT0dHh0qgBa3+vMGgmX9k+yzQr1pu/wqUeE=; b=Xnv74KQ7eqJjHQPECodNQeYmeVO0MX8UU23hZH/Cq1/nMyY8zrjPctiS0kzB+GAj5J le/8aSSMuxp1dbekBwXt3Ldf/QClqBByHkJTNRzxUL+vE/jH3m8bPks9/8EkJMCQONjq tI/J31MnGX2OrcFY0UKqpYHjkFCe6o1gb15zEXegj03C7N/NQ/iSG8ODGjJayML+Xbpd laHx7kf4b3242fCAU+PfpFKCyjFn7juvdW72Y/o9BZxboJfNg506iyJyrKhuhQzGY4bq jeWQH/CtiJZc/4Rt1XQsnZpWsZ9nO1HkyQEs6iBd/o9Ta7UbdPD3AGDfAS1bWFr7lhbX xNOA== 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=PNb4m+fcbT0dHh0qgBa3+vMGgmX9k+yzQr1pu/wqUeE=; b=uVbTISqOzZXO71GmTHwtuoHi3z34A05MPsTTN6DXhGxTg4Xn0Uv2SWF47w9uf3bca/ 6giwKQcZXH6HXyeAR/GtZ+0js4kGDExhen8Fi3/GlsROw75uL1mAzf+zt19RrWc5fzDu BJgvFqnNQoPPc/z7GLdcG1jvdcl1psUyf110Q6+G38bpDwgzCYHi0z/pa+89+WUHWI5/ 8/ChWBpKFLwKl9wyBygpCKN+yZqnvUyuge6S+ETyFicfsqwlgbv8vx3SqJr6O2TOqLed dFP0OFGUm6XH+IUR/QCs6uyVI8v1RG9Nwq0TOjQxb2Q2BhNmXYsyBsTOGSdm4etVW8T7 osfA== X-Gm-Message-State: AOAM530gKzLb1k5netBIceK9Vi2I10S0Oz/R6/E3ixQ3CQHlh39UOshr fzXreCtQ8r6ncbiVEkDcqbZdJl4PngksEw== X-Google-Smtp-Source: ABdhPJz0IQ67LWvMowwsLrG3GzOhHB8W7UB53OuC99VZrz82REWwsP8qKabiOVyFQZg4bQlRtpfC3Q== X-Received: by 2002:a05:6830:150d:: with SMTP id k13mr14595529otp.26.1605043326987; Tue, 10 Nov 2020 13:22:06 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id f5sm22683otl.48.2020.11.10.13.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:06 -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 v2 14/26] completion: bash: change suffix check in __gitcomp Date: Tue, 10 Nov 2020 15:21:24 -0600 Message-Id: <20201110212136.870769-15-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We don't match the prefix, we shouldn't match the suffix either. There are no functional changes since all the callers that add a suffix add an =, and if $cur_ ended with that suffix, we would return immediately. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 9f5dd4e3e7..829985e4fb 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -337,8 +337,8 @@ __gitcomp () fi break fi - c="$c${4-}" if [[ $c == "$cur_"* ]]; then + c="$c${4-}" case $c in *=|*.) ;; *) c="$c " ;; From patchwork Tue Nov 10 21:21:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895363 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 65DACC55ABD for ; Tue, 10 Nov 2020 21:22:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E9C4206F1 for ; Tue, 10 Nov 2020 21:22:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nNbTDZvx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731951AbgKJVWK (ORCPT ); Tue, 10 Nov 2020 16:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731912AbgKJVWJ (ORCPT ); Tue, 10 Nov 2020 16:22:09 -0500 Received: from mail-oo1-xc44.google.com (mail-oo1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E435C0613D3 for ; Tue, 10 Nov 2020 13:22:09 -0800 (PST) Received: by mail-oo1-xc44.google.com with SMTP id l20so3467993oot.3 for ; Tue, 10 Nov 2020 13:22:09 -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=1Z5A+ReXvPAK1KMPYkePZvPxt9tNtBGjJsIazUNz07M=; b=nNbTDZvxc1zo3wIFILt4kxUwirTgLf7KhLUY9dYxdvP14YULJs9MrHXSzgcOSTLYOZ BdgdP3LxWPgpIWi3/7FDkbzK2WmBRiGhpjSmiW5krpx8mExFuMjcFKmxO2751ScB/YYc CFYWnkP/bmYpdgB/I2WDRiTZM+2GzTd4gxNpYWQr3LSuqHSjkxnwBft3LOahSW5bLrSw 2Vxd63GQKr3+4JED/1zeEw9s1yxHfojbHxwdgMp986rwOTyE7CMcjlhuPgq91uMKSEjh Ath96UM8LNsFpy/H8vfWL+SXKIwp3c6WD+PtADlCBhAuMcr5KJvo5Q8OddlgI6Sk9cen OtdQ== 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=1Z5A+ReXvPAK1KMPYkePZvPxt9tNtBGjJsIazUNz07M=; b=VL1vcXO/ZplxDEyyZmTRBeZs6N3qq6VFSOHy/3sWrZR2huuQWBf73WJEVQq673Lati e7hOHJGZja8yy57SRnFGwxufYn+aUkpok1k7tEsIb7e0ww71AD3o5qSY5gTOJaICGs3T 4L8YIW6WSjLmf5qDhvHWco9Xp++mXqPmWtd16/uUS6DvEl1cJoY+bkblqRDvdm9ceW2z IdeEugxQpbLMknASTb93ow2tRWlwMusYBV5BjN//0jRhTlbKP8u9NEbleYhJP4IMgjTR a35K/2lYvZBkxM0gil5GDVoRnXv1RvDcc2c27No1B52/c38nqhHbJ3N08xoXJ1r2Ebdz HI2w== X-Gm-Message-State: AOAM532SLIxebKaXD/ziwfu5P4kFnmzZv6xLVswcWl4UkqQ5F1AnuNdj vULf/AymwhiGhWOXKQDCMJ1R1JZv3RdK3w== X-Google-Smtp-Source: ABdhPJyJFMUnlxVyWSzxYrMcz8vARuUvrnfHULTqWVZqnin2bCFCoRGuMLERwajbIiomnuXx1cKqQg== X-Received: by 2002:a4a:1e43:: with SMTP id 64mr14802789ooq.57.1605043328806; Tue, 10 Nov 2020 13:22:08 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id 186sm40867ooe.20.2020.11.10.13.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:08 -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 v2 15/26] completion: bash: improve __gitcomp suffix code Date: Tue, 10 Nov 2020 15:21:25 -0600 Message-Id: <20201110212136.870769-16-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 adding a suffix after a suffix. If a suffix is provided, we add it, if not, then the default heuristic is used. There's no functional change since most callers don't specify a suffix, and the ones that do use an =, which by default doesn't add an additional suffix. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 829985e4fb..594e41276e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -325,7 +325,7 @@ __gitcomp () return fi - local c i=0 IFS=$' \t\n' + local c i=0 IFS=$' \t\n' sfx for c in $1; do if [[ $c == "--" ]]; then if [[ "$cur_" == --no-* ]]; then @@ -338,12 +338,11 @@ __gitcomp () break fi if [[ $c == "$cur_"* ]]; then - c="$c${4-}" case $c in - *=|*.) ;; - *) c="$c " ;; + *=|*.) sfx="" ;; + *) sfx=" " ;; esac - COMPREPLY[i++]="${2-}$c" + COMPREPLY[i++]="${2-}$c${4:-$sfx}" fi done } From patchwork Tue Nov 10 21:21:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895355 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=-9.8 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,UNWANTED_LANGUAGE_BODY,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 D816EC55ABD for ; Tue, 10 Nov 2020 21:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A0FB206F1 for ; Tue, 10 Nov 2020 21:22:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VYIodIQQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731956AbgKJVWM (ORCPT ); Tue, 10 Nov 2020 16:22:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731912AbgKJVWL (ORCPT ); Tue, 10 Nov 2020 16:22:11 -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 7D3BDC0613D1 for ; Tue, 10 Nov 2020 13:22:11 -0800 (PST) Received: by mail-ot1-x341.google.com with SMTP id i18so154275ots.0 for ; Tue, 10 Nov 2020 13:22:11 -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=frUXtU19zgmRSJYaTvhzBs5XfOOvZgKr8wfiNO7CmE8=; b=VYIodIQQUYvLtioDsWPun2e5k43qsM5eBfbQdsfyLv9MH9fvt5lgLT6hM5RLp7dLg6 Rg0RNQhi0D/UBadi6MW4j8B+IADeH3l+TB2XUh3cRSSIV4MLCoxRGWqMoqJs6ynX58GM eIqu6QBIUqqxBDJcvaPvbFGYdbZuNvpkdnXyAOai7/pcIcFJioU9IXyG22nDmf3UdZpM 82pTreqd6k2ZzsbYsxsTWENXb/og/vf/bl4Q6f+FojfzXjDebYcOf0KMms0D9mzLVguT 8HbrPj6jJfrnYPy+6dQ7u510PkQZYF8c4mYAF20A9iepf6jwFX0xezgeAJ6g1DXL8Pd5 2szg== 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=frUXtU19zgmRSJYaTvhzBs5XfOOvZgKr8wfiNO7CmE8=; b=hT2qGved88F8kX2rOtXQCvRZNPnFLxnal+GodRD9NhjI1FSqzdov4Mxj5gmOxhFhyh gNWKbS9te+y25loTxdgJJDckVTkKDicaGdGH476r4odmR9ZNvEfY1MC0EFociEZTJqI0 sJaqLtXtae2T9QCWrC1naGw8xq+dTLb4NGTuFRw2sNpazbXJTXivDJ+ibkCgKpiAwwYF xEsWvpxrTnjlWCZ0dG8EB8L40DO1WnUPGEO8O/PIMe9XE0T0+ZpHLVIWKnl0cnuBZoEx 2Fev/ZFHvJzZLmQIb/5QjCqz9sSnlXOW0QzB3t6N613A2hWdssBU3W4CyxCeQNHCKphj aAaA== X-Gm-Message-State: AOAM533vDD2b/mZChLQ4AmkPfE7c8Nf5D9SdTNamvJsH0tVR5jILj+MX 5koJoJUsJXXQVz6eb0aIqXoQco0hIvoxfw== X-Google-Smtp-Source: ABdhPJzioz1DDkJp+hrBbb22Ir26T5plze0cdQT4Bns940g77ilNyArhhj/etQ+y126OUZ69DHDOnQ== X-Received: by 2002:a9d:eeb:: with SMTP id 98mr462858otj.179.1605043330689; Tue, 10 Nov 2020 13:22:10 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id e127sm3376400oia.12.2020.11.10.13.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:10 -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 v2 16/26] completion: bash: simplify config_variable_name Date: Tue, 10 Nov 2020 15:21:26 -0600 Message-Id: <20201110212136.870769-17-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we can actually pass a suffix to __gitcomp function, and it does the right thing, all the functions can receive the same suffix. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 594e41276e..56a66a375a 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2547,7 +2547,7 @@ __git_complete_config_variable_value () # subsections) instead of the default space. __git_complete_config_variable_name () { - local cur_="$cur" sfx + local cur_="$cur" sfx=" " while test $# != 0; do case "$1" in @@ -2569,7 +2569,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")" - __gitcomp_nl $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }" + __gitcomp_nl $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx" return ;; guitool.*.*) @@ -2603,7 +2603,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __git_compute_all_commands - __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }" + __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx" return ;; remote.*.*) @@ -2619,7 +2619,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." - __gitcomp_nl "pushDefault" "$pfx" "$cur_" "${sfx- }" + __gitcomp_nl "pushDefault" "$pfx" "$cur_" "$sfx" return ;; url.*.*) From patchwork Tue Nov 10 21:21:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895357 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 56644C56201 for ; Tue, 10 Nov 2020 21:22:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEAE020781 for ; Tue, 10 Nov 2020 21:22:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cfwiw54/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731968AbgKJVWO (ORCPT ); Tue, 10 Nov 2020 16:22:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731912AbgKJVWN (ORCPT ); Tue, 10 Nov 2020 16:22:13 -0500 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C282C0613D1 for ; Tue, 10 Nov 2020 13:22:13 -0800 (PST) Received: by mail-oo1-xc34.google.com with SMTP id t10so241128oon.4 for ; Tue, 10 Nov 2020 13:22:13 -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=UkU5z8sfNDXovy2ZdIiqze3JF/d4JAzCtCfhdyoJj/g=; b=Cfwiw54/fdNG+4yQ8Zq48UcPkYHtJnshc4DIlLQmzQVgFy72S3+hOLB7U59Jlo4jcH 2jS7J7Gyf1DKc+W2cxOR9+yDqa7mKW139Hk6h5Brpu7t3I+bw9E1Tj3svBvUfPnkc+5V Vve0IPaNxJPJXKXzsSnceCSegnGcehFDMZNwch8RJTkixl83hAE4K8oJQjb4P+xSLRit 14+C+Fjn1EocbF1LH4g/U2Dgl9SAqV3XCiTIrw47Gx+NgVUGQTZYJyf1sxPE7SXRRZbj UvLhaKm1OYA87Qb00H/XoO+UbsOnSh8lk1e1+xeRwUC+ylY7LvLUnSRKniT9JegxQy8u oaTA== 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=UkU5z8sfNDXovy2ZdIiqze3JF/d4JAzCtCfhdyoJj/g=; b=C/0EFexmGAPATMlizoV2fnV5tLY6dVXQOxAr2TL/IQrCNnlwh2Wt1YlLJ7IW5IYmH9 GqmgClLX6Yv/fED1qOhTYJEbTHmcWIgvbqYRmSCnJdT94CU3jh0RQeBBsxI8SkfvZS/P Q7lWzov8oXbt8gLxZgieZ7+SxIKiV37SXRI5UsbMDlaMFyQIIyuoI/UcEM/cqviAvgaG 3tDFDP0r7XD6UDfkhj7GlLkmyMS4fVXKrMwzNmZ8r1hqWoKSk8T40iGRL9GWMt4TG9Oz r9YqwIjdrRDCqWCyaftzMFa9ViGpgT3VsQgeVqhPlqSpkfP345VLybAL556Bv0VnXHbA FPIQ== X-Gm-Message-State: AOAM5325oby6b2oE/A6xPe9Mq5eajEZJEGHFdyEGaB4H1QagQfQIasIf 9Fo/TVZi3wwmS7X7fXJH2vncVpW6OVWj9g== X-Google-Smtp-Source: ABdhPJy+9eAiZi1BOCeMHHQpqqZsFMrn+898U3l9uB1qoiu05iSujL7/mJCXmvhP1eUrqHQyTZnJyg== X-Received: by 2002:a4a:e09a:: with SMTP id w26mr14977174oos.18.1605043332361; Tue, 10 Nov 2020 13:22:12 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id l2sm19923otl.67.2020.11.10.13.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:11 -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 v2 17/26] test: completion: switch __gitcomp_nl prefix test Date: Tue, 10 Nov 2020 15:21:27 -0600 Message-Id: <20201110212136.870769-18-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By default COMP_WORDBREAKS includes =, so it's not realistic to test for a prefix that almost never will be there. No functional changes. Signed-off-by: Felipe Contreras --- t/t9902-completion.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 3ec9ff9308..012dade4a5 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -570,9 +570,9 @@ test_expect_success '__gitcomp_nl - trailing space' ' ' test_expect_success '__gitcomp_nl - prefix' ' - test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF - --fixup=main Z - --fixup=maint Z + test_gitcomp_nl "branch.m" "$refs" "branch." "m" <<-EOF + branch.main Z + branch.maint Z EOF ' From patchwork Tue Nov 10 21:21:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895353 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 68229C388F7 for ; Tue, 10 Nov 2020 21:22:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 070F920781 for ; Tue, 10 Nov 2020 21:22:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JCFSefGx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731984AbgKJVWR (ORCPT ); Tue, 10 Nov 2020 16:22:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731912AbgKJVWO (ORCPT ); Tue, 10 Nov 2020 16:22:14 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E59C0613D1 for ; Tue, 10 Nov 2020 13:22:14 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id g19so80977otp.13 for ; Tue, 10 Nov 2020 13:22:14 -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=GZ/l6PPoJxJkWA6o1N5NxZ2CSXJuFnIR4oTtK8vHmKM=; b=JCFSefGx3uL5fHVc7ctfoV7dSDKloqRRDi5QMTPdj0DLqwSemejn1xVIDMeS9pTJdu P7guZ6kO32gX6t2CumwE5PROXS6/p83ZSq+QvYX14TLA3mTu2HyMOW2vyduUccd4SEVq 6tW40Jx1uTEBn7l71i/1Ggwp27gcFKxKyUz9Dx4epqjlMiKH68CMnseviSNtETl88PbM tAjIjlkPxCQQ+Jk4bybqtOhg3RvNKpQU++svQF2XT47q3eoib55twZDltAD5cFvAlDth fXC9/6VZOwScYnyi3aVj/upJXyHdsIyPjpZUrrCafqkX5LdqC3J8n07LBxyUpoEuC214 pEjw== 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=GZ/l6PPoJxJkWA6o1N5NxZ2CSXJuFnIR4oTtK8vHmKM=; b=G4KqLK3qlClRBRLqveGR3igsD3pZIslYZOs12XwP4kuxQ5NFAGkwbNkj1tGuesHI+I X4drEWDMDaXg/UKvyK6elq3MoRODu2zysGmIdpNiSeHRfYnKHkVYXmL7xp3iVbkE+l1X TVjccTQ4aPHkLLrJsaO5hlVVekHBKt5JwOj0oMoIEbStDL9xgpnH3LC0Jh8xn/29MDzz hdoSszCNv2QZyR+RB5FuJARFlu8QwH4gaYU4XrlHIWKGS67aU7qZJ28clqATuEYn0Vae mSZDXYrjogur6WUntzR8dHiScjgg3T7ClkrQILJpo27M4dZ9txKwch11UWW6AIXW108S vwCQ== X-Gm-Message-State: AOAM530cyjDiCsneoWgZdMH4+Vsqtkv3m6CnvD/Bneawq0JZenmjKC4H vi6ieumk10mlMG7Wjssjlfy6RmhT3dfLBA== X-Google-Smtp-Source: ABdhPJxp2mqQVPygO2tecCa80pU9pVVUsq9k7PTFBBhaPNCU6wcgdYgz7+5qnrMfd4sQa3CaZai3Rg== X-Received: by 2002:a9d:5910:: with SMTP id t16mr16492209oth.155.1605043333802; Tue, 10 Nov 2020 13:22:13 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id y15sm17791otq.79.2020.11.10.13.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:13 -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 v2 18/26] completion: bash: simplify _get_comp_words_by_ref() Date: Tue, 10 Nov 2020 15:21:28 -0600 Message-Id: <20201110212136.870769-19-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 56a66a375a..4548f0c5bf 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 012dade4a5..e39febcc4a 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 Tue Nov 10 21:21:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895365 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 27E57C56201 for ; Tue, 10 Nov 2020 21:22:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D80DD20781 for ; Tue, 10 Nov 2020 21:22:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HWb+N4gP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731992AbgKJVWS (ORCPT ); Tue, 10 Nov 2020 16:22:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731981AbgKJVWR (ORCPT ); Tue, 10 Nov 2020 16:22:17 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4253C0613D1 for ; Tue, 10 Nov 2020 13:22:16 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id f16so93218otl.11 for ; Tue, 10 Nov 2020 13:22:16 -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=IYC7gVr5eIGjvppjJl0gAqkW+P5nqXGLpF5XTw5hth4=; b=HWb+N4gPCNtgHJ56FTdJH/Rv67jNi+ZXgB+59ShwSj6cd5vSk0mBtdM7VmNYCbTf/w qpEtvtlAe9Mt96rlfnximkXzUogwdrKTDT99j7Y/wodQVORTyKOMAJ2mvGaXMznbDSOA c0IRBYsd5OCOmxEs9ZA6xthKm7/EltqMNAH77TNnHuEoInBiueHwTu27LfIl2fwH/6vJ R5SH6DbN99wVAH5A9KkRYGflvAgwaxrtmp5UtFqNR1/yYQKzzfm6322cmDbq7qF0Kzt+ XRnazlqXIogQS3GNwzh4p9zfbegEoVPyxcvYOjDT2hE18wRYvnRlSz9JzIyr6LqltRx1 lSdQ== 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=IYC7gVr5eIGjvppjJl0gAqkW+P5nqXGLpF5XTw5hth4=; b=qz9VQZc93QGkvXtIfT4RwPj4JN0uCcBGcy+VnuZcVPdbnH31saO210xyhXseUafpCL 5EI4vJYOwI8YWFSetaRqvS5hrypgembpiY/5gJNWhfmvMd0SV1XN2Rp7F3+vDOf0vCsr cX6Hsk/GGnriVISUWwxmpG7/7V20Y3IYD/SEesKKTbqpyhhq6j9h5XdXY8mgB6CrZNPt XQURmoZVVoE7EZ4W9qp6T5ZNjnuKNdSLRLPJgB/HdMet6AZHQ1x9st4dPDVmRSO1aeHv 9mRgIrMBWotN44WF6i8gQrPB50+iX4EIWVFVHdC1jDPTMEi2Gt3BnYDYqNTXSyP/Ny8h 8+ZA== X-Gm-Message-State: AOAM531EAdOS5jQBx7LjO7V6N6xxjMzZ3yQZm8dI/CpNDFUWZHBLFB96 HLgdgBrPaK36XGANsIXwPzzVPilX4wQCgQ== X-Google-Smtp-Source: ABdhPJy+7VjovC6j8y9vK6Bt2FnVfFwct+wDTuYmgIxzDI4NzblT4e8l0o3qO01gwOTQv++3ImT7kA== X-Received: by 2002:a9d:481a:: with SMTP id c26mr15776515otf.58.1605043335829; Tue, 10 Nov 2020 13:22:15 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id r67sm3389165oif.43.2020.11.10.13.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:15 -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 v2 19/26] completion: bash: refactor _get_comp_words_by_ref() Date: Tue, 10 Nov 2020 15:21:29 -0600 Message-Id: <20201110212136.870769-20-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 4548f0c5bf..a7dd04bb31 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 Tue Nov 10 21:21:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895361 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 D0FEFC55ABD for ; Tue, 10 Nov 2020 21:22:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87D6420781 for ; Tue, 10 Nov 2020 21:22:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fm3QGxEm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731997AbgKJVWU (ORCPT ); Tue, 10 Nov 2020 16:22:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731985AbgKJVWS (ORCPT ); Tue, 10 Nov 2020 16:22:18 -0500 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A291C0613D1 for ; Tue, 10 Nov 2020 13:22:18 -0800 (PST) Received: by mail-ot1-x32a.google.com with SMTP id a15so125462otf.5 for ; Tue, 10 Nov 2020 13:22:18 -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=DXZAVWG0M4U5JwK1FPNGQG1iy+b7fd3t8SiEHSWljbs=; b=Fm3QGxEmLBm2uHDSawu77ZKjOfS6UVvKKgHR+fRtKNuhQGWd6gMVLv2SWLlqHf7xtc n8uqmjbKuQSBC611Ksfkeih+9hdq5THOJUjUA5XHlNj8IA++zyV0lYwMFd64enavEXK5 IJHKDW/a2jyww8lVRhLfXTu52c17JtRPVAYvmKg8GWdXJIx7h+ZJqPdxtFS6t19mXcCU iAB9hjhz+7bKgswk13nXvTqbcgJq4WUSflDktgPbqVbm7a2c8+YUIMZSWU+Aa/QgIxOb 2ca3q+1Bo9ohEw59lH9QsyGuvGRPwmYFZA8O1X5eud1DDGSTzJNaxxKo/YlT06UPFdml T6DQ== 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=DXZAVWG0M4U5JwK1FPNGQG1iy+b7fd3t8SiEHSWljbs=; b=bP9RMEPfNQRLfwcUOtR+1HBmAhN8DY3iEgGp7Vmpg3i3bcS8Gqy1eU3Ca3kXZ3TcZz N6vJklFiIjQe+KAYhDGAM9xYFfHFEkxAcnVrEy5TiOp3qqgBMQwl8tqreua6GNDw5TdK XD92fyogJ6WIK0q9WUsSBTryS/eiTBbDYDnK85e5dp40xLltF7g7OSYA5WZ0Q085tjH0 kuZnmXnkUsto8rOmo55rzSS2efddS2rXSktfkquj90JvGGbdCwCludQwhsMTS5Ku/L5p EnF687SmkuZjuiem0kCt0TE2jaILZDnR7UJ5GlHQILz+7vYoqi35AYzFjlDLWV1yS/6C nt9g== X-Gm-Message-State: AOAM5309XzUHStb65OCaB89PfsIGTHNEikK+7X1bc2sEjoAUf4PditjQ mmIYrygu15g2S8urp8Y7JKjh+ZNAwMid8Q== X-Google-Smtp-Source: ABdhPJyL4WDOVLpfQ19o1ahlGLQ3MIpSf3SmRA+35K2YCvZ4rJf7eGbHX855ySDG2Uvs7NE/JSkf+Q== X-Received: by 2002:a9d:171a:: with SMTP id i26mr14942119ota.313.1605043337560; Tue, 10 Nov 2020 13:22:17 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id d10sm1662289oic.11.2020.11.10.13.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:17 -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 v2 20/26] completion: bash: cleanup _get_comp_words_by_ref() Date: Tue, 10 Nov 2020 15:21:30 -0600 Message-Id: <20201110212136.870769-21-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 a7dd04bb31..6da7aca481 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 Tue Nov 10 21:21:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895369 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 AABB7C388F7 for ; Tue, 10 Nov 2020 21:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D51F206F1 for ; Tue, 10 Nov 2020 21:22:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pgi98rx4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732013AbgKJVWZ (ORCPT ); Tue, 10 Nov 2020 16:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731985AbgKJVWV (ORCPT ); Tue, 10 Nov 2020 16:22:21 -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 2E814C0613D1 for ; Tue, 10 Nov 2020 13:22:20 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id k26so16145599oiw.0 for ; Tue, 10 Nov 2020 13:22:20 -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=vR0rKYTjjX/qX3q2vcSfWbxdK1CoLcjvfq1eLIBdD78=; b=pgi98rx4T+CZNs7LSxG4BLliBYhb5KWFHAWtowl2hQRjOM8fJsEqzBIvbgO/h18fNJ LjqvCNwY/B+nz/69dAxsugHS4BQEWg1i78UC4qbdR08sKtXRSEBJ4kzVqtP/2Fc/RxjC 8WVuUzOzq4ar95Si2UATWOkgLUxEy/s3e6YsjLgGaed62PojPt/RPfNg65NfaIj/D+df 2FN5nuYGmYl+Wx/ykjqxJJXbUl4Dlz9XpPbUVC2VWMCcVc7XZ/F9AYHbMB6db6GXkJyL RmJHh0GDSZGdaVT06O6M64PzLyIXf0jTJaoTMrhJd/2PxTzznkE4FMyBXxm8eNBcvl5l 8YSQ== 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=vR0rKYTjjX/qX3q2vcSfWbxdK1CoLcjvfq1eLIBdD78=; b=djMzg3HYd7EM1arYbRvExXPrPImSm+xhTpcEfonmuuqLEUs9j22rsxJD4BUxJrRzMj ODGjGPlxOlgBvfUyiZNgRKvObABxe2OXHqDge5ISXVWvjoukwovnn1ET+IjXgA2HvYxO jYCTjL1PsBq09OWWco+dc269S7mq2egVRJNbz3WVWOqfZqpjCYqRQXA5TXe73nmTeXXl gjJjZScLkw+6IF7KUVDr6JArPVUKvjtPt16IOjPYu5hSauSPDeruj2o939FkKVwXCUEp AMBudGueWJnoiO84tw4j3Niwh2sQnBzmQfl01mdiycrVHhrWEpgQh/wdZF702l4MUefN OHYg== X-Gm-Message-State: AOAM531/p2mi6VrgSnrHqibtnu0v78/LO4cDB7D7Y3SmRtEJkcn+6/EL gncwgwESuoaxu5JX+wvFkU+hSSsckKKdqA== X-Google-Smtp-Source: ABdhPJyfT/HdTxhtZ9cVlEJwOU09F48FrFuQv3ZrGCmyqpCEJNx0kG2mGSNP+RfXmV/Eq3ZfsaTIbQ== X-Received: by 2002:aca:b887:: with SMTP id i129mr47960oif.25.1605043339394; Tue, 10 Nov 2020 13:22:19 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id m10sm39766oon.27.2020.11.10.13.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:18 -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 v2 21/26] completion: bash: trivial cleanup Date: Tue, 10 Nov 2020 15:21:31 -0600 Message-Id: <20201110212136.870769-22-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 6da7aca481..26f9accc30 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 Tue Nov 10 21:21:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895367 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 E8025C56201 for ; Tue, 10 Nov 2020 21:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90E85206F1 for ; Tue, 10 Nov 2020 21:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TxK3KOIZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732020AbgKJVW0 (ORCPT ); Tue, 10 Nov 2020 16:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732000AbgKJVWW (ORCPT ); Tue, 10 Nov 2020 16:22:22 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FCEDC0613D1 for ; Tue, 10 Nov 2020 13:22:22 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id f16so93457otl.11 for ; Tue, 10 Nov 2020 13:22:22 -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=0VqKHIhymTntDzvr1gPM0ji+e+nE+poyW90nI4hjCmw=; b=TxK3KOIZE07qBmTsBscAznjQt4975bylyWu2Zuf9AJYIoiAUG74N/jC/51lq/qRYNg tV4hJw1BxyKvEha+zhQ6ieaCEFgtCqiTampK8zXRzawEm2DRylIs9awXuquYwSW2jqa7 VC3eacPVnRyTC5j420kxqSHpsOBDr0+fuytH3xCcO/P9C3PZ/VlhcS7hWDzh8XafNIZV QKXgdi9y6mMPlwdDxmfwo2Hyca2oLCAesYYDwGzV4bChte+AXEoI8EFy9zasTtamfAQw 29lXy2wGv8/ZQ+BejL5AYln3wK02m8nZmmI0bWSPb9+r9PLWywgk5HT30b7HyEgRghC9 uX+Q== 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=0VqKHIhymTntDzvr1gPM0ji+e+nE+poyW90nI4hjCmw=; b=MtSP7XBbBQr59rhH0TC/5jnzeM3Cvtvks78fnvT49XBFbb7u2t48F/n9+el0xo0xst xdGaJwZafu74RTphmPAngPbr5lJGoO+Uyse7Yf2DdaPcOhp+Nc5WnOPHZucCD/7kFijA kEwOzVxHxpUmQcPb0YhXvNB41ypkL//7vjOaFPnU4rDke19WPWbJ32pZ4mi9zH17b36+ 0WG/SdtUNwMHOIa/BIT/wvLBq3s96mD+MykcDvTJODGDy319+EqJ1VqqNb4hOgEx+Nc5 /vAXsLh79NpI2anEpBpKlg14JC61+xSPifFiwTLwT2Mb/BE9gqdPalE5Npw+3F3Eh05z naLA== X-Gm-Message-State: AOAM530x8jiSy8/aiLKZ0ZlKpTKHzOsFenpboEdPeTnMGc2GYxJw23CS P1+2TKXRy9LELJpxAHg0veJQ1iwe7LSlcA== X-Google-Smtp-Source: ABdhPJxcI33sQfz9TDCD2yBMLxQcZ7b3Bpg+Yxvp30mSYEjR2FHDNvFf7HAqTRRjl+bPQ/MrSqt+4A== X-Received: by 2002:a9d:4aa:: with SMTP id 39mr15648809otm.11.1605043341502; Tue, 10 Nov 2020 13:22:21 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id e127sm3376501oia.12.2020.11.10.13.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22: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 v2 22/26] completion: bash: rename _get_comp_words_by_ref() Date: Tue, 10 Nov 2020 15:21:32 -0600 Message-Id: <20201110212136.870769-23-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-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 more inefficient version of _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 26f9accc30..ffff7e2317 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 @@ -3383,10 +3291,100 @@ if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then 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 e39febcc4a..efb98cc96c 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]} From patchwork Tue Nov 10 21:21:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895373 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 E1BA8C55ABD for ; Tue, 10 Nov 2020 21:22:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9466F20781 for ; Tue, 10 Nov 2020 21:22:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HKjTAXob" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732029AbgKJVW1 (ORCPT ); Tue, 10 Nov 2020 16:22:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732011AbgKJVWY (ORCPT ); Tue, 10 Nov 2020 16:22:24 -0500 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA47C0613D1 for ; Tue, 10 Nov 2020 13:22:23 -0800 (PST) Received: by mail-ot1-x330.google.com with SMTP id z16so119237otq.6 for ; Tue, 10 Nov 2020 13:22: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=jvauBapL0uN6zq2yeHB/f8iB1nCDxZWO+X+6woXLnrc=; b=HKjTAXobVp3UD13VdoVzrGySb+tK75ZL6KuVPQ7+2UI3RO+pFhkt4nXiv5zyzVIjlI rUBetvS2iGM8L7xGQWZcKhphBE1MIoc/R2tNDBl5sfcUJsDwAGZIwLz8ru+3BKrEmmmx DZUPzTXCDfXUHPOmLy/JWbvaHjZbSEr3ksToyRCeSjjb+2CLjxETMI12eMo4lCSaGzFq cLLdW9J++TUk0K2aeiTXluCaRrrqT6U+2mOAag7+T6iAnTCVYz7odwtUtkgmwQ7RRe3T 4hyMYZn7IcBZbb9/V1EdPOIUiEWZiP7JjuCghp5fnpOQS8nuWcBqgVRw/YfJzCiNhy/Z XIwg== 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=jvauBapL0uN6zq2yeHB/f8iB1nCDxZWO+X+6woXLnrc=; b=OVFXJE9iwYCkxzoP4ZMdblFdBXq106U3j9bHy+umJgHc8jSq+Ynd5XDe2lErnOHnbZ b7HMlNYMlVIGbEfD87rtgPsqmBtly86nOti9Q+oDpsweC3Kg7Bu7g9UQntZlz7Ks10q+ icr02uVdKk315x4y9+QSCROFM3n2KvH8YokUQVIIMiTxf7Eo073DDXa4Yi4lPQDWxihQ ifD1Jtm9KH1YXqKQvdF+GlUW6+O31OyoDPSiGEKWLOQOGGeCR2oeJbm44cdQmPDfgTXu hGxL5xa6rwh2YJY4UkyY1g+gdzisYbhi5NOlBkRt+uBs9kF7401JudbrKQFh6EI+Tgid 1iFg== X-Gm-Message-State: AOAM530OSCb37pn2P62+abo+4iYp3CSlBRb3gTkiqaVlTOu6XSHdkod5 5Y+L+0ELRIDgQcoiOwuHtyMs024+Rl1UIQ== X-Google-Smtp-Source: ABdhPJxpF+proBeCQKciNiyKDB6fnM1n+lJaf/5tKhq1xfFuvB7TQk0VFtR0n9UMesF8/nD2n87T3A== X-Received: by 2002:a9d:654c:: with SMTP id q12mr14655235otl.84.1605043343191; Tue, 10 Nov 2020 13:22:23 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t5sm29246oth.16.2020.11.10.13.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:22 -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 v2 23/26] completion: bash: improve __gitcomp description Date: Tue, 10 Nov 2020 15:21:33 -0600 Message-Id: <20201110212136.870769-24-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It does a lot more than what is stated now. 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 ffff7e2317..8e6723874e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -182,8 +182,7 @@ __gitcompadd () done } -# Generates completion reply, appending a space to possible completion words, -# if necessary. +# Creates completion replies, reorganizing options and adding suffixes as needed. # It accepts 1 to 4 arguments: # 1: List of possible completion words. # 2: A prefix to be added to each possible completion word (optional). From patchwork Tue Nov 10 21:21:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895375 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 87661C56201 for ; Tue, 10 Nov 2020 21:22:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2176120781 for ; Tue, 10 Nov 2020 21:22:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iAOp46ys" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732034AbgKJVWb (ORCPT ); Tue, 10 Nov 2020 16:22:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732023AbgKJVW0 (ORCPT ); Tue, 10 Nov 2020 16:22:26 -0500 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 884AEC0613D1 for ; Tue, 10 Nov 2020 13:22:26 -0800 (PST) Received: by mail-oi1-x229.google.com with SMTP id j7so16095659oie.12 for ; Tue, 10 Nov 2020 13:22: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=h7zN0nSLgY/3/vY0Ap3P6GJRm+kYhdpu8VQeX/X9xOs=; b=iAOp46ysmrGzQ5khV0pdX7flxQYyPR1NoR4zpBSlmnrpAq/0WhORlaImPLQw7NMo1k qanQFp3iMiCXdZb1KHOtQPFHcU15Qwk5yfrj/ADJOc9wILnDMSelkEMzcPF/FplZS7r4 hS42a1gqVTU5y/4kQRBShbcz3A/BPCU+YuFRETQI9ZE2Mk6nlbVyalGrsso+Z1Z2fdOz JcIE7HMFGXPHw+pR6iT4CrWC9xPY99u4fY5R1XOKGXSjxaNHpp3x+dM/BiVQFlohZSW6 EiXQFQ9MOPmOG15zVtFwMSnxdFIl18RCtMcg6LDJ0ho02aBMzD0DtDLHWQ2Q0gjUt9NJ li/Q== 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=h7zN0nSLgY/3/vY0Ap3P6GJRm+kYhdpu8VQeX/X9xOs=; b=hzqi7B2h9zWM00d3VItuUuQqE6BhP81d1VLcp8aDwniyoe2uEpMoDIHLhrbN4ZS/ar vVesSEBwkJ/FeYyKj/t9h1iYUHEYBcG1t0CIMRp2bXAdzy/n38RNuB4glrHDVQOX8P5f 0khvqYBLSYVBUKAFUL/mden3srwFnPBxAgPhBHBlbCDmAfAQemPa7edtUskCD6gsV6gr QXFi/usuzIX7/SgG4EMfrVsDSzNZu4byvIpBSrpiX6fwcMksYK80Meef03gp5+jBHphG l8T5XY9Oim0IrDUM/Fb/4UdsJIh57TqLDJWkdGy68scKay/5uE9T/uxGs5k4oeIenzHe 96Gw== X-Gm-Message-State: AOAM531PVlCC50tFEKzQltrj01Vxvo0Me9an/ypMIBGUuEKRodtm36QZ bQthSSqu1lC30OTLZp+XVd1JqUuapL6Nag== X-Google-Smtp-Source: ABdhPJwgOe9gmbpLP+d8Qj3qnWvsseiRJcXdyBBgrzZK69iDiLh8BxQkvyQEyIM5S0tWeqFX4xuTCA== X-Received: by 2002:aca:5c82:: with SMTP id q124mr51167oib.33.1605043345439; Tue, 10 Nov 2020 13:22:25 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id b13sm27360otp.28.2020.11.10.13.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:24 -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 v2 24/26] completion: bash: add __gitcomp_opts Date: Tue, 10 Nov 2020 15:21:34 -0600 Message-Id: <20201110212136.870769-25-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Create a new simplified version of __gitcomp for most callers, and __gitcomp_opts for the ones that need reorganizing all the options. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 114 ++++++++++++++----------- contrib/completion/git-completion.zsh | 9 ++ t/t9902-completion.sh | 58 ++++++------- 3 files changed, 101 insertions(+), 80 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8e6723874e..324793368d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -182,13 +182,25 @@ __gitcompadd () done } -# Creates completion replies, reorganizing options and adding suffixes as needed. +# Creates completion replies. # It accepts 1 to 4 arguments: # 1: List of possible completion words. # 2: A prefix to be added to each possible completion word (optional). # 3: Generate possible completion matches for this word (optional). # 4: A suffix to be appended to each possible completion word (optional). __gitcomp () +{ + local IFS=$' \t\n' + __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" +} + +# Creates completion replies, reorganizing options and adding suffixes as needed. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word (optional). +__gitcomp_opts () { local cur_="${3-$cur}" @@ -228,7 +240,7 @@ fi # This function is equivalent to # -# __gitcomp "$(git xxx --git-completion-helper) ..." +# __gitcomp_opts "$(git xxx --git-completion-helper) ..." # # except that the output is cached. Accept 1-3 arguments: # 1: the git command to execute, this is also the cache key @@ -263,7 +275,7 @@ __gitcomp_builtin () eval "$var=\"$options\"" fi - __gitcomp "$options" + __gitcomp_opts "$options" } # Generates completion reply from newline-separated possible completion words @@ -900,7 +912,7 @@ __git_complete_strategy () return 0 ;; -X) - __gitcomp "$__git_merge_strategy_options" + __gitcomp_opts "$__git_merge_strategy_options" return 0 ;; esac @@ -910,7 +922,7 @@ __git_complete_strategy () return 0 ;; --strategy-option=*) - __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}" + __gitcomp_opts "$__git_merge_strategy_options" "" "${cur##--strategy-option=}" return 0 ;; esac @@ -1133,7 +1145,7 @@ _git_am () { __git_find_repo_path if [ -d "$__git_repo_path"/rebase-apply ]; then - __gitcomp "$__git_am_inprogress_options" + __gitcomp_opts "$__git_am_inprogress_options" return fi case "$cur" in @@ -1387,7 +1399,7 @@ _git_cherry_pick () { __git_find_repo_path if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then - __gitcomp "$__git_cherry_pick_inprogress_options" + __gitcomp_opts "$__git_cherry_pick_inprogress_options" return fi @@ -1545,7 +1557,7 @@ _git_diff () return ;; --*) - __gitcomp "$__git_diff_difftool_options" + __gitcomp_opts "$__git_diff_difftool_options" return ;; esac @@ -1839,7 +1851,7 @@ _git_log () return ;; --*) - __gitcomp " + __gitcomp_opts " $__git_log_common_options $__git_log_shortlog_options $__git_log_gitk_options @@ -1902,7 +1914,7 @@ _git_mergetool () return ;; --*) - __gitcomp "--tool= --prompt --no-prompt --gui --no-gui" + __gitcomp_opts "--tool= --prompt --no-prompt --gui --no-gui" return ;; esac @@ -2050,7 +2062,7 @@ _git_range_diff () { case "$cur" in --*) - __gitcomp " + __gitcomp_opts " --creation-factor= --no-dual-color $__git_diff_common_options " @@ -2067,11 +2079,11 @@ _git_rebase () { __git_find_repo_path if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then - __gitcomp "$__git_rebase_interactive_inprogress_options" + __gitcomp_opts "$__git_rebase_interactive_inprogress_options" return elif [ -d "$__git_repo_path"/rebase-apply ] || \ [ -d "$__git_repo_path"/rebase-merge ]; then - __gitcomp "$__git_rebase_inprogress_options" + __gitcomp_opts "$__git_rebase_inprogress_options" return fi __git_complete_strategy && return @@ -2513,7 +2525,7 @@ __git_complete_config_variable_name () for (s in sections) print s "." } - ')" "" "$cur_" + ')" "" "$cur_" "" ;; esac } @@ -2691,7 +2703,7 @@ _git_revert () { __git_find_repo_path if [ -f "$__git_repo_path"/REVERT_HEAD ]; then - __gitcomp "$__git_revert_inprogress_options" + __gitcomp_opts "$__git_revert_inprogress_options" return fi __git_complete_strategy && return @@ -2723,7 +2735,7 @@ _git_shortlog () case "$cur" in --*) - __gitcomp " + __gitcomp_opts " $__git_log_common_options $__git_log_shortlog_options --numbered --summary --email @@ -2761,7 +2773,7 @@ _git_show () return ;; --*) - __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit + __gitcomp_opts "--pretty= --format= --abbrev-commit --no-abbrev-commit --oneline --show-signature --expand-tabs --expand-tabs= --no-expand-tabs $__git_diff_common_options @@ -2794,10 +2806,10 @@ _git_sparse_checkout () case "$subcommand,$cur" in init,--*) - __gitcomp "--cone" + __gitcomp_opts "--cone" ;; set,--*) - __gitcomp "--stdin" + __gitcomp_opts "--stdin" ;; *) ;; @@ -2815,7 +2827,7 @@ _git_stash () if [ -z "$subcommand" ]; then case "$cur" in --*) - __gitcomp "$save_opts" + __gitcomp_opts "$save_opts" ;; sa*) if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then @@ -2831,22 +2843,22 @@ _git_stash () else case "$subcommand,$cur" in push,--*) - __gitcomp "$save_opts --message" + __gitcomp_opts "$save_opts --message" ;; save,--*) - __gitcomp "$save_opts" + __gitcomp_opts "$save_opts" ;; apply,--*|pop,--*) - __gitcomp "--index --quiet" + __gitcomp_opts "--index --quiet" ;; drop,--*) - __gitcomp "--quiet" + __gitcomp_opts "--quiet" ;; list,--*) - __gitcomp "--name-status --oneline --patch-with-stat" + __gitcomp_opts "--name-status --oneline --patch-with-stat" ;; show,--*) - __gitcomp "$__git_diff_common_options" + __gitcomp_opts "$__git_diff_common_options" ;; branch,--*) ;; @@ -2877,7 +2889,7 @@ _git_submodule () if [ -z "$subcommand" ]; then case "$cur" in --*) - __gitcomp "--quiet" + __gitcomp_opts "--quiet" ;; *) __gitcomp "$subcommands" @@ -2888,29 +2900,29 @@ _git_submodule () case "$subcommand,$cur" in add,--*) - __gitcomp "--branch --force --name --reference --depth" + __gitcomp_opts "--branch --force --name --reference --depth" ;; status,--*) - __gitcomp "--cached --recursive" + __gitcomp_opts "--cached --recursive" ;; deinit,--*) - __gitcomp "--force --all" + __gitcomp_opts "--force --all" ;; update,--*) - __gitcomp " + __gitcomp_opts " --init --remote --no-fetch --recommend-shallow --no-recommend-shallow --force --rebase --merge --reference --depth --recursive --jobs " ;; set-branch,--*) - __gitcomp "--default --branch" + __gitcomp_opts "--default --branch" ;; summary,--*) - __gitcomp "--cached --files --summary-limit" + __gitcomp_opts "--cached --files --summary-limit" ;; foreach,--*|sync,--*) - __gitcomp "--recursive" + __gitcomp_opts "--recursive" ;; *) ;; @@ -2951,64 +2963,64 @@ _git_svn () case "$subcommand,$cur" in fetch,--*) - __gitcomp "--revision= --fetch-all $fc_opts" + __gitcomp_opts "--revision= --fetch-all $fc_opts" ;; clone,--*) - __gitcomp "--revision= $fc_opts $init_opts" + __gitcomp_opts "--revision= $fc_opts $init_opts" ;; init,--*) - __gitcomp "$init_opts" + __gitcomp_opts "$init_opts" ;; dcommit,--*) - __gitcomp " + __gitcomp_opts " --merge --strategy= --verbose --dry-run --fetch-all --no-rebase --commit-url --revision --interactive $cmt_opts $fc_opts " ;; set-tree,--*) - __gitcomp "--stdin $cmt_opts $fc_opts" + __gitcomp_opts "--stdin $cmt_opts $fc_opts" ;; create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\ show-externals,--*|mkdirs,--*) - __gitcomp "--revision=" + __gitcomp_opts "--revision=" ;; log,--*) - __gitcomp " + __gitcomp_opts " --limit= --revision= --verbose --incremental --oneline --show-commit --non-recursive --authors-file= --color " ;; rebase,--*) - __gitcomp " + __gitcomp_opts " --merge --verbose --strategy= --local --fetch-all --dry-run $fc_opts " ;; commit-diff,--*) - __gitcomp "--message= --file= --revision= $cmt_opts" + __gitcomp_opts "--message= --file= --revision= $cmt_opts" ;; info,--*) - __gitcomp "--url" + __gitcomp_opts "--url" ;; branch,--*) - __gitcomp "--dry-run --message --tag" + __gitcomp_opts "--dry-run --message --tag" ;; tag,--*) - __gitcomp "--dry-run --message" + __gitcomp_opts "--dry-run --message" ;; blame,--*) - __gitcomp "--git-format" + __gitcomp_opts "--git-format" ;; migrate,--*) - __gitcomp " + __gitcomp_opts " --config-dir= --ignore-paths= --minimize --no-auth-cache --username= " ;; reset,--*) - __gitcomp "--revision= --parent" + __gitcomp_opts "--revision= --parent" ;; *) ;; @@ -3223,7 +3235,7 @@ __git_main () ;; esac case "$cur" in - --*) __gitcomp " + --*) __gitcomp_opts " --paginate --no-pager --git-dir= @@ -3274,7 +3286,7 @@ __gitk_main () fi case "$cur" in --*) - __gitcomp " + __gitcomp_opts " $__git_log_common_options $__git_log_gitk_options $merge diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 1781401f5d..fc6d44bce0 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -53,6 +53,15 @@ __gitcomp () { emulate -L zsh + local IFS=$' \t\n' + compset -P '*[=:]' + compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 +} + +__gitcomp_opts () +{ + emulate -L zsh + local cur_="${3-$cur}" case "$cur_" in diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index efb98cc96c..ea572960de 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -85,17 +85,17 @@ test_completion () test_cmp expected out_sorted } -# Test __gitcomp. +# Test __gitcomp_opts. # The first argument is the typed text so far (cur); the rest are -# passed to __gitcomp. Expected output comes is read from the +# passed to __gitcomp_opts. Expected output comes is read from the # standard input, like test_completion(). -test_gitcomp () +test_gitcomp_opts () { local -a COMPREPLY && sed -e 's/Z$//' >expected && local cur="$1" && shift && - __gitcomp "$@" && + __gitcomp_opts "$@" && print_comp && test_cmp expected out } @@ -450,8 +450,8 @@ test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' ' test_cmp expected out ' -test_expect_success '__gitcomp - trailing space - options' ' - test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message= +test_expect_success '__gitcomp_opts - trailing space - options' ' + test_gitcomp_opts "--re" "--dry-run --reuse-message= --reedit-message= --reset-author" <<-EOF --reuse-message=Z --reedit-message=Z @@ -459,8 +459,8 @@ test_expect_success '__gitcomp - trailing space - options' ' EOF ' -test_expect_success '__gitcomp - trailing space - config keys' ' - test_gitcomp "br" "branch. branch.autosetupmerge +test_expect_success '__gitcomp_opts - trailing space - config keys' ' + test_gitcomp_opts "br" "branch. branch.autosetupmerge branch.autosetuprebase browser." <<-\EOF branch.Z branch.autosetupmerge Z @@ -469,32 +469,32 @@ test_expect_success '__gitcomp - trailing space - config keys' ' EOF ' -test_expect_success '__gitcomp - option parameter' ' - test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \ +test_expect_success '__gitcomp_opts - option parameter' ' + test_gitcomp_opts "--strategy=re" "octopus ours recursive resolve subtree" \ "" "re" <<-\EOF recursive Z resolve Z EOF ' -test_expect_success '__gitcomp - prefix' ' - test_gitcomp "branch.maint.me" "remote merge mergeoptions rebase" \ +test_expect_success '__gitcomp_opts - prefix' ' + test_gitcomp_opts "branch.maint.me" "remote merge mergeoptions rebase" \ "branch.maint." "me" <<-\EOF branch.maint.merge Z branch.maint.mergeoptions Z EOF ' -test_expect_success '__gitcomp - suffix' ' - test_gitcomp "branch.ma" "master maint next seen" "branch." \ +test_expect_success '__gitcomp_opts - suffix' ' + test_gitcomp_opts "branch.ma" "master maint next seen" "branch." \ "ma" "." <<-\EOF branch.master.Z branch.maint.Z EOF ' -test_expect_success '__gitcomp - ignore optional negative options' ' - test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF +test_expect_success '__gitcomp_opts - ignore optional negative options' ' + test_gitcomp_opts "--" "--abc --def --no-one -- --no-two" <<-\EOF --abc Z --def Z --no-one Z @@ -502,44 +502,44 @@ test_expect_success '__gitcomp - ignore optional negative options' ' EOF ' -test_expect_success '__gitcomp - ignore/narrow optional negative options' ' - test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF +test_expect_success '__gitcomp_opts - ignore/narrow optional negative options' ' + test_gitcomp_opts "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF --abc Z --abcdef Z EOF ' -test_expect_success '__gitcomp - ignore/narrow optional negative options' ' - test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF +test_expect_success '__gitcomp_opts - ignore/narrow optional negative options' ' + test_gitcomp_opts "--n" "--abc --def --no-one -- --no-two" <<-\EOF --no-one Z --no-... Z EOF ' -test_expect_success '__gitcomp - expand all negative options' ' - test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF +test_expect_success '__gitcomp_opts - expand all negative options' ' + test_gitcomp_opts "--no-" "--abc --def --no-one -- --no-two" <<-\EOF --no-one Z --no-two Z EOF ' -test_expect_success '__gitcomp - expand/narrow all negative options' ' - test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF +test_expect_success '__gitcomp_opts - expand/narrow all negative options' ' + test_gitcomp_opts "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF --no-one Z EOF ' -test_expect_success '__gitcomp - equal skip' ' - test_gitcomp "--option=" "--option=" <<-\EOF && +test_expect_success '__gitcomp_opts - equal skip' ' + test_gitcomp_opts "--option=" "--option=" <<-\EOF && EOF - test_gitcomp "option=" "option=" <<-\EOF + test_gitcomp_opts "option=" "option=" <<-\EOF EOF ' -test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' - run_func __gitcomp "$invalid_variable_name" +test_expect_success '__gitcomp_opts - doesnt fail because of invalid variable name' ' + run_func __gitcomp_opts "$invalid_variable_name" ' read -r -d "" refs <<-\EOF From patchwork Tue Nov 10 21:21:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895371 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 19BECC388F7 for ; Tue, 10 Nov 2020 21:22:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7A2420781 for ; Tue, 10 Nov 2020 21:22:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T+enHlns" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732048AbgKJVWc (ORCPT ); Tue, 10 Nov 2020 16:22:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732011AbgKJVW2 (ORCPT ); Tue, 10 Nov 2020 16:22:28 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578B6C0613D3 for ; Tue, 10 Nov 2020 13:22:28 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id j7so16095753oie.12 for ; Tue, 10 Nov 2020 13:22: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=+CnwyocRf4rS0+/UoR53YzU+cVA0Tigl5erPb+Z7BE0=; b=T+enHlnsQxzMq9d4CMNvgPtg6tvU+M/C72Mum6OoOnsQQsg88mGte5MBULyFuGKTxM yovO3d+YJ8WteA2a62CNJHL0ZYqGdbcfyokCdf/Iwap3h9x3l4pr9MV05KbBsV6bvXgq g7t35evtEGlFJjM4BiuXcI2TKNjkT/j8JsSMB2OHO31vzv9VNPaGeWBReqQZQUXnEPl3 jq05469G04/9OWGzf9ZDCx/vCNOb4UhWCvkdswqWCBWCWkWg2jGZGzjyMtkRIMPo4fYU ooSemqGdZ1lrsXdVymrn6lIvp6cIYKijdo5NI5dzqHSeCAKpZERNub3jYg55TqiYgVz6 0WLQ== 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=+CnwyocRf4rS0+/UoR53YzU+cVA0Tigl5erPb+Z7BE0=; b=gvqExtjRTvS/TcMi/X0CnBLs0LVHRnHIOxO1Bo6IXl/EtSMtApDHztfuo9fwvUCDHn Ilmsjm+uIqknES7LLV3k6YjT/75/ogOhehwgYVzleluZ6BnB0cMvxUdRX6w1m66MAxWm +lnm1K2uWnMrc0SsU5I+xowrtByv4TEBFuLYlEn3QVfQvz9vF5Y4iji4fMVIu0s2kDz1 mrwnZhPFAJNt66QPzOn632Ukn0uA+nVOniCHwKVXPv5yVDQE7Jbxv9Wo/GIftjc48lrI 7U3dV/Id72pVJigQyWdTAhJch3MXGnQ0HYUlHQ+SkDyuJij4wbKqOf7Jd5YPuY2PJ3TW eR0Q== X-Gm-Message-State: AOAM531h4oIPuDLahLW1U0L4K2X0krdofNaNo3y1HYVo4/CdAkauEk7W obXZ4japDF3nHzstONYKf68rBQv+TCbSVg== X-Google-Smtp-Source: ABdhPJyLQ8fqFwdWFZ8BONerqeUs3BfCfbnCz5GBOEZ65t+Fwxltd4HNayNzpfN2jao3mV1zEeBVGA== X-Received: by 2002:aca:d583:: with SMTP id m125mr45525oig.47.1605043347479; Tue, 10 Nov 2020 13:22:27 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id w21sm28384otq.20.2020.11.10.13.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22:27 -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 v2 25/26] completion: bash: cleanup __gitcomp* invocations Date: Tue, 10 Nov 2020 15:21:35 -0600 Message-Id: <20201110212136.870769-26-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Some __gitcomp calls should be __gitcomp_nl, and vice versa. No functional changes. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 324793368d..d73cdb7096 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1205,7 +1205,7 @@ _git_archive () { case "$cur" in --format=*) - __gitcomp "$(git archive --list)" "" "${cur##--format=}" + __gitcomp_nl "$(git archive --list)" "" "${cur##--format=}" return ;; --remote=*) @@ -1616,9 +1616,7 @@ _git_format_patch () { case "$cur" in --thread=*) - __gitcomp " - deep shallow - " "" "${cur##--thread=}" + __gitcomp "deep shallow" "" "${cur##--thread=}" return ;; --base=*|--interdiff=*|--range-diff=*) @@ -2124,7 +2122,7 @@ _git_send_email () { case "$prev" in --to|--cc|--bcc|--from) - __gitcomp "$(__git send-email --dump-aliases)" + __gitcomp_nl "$(__git send-email --dump-aliases)" return ;; esac @@ -2148,9 +2146,7 @@ _git_send_email () return ;; --thread=*) - __gitcomp " - deep shallow - " "" "${cur##--thread=}" + __gitcomp "deep shallow" "" "${cur##--thread=}" return ;; --to=*|--cc=*|--bcc=*|--from=*) @@ -2452,7 +2448,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")" - __gitcomp_nl $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx" + __gitcomp "autoSetupMerge autoSetupRebase" "$pfx" "$cur_" "$sfx" return ;; guitool.*.*) @@ -2502,7 +2498,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." - __gitcomp_nl "pushDefault" "$pfx" "$cur_" "$sfx" + __gitcomp "pushDefault" "$pfx" "$cur_" "$sfx" return ;; url.*.*) @@ -2517,7 +2513,7 @@ __git_complete_config_variable_name () ;; *) __git_compute_config_vars - __gitcomp "$(echo "$__git_config_vars" | + __gitcomp_nl "$(echo "$__git_config_vars" | awk -F . '{ sections[$1] = 1 } @@ -2619,7 +2615,7 @@ _git_remote () __gitcomp_builtin remote_update ;; update,*) - __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")" + __gitcomp_nl "$(__git_remotes) $(__git_get_config_variables "remotes")" ;; set-url,--*) __gitcomp_builtin remote_set-url @@ -3257,7 +3253,7 @@ __git_main () then __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST" else - __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)" + __gitcomp_nl "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)" fi ;; esac From patchwork Tue Nov 10 21:21:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11895377 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 0B223C55ABD for ; Tue, 10 Nov 2020 21:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B08A4206F1 for ; Tue, 10 Nov 2020 21:22:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lDNw1s94" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732052AbgKJVWe (ORCPT ); Tue, 10 Nov 2020 16:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732030AbgKJVWa (ORCPT ); Tue, 10 Nov 2020 16:22:30 -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 05987C0613D4 for ; Tue, 10 Nov 2020 13:22:30 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id n89so137721otn.3 for ; Tue, 10 Nov 2020 13:22:29 -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=5/1QeBCX0cJkbLMBnrlRk2Qmcs/II1ykY3MtvDvC5mo=; b=lDNw1s94+8qYVy+indI40yH/QEmZsF8yMEiH2DdHn1TIP8yVYGjUrNvbbCWyzsn2U5 XvSBa/ZVNx+aMEissPktd6GZJRpeTgxN44puygv6vM5ZlXPTXInh664wOWjYvgJEVFrI srAjBLYTRqkwGA8267teFiO+e0xTJGqpgZMouRjIAg9jvBlX8j+VUblPcVeS5yXjuQnL oDGQ0Z/LNAOax39XqzvR5t8uOg5Bz5QaLs4TbycZKfCAgQw4QkjjnGUY2ZyjyYF43FwW XpbsPTLibtdEHPBH36Zuws/8PdFgmhvjIWwoUI8pVgcFxGMjMmHy1Mh98iLC4nD1AFSo cE0w== 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=5/1QeBCX0cJkbLMBnrlRk2Qmcs/II1ykY3MtvDvC5mo=; b=Pyb6h1xXUKghNAsii6aAz4y1j9ZiW4ijWteVJh5qGPnTEzadWs6VZvqXuFw5LONeM+ RcG7w6U2ovhq8wHaP3NeL2qXFLs4egERk8/K+xIeyXvW5y3rZtDv6r4fXK4xvXdqTUHc Yfs2NX1rVD1XhHI3XkKWmq6enBqg97aNZGvZaJHLxO7sCKRxUkg1gIJvrc5wFb42Tpxl lf10zKVu34TSaeOy04j+8U6jVNMwg9jIpT6XExL0PNdU8QawvS01B0HKsYNsHTGhd9w/ PVElSbpXxAZgCHUCxdikrYkYG1cIYMLEup8VOOjWPpcPbgQFEPmvLPHK3Lt/Qmuy48ov aamg== X-Gm-Message-State: AOAM533KIEqrHve8d98L3XYwTXXcaHtf08rDtuDNPB20CLqn4hkRTfBV 5eU6/RgiwTGO/cJj60zDsQRveY/Lgx6J/w== X-Google-Smtp-Source: ABdhPJwHeFnWEZIYIyYc3a3B/OJ3PU+NSEum8hwUwABdjhVVALkb0p70Zr1roSad9p1M69+WCDhaXw== X-Received: by 2002:a9d:d37:: with SMTP id 52mr14975784oti.60.1605043349001; Tue, 10 Nov 2020 13:22:29 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id k13sm35258ooi.41.2020.11.10.13.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 13:22: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 v2 26/26] completion: bash: shuffle __gitcomp functions Date: Tue, 10 Nov 2020 15:21:36 -0600 Message-Id: <20201110212136.870769-27-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110212136.870769-1-felipe.contreras@gmail.com> References: <20201110212136.870769-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org They are the ones that actually do the completion, put them at the top. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 262 +++++++++++++------------ 1 file changed, 135 insertions(+), 127 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index d73cdb7096..578b6b0d2f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -45,6 +45,141 @@ # When set to "1" suggest all options, including options which are # typically hidden (e.g. '--allow-empty' for 'git commit'). +# The following functions are meant to modify COMPREPLY, which should not be +# modified directly. The purpose is to localize the modifications so it's +# easier to emulate it in Zsh. Every time a new __gitcomp* function is added, +# the corresponding function should be added to Zsh. + +__gitcompadd () +{ + local x i=${#COMPREPLY[@]} + for x in $1; do + if [[ "$x" == "$3"* ]]; then + COMPREPLY[i++]="$2$x$4" + fi + done +} + +# Creates completion replies. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word (optional). +__gitcomp () +{ + local IFS=$' \t\n' + __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" +} + +# Generates completion reply from newline-separated possible completion words +# 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). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word instead of +# the default space (optional). If specified but empty, nothing is +# appended. +__gitcomp_nl () +{ + local IFS=$'\n' + __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" +} + +# 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. +# 1: List of newline-separated matching completion words, complete with +# prefix and suffix. +__gitcomp_direct () +{ + local IFS=$'\n' + + COMPREPLY+=($1) +} + +# Generates completion reply with compgen from newline-separated possible +# completion filenames. +# It accepts 1 to 3 arguments: +# 1: List of possible completion filenames, separated by a single newline. +# 2: A directory prefix to be added to each possible completion filename +# (optional). +# 3: Generate possible completion matches for this word (optional). +__gitcomp_file () +{ + local IFS=$'\n' + + # XXX does not work when the directory prefix contains a tilde, + # 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}" "" + + # use a hack to enable file mode in bash < 4 + compopt -o filenames +o nospace 2>/dev/null || + compgen -f /non-existing-dir/ >/dev/null || + true +} + +# Fills the COMPREPLY array with prefiltered paths without any additional +# processing. +# Callers must take care of providing only paths that match the current path +# to be completed and adding any prefix path components, if necessary. +# 1: List of newline-separated matching paths, complete with all prefix +# path components. +__gitcomp_file_direct () +{ + local IFS=$'\n' + + COMPREPLY+=($1) + + # use a hack to enable file mode in bash < 4 + compopt -o filenames +o nospace 2>/dev/null || + compgen -f /non-existing-dir/ >/dev/null || + true +} + +# Creates completion replies, reorganizing options and adding suffixes as needed. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word (optional). +__gitcomp_opts () +{ + local cur_="${3-$cur}" + + if [[ "$cur_" == *= ]]; then + return + fi + + local c i=0 IFS=$' \t\n' sfx + for c in $1; do + if [[ $c == "--" ]]; then + if [[ "$cur_" == --no-* ]]; then + continue + fi + + if [[ --no == "$cur_"* ]]; then + COMPREPLY[i++]="--no-... " + fi + break + fi + if [[ $c == "$cur_"* ]]; then + case $c in + *=|*.) sfx="" ;; + *) sfx=" " ;; + esac + COMPREPLY[i++]="${2-}$c${4:-$sfx}" + fi + done +} + +# __gitcomp functions end here +# ============================================================================== + # 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. @@ -159,77 +294,6 @@ __git_dequote () done } -# 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. -# 1: List of newline-separated matching completion words, complete with -# prefix and suffix. -__gitcomp_direct () -{ - local IFS=$'\n' - - COMPREPLY+=($1) -} - -__gitcompadd () -{ - local x i=${#COMPREPLY[@]} - for x in $1; do - if [[ "$x" == "$3"* ]]; then - COMPREPLY[i++]="$2$x$4" - fi - done -} - -# Creates completion replies. -# It accepts 1 to 4 arguments: -# 1: List of possible completion words. -# 2: A prefix to be added to each possible completion word (optional). -# 3: Generate possible completion matches for this word (optional). -# 4: A suffix to be appended to each possible completion word (optional). -__gitcomp () -{ - local IFS=$' \t\n' - __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" -} - -# Creates completion replies, reorganizing options and adding suffixes as needed. -# It accepts 1 to 4 arguments: -# 1: List of possible completion words. -# 2: A prefix to be added to each possible completion word (optional). -# 3: Generate possible completion matches for this word (optional). -# 4: A suffix to be appended to each possible completion word (optional). -__gitcomp_opts () -{ - local cur_="${3-$cur}" - - if [[ "$cur_" == *= ]]; then - return - fi - - local c i=0 IFS=$' \t\n' sfx - for c in $1; do - if [[ $c == "--" ]]; then - if [[ "$cur_" == --no-* ]]; then - continue - fi - - if [[ --no == "$cur_"* ]]; then - COMPREPLY[i++]="--no-... " - fi - break - fi - if [[ $c == "$cur_"* ]]; then - case $c in - *=|*.) sfx="" ;; - *) sfx=" " ;; - esac - COMPREPLY[i++]="${2-}$c${4:-$sfx}" - fi - done -} - # Clear the variables caching builtins' options when (re-)sourcing # the completion script. if [[ -n ${ZSH_VERSION-} ]]; then @@ -278,62 +342,6 @@ __gitcomp_builtin () __gitcomp_opts "$options" } -# Generates completion reply from newline-separated possible completion words -# 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). -# 3: Generate possible completion matches for this word (optional). -# 4: A suffix to be appended to each possible completion word instead of -# the default space (optional). If specified but empty, nothing is -# appended. -__gitcomp_nl () -{ - local IFS=$'\n' - __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" -} - -# Fills the COMPREPLY array with prefiltered paths without any additional -# processing. -# Callers must take care of providing only paths that match the current path -# to be completed and adding any prefix path components, if necessary. -# 1: List of newline-separated matching paths, complete with all prefix -# path components. -__gitcomp_file_direct () -{ - local IFS=$'\n' - - COMPREPLY+=($1) - - # use a hack to enable file mode in bash < 4 - compopt -o filenames +o nospace 2>/dev/null || - compgen -f /non-existing-dir/ >/dev/null || - true -} - -# Generates completion reply with compgen from newline-separated possible -# completion filenames. -# It accepts 1 to 3 arguments: -# 1: List of possible completion filenames, separated by a single newline. -# 2: A directory prefix to be added to each possible completion filename -# (optional). -# 3: Generate possible completion matches for this word (optional). -__gitcomp_file () -{ - local IFS=$'\n' - - # XXX does not work when the directory prefix contains a tilde, - # 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}" "" - - # use a hack to enable file mode in bash < 4 - compopt -o filenames +o nospace 2>/dev/null || - compgen -f /non-existing-dir/ >/dev/null || - true -} - # Execute 'git ls-files', unless the --committable option is specified, in # which case it runs 'git diff-index' to find out the files that can be # committed. It return paths relative to the directory specified in the first