Skip to content

Commit 484d09c

Browse files
seraphiregitster
authored andcommitted
git-p4: change the expansion test from basestring to list
Python 3 handles strings differently than Python 2.7. Since Python 2 is reaching it's end of life, a series of changes are being submitted to enable python 3.5 and following support. The current code fails basic tests under python 3.5. Some codepaths can represent a command line the program internally prepares to execute either as a single string (i.e. each token properly quoted, concatenated with $IFS) or as a list of argv[] elements, and there are 9 places where we say "if X is isinstance(_, basestring), then do this thing to handle X as a command line in a single string; if not, X is a command line in a list form". This does not work well with Python 3, as there is no basestring (everything is Unicode now), and even with Python 2, it was not an ideal way to tell the two cases apart, because an internally formed command line could have been in a single Unicode string. Flip the check to say "if X is not a list, then handle X as a command line in a single string; otherwise treat it as a command line in a list form". This will get rid of references to 'basestring', to migrate the code ready for Python 3. Thanks-to: Junio C Hamano <[email protected]> Signed-off-by: Ben Keene <[email protected]> Signed-off-by: Yang Zhao <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b4396f commit 484d09c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

git-p4.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def p4_build_cmd(cmd):
8989
# Provide a way to not pass this option by setting git-p4.retries to 0
9090
real_cmd += ["-r", str(retries)]
9191

92-
if isinstance(cmd,basestring):
92+
if not isinstance(cmd, list):
9393
real_cmd = ' '.join(real_cmd) + ' ' + cmd
9494
else:
9595
real_cmd += cmd
@@ -155,7 +155,7 @@ def write_pipe(c, stdin):
155155
if verbose:
156156
sys.stderr.write('Writing pipe: %s\n' % str(c))
157157

158-
expand = isinstance(c,basestring)
158+
expand = not isinstance(c, list)
159159
p = subprocess.Popen(c, stdin=subprocess.PIPE, shell=expand)
160160
pipe = p.stdin
161161
val = pipe.write(stdin)
@@ -177,7 +177,7 @@ def read_pipe_full(c):
177177
if verbose:
178178
sys.stderr.write('Reading pipe: %s\n' % str(c))
179179

180-
expand = isinstance(c,basestring)
180+
expand = not isinstance(c, list)
181181
p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
182182
(out, err) = p.communicate()
183183
return (p.returncode, out, err)
@@ -213,7 +213,7 @@ def read_pipe_lines(c):
213213
if verbose:
214214
sys.stderr.write('Reading pipe: %s\n' % str(c))
215215

216-
expand = isinstance(c, basestring)
216+
expand = not isinstance(c, list)
217217
p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
218218
pipe = p.stdout
219219
val = pipe.readlines()
@@ -256,7 +256,7 @@ def p4_has_move_command():
256256
return True
257257

258258
def system(cmd, ignore_error=False):
259-
expand = isinstance(cmd,basestring)
259+
expand = not isinstance(cmd, list)
260260
if verbose:
261261
sys.stderr.write("executing %s\n" % str(cmd))
262262
retcode = subprocess.call(cmd, shell=expand)
@@ -268,7 +268,7 @@ def system(cmd, ignore_error=False):
268268
def p4_system(cmd):
269269
"""Specifically invoke p4 as the system command. """
270270
real_cmd = p4_build_cmd(cmd)
271-
expand = isinstance(real_cmd, basestring)
271+
expand = not isinstance(real_cmd, list)
272272
retcode = subprocess.call(real_cmd, shell=expand)
273273
if retcode:
274274
raise CalledProcessError(retcode, real_cmd)
@@ -506,7 +506,7 @@ def getP4OpenedType(file):
506506
# Return the set of all p4 labels
507507
def getP4Labels(depotPaths):
508508
labels = set()
509-
if isinstance(depotPaths,basestring):
509+
if not isinstance(depotPaths, list):
510510
depotPaths = [depotPaths]
511511

512512
for l in p4CmdList(["labels"] + ["%s..." % p for p in depotPaths]):
@@ -593,7 +593,7 @@ def isModeExecChanged(src_mode, dst_mode):
593593
def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
594594
errors_as_exceptions=False):
595595

596-
if isinstance(cmd,basestring):
596+
if not isinstance(cmd, list):
597597
cmd = "-G " + cmd
598598
expand = True
599599
else:
@@ -610,7 +610,7 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
610610
stdin_file = None
611611
if stdin is not None:
612612
stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode)
613-
if isinstance(stdin,basestring):
613+
if not isinstance(stdin, list):
614614
stdin_file.write(stdin)
615615
else:
616616
for i in stdin:

0 commit comments

Comments
 (0)