git-p4: Fix 'p4 opened' in git-p4 for names with spaces
PATCH 1/1 git-p4: Fix 'p4 opened' in git-p4 for names with spaces
There is problem with git-p4 when trying to submit changes to file containing spaces in name - submit fails with "Command failed: p4 opened [name with spaces here]"
It's caused by not quoting name for p4 opened, and the patch attached fixes it.
Jerzy Kozera (1):
Fix 'p4 opened' in git-p4 for names with spaces
contrib/fast-import/git-p4 | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
PATCH 1/1 git-p4: Fix 'p4 opened' in git-p4 for names with spaces
--- contrib/fast-import/git-p4 | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
contrib/fast-import/git-p4 +1 -1
@@ -144,7 +144,7 @@ def setP4ExecBit(file, mode): def getP4OpenedType(file): # Returns the perforce file type for the given file. - result = p4_read_pipe("opened %s" % file) + result = p4_read_pipe("opened \"%s\"" % file) match = re.match(".*\((.+)\)\r?$", result) if match: return match.group(1)
Signature · 1 line
1.6.5.2
Quoted 10 lines · Jerzy Kozera
Signed-off-by Jerzy Kozera <[email protected]>--- contrib/fast-import/git-p4 | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)contrib/fast-import/git-p4 +0
-0
contrib/fast-import/git-p4 def setP4ExecBit(file, mode): · line 147
Quoted 5 lines
contrib/fast-import/git-p4 +1
-1@@ -144,7 +144,7 @@ def setP4ExecBit(file, mode): def getP4OpenedType(file): # Returns the perforce file type for the given file. - result = p4_read_pipe("opened %s" % file) + result = p4_read_pipe("opened \"%s\"" % file)
Don't you need a lot more than that? What if file has " or \ in it?
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · Jerzy Kozera
Signed-off-by Jerzy Kozera <[email protected]>---
contrib/fast-import/git-p4 | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)contrib/fast-import/git-p4 +0
-0@@ -144,7 +144,7 @@ def setP4ExecBit(file, mode):def getP4OpenedType(file):
# Returns the perforce file type for the given file.
Quoted 4 lines
Quoted 2 lines
- result =
p4_read_pipe("opened %s" % file)
+ result =p4_read_pipe("opened \"%s\"" % file)Don't you need a lot more than that? What if file has " or \ in it?
Those are invalid characters for a filename on Windows, so cannot be entered/present in the filename. On Linux, they are accepted, but don't get put into the filename, so it all depends on where the data for file comes from (API call or user/external source). Not sure how Mac/BSD/Solaris handle those characters.
This looks fine to me, but I wonder if there are other places referencing file paths that require quoting to correctly handle spaces.
Also, escaping the quote characters can be avoided by using single quoted string literals:
+ result = p4_read_pipe('opened "%s"' % file)
- Reece
PATCH 1/1 git-p4: Fixed handling of file names with spaces
Hi,
I've noticed the same issue in reopen and rm calls - not saying these three are all occurences of this problem, but I guess fixing them is a good start.
I'm using \" instead of '' quoting for consistency with rest of the file.
Regards,
Jerzy
--- contrib/fast-import/git-p4 | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
contrib/fast-import/git-p4 +3 -3
@@ -139,12 +139,12 @@ def setP4ExecBit(file, mode): if p4Type[-1] == "+": p4Type = p4Type[0:-1] - p4_system("reopen -t %s %s" % (p4Type, file)) + p4_system("reopen -t %s \"%s\"" % (p4Type, file)) def getP4OpenedType(file): # Returns the perforce file type for the given file. - result = p4_read_pipe("opened %s" % file) + result = p4_read_pipe("opened \"%s\"" % file) match = re.match(".*\((.+)\)\r?$", result) if match: return match.group(1)
@@ -666,7 +666,7 @@ class P4Submit(Command): for f in editedFiles: p4_system("revert \"%s\"" % f); for f in filesToAdd: - system("rm %s" %f) + system("rm \"%s\"" % f) return elif response == "a": os.system(applyPatchCmd)
Signature · 1 line
1.7.1
Re: [PATCH] git-p4: Fixed handling of file names with spaces
Quoted 1 line · Jerzy Kozera
I've noticed the same issue in reopen and rm calls - not saying these three are all occurences of this problem, but I guess fixing them is a good start.
Can those file names also include a double quote or a backquote or a dollar sign?
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Re: [PATCH] git-p4: Fixed handling of file names with spaces
Quoted 2 lines · Andreas Schwab
Can those file names also include a double quote or a backquote or a dollar sign?
Double quote and backquote get escaped by git so they are not a problem:
$ git diff-tree -r HEAD^ HEAD :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A "\" \\ $"
But as you can see above, the dollar sign remains intact, so it needs to be handled as well - patch below takes it into account.
Thanks,
Jerzy
--- contrib/fast-import/git-p4 | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
contrib/fast-import/git-p4 +4 -4
@@ -47,7 +47,7 @@ def p4_build_cmd(cmd): real_cmd += "%s" % (cmd) if verbose: print real_cmd - return real_cmd + return real_cmd.replace('$', '\\$') def chdir(dir): if os.name == 'nt':
@@ -139,12 +139,12 @@ def setP4ExecBit(file, mode): if p4Type[-1] == "+": p4Type = p4Type[0:-1] - p4_system("reopen -t %s %s" % (p4Type, file)) + p4_system("reopen -t %s \"%s\"" % (p4Type, file)) def getP4OpenedType(file): # Returns the perforce file type for the given file. - result = p4_read_pipe("opened %s" % file) + result = p4_read_pipe("opened \"%s\"" % file) match = re.match(".*\((.+)\)\r?$", result) if match: return match.group(1)
@@ -666,7 +666,7 @@ class P4Submit(Command): for f in editedFiles: p4_system("revert \"%s\"" % f); for f in filesToAdd: - system("rm %s" %f) + system("rm \"%s\"" % f.replace('$', '\\$')) return elif response == "a": os.system(applyPatchCmd)
Signature · 1 line
1.7.1
Re: [PATCH] git-p4: Fixed handling of file names with spaces
[email protected] wrote on Fri, 14 Jan 2011 22:45 +0000:
Quoted 10 lines · Andreas Schwab
Quoted 2 lines
Can those file names also include a double quote or a backquote or a dollar sign?
Double quote and backquote get escaped by git so they are not a problem:
$ git diff-tree -r HEAD^ HEAD :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A "\" \\ $"But as you can see above, the dollar sign remains intact, so it needs to be handled as well - patch below takes it into account.
[..]
contrib/fast-import/git-p4 def setP4ExecBit(file, mode): · line 142
Quoted 2 lines
contrib/fast-import/git-p4 +1
-1- p4_system("reopen -t %s %s" % (p4Type, file)) + p4_system("reopen -t %s \"%s\"" % (p4Type, file))
These changes are important for correctness. Thanks for fixing them.
It is kind of ugly to have to do file escaping all over the source. I'd rather see all the os.system() calls go away, in favor of subprocess.Popen(). You can use the latter without going through the shell at all, hence no escapes are needed. If you feel ambitious, this would be a nice fix.
Spaces can happen in depot paths too. That isn't handled current. All the p4Cmd and p4CmdList calls that work on depotPaths should avoid going through the shell too.
But at least what you have done already should go in. If you feel adventurous, addressing these other space-related issues would be nice too.
-- Pete