From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id B2B3E20958 for ; Thu, 23 Mar 2017 15:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965232AbdCWPao (ORCPT ); Thu, 23 Mar 2017 11:30:44 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33193 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756020AbdCWP3k (ORCPT ); Thu, 23 Mar 2017 11:29:40 -0400 Received: by mail-wm0-f68.google.com with SMTP id n11so17293294wma.0 for ; Thu, 23 Mar 2017 08:29:38 -0700 (PDT) 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=wNtoxrbhBdjZlKKul0y50BiO99MUzHLLq2SWqkCeqOo=; b=WdLKjfJ2qfQLs5RrCFsLyDOSWfIXoRdTwhMaIuUJi4iliO1kDs2g4BCl0Xl3i+dTc0 pJm2IqLPZXCNQAFr9GOOTuflkfCvSxZMs3dYobGzpA3oL73xXshdqSdVgfmj5LFJQugO 8VjYLM6iz7fwtVXzZNMNUK7SjmCXOfZbFvMpbHE99/lsvLmBxdhP5TY88jMEQ1GhFFeM 4OZMADcFrEoq3sfMwOikr6e98SqcKlwJEZIEadj/HsvQ9rY42qApYAqyln1ndotqADHV Qu/rSHjKHYtOUreymBEbk3iYFHvh1Lx0gnDl+LfPFKQASLTiSAfzk3ENq2txf79Zy/FR py3w== 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=wNtoxrbhBdjZlKKul0y50BiO99MUzHLLq2SWqkCeqOo=; b=mRCGHjvLumB9hrBmFB+8VWbuvy55GsFsdfWm96PglKzMMzkc2RbQZNWALRGM2VTfmc QTBcBaThUw8CcdcuKh6nu2ZwsHc8QCBlZY7ASLE/Jq2GWvoWYoq0T1CVoe12m8uPTft3 Bw+cvHt8Jkh0hYIX2gGXfUyPTF9AQB9GiyGwhjEQ7S4VNIMzP0lC00z75jQ98MN0wstL t2kHIqRF9TXsZOXvFfBp7d2PUOi3maELZV/trvUytOOOjKKOq/QjI1aZwGyTHawS9UCO XwziijPTPEN1NkoY8BdL+a/ZhYIT59eIW34UarpyVzycfTDJ0yNP7CLH5bTOOdbdAQXs pJYw== X-Gm-Message-State: AFeK/H29mq+U0Jb8stxqrK8h0PfLLxg5P/QPfg+eAUxN/sVha2KG2DIMvWMyAhY1vdYA5g== X-Received: by 10.28.66.74 with SMTP id p71mr3541123wma.131.1490282977773; Thu, 23 Mar 2017 08:29:37 -0700 (PDT) Received: from localhost.localdomain (x4db02660.dyn.telefonica.de. [77.176.38.96]) by smtp.gmail.com with ESMTPSA id q135sm455057wmd.8.2017.03.23.08.29.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Mar 2017 08:29:37 -0700 (PDT) From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= To: Junio C Hamano Cc: git@vger.kernel.org, =?UTF-8?q?SZEDER=20G=C3=A1bor?= Subject: [PATCHv2 02/14] completion: wrap __git_refs() for better option parsing Date: Thu, 23 Mar 2017 16:29:12 +0100 Message-Id: <20170323152924.23944-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.12.1.485.g1616aa492 In-Reply-To: <20170323152924.23944-1-szeder.dev@gmail.com> References: <20170323152924.23944-1-szeder.dev@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org __git_refs() currently accepts two optional positional parameters: a remote and a flag for 'git checkout's tracking DWIMery. To fix a minor bug, and, more importantly, for faster refs completion, this series will add three more parameters: a prefix, the current word to be completed and a suffix, i.e. the options accepted by __gitcomp() & friends, and will change __git_refs() to list only refs matching that given current word and to add that given prefix and suffix to the listed refs. However, __git_refs() is the helper function that is most likely used in users' custom completion scriptlets for their own git commands, and we don't want to break those, so - we can't change __git_refs()'s default output format, i.e. we can't by default append a trailing space to every listed ref, meaning that the suffix parameter containing the default trailing space would have to be specified on every invocation, and - we can't change the position of existing positional parameters either, so there would have to be plenty of set-but-empty placeholder positional parameters all over the completion script. Furthermore, with five positional parameters it would be really hard to remember which position means what. To keep callsites simple, add the new wrapper function __git_complete_refs() around __git_refs(), which: - instead of positional parameters accepts real '--opt=val'-style options and with minimalistic option parsing translates them to __git_refs()'s and __gitcomp_nl()'s positional parameters, and - includes the '__gitcomp_nl "$(__git_refs ...)" ...' command substitution to make its behavior match its name and the behavior of other __git_complete_* functions, and to limit future changes in this series to __git_refs() and this new wrapper function. Call this wrapper function instead of __git_refs() wherever possible throughout the completion script, i.e. when __git_refs()'s output is fed to __gitcomp_nl() right away without further processing, which means all callsites except a single one in the __git_refs2() helper. Signed-off-by: SZEDER Gábor --- contrib/completion/git-completion.bash | 102 ++++++++++++++++++++----------- t/t9902-completion.sh | 106 +++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 35 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 91fda7ffb..0b90cfa54 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -354,6 +354,8 @@ __git_tags () # Can be the name of a configured remote, a path, or a URL. # 2: In addition to local refs, list unique branches from refs/remotes/ for # 'git checkout's tracking DWIMery (optional; ignored, if set but empty). +# +# Use __git_complete_refs() instead. __git_refs () { local i hash dir track="${2-}" @@ -446,6 +448,36 @@ __git_refs () esac } +# Completes refs, short and long, local and remote, symbolic and pseudo. +# +# Usage: __git_complete_refs [