Rev 5277: (lifeless) Tab-complete tags with names or at the edge of a revision range. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 2 01:25:56 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5277 [merge]
revision-id: pqm at pqm.ubuntu.com-20100602002552-r3uvzo8k1ma0kjb4
parent: pqm at pqm.ubuntu.com-20100601224623-bdsqp9mwnq4ehwq5
parent: martin.vgagern at gmx.net-20100529103053-tydlklu68wwoq41r
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-06-02 01:25:52 +0100
message:
  (lifeless) Tab-complete tags with names or at the edge of a revision range.
   Includes bzr-bash-completion 1.2.0. (Martin von Gagern)
modified:
  bzrlib/plugins/bash_completion/bashcomp.py bzr-20090930204816-30t9rmd0lpi17536-1
  bzrlib/plugins/bash_completion/tests/test_bashcomp.py test_bashcomp.py-20100429205005-o3im24mr5pdqog19-3
=== modified file 'bzrlib/plugins/bash_completion/bashcomp.py'
--- a/bzrlib/plugins/bash_completion/bashcomp.py	2010-05-21 06:17:55 +0000
+++ b/bzrlib/plugins/bash_completion/bashcomp.py	2010-05-29 08:47:10 +0000
@@ -66,12 +66,13 @@
 {
 	local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
 	local curOpt optEnums
+	local IFS=$' \\n'
 
 	COMPREPLY=()
 	cur=${COMP_WORDS[COMP_CWORD]}
 
 	cmds='%(cmds)s'
-	globalOpts='%(global_options)s'
+	globalOpts=( %(global_options)s )
 
 	# do ordinary expansion if we are anywhere after a -- argument
 	for ((i = 1; i < COMP_CWORD; ++i)); do
@@ -89,7 +90,7 @@
 
 	# complete command name if we are not already past the command
 	if [[ $COMP_CWORD -le cmdIdx ]]; then
-		COMPREPLY=( $( compgen -W "$cmds $globalOpts" -- $cur ) )
+		COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
 		return 0
 	fi
 
@@ -107,32 +108,45 @@
 		fi
 	fi
 %(debug)s
-	cmdOpts=
-	optEnums=
-	fixedWords=
+	cmdOpts=( )
+	optEnums=( )
+	fixedWords=( )
 	case $cmd in
 %(cases)s\
 	*)
-		cmdOpts='--help -h'
+		cmdOpts=(--help -h)
 		;;
 	esac
 
-	if [[ -z $fixedWords ]] && [[ -z $optEnums ]] && [[ $cur != -* ]]; then
+	IFS=$'\\n'
+	if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
 		case $curOpt in
-			tag:*)
-				fixedWords="$(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//')"
-				;;
-		esac
-	elif [[ $cur == = ]] && [[ -n $optEnums ]]; then
+			tag:|*..tag:)
+				fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
+				;;
+		esac
+		case $cur in
+			[\\"\\']tag:*)
+				fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
+				;;
+			[\\"\\']*..tag:*)
+				fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//') )
+				fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
+				;;
+		esac
+	elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
 		# complete directly after "--option=", list all enum values
-		COMPREPLY=( $optEnums )
+		COMPREPLY=( "${optEnums[@]}" )
 		return 0
 	else
-		fixedWords="$cmdOpts $globalOpts $optEnums $fixedWords"
+		fixedWords=( "${cmdOpts[@]}"
+		             "${globalOpts[@]}"
+		             "${optEnums[@]}"
+		             "${fixedWords[@]}" )
 	fi
 
-	if [[ -n $fixedWords ]]; then
-		COMPREPLY=( $( compgen -W "$fixedWords" -- $cur ) )
+	if [[ ${#fixedWords[@]} -gt 0 ]]; then
+		COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
 	fi
 
 	return 0
@@ -144,6 +158,7 @@
             "global_options": self.global_options(),
             "debug": self.debug_output(),
         })
+        # Help Emacs terminate strings: "
 
     def command_names(self):
         return " ".join(self.data.all_command_aliases())
@@ -196,15 +211,15 @@
             if option.registry_keys:
                 for key in option.registry_keys:
                     options.append("%s=%s" % (option, key))
-                enums.append("%s) optEnums='%s' ;;" %
+                enums.append("%s) optEnums=( %s ) ;;" %
                              (option, ' '.join(option.registry_keys)))
             else:
                 options.append(str(option))
-        case += "\t\tcmdOpts='%s'\n" % " ".join(options)
+        case += "\t\tcmdOpts=( %s )\n" % " ".join(options)
         if command.fixed_words:
             fixed_words = command.fixed_words
             if isinstance(fixed_words, list):
-                fixed_words = "'%s'" + ' '.join(fixed_words)
+                fixed_words = "( %s )" + ' '.join(fixed_words)
             case += "\t\tfixedWords=%s\n" % fixed_words
         if enums:
             case += "\t\tcase $curOpt in\n\t\t\t"
@@ -241,7 +256,10 @@
 
     def __init__(self, name, version=None):
         if version is None:
-            version = bzrlib.plugin.plugins()[name].__version__
+            try:
+                version = bzrlib.plugin.plugins()[name].__version__
+            except:
+                version = 'unknown'
         self.name = name
         self.version = version
 
@@ -335,7 +353,7 @@
             cmd_data.options.extend(self.option(opt))
 
         if 'help' == name or 'help' in cmd.aliases:
-            cmd_data.fixed_words = ('"$cmds %s"' %
+            cmd_data.fixed_words = ('($cmds %s)' %
                 " ".join(sorted(help_topics.topic_registry.keys())))
 
         return cmd_data

=== modified file 'bzrlib/plugins/bash_completion/tests/test_bashcomp.py'
--- a/bzrlib/plugins/bash_completion/tests/test_bashcomp.py	2010-05-25 11:20:16 +0000
+++ b/bzrlib/plugins/bash_completion/tests/test_bashcomp.py	2010-05-29 10:30:53 +0000
@@ -16,6 +16,7 @@
 
 import bzrlib
 from bzrlib import commands, tests
+from bzrlib.tests import features
 from bzrlib.plugins.bash_completion.bashcomp import *
 
 import os
@@ -25,7 +26,7 @@
 class BashCompletionMixin(object):
     """Component for testing execution of a bash completion script."""
 
-    _test_needs_features = [tests.features.bash_feature]
+    _test_needs_features = [features.bash_feature]
 
     def complete(self, words, cword=-1):
         """Perform a bash completion.
@@ -35,7 +36,7 @@
         """
         if self.script is None:
             self.script = self.get_script()
-        proc = subprocess.Popen([tests.features.bash_feature.path,
+        proc = subprocess.Popen([features.bash_feature.path,
                                  '--noprofile'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
@@ -163,7 +164,7 @@
         return s.replace("$(bzr ", "$('%s' " % self.get_bzr_path())
 
     def test_revspec_tag_all(self):
-        self.requireFeature(tests.features.sed_feature)
+        self.requireFeature(features.sed_feature)
         wt = self.make_branch_and_tree('.', format='dirstate-tags')
         wt.branch.tags.set_tag('tag1', 'null:')
         wt.branch.tags.set_tag('tag2', 'null:')
@@ -172,7 +173,7 @@
         self.assertCompletionEquals('tag1', 'tag2', '3tag')
 
     def test_revspec_tag_prefix(self):
-        self.requireFeature(tests.features.sed_feature)
+        self.requireFeature(features.sed_feature)
         wt = self.make_branch_and_tree('.', format='dirstate-tags')
         wt.branch.tags.set_tag('tag1', 'null:')
         wt.branch.tags.set_tag('tag2', 'null:')
@@ -180,6 +181,29 @@
         self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
         self.assertCompletionEquals('tag1', 'tag2')
 
+    def test_revspec_tag_spaces(self):
+        self.requireFeature(features.sed_feature)
+        wt = self.make_branch_and_tree('.', format='dirstate-tags')
+        wt.branch.tags.set_tag('tag with spaces', 'null:')
+        self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
+        self.assertCompletionEquals(r'tag\ with\ spaces')
+        self.complete(['bzr', 'log', '-r', '"tag:t'])
+        self.assertCompletionEquals('tag:tag with spaces')
+        self.complete(['bzr', 'log', '-r', "'tag:t"])
+        self.assertCompletionEquals('tag:tag with spaces')
+
+    def test_revspec_tag_endrange(self):
+        self.requireFeature(features.sed_feature)
+        wt = self.make_branch_and_tree('.', format='dirstate-tags')
+        wt.branch.tags.set_tag('tag1', 'null:')
+        wt.branch.tags.set_tag('tag2', 'null:')
+        self.complete(['bzr', 'log', '-r', '3..tag', ':', 't'])
+        self.assertCompletionEquals('tag1', 'tag2')
+        self.complete(['bzr', 'log', '-r', '"3..tag:t'])
+        self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
+        self.complete(['bzr', 'log', '-r', "'3..tag:t"])
+        self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
+
 
 class TestBashCodeGen(tests.TestCase):
 
@@ -226,10 +250,10 @@
         cg = BashCodeGen(data)
         self.assertEqualDiff('''\
 \tbar|baz)
-\t\tcmdOpts='--opt'
+\t\tcmdOpts=( --opt )
 \t\t;;
 \tfoo)
-\t\tcmdOpts=''
+\t\tcmdOpts=(  )
 \t\t;;
 ''', cg.command_cases())
 
@@ -248,9 +272,9 @@
 \tcmd)
 \t\t# plugin "plugger 1.0"
 \t\t# Some error message
-\t\tcmdOpts='--bar=that --bar=this --foo'
+\t\tcmdOpts=( --bar=that --bar=this --foo )
 \t\tcase $curOpt in
-\t\t\t--bar) optEnums='that this' ;;
+\t\t\t--bar) optEnums=( that this ) ;;
 \t\tesac
 \t\t;;
 ''', cg.command_case(cmd))
@@ -274,6 +298,12 @@
         self.assertSubset(['init', 'init-repo', 'init-repository'],
                            dc.data.all_command_aliases())
 
+    def test_commands_from_plugins(self):
+        dc = DataCollector()
+        dc.commands()
+        self.assertSubset(['bash-completion'],
+                           dc.data.all_command_aliases())
+
     def test_commit_dashm(self):
         dc = DataCollector()
         cmd = dc.command('commit')




More information about the bazaar-commits mailing list