{"thread":{"id":"52585","subject":"git-p4 cannot use perforce client created by p4java — \"Expected view key View1 missing\"","startedAt":"2020-01-07T15:53:19Z","lastAt":"2020-01-31T18:15:47Z","messageCount":5,"participants":["Ivan Selin","Luke Diamand","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"389389","messageId":"CAPgZwKbZ0g+VXjnD03hGkRXfwU2DpygLhLBFG3xv1W9c8oQ1fQ@mail.gmail.com","threadId":"52585","inReplyTo":null,"subject":"git-p4 cannot use perforce client created by p4java — \"Expected view key View1 missing\"","fromName":"Ivan Selin","fromEmail":"ivan.selin@toptal.com","sentAt":"2020-01-07T15:53:04Z","receivedAt":"2020-01-07T15:53:19Z","isPatch":false,"sender":{"key":"ivan.selin@toptal.com","avatar":null},"body":"Hello!\n\nIf I create a perforce client from java using p4java, it gets created\nwith an extra key \"ViewDepotType\" in client definition. When I try to\ndo `git p4 sync --use-client-spec`, git-p4 dies with message like\n\"Expected view key View1 missing\" — because it assumes that all keys\nstarting with \"View\" are \"View0\", \"View1\" and so on.\n\nHow to reproduce:\n1) Create perforce repository;\n2) Create a perforce client (let's name it \"my-client\") in said\nperforce repository using p4java; add one view mapping to the client\non creation;\n3) Run `P4CLIENT=my-client git p4 sync --use-client-spec`;\n4) git p4 finishes with error \"Expected view key View1 missing\".\n\nAttaching hexdumped/unmarshalled examples of \"regular\" client\ndefinition and client created with p4java. Note that p4java's version\nhas \"ViewDepotType\" key and regular client does not. Also,\n\"ViewDepotType\" key is not showing up in text output of `p4 client\n-o`, only in binary format (`p4 -G client -o`). And I'm attaching a\npatch that solved the issue for me.\n\nIs that information enough or should I add anything else? I'm new to\ngit community, but willing to help.\n\nRegards,\nIvan.\n\n\n  $ p4 -G client -o c-1 | hexdump -C\n00000000  7b 73 04 00 00 00 63 6f  64 65 73 04 00 00 00 73  |{s....codes....s|\n00000010  74 61 74 73 06 00 00 00  43 6c 69 65 6e 74 73 03  |tats....Clients.|\n00000020  00 00 00 63 2d 31 73 06  00 00 00 55 70 64 61 74  |...c-1s....Updat|\n00000030  65 73 13 00 00 00 32 30  32 30 2f 30 31 2f 30 35  |es....2020/01/05|\n00000040  20 31 36 3a 34 35 3a 33  36 73 06 00 00 00 41 63  | 16:45:36s....Ac|\n00000050  63 65 73 73 73 13 00 00  00 32 30 32 30 2f 30 31  |cesss....2020/01|\n00000060  2f 30 35 20 31 36 3a 34  35 3a 33 36 73 04 00 00  |/05 16:45:36s...|\n00000070  00 52 6f 6f 74 73 3e 00  00 00 2f 68 6f 6d 65 2f  |.Roots>.../home/|\n00000080  64 69 72 65 63 74 6f 72  79 2f 64 65 76 2f 66 72  |directory/dev/fr|\n00000090  65 65 2f 67 69 74 2d 70  34 2f 70 34 2d 73 61 6d  |ee/git-p4/p4-sam|\n000000a0  70 6c 65 2d 72 65 70 6f  2f 64 69 72 65 63 74 2d  |ple-repo/direct-|\n000000b0  63 6d 64 2d 74 65 73 74  73 07 00 00 00 4f 70 74  |cmd-tests....Opt|\n000000c0  69 6f 6e 73 73 3a 00 00  00 6e 6f 61 6c 6c 77 72  |ionss:...noallwr|\n000000d0  69 74 65 20 6e 6f 63 6c  6f 62 62 65 72 20 6e 6f  |ite noclobber no|\n000000e0  63 6f 6d 70 72 65 73 73  20 75 6e 6c 6f 63 6b 65  |compress unlocke|\n000000f0  64 20 6e 6f 6d 6f 64 74  69 6d 65 20 6e 6f 72 6d  |d nomodtime norm|\n00000100  64 69 72 73 0d 00 00 00  53 75 62 6d 69 74 4f 70  |dirs....SubmitOp|\n00000110  74 69 6f 6e 73 73 0f 00  00 00 73 75 62 6d 69 74  |tionss....submit|\n00000120  75 6e 63 68 61 6e 67 65  64 73 07 00 00 00 4c 69  |unchangeds....Li|\n00000130  6e 65 45 6e 64 73 05 00  00 00 6c 6f 63 61 6c 73  |neEnds....locals|\n00000140  05 00 00 00 56 69 65 77  30 73 15 00 00 00 2f 2f  |....View0s....//|\n00000150  64 65 70 6f 74 2f 2e 2e  2e 20 2f 2f 63 2d 31 2f  |depot/... //c-1/|\n00000160  2e 2e 2e 73 04 00 00 00  54 79 70 65 73 09 00 00  |...s....Types...|\n00000170  00 77 72 69 74 65 61 62  6c 65 73 06 00 00 00 42  |.writeables....B|\n00000180  61 63 6b 75 70 73 06 00  00 00 65 6e 61 62 6c 65  |ackups....enable|\n00000190  30                                                |0|\n00000191\n\n  $ p4 -G client -o c-1 | python -c 'import marshal, pprint, sys; pprint.pprint(marshal.load(sys.stdin))'\n{'Access': '2020/01/05 16:45:36',\n 'Backup': 'enable',\n 'Client': 'c-1',\n 'LineEnd': 'local',\n 'Options': 'noallwrite noclobber nocompress unlocked nomodtime normdir',\n 'Root': '/home/directory/dev/free/git-p4/p4-sample-repo/direct-cmd-test',\n 'SubmitOptions': 'submitunchanged',\n 'Type': 'writeable',\n 'Update': '2020/01/05 16:45:36',\n 'View0': '//depot/... //c-1/...',\n 'code': 'stat'}\n\n\n\n git-p4.py | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git git-p4.py git-p4.py\nindex ca0a874501..1dc1588255 100755\n--- git-p4.py\n+++ git-p4.py\n@@ -1108,8 +1108,8 @@ def getClientSpec():\n     # the //client/ name\n     client_name = entry[\"Client\"]\n \n-    # just the keys that start with \"View\"\n-    view_keys = [ k for k in entry.keys() if k.startswith(\"View\") ]\n+    # just the keys \"View0\", \"View1\", ...\n+    view_keys = [ k for k in entry.keys() if re.match(r\"View\\d+\", k) ]\n \n     # hold this new View\n     view = View(client_name)\n\n\n  $ p4 -G client -o git-p4-sync-2 | hexdump -C\n00000000  7b 73 04 00 00 00 63 6f  64 65 73 04 00 00 00 73  |{s....codes....s|\n00000010  74 61 74 73 06 00 00 00  43 6c 69 65 6e 74 73 0d  |tats....Clients.|\n00000020  00 00 00 67 69 74 2d 70  34 2d 73 79 6e 63 2d 32  |...git-p4-sync-2|\n00000030  73 06 00 00 00 55 70 64  61 74 65 73 13 00 00 00  |s....Updates....|\n00000040  32 30 31 39 2f 31 32 2f  31 35 20 31 33 3a 34 39  |2019/12/15 13:49|\n00000050  3a 35 31 73 06 00 00 00  41 63 63 65 73 73 73 13  |:51s....Accesss.|\n00000060  00 00 00 32 30 31 39 2f  31 32 2f 31 35 20 31 33  |...2019/12/15 13|\n00000070  3a 34 39 3a 35 31 73 05  00 00 00 4f 77 6e 65 72  |:49:51s....Owner|\n00000080  73 02 00 00 00 73 61 73  04 00 00 00 52 6f 6f 74  |s....sas....Root|\n00000090  73 52 00 00 00 2f 76 61  72 2f 61 74 6c 61 73 73  |sR.../var/atlass|\n000000a0  69 61 6e 2f 61 70 70 6c  69 63 61 74 69 6f 6e 2d  |ian/application-|\n000000b0  64 61 74 61 2f 62 69 74  62 75 63 6b 65 74 2f 73  |data/bitbucket/s|\n000000c0  68 61 72 65 64 2f 69 73  2d 67 69 74 2d 70 34 2f  |hared/is-git-p4/|\n000000d0  72 65 70 6f 73 69 74 6f  72 79 2f 72 65 70 6f 5f  |repository/repo_|\n000000e0  6c 6f 63 61 6c 5f 32 73  07 00 00 00 4f 70 74 69  |local_2s....Opti|\n000000f0  6f 6e 73 73 3a 00 00 00  6e 6f 61 6c 6c 77 72 69  |onss:...noallwri|\n00000100  74 65 20 6e 6f 63 6c 6f  62 62 65 72 20 6e 6f 63  |te noclobber noc|\n00000110  6f 6d 70 72 65 73 73 20  75 6e 6c 6f 63 6b 65 64  |ompress unlocked|\n00000120  20 6e 6f 6d 6f 64 74 69  6d 65 20 6e 6f 72 6d 64  | nomodtime normd|\n00000130  69 72 73 0d 00 00 00 53  75 62 6d 69 74 4f 70 74  |irs....SubmitOpt|\n00000140  69 6f 6e 73 73 0f 00 00  00 73 75 62 6d 69 74 75  |ionss....submitu|\n00000150  6e 63 68 61 6e 67 65 64  73 07 00 00 00 4c 69 6e  |nchangeds....Lin|\n00000160  65 45 6e 64 73 05 00 00  00 6c 6f 63 61 6c 73 05  |eEnds....locals.|\n00000170  00 00 00 56 69 65 77 30  73 1e 00 00 00 2f 2f 72  |...View0s....//r|\n00000180  65 70 6f 2f 2e 2e 2e 20  2f 2f 67 69 74 2d 70 34  |epo/... //git-p4|\n00000190  2d 73 79 6e 63 2d 32 2f  2e 2e 2e 73 04 00 00 00  |-sync-2/...s....|\n000001a0  54 79 70 65 73 09 00 00  00 77 72 69 74 65 61 62  |Types....writeab|\n000001b0  6c 65 73 06 00 00 00 42  61 63 6b 75 70 73 06 00  |les....Backups..|\n000001c0  00 00 65 6e 61 62 6c 65  73 09 00 00 00 65 78 74  |..enables....ext|\n000001d0  72 61 54 61 67 30 73 0d  00 00 00 56 69 65 77 44  |raTag0s....ViewD|\n000001e0  65 70 6f 74 54 79 70 65  73 0d 00 00 00 65 78 74  |epotTypes....ext|\n000001f0  72 61 54 61 67 54 79 70  65 30 73 04 00 00 00 77  |raTagType0s....w|\n00000200  6f 72 64 73 0d 00 00 00  56 69 65 77 44 65 70 6f  |ords....ViewDepo|\n00000210  74 54 79 70 65 73 05 00  00 00 67 72 61 70 68 30  |tTypes....graph0|\n00000220\n\n  $ p4 -G client -o git-p4-sync-2 | python -c 'import marshal, pprint, sys; pprint.pprint(marshal.load(sys.stdin))'\n{'Access': '2019/12/15 13:49:51',\n 'Backup': 'enable',\n 'Client': 'git-p4-sync-2',\n 'LineEnd': 'local',\n 'Options': 'noallwrite noclobber nocompress unlocked nomodtime normdir',\n 'Owner': 'sa',\n 'Root': '/var/atlassian/application-data/bitbucket/shared/is-git-p4/repository/repo_local_2',\n 'SubmitOptions': 'submitunchanged',\n 'Type': 'writeable',\n 'Update': '2019/12/15 13:49:51',\n 'View0': '//repo/... //git-p4-sync-2/...',\n 'ViewDepotType': 'graph',\n 'code': 'stat',\n 'extraTag0': 'ViewDepotType',\n 'extraTagType0': 'word'}\n"},{"id":"390711","messageId":"CAE5ih79j+o87yEPbj+nFR6b4rx_NU2eLJite69=+qMdpXdEidw@mail.gmail.com","threadId":"52585","inReplyTo":"CAPgZwKbZ0g+VXjnD03hGkRXfwU2DpygLhLBFG3xv1W9c8oQ1fQ@mail.gmail.com","subject":"Re: git-p4 cannot use perforce client created by p4java — \"Expected view key View1 missing\"","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2020-01-29T10:35:06Z","receivedAt":"2020-01-29T10:35:20Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On Tue, 7 Jan 2020 at 15:53, Ivan Selin <ivan.selin@toptal.com> wrote:\n>\n> Hello!\n>\n> If I create a perforce client from java using p4java, it gets created\n> with an extra key \"ViewDepotType\" in client definition. When I try to\n> do `git p4 sync --use-client-spec`, git-p4 dies with message like\n> \"Expected view key View1 missing\" — because it assumes that all keys\n> starting with \"View\" are \"View0\", \"View1\" and so on.\n>\n> How to reproduce:\n> 1) Create perforce repository;\n> 2) Create a perforce client (let's name it \"my-client\") in said\n> perforce repository using p4java; add one view mapping to the client\n> on creation;\n> 3) Run `P4CLIENT=my-client git p4 sync --use-client-spec`;\n> 4) git p4 finishes with error \"Expected view key View1 missing\".\n>\n> Attaching hexdumped/unmarshalled examples of \"regular\" client\n> definition and client created with p4java. Note that p4java's version\n> has \"ViewDepotType\" key and regular client does not. Also,\n> \"ViewDepotType\" key is not showing up in text output of `p4 client\n> -o`, only in binary format (`p4 -G client -o`). And I'm attaching a\n> patch that solved the issue for me.\n>\n> Is that information enough or should I add anything else? I'm new to\n> git community, but willing to help.\n\nI suspect the problem lies at around line 4220 of git-p4, where it does this:\n\n     view_keys = [ k for k in entry.keys() if k.startswith(\"View\") ]\n\nI think changing that startswith to a regex match would fix this,\nalthough I have not tried it.\nSomething like:\n\nis_view = re.compile(r'^View\\d+$')\nview_keys = [ k for k in entry.keys() if is_view.match(k) ]\n\n\n>\n> Regards,\n> Ivan.\n"},{"id":"390903","messageId":"CAPgZwKbYKPbZeEY2O22DJBvDpjHRR2XVW9hQ7-tML-UE2bkXYA@mail.gmail.com","threadId":"52585","inReplyTo":"CAE5ih79j+o87yEPbj+nFR6b4rx_NU2eLJite69=+qMdpXdEidw@mail.gmail.com","subject":"Re: git-p4 cannot use perforce client created by p4java — \"Expected view key View1 missing\"","fromName":"Ivan Selin","fromEmail":"ivan.selin@toptal.com","sentAt":"2020-01-31T13:42:49Z","receivedAt":"2020-01-31T13:43:02Z","isPatch":false,"sender":{"key":"ivan.selin@toptal.com","avatar":null},"body":"Yes, that's exactly the way that I've tried it and it worked for me.\nCan we have that integrated into git-p4? What can I do to make it\nhappen?\n\nOn Wed, Jan 29, 2020 at 1:35 PM Luke Diamand <luke@diamand.org> wrote:\n>\n> On Tue, 7 Jan 2020 at 15:53, Ivan Selin <ivan.selin@toptal.com> wrote:\n> >\n> > Hello!\n> >\n> > If I create a perforce client from java using p4java, it gets created\n> > with an extra key \"ViewDepotType\" in client definition. When I try to\n> > do `git p4 sync --use-client-spec`, git-p4 dies with message like\n> > \"Expected view key View1 missing\" — because it assumes that all keys\n> > starting with \"View\" are \"View0\", \"View1\" and so on.\n> >\n> > How to reproduce:\n> > 1) Create perforce repository;\n> > 2) Create a perforce client (let's name it \"my-client\") in said\n> > perforce repository using p4java; add one view mapping to the client\n> > on creation;\n> > 3) Run `P4CLIENT=my-client git p4 sync --use-client-spec`;\n> > 4) git p4 finishes with error \"Expected view key View1 missing\".\n> >\n> > Attaching hexdumped/unmarshalled examples of \"regular\" client\n> > definition and client created with p4java. Note that p4java's version\n> > has \"ViewDepotType\" key and regular client does not. Also,\n> > \"ViewDepotType\" key is not showing up in text output of `p4 client\n> > -o`, only in binary format (`p4 -G client -o`). And I'm attaching a\n> > patch that solved the issue for me.\n> >\n> > Is that information enough or should I add anything else? I'm new to\n> > git community, but willing to help.\n>\n> I suspect the problem lies at around line 4220 of git-p4, where it does this:\n>\n>      view_keys = [ k for k in entry.keys() if k.startswith(\"View\") ]\n>\n> I think changing that startswith to a regex match would fix this,\n> although I have not tried it.\n> Something like:\n>\n> is_view = re.compile(r'^View\\d+$')\n> view_keys = [ k for k in entry.keys() if is_view.match(k) ]\n>\n>\n> >\n> > Regards,\n> > Ivan.\n"},{"id":"390910","messageId":"CAE5ih79xWfjLC48y=mSLhdG2zVR5d-XeAbJJFV2SPTew5FGf+Q@mail.gmail.com","threadId":"52585","inReplyTo":"CAPgZwKbYKPbZeEY2O22DJBvDpjHRR2XVW9hQ7-tML-UE2bkXYA@mail.gmail.com","subject":"Re: git-p4 cannot use perforce client created by p4java — \"Expected view key View1 missing\"","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2020-01-31T15:52:08Z","receivedAt":"2020-01-31T15:52:23Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On Fri, 31 Jan 2020 at 13:43, Ivan Selin <ivan.selin@toptal.com> wrote:\n>\n> Yes, that's exactly the way that I've tried it and it worked for me.\n> Can we have that integrated into git-p4? What can I do to make it\n> happen?\n\nA patch would be very welcome!\n\nSee Documentation/SubmittingPatches for details, but it's likely\nenough to just make the change, and then use git format-patch and git\nsend-email.\n\nPlease ensure you add a \"Signed-off-by\" (git commit -s).\n\nThanks!\nLuke\n\n\n>\n> On Wed, Jan 29, 2020 at 1:35 PM Luke Diamand <luke@diamand.org> wrote:\n> >\n> > On Tue, 7 Jan 2020 at 15:53, Ivan Selin <ivan.selin@toptal.com> wrote:\n> > >\n> > > Hello!\n> > >\n> > > If I create a perforce client from java using p4java, it gets created\n> > > with an extra key \"ViewDepotType\" in client definition. When I try to\n> > > do `git p4 sync --use-client-spec`, git-p4 dies with message like\n> > > \"Expected view key View1 missing\" — because it assumes that all keys\n> > > starting with \"View\" are \"View0\", \"View1\" and so on.\n> > >\n> > > How to reproduce:\n> > > 1) Create perforce repository;\n> > > 2) Create a perforce client (let's name it \"my-client\") in said\n> > > perforce repository using p4java; add one view mapping to the client\n> > > on creation;\n> > > 3) Run `P4CLIENT=my-client git p4 sync --use-client-spec`;\n> > > 4) git p4 finishes with error \"Expected view key View1 missing\".\n> > >\n> > > Attaching hexdumped/unmarshalled examples of \"regular\" client\n> > > definition and client created with p4java. Note that p4java's version\n> > > has \"ViewDepotType\" key and regular client does not. Also,\n> > > \"ViewDepotType\" key is not showing up in text output of `p4 client\n> > > -o`, only in binary format (`p4 -G client -o`). And I'm attaching a\n> > > patch that solved the issue for me.\n> > >\n> > > Is that information enough or should I add anything else? I'm new to\n> > > git community, but willing to help.\n> >\n> > I suspect the problem lies at around line 4220 of git-p4, where it does this:\n> >\n> >      view_keys = [ k for k in entry.keys() if k.startswith(\"View\") ]\n> >\n> > I think changing that startswith to a regex match would fix this,\n> > although I have not tried it.\n> > Something like:\n> >\n> > is_view = re.compile(r'^View\\d+$')\n> > view_keys = [ k for k in entry.keys() if is_view.match(k) ]\n> >\n> >\n> > >\n> > > Regards,\n> > > Ivan.\n"},{"id":"390920","messageId":"xmqqa763bigj.fsf@gitster-ct.c.googlers.com","threadId":"52585","inReplyTo":"CAE5ih79xWfjLC48y=mSLhdG2zVR5d-XeAbJJFV2SPTew5FGf+Q@mail.gmail.com","subject":"Re: git-p4 cannot use perforce client created by p4java — \"Expected view key View1 missing\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-01-31T18:15:40Z","receivedAt":"2020-01-31T18:15:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luke Diamand <luke@diamand.org> writes:\n\n> On Fri, 31 Jan 2020 at 13:43, Ivan Selin <ivan.selin@toptal.com> wrote:\n>>\n>> Yes, that's exactly the way that I've tried it and it worked for me.\n>> Can we have that integrated into git-p4? What can I do to make it\n>> happen?\n>\n> A patch would be very welcome!\n>\n> See Documentation/SubmittingPatches for details, but it's likely\n> enough to just make the change, and then use git format-patch and git\n> send-email.\n>\n> Please ensure you add a \"Signed-off-by\" (git commit -s).\n\nThanks for helping.  Another area a new person struggles is to\npropose a good commit log message.  I'd expect this change to be\nexplained something like this:\n\n    Subject: git-p4: tighten detection of view names\n\n    The current \"git p4\" code expects that all keys starting with\n    \"View\" are view names (i.e. \"View0\", \"View1\", etc.), but a\n    Perforce client created using p4java gets an extra key\n    \"ViewDepotType\", which is not something we want to be treated as\n    a view key.\n\n    Tighten the filter of keys to accept only string \"View\" followed\n    by nothing but digits.\n\n    Helped-by: Luke Diamand <luke@diamand.org>\n    Signed-off-by: ...\n\nNote that I am not a Perforce person, so the phrase \"view names\" I\nused in the above may totally be wrong as P4-lingo, in which case\nplease replace them with what is acceptable by our Perforce friends\n;-)\n\nThanks.\n\n>> ...\n>> > is_view = re.compile(r'^View\\d+$')\n>> > view_keys = [ k for k in entry.keys() if is_view.match(k) ]\n"}]}