git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: cornelius.weig@tngtech.com
To: git@vger.kernel.org
Cc: Cornelius Weig <cornelius.weig@tngtech.com>,
	szeder.dev@gmail.com,
	bitte.keine.werbung.einwerfen@googlemail.com, j6t@kdbg.org
Subject: [PATCH v2 1/2] completion: extract utility to complete paths from tree-ish
Date: Tue, 14 Feb 2017 22:24:03 +0100	[thread overview]
Message-ID: <20170214212404.31469-1-cornelius.weig@tngtech.com> (raw)
In-Reply-To: <4f8a0aaa-4ce1-d4a6-d2e1-28aac7209c90@tngtech.com>

From: Cornelius Weig <cornelius.weig@tngtech.com>

The function __git_complete_revlist_file understands how to complete a
path such as 'topic:ref<TAB>'. In that case, the revision (topic) and
the path component (ref) are both part of the same word. However,
some cases require that the revision is specified elsewhere than the
current word for completion, such as 'git checkout topic ref<TAB>'.

In order to allow callers to specify the revision, extract a utility
function to complete paths from a tree-ish object. The utility will be
used later to implement path completion for git-checkout.

Signed-off-by: Cornelius Weig <cornelius.weig@tngtech.com>
---
 contrib/completion/git-completion.bash | 73 +++++++++++++++++++---------------
 1 file changed, 41 insertions(+), 32 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6c6e1c7..4ab119d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -442,6 +442,46 @@ __git_compute_merge_strategies ()
 	__git_merge_strategies=$(__git_list_merge_strategies)
 }
 
+# __git_complete_tree_file requires 2 argument:
+# 1: the the tree-like to look at for completion
+# 2: the path component to complete
+__git_complete_tree_file ()
+{
+	local pfx ls ref="$1" cur_="$2"
+	case "$cur_" in
+	?*/*)
+		pfx="${cur_%/*}"
+		cur_="${cur_##*/}"
+		ls="$ref:$pfx"
+		pfx="$pfx/"
+		;;
+	*)
+		ls="$ref"
+		;;
+	esac
+
+	case "$COMP_WORDBREAKS" in
+	*:*) : great ;;
+	*)   pfx="$ref:$pfx" ;;
+	esac
+
+	__gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
+				| sed '/^100... blob /{
+						   s,^.*	,,
+						   s,$, ,
+					   }
+					   /^120000 blob /{
+						   s,^.*	,,
+						   s,$, ,
+					   }
+					   /^040000 tree /{
+						   s,^.*	,,
+						   s,$,/,
+					   }
+					   s/^.*	//')" \
+				"$pfx" "$cur_" ""
+}
+
 __git_complete_revlist_file ()
 {
 	local pfx ls ref cur_="$cur"
@@ -452,38 +492,7 @@ __git_complete_revlist_file ()
 	?*:*)
 		ref="${cur_%%:*}"
 		cur_="${cur_#*:}"
-		case "$cur_" in
-		?*/*)
-			pfx="${cur_%/*}"
-			cur_="${cur_##*/}"
-			ls="$ref:$pfx"
-			pfx="$pfx/"
-			;;
-		*)
-			ls="$ref"
-			;;
-		esac
-
-		case "$COMP_WORDBREAKS" in
-		*:*) : great ;;
-		*)   pfx="$ref:$pfx" ;;
-		esac
-
-		__gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
-				| sed '/^100... blob /{
-				           s,^.*	,,
-				           s,$, ,
-				       }
-				       /^120000 blob /{
-				           s,^.*	,,
-				           s,$, ,
-				       }
-				       /^040000 tree /{
-				           s,^.*	,,
-				           s,$,/,
-				       }
-				       s/^.*	//')" \
-			"$pfx" "$cur_" ""
+		__git_complete_tree_file "$ref" "$cur_"
 		;;
 	*...*)
 		pfx="${cur_%...*}..."
-- 
2.10.2


  reply	other threads:[~2017-02-14 21:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 23:33 [PATCH] completion: complete modified files for checkout with '--' cornelius.weig
2017-02-14  0:50 ` SZEDER Gábor
2017-02-14 21:13   ` Cornelius Weig
2017-02-14 21:24     ` cornelius.weig [this message]
2017-02-14 21:24       ` [PATCH v2 2/2] completion: checkout: complete paths when ref given cornelius.weig
2017-02-14 21:31         ` Junio C Hamano
2017-02-14 22:13           ` Cornelius Weig
2017-02-14 22:45             ` Junio C Hamano
2017-02-15  3:11         ` SZEDER Gábor
2017-02-15 10:46           ` Cornelius Weig
2017-02-15 14:26         ` SZEDER Gábor
2017-02-15 22:45           ` Cornelius Weig

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

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

  git send-email \
    --in-reply-to=20170214212404.31469-1-cornelius.weig@tngtech.com \
    --to=cornelius.weig@tngtech.com \
    --cc=bitte.keine.werbung.einwerfen@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=szeder.dev@gmail.com \
    /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.
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 NNTP newsgroup(s).