Rev 5315: (gz) Allow use of Python arguments preceding bzr script in Windows command in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Jun 22 23:40:33 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5315 [merge]
revision-id: pqm at pqm.ubuntu.com-20100622224029-uycecuqjhtzi4onm
parent: pqm at pqm.ubuntu.com-20100622065243-mhmcsqhkkoi2uzcz
parent: gzlist at googlemail.com-20100622005251-mdkisqrk45a5e210
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-06-22 23:40:29 +0100
message:
(gz) Allow use of Python arguments preceding bzr script in Windows command
lines (Jason Spashett)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzr bzr.py-20050313053754-5485f144c7006fa6
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/tests/test_win32utils.py test_win32utils.py-20070713181630-8xsrjymd3e8mgw23-108
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
=== modified file 'NEWS'
--- a/NEWS 2010-06-21 04:16:16 +0000
+++ b/NEWS 2010-06-22 22:40:29 +0000
@@ -96,6 +96,11 @@
* ``walkdirs`` now raises a useful message when the filenames are not using
the filesystem encoding. (Eric Moritz, #488519)
+* Enable debugging of bzr on windows with pdb and other tools. This was
+ broken because we call GetCommandLineW on windows. The fix adjusts the
+ command line we get to be the same length as sys.argv.
+ (Jason Spashett, Alexander Belchenko, #587868)
+
Improvements
************
=== modified file 'bzr'
--- a/bzr 2010-06-21 03:55:08 +0000
+++ b/bzr 2010-06-22 22:40:29 +0000
@@ -52,7 +52,6 @@
profiling = False
if '--profile-imports' in sys.argv:
- sys.argv.remove('--profile-imports')
import profile_imports
profile_imports.install()
profiling = True
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2010-05-27 21:16:48 +0000
+++ b/bzrlib/commands.py 2010-06-18 11:07:07 +0000
@@ -1054,6 +1054,8 @@
elif a == '--coverage':
opt_coverage_dir = argv[i + 1]
i += 1
+ elif a == '--profile-imports':
+ pass # already handled in startup script Bug #588277
elif a.startswith('-D'):
debug.debug_flags.add(a[2:])
else:
=== modified file 'bzrlib/tests/test_win32utils.py'
--- a/bzrlib/tests/test_win32utils.py 2010-05-20 02:57:52 +0000
+++ b/bzrlib/tests/test_win32utils.py 2010-06-22 00:52:51 +0000
@@ -276,10 +276,13 @@
class Test_CommandLineToArgv(tests.TestCaseInTempDir):
- def assertCommandLine(self, expected, line, single_quotes_allowed=False):
+ def assertCommandLine(self, expected, line, argv=None,
+ single_quotes_allowed=False):
# Strictly speaking we should respect parameter order versus glob
# expansions, but it's not really worth the effort here
- argv = win32utils._command_line_to_argv(line,
+ if argv is None:
+ argv = [line]
+ argv = win32utils._command_line_to_argv(line, argv,
single_quotes_allowed=single_quotes_allowed)
self.assertEqual(expected, sorted(argv))
@@ -313,9 +316,12 @@
def test_single_quote_support(self):
self.assertCommandLine(["add", "let's-do-it.txt"],
- "add let's-do-it.txt")
- self.assertCommandLine(["add", "lets do it.txt"],
- "add 'lets do it.txt'", single_quotes_allowed=True)
+ "add let's-do-it.txt",
+ ["add", "let's-do-it.txt"])
+ self.expectFailure("Using single quotes breaks trimming from argv",
+ self.assertCommandLine, ["add", "lets do it.txt"],
+ "add 'lets do it.txt'", ["add", "'lets", "do", "it.txt'"],
+ single_quotes_allowed=True)
def test_case_insensitive_globs(self):
self.requireFeature(tests.CaseInsCasePresFilenameFeature)
@@ -326,3 +332,11 @@
self.requireFeature(backslashdir_feature)
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
self.assertCommandLine([u'a/b.c'], 'a\\b*')
+
+ def test_with_pdb(self):
+ """Check stripping Python arguments before bzr script per lp:587868"""
+ self.assertCommandLine([u"rocks"], "-m pdb rocks", ["rocks"])
+ self.build_tree(['d/', 'd/f1', 'd/f2'])
+ self.assertCommandLine([u"rm", u"x*"], "-m pdb rm x*", ["rm", u"x*"])
+ self.assertCommandLine([u"add", u"d/f1", u"d/f2"], "-m pdb add d/*",
+ ["add", u"d/*"])
=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py 2010-06-01 14:24:01 +0000
+++ b/bzrlib/win32utils.py 2010-06-22 00:32:37 +0000
@@ -522,7 +522,7 @@
trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
-def _command_line_to_argv(command_line, single_quotes_allowed=False):
+def _command_line_to_argv(command_line, argv, single_quotes_allowed=False):
"""Convert a Unicode command line into a list of argv arguments.
It performs wildcard expansion to make wildcards act closer to how they
@@ -535,12 +535,27 @@
default.
:return: A list of unicode strings.
"""
+ # First, spit the command line
s = cmdline.Splitter(command_line, single_quotes_allowed=single_quotes_allowed)
- # Now that we've split the content, expand globs if necessary
+
+ # Bug #587868 Now make sure that the length of s agrees with sys.argv
+ # we do this by simply counting the number of arguments in each. The counts should
+ # agree no matter what encoding sys.argv is in (AFAIK)
+ # len(arguments) < len(sys.argv) should be an impossibility since python gets
+ # args from the very same PEB as does GetCommandLineW
+ arguments = list(s)
+
+ # Now shorten the command line we get from GetCommandLineW to match sys.argv
+ if len(arguments) < len(argv):
+ raise AssertionError("Split command line can't be shorter than argv")
+ arguments = arguments[len(arguments) - len(argv):]
+
+ # Carry on to process globs (metachars) in the command line
+ # expand globs if necessary
# TODO: Use 'globbing' instead of 'glob.glob', this gives us stuff like
# '**/' style globs
args = []
- for is_quoted, arg in s:
+ for is_quoted, arg in arguments:
if is_quoted or not glob.has_magic(arg):
args.append(arg)
else:
@@ -557,21 +572,7 @@
if command_line is None:
raise ctypes.WinError()
# Skip the first argument, since we only care about parameters
- argv = _command_line_to_argv(command_line)[1:]
- if getattr(sys, 'frozen', None) is None:
- # Invoked via 'python.exe' which takes the form:
- # python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
- # we need to get only BZR_OPTIONS part,
- # We already removed 'python.exe' so we remove everything up to and
- # including the first non-option ('-') argument.
- for idx in xrange(len(argv)):
- if argv[idx][:1] != '-':
- break
- argv = argv[idx+1:]
- # we should remove '--profile-imports' option as well (bug #588277)
- # see bzr script ~ line 54
- if '--profile-imports' in argv and '--profile-imports' not in sys.argv:
- argv.remove('--profile-imports')
+ argv = _command_line_to_argv(command_line, sys.argv)[1:]
return argv
else:
get_unicode_argv = None
More information about the bazaar-commits
mailing list