git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Jeff King" <peff@peff.net>,
	"Christian Couder" <christian.couder@gmail.com>,
	git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCHv3 2/2] completion: list variable names reliably with 'git config --names-only'
Date: Mon, 10 Aug 2015 11:46:07 +0200	[thread overview]
Message-ID: <1439199967-9655-3-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <1439199967-9655-1-git-send-email-szeder@ira.uka.de>

Recenty I created a multi-line branch description with '.' and '='
characters on one of the lines, and noticed that fragments of that line
show up when completing set variable names for 'git config', e.g.:

  $ git config --get branch.b.description
  Branch description to fool the completion script with a
  second line containing dot . and equals = characters.
  $ git config --unset <TAB>
  ...
  second line containing dot . and equals
  ...

The completion script runs 'git config --list' and processes its output
to strip the values and keep only the variable names.  It does so by
looking for lines containing '.' and '=' and outputting everything
before the '=', which was fooled by my multi-line branch description.

A similar issue exists with aliases and pretty format aliases with
multi-line values, but in that case 'git config --get-regexp' is run and
lines in its output are simply stripped after the first space, so
subsequent lines don't even have to contain '.' and '=' to fool the
completion script.

Use the new '--names-only' option added in the previous commit to list
config variable names reliably in both cases, without error-prone post
processing.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6eaab141e2..7200828fc4 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -744,9 +744,8 @@ __git_compute_porcelain_commands ()
 __git_get_config_variables ()
 {
 	local section="$1" i IFS=$'\n'
-	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "^$section\..*" 2>/dev/null); do
-		i="${i#$section.}"
-		echo "${i/ */}"
+	for i in $(git --git-dir="$(__gitdir)" config --names-only --get-regexp "^$section\..*" 2>/dev/null); do
+		echo "${i#$section.}"
 	done
 }
 
@@ -1774,15 +1773,7 @@ __git_config_get_set_variables ()
 		c=$((--c))
 	done
 
-	git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
-	while read -r line
-	do
-		case "$line" in
-		*.*=*)
-			echo "${line/=*/}"
-			;;
-		esac
-	done
+	git --git-dir="$(__gitdir)" config $config_file --names-only --list 2>/dev/null
 }
 
 _git_config ()
-- 
2.5.0.245.gff6622b

  parent reply	other threads:[~2015-08-10  9:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10  9:46 [PATCHv3 0/2] 'git config --names-only' to help the completion script SZEDER Gábor
2015-08-10  9:46 ` [PATCHv3 1/2] config: add '--names-only' option to list only variable names SZEDER Gábor
2015-08-10 13:41   ` Jeff King
2015-08-10 17:18   ` Junio C Hamano
2015-08-12 23:47     ` SZEDER Gábor
2015-08-13  1:39       ` Junio C Hamano
2015-08-20 14:14         ` [PATCH] config: restructure format_config() for better control flow SZEDER Gábor
2015-08-20 14:45           ` Jeff King
2015-08-20 14:46             ` [PATCH 1/3] format_config: don't init strbuf Jeff King
2015-08-20 14:47             ` [PATCH 2/3] format_config: simplify buffer handling Jeff King
2015-08-21 11:52               ` SZEDER Gábor
2015-08-21 17:42               ` Junio C Hamano
2015-08-21 17:43                 ` Junio C Hamano
2015-08-21 19:40                   ` Jeff King
2015-08-20 14:49             ` [PATCH 3/3] get_urlmatch: avoid useless strbuf write Jeff King
2015-08-20 20:19             ` [PATCH] config: restructure format_config() for better control flow Junio C Hamano
2015-08-10  9:46 ` SZEDER Gábor [this message]
2015-08-10 13:45   ` [PATCHv3 2/2] completion: list variable names reliably with 'git config --names-only' Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439199967-9655-3-git-send-email-szeder@ira.uka.de \
    --to=szeder@ira.uka.de \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).