All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-p4: Fix 'p4 opened' in git-p4 for names with spaces
@ 2010-12-14 20:56 Jerzy Kozera
  2010-12-14 20:56 ` Jerzy Kozera
  0 siblings, 1 reply; 8+ messages in thread
From: Jerzy Kozera @ 2010-12-14 20:56 UTC (permalink / raw)
  To: git; +Cc: Jerzy Kozera

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(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] git-p4: Fix 'p4 opened' in git-p4 for names with spaces
  2010-12-14 20:56 [PATCH] git-p4: Fix 'p4 opened' in git-p4 for names with spaces Jerzy Kozera
@ 2010-12-14 20:56 ` Jerzy Kozera
  2010-12-14 23:16   ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jerzy Kozera @ 2010-12-14 20:56 UTC (permalink / raw)
  To: git; +Cc: Jerzy Kozera

Signed-off-by: Jerzy Kozera <jerzy.kozera@gmail.com>
---
 contrib/fast-import/git-p4 |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 04ce7e3..a5297e7 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -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)
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: Fix 'p4 opened' in git-p4 for names with spaces
  2010-12-14 20:56 ` Jerzy Kozera
@ 2010-12-14 23:16   ` Junio C Hamano
  2010-12-14 23:36     ` Reece Dunn
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2010-12-14 23:16 UTC (permalink / raw)
  To: Jerzy Kozera; +Cc: git

Jerzy Kozera <jerzy.kozera@gmail.com> writes:

> Signed-off-by: Jerzy Kozera <jerzy.kozera@gmail.com>
> ---
>  contrib/fast-import/git-p4 |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
> index 04ce7e3..a5297e7 100755
> --- a/contrib/fast-import/git-p4
> +++ b/contrib/fast-import/git-p4
> @@ -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?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: Fix 'p4 opened' in git-p4 for names with spaces
  2010-12-14 23:16   ` Junio C Hamano
@ 2010-12-14 23:36     ` Reece Dunn
  2011-01-13 18:51       ` [PATCH] git-p4: Fixed handling of file " Jerzy Kozera
  0 siblings, 1 reply; 8+ messages in thread
From: Reece Dunn @ 2010-12-14 23:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jerzy Kozera, git

On 14 December 2010 23:16, Junio C Hamano <gitster@pobox.com> wrote:
> Jerzy Kozera <jerzy.kozera@gmail.com> writes:
>
>> Signed-off-by: Jerzy Kozera <jerzy.kozera@gmail.com>
>> ---
>>  contrib/fast-import/git-p4 |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
>> index 04ce7e3..a5297e7 100755
>> --- a/contrib/fast-import/git-p4
>> +++ b/contrib/fast-import/git-p4
>> @@ -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?

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] git-p4: Fixed handling of file names with spaces
  2010-12-14 23:36     ` Reece Dunn
@ 2011-01-13 18:51       ` Jerzy Kozera
  2011-01-14 22:01         ` Andreas Schwab
  0 siblings, 1 reply; 8+ messages in thread
From: Jerzy Kozera @ 2011-01-13 18:51 UTC (permalink / raw)
  To: git; +Cc: gitster, msclrhd, Jerzy Kozera

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(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 04ce7e3..2147315 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -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)
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: Fixed handling of file names with spaces
  2011-01-13 18:51       ` [PATCH] git-p4: Fixed handling of file " Jerzy Kozera
@ 2011-01-14 22:01         ` Andreas Schwab
  2011-01-14 22:45           ` Jerzy Kozera
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2011-01-14 22:01 UTC (permalink / raw)
  To: Jerzy Kozera; +Cc: git, gitster, msclrhd

Jerzy Kozera <jerzy.kozera@gmail.com> writes:

> 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.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: Fixed handling of file names with spaces
  2011-01-14 22:01         ` Andreas Schwab
@ 2011-01-14 22:45           ` Jerzy Kozera
  2011-01-15 14:35             ` Pete Wyckoff
  0 siblings, 1 reply; 8+ messages in thread
From: Jerzy Kozera @ 2011-01-14 22:45 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: git, gitster, msclrhd

On 14 Jan 2011, at 22:01, Andreas Schwab wrote:
> 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(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 04ce7e3..d930908 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -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)
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] git-p4: Fixed handling of file names with spaces
  2011-01-14 22:45           ` Jerzy Kozera
@ 2011-01-15 14:35             ` Pete Wyckoff
  0 siblings, 0 replies; 8+ messages in thread
From: Pete Wyckoff @ 2011-01-15 14:35 UTC (permalink / raw)
  To: Jerzy Kozera; +Cc: Andreas Schwab, git, gitster, msclrhd

jerzy.kozera@gmail.com wrote on Fri, 14 Jan 2011 22:45 +0000:
> On 14 Jan 2011, at 22:01, Andreas Schwab wrote:
> > 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.
[..]
> -    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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-01-15 14:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-14 20:56 [PATCH] git-p4: Fix 'p4 opened' in git-p4 for names with spaces Jerzy Kozera
2010-12-14 20:56 ` Jerzy Kozera
2010-12-14 23:16   ` Junio C Hamano
2010-12-14 23:36     ` Reece Dunn
2011-01-13 18:51       ` [PATCH] git-p4: Fixed handling of file " Jerzy Kozera
2011-01-14 22:01         ` Andreas Schwab
2011-01-14 22:45           ` Jerzy Kozera
2011-01-15 14:35             ` Pete Wyckoff

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.