* Bug: git-p4: Sometimes p4 generates Windows-style output on OS X
@ 2013-05-06 17:59 David Foster
2013-05-12 12:59 ` Pete Wyckoff
0 siblings, 1 reply; 2+ messages in thread
From: David Foster @ 2013-05-06 17:59 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 878 bytes --]
I've observed that the p4 command that git-p4 delegates to occasionally
outputs Windows-style line endings even on the OS X platform. When this
happens, git-p4 gets very confused and crashes out.
I've attached a patch which seems to fix the issue in my case. Now this
patch is a pretty bad hack, and I don't recommend that it be accepted
as-is. It is just a starting point.
A real fix would determine in advance whether Perforce was going to emit
Windows-style output. Since I don't know the circumstances under which
this happens on non-Windows platforms, I can't provide a better patch.
Someone who has intimate knowledge of p4's operating modes would be best
to examine what's really going on with p4.
P.S. In case it matters, I am not subscribed to this mailing list, so
you will need to CC me for any replies to reach me.
---
David Foster
http://dafoster.net/
[-- Attachment #2: 0001-Compensate-for-Windows-style-output-from-the-p4-comm.patch --]
[-- Type: text/plain, Size: 1804 bytes --]
>From aef963f0c45dea81f3e6f30d3b4185a0983ca4de Mon Sep 17 00:00:00 2001
From: David Foster <davidfstr@gmail.com>
Date: Mon, 6 May 2013 10:50:01 -0700
Subject: [PATCH] Compensate for Windows-style output from the p4 command on
non-Windows systems.
---
git-p4.py | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 647f110..949d66d 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1454,6 +1454,24 @@ class P4Submit(Command, P4UserMap):
tmpFile = open(fileName, "rb")
message = tmpFile.read()
tmpFile.close()
+
+ # HACK: If Perforce spontaneously generates Windows-style output,
+ # compensate by assuming the entire p4 command went into
+ # Windows mode.
+ if separatorLine not in message:
+ print "WARNING: Perforce has spontaneously decided to generate Windows-style output. Compensating."
+
+ # Assume that Perforce is now inexplicably operating in Windows mode
+ self.isWindows = True
+
+ # Retroactively rewrite expected output
+ submitTemplate = submitTemplate.replace("\n", "\r\n")
+ separatorLine = separatorLine.replace("\n", "\r\n")
+ newdiff = newdiff.replace("\n", "\r\n")
+
+ if separatorLine not in message:
+ raise ValueError('Confused. Thought Perforce went into Windows mode but apparently something else is wrong.')
+
submitTemplate = message[:message.index(separatorLine)]
if self.isWindows:
submitTemplate = submitTemplate.replace("\r\n", "\n")
--
1.7.7.5 (Apple Git-26)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Bug: git-p4: Sometimes p4 generates Windows-style output on OS X
2013-05-06 17:59 Bug: git-p4: Sometimes p4 generates Windows-style output on OS X David Foster
@ 2013-05-12 12:59 ` Pete Wyckoff
0 siblings, 0 replies; 2+ messages in thread
From: Pete Wyckoff @ 2013-05-12 12:59 UTC (permalink / raw)
To: David Foster; +Cc: git
davidfstr@gmail.com wrote on Mon, 06 May 2013 10:59 -0700:
> I've observed that the p4 command that git-p4 delegates to
> occasionally outputs Windows-style line endings even on the OS X
> platform. When this happens, git-p4 gets very confused and crashes
> out.
>
> I've attached a patch which seems to fix the issue in my case. Now
> this patch is a pretty bad hack, and I don't recommend that it be
> accepted as-is. It is just a starting point.
>
> A real fix would determine in advance whether Perforce was going to
> emit Windows-style output. Since I don't know the circumstances
> under which this happens on non-Windows platforms, I can't provide a
> better patch. Someone who has intimate knowledge of p4's operating
> modes would be best to examine what's really going on with p4.
You've changed the part where git-p4 reads the submit message
back from the text editor. There has been no interaction with p4
yet. The self.isWindows check after your changes is just to
remove "\r" from newlines that many windows editors produce.
Now could be that you're worried not about this message, but
about failing in the later apply when it tries to put the
"\n"-terminated patch onto a workspace full of "\r\n". There
was a recent thread:
http://thread.gmane.org/gmane.comp.version-control.git/221664/focus=223625
suggesting that core.autocrlf was to blame. Would be interesting
if this turns out to be your problem too. Maybe we could look
for that and do something sensible.
The other thing to check is "p4 client -o" and see what LineEnd
setting exists for the backing p4 workspace.
-- Pete
> From aef963f0c45dea81f3e6f30d3b4185a0983ca4de Mon Sep 17 00:00:00 2001
> From: David Foster <davidfstr@gmail.com>
> Date: Mon, 6 May 2013 10:50:01 -0700
> Subject: [PATCH] Compensate for Windows-style output from the p4 command on
> non-Windows systems.
>
> ---
> git-p4.py | 18 ++++++++++++++++++
> 1 files changed, 18 insertions(+), 0 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 647f110..949d66d 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1454,6 +1454,24 @@ class P4Submit(Command, P4UserMap):
> tmpFile = open(fileName, "rb")
> message = tmpFile.read()
> tmpFile.close()
> +
> + # HACK: If Perforce spontaneously generates Windows-style output,
> + # compensate by assuming the entire p4 command went into
> + # Windows mode.
> + if separatorLine not in message:
> + print "WARNING: Perforce has spontaneously decided to generate Windows-style output. Compensating."
> +
> + # Assume that Perforce is now inexplicably operating in Windows mode
> + self.isWindows = True
> +
> + # Retroactively rewrite expected output
> + submitTemplate = submitTemplate.replace("\n", "\r\n")
> + separatorLine = separatorLine.replace("\n", "\r\n")
> + newdiff = newdiff.replace("\n", "\r\n")
> +
> + if separatorLine not in message:
> + raise ValueError('Confused. Thought Perforce went into Windows mode but apparently something else is wrong.')
> +
> submitTemplate = message[:message.index(separatorLine)]
> if self.isWindows:
> submitTemplate = submitTemplate.replace("\r\n", "\n")
> --
> 1.7.7.5 (Apple Git-26)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-12 12:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-06 17:59 Bug: git-p4: Sometimes p4 generates Windows-style output on OS X David Foster
2013-05-12 12:59 ` Pete Wyckoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).