{"thread":{"id":"34640","subject":"[PATCH] git-p4: Fix occasional truncation of symlink contents.","startedAt":"2013-08-08T13:17:38Z","lastAt":"2013-08-12T17:11:51Z","messageCount":6,"participants":["Alexandru Juncu","Pete Wyckoff","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"224806","messageId":"1375967858-10615-1-git-send-email-ajuncu@ixiacom.com","threadId":"34640","inReplyTo":null,"subject":"[PATCH] git-p4: Fix occasional truncation of symlink contents.","fromName":"Alexandru Juncu","fromEmail":"alexj@rosedu.org","sentAt":"2013-08-08T13:17:38Z","receivedAt":"2013-08-08T13:17:38Z","isPatch":true,"sender":{"key":"alexj@rosedu.org","avatar":"https://avatars.githubusercontent.com/u/1159557?v=4"},"body":"Symlink contents in p4 print sometimes have a trailing\nnew line character, but sometimes it doesn't. git-p4\nshould only remove the last character if that character\nis '\\n'.\n\nSigned-off-by: Alex Juncu <ajuncu@ixiacom.com>\nSigned-off-by: Alex Badea <abadea@ixiacom.com>\n---\n git-p4.py | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex 31e71ff..a53a6dc 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -2180,9 +2180,13 @@ class P4Sync(Command, P4UserMap):\n             git_mode = \"100755\"\n         if type_base == \"symlink\":\n             git_mode = \"120000\"\n-            # p4 print on a symlink contains \"target\\n\"; remove the newline\n+            # p4 print on a symlink sometimes contains \"target\\n\";\n+            # if it does, remove the newline\n             data = ''.join(contents)\n-            contents = [data[:-1]]\n+            if data[-1] == '\\n':\n+                contents = [data[:-1]]\n+            else:\n+                contents = [data]\n \n         if type_base == \"utf16\":\n             # p4 delivers different text in the python output to -G\n-- \n1.8.4.rc0.1.g8f6a3e5\n"},{"id":"225055","messageId":"20130811115738.GA26658@padd.com","threadId":"34640","inReplyTo":"1375967858-10615-1-git-send-email-ajuncu@ixiacom.com","subject":"Re: [PATCH] git-p4: Fix occasional truncation of symlink contents.","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2013-08-11T11:57:38Z","receivedAt":"2013-08-11T11:57:38Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"alexj@rosedu.org wrote on Thu, 08 Aug 2013 16:17 +0300:\n> Symlink contents in p4 print sometimes have a trailing\n> new line character, but sometimes it doesn't. git-p4\n> should only remove the last character if that character\n> is '\\n'.\n\nYour patch looks fine, and harmless if symlinks continue\nto have \\n on the end.  I'd like to understand a bit why\nthis behavior is different for you, though.  Could you do\nthis test on a symlink in your depot?\n\nHere //depot/symlink points to \"symlink-target\".  You can\nsee the \\n in position 0o332 below.  What happens on a\nsymlink in your repo?\n\n    arf-git-test$ p4 fstat //depot/symlink\n    ... depotFile //depot/symlink\n    ... clientFile /dev/shm/trash directory.t9802-git-p4-filetype/cli/symlink\n    ... isMapped \n    ... headAction add\n    ... headType symlink\n    ... headTime 1376221978\n    ... headRev 1\n    ... headChange 6\n    ... headModTime 1376221978\n    ... haveRev 1\n\n    arf-git-test$ p4 -G print //depot/symlink | od -c\n    0000000   {   s 004  \\0  \\0  \\0   c   o   d   e   s 004  \\0  \\0  \\0   s\n    0000020   t   a   t   s  \\t  \\0  \\0  \\0   d   e   p   o   t   F   i   l\n    0000040   e   s 017  \\0  \\0  \\0   /   /   d   e   p   o   t   /   s   y\n    0000060   m   l   i   n   k   s 003  \\0  \\0  \\0   r   e   v   s 001  \\0\n    0000100  \\0  \\0   1   s 006  \\0  \\0  \\0   c   h   a   n   g   e   s 001\n    0000120  \\0  \\0  \\0   6   s 006  \\0  \\0  \\0   a   c   t   i   o   n   s\n    0000140 003  \\0  \\0  \\0   a   d   d   s 004  \\0  \\0  \\0   t   y   p   e\n    0000160   s  \\a  \\0  \\0  \\0   s   y   m   l   i   n   k   s 004  \\0  \\0\n    0000200  \\0   t   i   m   e   s  \\n  \\0  \\0  \\0   1   3   7   6   2   2\n    0000220   1   9   7   8   s  \\b  \\0  \\0  \\0   f   i   l   e   S   i   z\n    0000240   e   s 002  \\0  \\0  \\0   1   5   0   {   s 004  \\0  \\0  \\0   c\n    0000260   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r   y   s 004\n    0000300  \\0  \\0  \\0   d   a   t   a   s 017  \\0  \\0  \\0   s   y   m   l\n    0000320   i   n   k   -   t   a   r   g   e   t  \\n   0   {   s 004  \\0\n    0000340  \\0  \\0   c   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r\n    0000360   y   s 004  \\0  \\0  \\0   d   a   t   a   s  \\0  \\0  \\0  \\0   0\n    0000400\n\nAlso, what version is your server, from \"p4 info\":\n\n    Server version: P4D/LINUX26X86_64/2013.1/610569 (2013/03/19)\n\n\t\t-- Pete\n\n\n> Signed-off-by: Alex Juncu <ajuncu@ixiacom.com>\n> Signed-off-by: Alex Badea <abadea@ixiacom.com>\n> ---\n>  git-p4.py | 8 ++++++--\n>  1 file changed, 6 insertions(+), 2 deletions(-)\n> \n> diff --git a/git-p4.py b/git-p4.py\n> index 31e71ff..a53a6dc 100755\n> --- a/git-p4.py\n> +++ b/git-p4.py\n> @@ -2180,9 +2180,13 @@ class P4Sync(Command, P4UserMap):\n>              git_mode = \"100755\"\n>          if type_base == \"symlink\":\n>              git_mode = \"120000\"\n> -            # p4 print on a symlink contains \"target\\n\"; remove the newline\n> +            # p4 print on a symlink sometimes contains \"target\\n\";\n> +            # if it does, remove the newline\n>              data = ''.join(contents)\n> -            contents = [data[:-1]]\n> +            if data[-1] == '\\n':\n> +                contents = [data[:-1]]\n> +            else:\n> +                contents = [data]\n>  \n>          if type_base == \"utf16\":\n>              # p4 delivers different text in the python output to -G\n> -- \n> 1.8.4.rc0.1.g8f6a3e5\n"},{"id":"225087","messageId":"CAPhGq=YBVvejZ2gacwroX3cw0K3nDo02kWmMdP6Uwgd5sfPXKQ@mail.gmail.com","threadId":"34640","inReplyTo":"20130811115738.GA26658@padd.com","subject":"Re: [PATCH] git-p4: Fix occasional truncation of symlink contents.","fromName":"Alexandru Juncu","fromEmail":"alexj@rosedu.org","sentAt":"2013-08-12T07:46:28Z","receivedAt":"2013-08-12T07:46:28Z","isPatch":true,"sender":{"key":"alexj@rosedu.org","avatar":"https://avatars.githubusercontent.com/u/1159557?v=4"},"body":"On 11 August 2013 14:57, Pete Wyckoff <pw@padd.com> wrote:\n> alexj@rosedu.org wrote on Thu, 08 Aug 2013 16:17 +0300:\n>> Symlink contents in p4 print sometimes have a trailing\n>> new line character, but sometimes it doesn't. git-p4\n>> should only remove the last character if that character\n>> is '\\n'.\n>\n> Your patch looks fine, and harmless if symlinks continue\n> to have \\n on the end.  I'd like to understand a bit why\n> this behavior is different for you, though.  Could you do\n> this test on a symlink in your depot?\n>\n> Here //depot/symlink points to \"symlink-target\".  You can\n> see the \\n in position 0o332 below.  What happens on a\n> symlink in your repo?\n>\n>     arf-git-test$ p4 fstat //depot/symlink\n>     ... depotFile //depot/symlink\n>     ... clientFile /dev/shm/trash directory.t9802-git-p4-filetype/cli/symlink\n>     ... isMapped\n>     ... headAction add\n>     ... headType symlink\n>     ... headTime 1376221978\n>     ... headRev 1\n>     ... headChange 6\n>     ... headModTime 1376221978\n>     ... haveRev 1\n>\n>     arf-git-test$ p4 -G print //depot/symlink | od -c\n>     0000000   {   s 004  \\0  \\0  \\0   c   o   d   e   s 004  \\0  \\0  \\0   s\n>     0000020   t   a   t   s  \\t  \\0  \\0  \\0   d   e   p   o   t   F   i   l\n>     0000040   e   s 017  \\0  \\0  \\0   /   /   d   e   p   o   t   /   s   y\n>     0000060   m   l   i   n   k   s 003  \\0  \\0  \\0   r   e   v   s 001  \\0\n>     0000100  \\0  \\0   1   s 006  \\0  \\0  \\0   c   h   a   n   g   e   s 001\n>     0000120  \\0  \\0  \\0   6   s 006  \\0  \\0  \\0   a   c   t   i   o   n   s\n>     0000140 003  \\0  \\0  \\0   a   d   d   s 004  \\0  \\0  \\0   t   y   p   e\n>     0000160   s  \\a  \\0  \\0  \\0   s   y   m   l   i   n   k   s 004  \\0  \\0\n>     0000200  \\0   t   i   m   e   s  \\n  \\0  \\0  \\0   1   3   7   6   2   2\n>     0000220   1   9   7   8   s  \\b  \\0  \\0  \\0   f   i   l   e   S   i   z\n>     0000240   e   s 002  \\0  \\0  \\0   1   5   0   {   s 004  \\0  \\0  \\0   c\n>     0000260   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r   y   s 004\n>     0000300  \\0  \\0  \\0   d   a   t   a   s 017  \\0  \\0  \\0   s   y   m   l\n>     0000320   i   n   k   -   t   a   r   g   e   t  \\n   0   {   s 004  \\0\n>     0000340  \\0  \\0   c   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r\n>     0000360   y   s 004  \\0  \\0  \\0   d   a   t   a   s  \\0  \\0  \\0  \\0   0\n>     0000400\n>\n> Also, what version is your server, from \"p4 info\":\n>\n>     Server version: P4D/LINUX26X86_64/2013.1/610569 (2013/03/19)\n>\n>                 -- Pete\n>\n\nHello!\n\nLet me give you an example. Here are the links as resulted in the git\np4 clone (one was correct, one wasn't):\n\n./lib/update.sh -> ../update.sh\n./apps/update.sh -> ../update.s\n\n\nalexj@ixro-alexj ~/perforce $ p4 print path/lib/update.sh\n//path/update.sh#6 - edit change 119890 (symlink)\n../update.sh\nalexj@ixro-alexj ~/perforce $ p4 print path/apps/update.sh\n//path/apps/update.sh#144 - edit change 116063 (symlink)\n../update.shalexj@ixro-alexj ~/perforce/unstable $\n\nNotice the output and the prompt.\n\n(I removed the exact path to the file from the output)\n\nThe fstat output is kind of irrelevant, but the hexdump shows the missing \\n:\n\np4 -G print lib/update.sh|od -c\n\n0000360   t   e   .   s   h  \\n   0\n\np4 -G print apps/update.sh|od -c\n0000360   p   d   a   t   e   .   s   h   0\n\n\nServer version: P4D/LINUX26X86_64/2013.1/610569\n\n>> Signed-off-by: Alex Juncu <ajuncu@ixiacom.com>\n>> Signed-off-by: Alex Badea <abadea@ixiacom.com>\n>> ---\n>>  git-p4.py | 8 ++++++--\n>>  1 file changed, 6 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/git-p4.py b/git-p4.py\n>> index 31e71ff..a53a6dc 100755\n>> --- a/git-p4.py\n>> +++ b/git-p4.py\n>> @@ -2180,9 +2180,13 @@ class P4Sync(Command, P4UserMap):\n>>              git_mode = \"100755\"\n>>          if type_base == \"symlink\":\n>>              git_mode = \"120000\"\n>> -            # p4 print on a symlink contains \"target\\n\"; remove the newline\n>> +            # p4 print on a symlink sometimes contains \"target\\n\";\n>> +            # if it does, remove the newline\n>>              data = ''.join(contents)\n>> -            contents = [data[:-1]]\n>> +            if data[-1] == '\\n':\n>> +                contents = [data[:-1]]\n>> +            else:\n>> +                contents = [data]\n>>\n>>          if type_base == \"utf16\":\n>>              # p4 delivers different text in the python output to -G\n>> --\n>> 1.8.4.rc0.1.g8f6a3e5\n"},{"id":"225104","messageId":"20130812123850.GA25532@padd.com","threadId":"34640","inReplyTo":"CAPhGq=YBVvejZ2gacwroX3cw0K3nDo02kWmMdP6Uwgd5sfPXKQ@mail.gmail.com","subject":"Re: [PATCH] git-p4: Fix occasional truncation of symlink contents.","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2013-08-12T12:38:50Z","receivedAt":"2013-08-12T12:38:50Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"alexj@rosedu.org wrote on Mon, 12 Aug 2013 10:46 +0300:\n> On 11 August 2013 14:57, Pete Wyckoff <pw@padd.com> wrote:\n> > alexj@rosedu.org wrote on Thu, 08 Aug 2013 16:17 +0300:\n> >> Symlink contents in p4 print sometimes have a trailing\n> >> new line character, but sometimes it doesn't. git-p4\n> >> should only remove the last character if that character\n> >> is '\\n'.\n> >\n> > Your patch looks fine, and harmless if symlinks continue\n> > to have \\n on the end.  I'd like to understand a bit why\n> > this behavior is different for you, though.  Could you do\n> > this test on a symlink in your depot?\n> >\n> > Here //depot/symlink points to \"symlink-target\".  You can\n> > see the \\n in position 0o332 below.  What happens on a\n> > symlink in your repo?\n> >\n> >     arf-git-test$ p4 fstat //depot/symlink\n> >     ... depotFile //depot/symlink\n> >     ... clientFile /dev/shm/trash directory.t9802-git-p4-filetype/cli/symlink\n> >     ... isMapped\n> >     ... headAction add\n> >     ... headType symlink\n> >     ... headTime 1376221978\n> >     ... headRev 1\n> >     ... headChange 6\n> >     ... headModTime 1376221978\n> >     ... haveRev 1\n> >\n> >     arf-git-test$ p4 -G print //depot/symlink | od -c\n> >     0000000   {   s 004  \\0  \\0  \\0   c   o   d   e   s 004  \\0  \\0  \\0   s\n> >     0000020   t   a   t   s  \\t  \\0  \\0  \\0   d   e   p   o   t   F   i   l\n> >     0000040   e   s 017  \\0  \\0  \\0   /   /   d   e   p   o   t   /   s   y\n> >     0000060   m   l   i   n   k   s 003  \\0  \\0  \\0   r   e   v   s 001  \\0\n> >     0000100  \\0  \\0   1   s 006  \\0  \\0  \\0   c   h   a   n   g   e   s 001\n> >     0000120  \\0  \\0  \\0   6   s 006  \\0  \\0  \\0   a   c   t   i   o   n   s\n> >     0000140 003  \\0  \\0  \\0   a   d   d   s 004  \\0  \\0  \\0   t   y   p   e\n> >     0000160   s  \\a  \\0  \\0  \\0   s   y   m   l   i   n   k   s 004  \\0  \\0\n> >     0000200  \\0   t   i   m   e   s  \\n  \\0  \\0  \\0   1   3   7   6   2   2\n> >     0000220   1   9   7   8   s  \\b  \\0  \\0  \\0   f   i   l   e   S   i   z\n> >     0000240   e   s 002  \\0  \\0  \\0   1   5   0   {   s 004  \\0  \\0  \\0   c\n> >     0000260   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r   y   s 004\n> >     0000300  \\0  \\0  \\0   d   a   t   a   s 017  \\0  \\0  \\0   s   y   m   l\n> >     0000320   i   n   k   -   t   a   r   g   e   t  \\n   0   {   s 004  \\0\n> >     0000340  \\0  \\0   c   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r\n> >     0000360   y   s 004  \\0  \\0  \\0   d   a   t   a   s  \\0  \\0  \\0  \\0   0\n> >     0000400\n> >\n> > Also, what version is your server, from \"p4 info\":\n> >\n> >     Server version: P4D/LINUX26X86_64/2013.1/610569 (2013/03/19)\n> >\n> >                 -- Pete\n> >\n> \n> Hello!\n> \n> Let me give you an example. Here are the links as resulted in the git\n> p4 clone (one was correct, one wasn't):\n> \n> ./lib/update.sh -> ../update.sh\n> ./apps/update.sh -> ../update.s\n> \n> \n> alexj@ixro-alexj ~/perforce $ p4 print path/lib/update.sh\n> //path/update.sh#6 - edit change 119890 (symlink)\n> ../update.sh\n> alexj@ixro-alexj ~/perforce $ p4 print path/apps/update.sh\n> //path/apps/update.sh#144 - edit change 116063 (symlink)\n> ../update.shalexj@ixro-alexj ~/perforce/unstable $\n> \n> Notice the output and the prompt.\n> \n> (I removed the exact path to the file from the output)\n> \n> The fstat output is kind of irrelevant, but the hexdump shows the missing \\n:\n> \n> p4 -G print lib/update.sh|od -c\n> \n> 0000360   t   e   .   s   h  \\n   0\n> \n> p4 -G print apps/update.sh|od -c\n> 0000360   p   d   a   t   e   .   s   h   0\n\nI had forgotten, in fact, another thread on this very topic:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/221500\n\nNow with your evidence, I think we can decide that no matter how\nthe symlink managed to sneak into p4d, git p4 should be able to\nhandle it.\n\nThe only problem is that due to the \\n ambiguity, in your setup\nwhere p4d loses the \\n, git p4 will not handle symlinks with a\ntarget that ends with a newline, e.g.:\n\n    symlink(\"foo\\n\", \"bar\");\n\nBut the small chance of someone actually doing that, coupled with\nthe fact that for you git p4 is unusable with these symlinks,\nsays we should go ahead and make the change.\n\nYou should send the patch to junio for inclusion in pu/ for the\nnext release, with:\n\nAcked-by: Pete Wyckoff <pw@padd.com>\n\nThanks for fixing this!\n\n\t\t-- Pete\n\n> Server version: P4D/LINUX26X86_64/2013.1/610569\n> \n> >> Signed-off-by: Alex Juncu <ajuncu@ixiacom.com>\n> >> Signed-off-by: Alex Badea <abadea@ixiacom.com>\n> >> ---\n> >>  git-p4.py | 8 ++++++--\n> >>  1 file changed, 6 insertions(+), 2 deletions(-)\n> >>\n> >> diff --git a/git-p4.py b/git-p4.py\n> >> index 31e71ff..a53a6dc 100755\n> >> --- a/git-p4.py\n> >> +++ b/git-p4.py\n> >> @@ -2180,9 +2180,13 @@ class P4Sync(Command, P4UserMap):\n> >>              git_mode = \"100755\"\n> >>          if type_base == \"symlink\":\n> >>              git_mode = \"120000\"\n> >> -            # p4 print on a symlink contains \"target\\n\"; remove the newline\n> >> +            # p4 print on a symlink sometimes contains \"target\\n\";\n> >> +            # if it does, remove the newline\n> >>              data = ''.join(contents)\n> >> -            contents = [data[:-1]]\n> >> +            if data[-1] == '\\n':\n> >> +                contents = [data[:-1]]\n> >> +            else:\n> >> +                contents = [data]\n> >>\n> >>          if type_base == \"utf16\":\n> >>              # p4 delivers different text in the python output to -G\n> >> --\n> >> 1.8.4.rc0.1.g8f6a3e5\n> \n"},{"id":"225110","messageId":"CAPhGq=a5=enAAkPH5ooRNWrQU+BwYX57=dqTnNKRF1qK3Q33QQ@mail.gmail.com","threadId":"34640","inReplyTo":"20130812123850.GA25532@padd.com","subject":"Re: [PATCH] git-p4: Fix occasional truncation of symlink contents.","fromName":"Alexandru Juncu","fromEmail":"alexj@rosedu.org","sentAt":"2013-08-12T13:30:59Z","receivedAt":"2013-08-12T13:30:59Z","isPatch":true,"sender":{"key":"alexj@rosedu.org","avatar":"https://avatars.githubusercontent.com/u/1159557?v=4"},"body":"On 12 August 2013 15:38, Pete Wyckoff <pw@padd.com> wrote:\n> alexj@rosedu.org wrote on Mon, 12 Aug 2013 10:46 +0300:\n>> On 11 August 2013 14:57, Pete Wyckoff <pw@padd.com> wrote:\n>> > alexj@rosedu.org wrote on Thu, 08 Aug 2013 16:17 +0300:\n>> >> Symlink contents in p4 print sometimes have a trailing\n>> >> new line character, but sometimes it doesn't. git-p4\n>> >> should only remove the last character if that character\n>> >> is '\\n'.\n>> >\n>> > Your patch looks fine, and harmless if symlinks continue\n>> > to have \\n on the end.  I'd like to understand a bit why\n>> > this behavior is different for you, though.  Could you do\n>> > this test on a symlink in your depot?\n>> >\n>> > Here //depot/symlink points to \"symlink-target\".  You can\n>> > see the \\n in position 0o332 below.  What happens on a\n>> > symlink in your repo?\n>> >\n>> >     arf-git-test$ p4 fstat //depot/symlink\n>> >     ... depotFile //depot/symlink\n>> >     ... clientFile /dev/shm/trash directory.t9802-git-p4-filetype/cli/symlink\n>> >     ... isMapped\n>> >     ... headAction add\n>> >     ... headType symlink\n>> >     ... headTime 1376221978\n>> >     ... headRev 1\n>> >     ... headChange 6\n>> >     ... headModTime 1376221978\n>> >     ... haveRev 1\n>> >\n>> >     arf-git-test$ p4 -G print //depot/symlink | od -c\n>> >     0000000   {   s 004  \\0  \\0  \\0   c   o   d   e   s 004  \\0  \\0  \\0   s\n>> >     0000020   t   a   t   s  \\t  \\0  \\0  \\0   d   e   p   o   t   F   i   l\n>> >     0000040   e   s 017  \\0  \\0  \\0   /   /   d   e   p   o   t   /   s   y\n>> >     0000060   m   l   i   n   k   s 003  \\0  \\0  \\0   r   e   v   s 001  \\0\n>> >     0000100  \\0  \\0   1   s 006  \\0  \\0  \\0   c   h   a   n   g   e   s 001\n>> >     0000120  \\0  \\0  \\0   6   s 006  \\0  \\0  \\0   a   c   t   i   o   n   s\n>> >     0000140 003  \\0  \\0  \\0   a   d   d   s 004  \\0  \\0  \\0   t   y   p   e\n>> >     0000160   s  \\a  \\0  \\0  \\0   s   y   m   l   i   n   k   s 004  \\0  \\0\n>> >     0000200  \\0   t   i   m   e   s  \\n  \\0  \\0  \\0   1   3   7   6   2   2\n>> >     0000220   1   9   7   8   s  \\b  \\0  \\0  \\0   f   i   l   e   S   i   z\n>> >     0000240   e   s 002  \\0  \\0  \\0   1   5   0   {   s 004  \\0  \\0  \\0   c\n>> >     0000260   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r   y   s 004\n>> >     0000300  \\0  \\0  \\0   d   a   t   a   s 017  \\0  \\0  \\0   s   y   m   l\n>> >     0000320   i   n   k   -   t   a   r   g   e   t  \\n   0   {   s 004  \\0\n>> >     0000340  \\0  \\0   c   o   d   e   s 006  \\0  \\0  \\0   b   i   n   a   r\n>> >     0000360   y   s 004  \\0  \\0  \\0   d   a   t   a   s  \\0  \\0  \\0  \\0   0\n>> >     0000400\n>> >\n>> > Also, what version is your server, from \"p4 info\":\n>> >\n>> >     Server version: P4D/LINUX26X86_64/2013.1/610569 (2013/03/19)\n>> >\n>> >                 -- Pete\n>> >\n>>\n>> Hello!\n>>\n>> Let me give you an example. Here are the links as resulted in the git\n>> p4 clone (one was correct, one wasn't):\n>>\n>> ./lib/update.sh -> ../update.sh\n>> ./apps/update.sh -> ../update.s\n>>\n>>\n>> alexj@ixro-alexj ~/perforce $ p4 print path/lib/update.sh\n>> //path/update.sh#6 - edit change 119890 (symlink)\n>> ../update.sh\n>> alexj@ixro-alexj ~/perforce $ p4 print path/apps/update.sh\n>> //path/apps/update.sh#144 - edit change 116063 (symlink)\n>> ../update.shalexj@ixro-alexj ~/perforce/unstable $\n>>\n>> Notice the output and the prompt.\n>>\n>> (I removed the exact path to the file from the output)\n>>\n>> The fstat output is kind of irrelevant, but the hexdump shows the missing \\n:\n>>\n>> p4 -G print lib/update.sh|od -c\n>>\n>> 0000360   t   e   .   s   h  \\n   0\n>>\n>> p4 -G print apps/update.sh|od -c\n>> 0000360   p   d   a   t   e   .   s   h   0\n>\n> I had forgotten, in fact, another thread on this very topic:\n>\n> http://thread.gmane.org/gmane.comp.version-control.git/221500\n>\n> Now with your evidence, I think we can decide that no matter how\n> the symlink managed to sneak into p4d, git p4 should be able to\n> handle it.\n>\n> The only problem is that due to the \\n ambiguity, in your setup\n> where p4d loses the \\n, git p4 will not handle symlinks with a\n> target that ends with a newline, e.g.:\n>\n>     symlink(\"foo\\n\", \"bar\");\n>\n> But the small chance of someone actually doing that, coupled with\n> the fact that for you git p4 is unusable with these symlinks,\n> says we should go ahead and make the change.\n>\n> You should send the patch to junio for inclusion in pu/ for the\n> next release, with:\n>\n> Acked-by: Pete Wyckoff <pw@padd.com>\n>\n> Thanks for fixing this!\n>\n>                 -- Pete\n\nSorry, I didn't get where I am supposed to submit the patch (I thought\nI was supposed to send it here, lkml style).\n\n>\n>> Server version: P4D/LINUX26X86_64/2013.1/610569\n>>\n>> >> Signed-off-by: Alex Juncu <ajuncu@ixiacom.com>\n>> >> Signed-off-by: Alex Badea <abadea@ixiacom.com>\n>> >> ---\n>> >>  git-p4.py | 8 ++++++--\n>> >>  1 file changed, 6 insertions(+), 2 deletions(-)\n>> >>\n>> >> diff --git a/git-p4.py b/git-p4.py\n>> >> index 31e71ff..a53a6dc 100755\n>> >> --- a/git-p4.py\n>> >> +++ b/git-p4.py\n>> >> @@ -2180,9 +2180,13 @@ class P4Sync(Command, P4UserMap):\n>> >>              git_mode = \"100755\"\n>> >>          if type_base == \"symlink\":\n>> >>              git_mode = \"120000\"\n>> >> -            # p4 print on a symlink contains \"target\\n\"; remove the newline\n>> >> +            # p4 print on a symlink sometimes contains \"target\\n\";\n>> >> +            # if it does, remove the newline\n>> >>              data = ''.join(contents)\n>> >> -            contents = [data[:-1]]\n>> >> +            if data[-1] == '\\n':\n>> >> +                contents = [data[:-1]]\n>> >> +            else:\n>> >> +                contents = [data]\n>> >>\n>> >>          if type_base == \"utf16\":\n>> >>              # p4 delivers different text in the python output to -G\n>> >> --\n>> >> 1.8.4.rc0.1.g8f6a3e5\n>>\n"},{"id":"225117","messageId":"7v4nau25rc.fsf@alter.siamese.dyndns.org","threadId":"34640","inReplyTo":"20130812123850.GA25532@padd.com","subject":"Re: [PATCH] git-p4: Fix occasional truncation of symlink contents.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-12T17:11:51Z","receivedAt":"2013-08-12T17:11:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pete Wyckoff <pw@padd.com> writes:\n\n> You should send the patch to junio for inclusion in pu/ for the\n> next release, with:\n>\n> Acked-by: Pete Wyckoff <pw@padd.com>\n\nThanks; I'll queue this then.\n\n-- >8 --\nFrom: Alexandru Juncu <alexj@rosedu.org>\nDate: Thu, 8 Aug 2013 16:17:38 +0300\nSubject: [PATCH] git-p4: Fix occasional truncation of symlink contents.\n\nSymlink contents in p4 print sometimes have a trailing\nnew line character, but sometimes it doesn't. git-p4\nshould only remove the last character if that character\nis '\\n'.\n\nSigned-off-by: Alex Juncu <ajuncu@ixiacom.com>\nSigned-off-by: Alex Badea <abadea@ixiacom.com>\nAcked-by: Pete Wyckoff <pw@padd.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-p4.py | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex 31e71ff..a53a6dc 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -2180,9 +2180,13 @@ class P4Sync(Command, P4UserMap):\n             git_mode = \"100755\"\n         if type_base == \"symlink\":\n             git_mode = \"120000\"\n-            # p4 print on a symlink contains \"target\\n\"; remove the newline\n+            # p4 print on a symlink sometimes contains \"target\\n\";\n+            # if it does, remove the newline\n             data = ''.join(contents)\n-            contents = [data[:-1]]\n+            if data[-1] == '\\n':\n+                contents = [data[:-1]]\n+            else:\n+                contents = [data]\n \n         if type_base == \"utf16\":\n             # p4 delivers different text in the python output to -G\n-- \n1.8.4-rc2-235-g32b7467\n"}]}