{"thread":{"id":"26475","subject":"[PATCH] Obey p4 views when using client spec","startedAt":"2011-02-12T00:33:48Z","lastAt":"2011-02-14T18:33:49Z","messageCount":4,"participants":["Ian Wienand","Pete Wyckoff","Tor Arvid Lund","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"160919","messageId":"4D55D56C.6050207@vmware.com","threadId":"26475","inReplyTo":null,"subject":"[PATCH] Obey p4 views when using client spec","fromName":"Ian Wienand","fromEmail":"ianw@vmware.com","sentAt":"2011-02-12T00:33:48Z","receivedAt":"2011-02-12T00:33:48Z","isPatch":true,"sender":{"key":"ianw@vmware.com","avatar":null},"body":"When using the p4 client spec, this attempts to obey the client's\noutput preferences.\n\nFor example, a view like\n\n//depot/foo/branch/... //client/branch/foo/...\n//depot/bar/branch/... //client/branch/bar/...\n\nwill result in a directory layout in the git tree of\n\nbranch/\nbranch/foo\nbranch/bar\n\np4 can do various other reordering that this change doesn't support,\nbut we should detect it and at least fail nicely.\n\nSigned-off-by: Ian Wienand <ianw@vmware.com>\n---\n contrib/fast-import/git-p4     |   50 ++++++++++++++++++++++++++++++++++++---\n contrib/fast-import/git-p4.txt |    5 ++++\n 2 files changed, 51 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 04ce7e3..a92beb6 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -910,6 +910,22 @@ class P4Sync(Command):\n         return files\n \n     def stripRepoPath(self, path, prefixes):\n+        if self.useClientSpec:\n+\n+            # if using the client spec, we use the output directory\n+            # specified in the client.  For example, a view\n+            #   //depot/foo/branch/... //client/branch/foo/...\n+            # will end up putting all foo/branch files into\n+            #  branch/foo/\n+            for val in self.clientSpecDirs:\n+                if path.startswith(val[0]):\n+                    # replace the depot path with the client path\n+                    path = path.replace(val[0], val[1][1])\n+                    # now strip out the client (//client/...)\n+                    path = re.sub(\"^(//[^/]+/)\", '', path)\n+                    # the rest is all path\n+                    return path\n+\n         if self.keepRepoPath:\n             prefixes = [re.sub(\"^(//[^/]+/).*\", r'\\1', prefixes[0])]\n \n@@ -1032,7 +1048,7 @@ class P4Sync(Command):\n             includeFile = True\n             for val in self.clientSpecDirs:\n                 if f['path'].startswith(val[0]):\n-                    if val[1] <= 0:\n+                    if val[1][0] <= 0:\n                         includeFile = False\n                     break\n \n@@ -1475,19 +1491,45 @@ class P4Sync(Command):\n         for entry in specList:\n             for k,v in entry.iteritems():\n                 if k.startswith(\"View\"):\n+\n+                    # p4 has these %%1 to %%9 arguments in specs to\n+                    # reorder paths; which we can't handle (yet :)\n+                    if re.match('%%\\d', v) != None:\n+                        print \"Sorry, can't handle %%n arguments in client specs\"\n+                        sys.exit(1)\n+\n                     if v.startswith('\"'):\n                         start = 1\n                     else:\n                         start = 0\n                     index = v.find(\"...\")\n+\n+                    # save the \"client view\"; i.e the RHS of the view\n+                    # line that tells the client where to put the\n+                    # files for this view.\n+                    cv = v[index+3:].strip() # +3 to remove previous '...'\n+\n+                    # if the client view doesn't end with a\n+                    # ... wildcard, then we're going to mess up the\n+                    # output directory, so fail gracefully.\n+                    if not cv.endswith('...'):\n+                        print 'Sorry, client view in \"%s\" needs to end with wildcard' % (k)\n+                        sys.exit(1)\n+                    cv=cv[:-3]\n+\n+                    # now save the view; +index means included, -index\n+                    # means it should be filtered out.\n                     v = v[start:index]\n                     if v.startswith(\"-\"):\n                         v = v[1:]\n-                        temp[v] = -len(v)\n+                        include = -len(v)\n                     else:\n-                        temp[v] = len(v)\n+                        include = len(v)\n+\n+                    temp[v] = (include, cv)\n+\n         self.clientSpecDirs = temp.items()\n-        self.clientSpecDirs.sort( lambda x, y: abs( y[1] ) - abs( x[1] ) )\n+        self.clientSpecDirs.sort( lambda x, y: abs( y[1][0] ) - abs( x[1][0] ) )\n \n     def run(self, args):\n         self.depotPaths = []\ndiff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt\nindex 49b3359..e09da44 100644\n--- a/contrib/fast-import/git-p4.txt\n+++ b/contrib/fast-import/git-p4.txt\n@@ -191,6 +191,11 @@ git-p4.useclientspec\n \n   git config [--global] git-p4.useclientspec false\n \n+The P4CLIENT environment variable should be correctly set for p4 to be\n+able to find the relevant client.  This client spec will be used to\n+both filter the files cloned by git and set the directory layout as\n+specified in the client (this implies --keep-path style semantics).\n+\n Implementation Details...\n =========================\n \n-- \n1.7.3.2\n"},{"id":"160960","messageId":"20110212215133.GA21494@mew.padd.com","threadId":"26475","inReplyTo":"4D55D56C.6050207@vmware.com","subject":"Re: [PATCH] Obey p4 views when using client spec","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2011-02-12T21:51:33Z","receivedAt":"2011-02-12T21:51:33Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"ianw@vmware.com wrote on Fri, 11 Feb 2011 16:33 -0800:\n> When using the p4 client spec, this attempts to obey the client's\n> output preferences.\n> \n> For example, a view like\n> \n> //depot/foo/branch/... //client/branch/foo/...\n> //depot/bar/branch/... //client/branch/bar/...\n> \n> will result in a directory layout in the git tree of\n> \n> branch/\n> branch/foo\n> branch/bar\n> \n> p4 can do various other reordering that this change doesn't support,\n> but we should detect it and at least fail nicely.\n> \n> Signed-off-by: Ian Wienand <ianw@vmware.com>\n\nNice, thanks for making the changes.\n\nAcked-by: Pete Wyckoff <pw@padd.com>\n"},{"id":"161034","messageId":"AANLkTinVp3EYFX3Ow2G8dO6Zn5BEWxuYjwO8vW2yOjcF@mail.gmail.com","threadId":"26475","inReplyTo":"20110212215133.GA21494@mew.padd.com","subject":"Re: [PATCH] Obey p4 views when using client spec","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2011-02-14T09:16:10Z","receivedAt":"2011-02-14T09:16:10Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Sat, Feb 12, 2011 at 10:51 PM, Pete Wyckoff <pw@padd.com> wrote:\n> ianw@vmware.com wrote on Fri, 11 Feb 2011 16:33 -0800:\n>> When using the p4 client spec, this attempts to obey the client's\n>> output preferences.\n>>\n>> For example, a view like\n>>\n>> //depot/foo/branch/... //client/branch/foo/...\n>> //depot/bar/branch/... //client/branch/bar/...\n>>\n>> will result in a directory layout in the git tree of\n>>\n>> branch/\n>> branch/foo\n>> branch/bar\n>>\n>> p4 can do various other reordering that this change doesn't support,\n>> but we should detect it and at least fail nicely.\n>>\n>> Signed-off-by: Ian Wienand <ianw@vmware.com>\n>\n> Nice, thanks for making the changes.\n>\n> Acked-by: Pete Wyckoff <pw@padd.com>\n\nGood work, Ian! Thanks.\n\nAcked-by: Tor Arvid Lund <torarvid@gmail.com>\n"},{"id":"161082","messageId":"7v7hd2tqia.fsf@alter.siamese.dyndns.org","threadId":"26475","inReplyTo":"AANLkTinVp3EYFX3Ow2G8dO6Zn5BEWxuYjwO8vW2yOjcF@mail.gmail.com","subject":"Re: [PATCH] Obey p4 views when using client spec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-14T18:33:49Z","receivedAt":"2011-02-14T18:33:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tor Arvid Lund <torarvid@gmail.com> writes:\n\n>>> ...\n>>> p4 can do various other reordering that this change doesn't support,\n>>> but we should detect it and at least fail nicely.\n>>>\n>>> Signed-off-by: Ian Wienand <ianw@vmware.com>\n>>\n>> Nice, thanks for making the changes.\n>>\n>> Acked-by: Pete Wyckoff <pw@padd.com>\n>\n> Good work, Ian! Thanks.\n>\n> Acked-by: Tor Arvid Lund <torarvid@gmail.com>\n\nWill apply; thanks.\n"}]}