Code

git-p4: Fix bug in p4Where method.
authorTor Arvid Lund <torarvid@gmail.com>
Thu, 4 Dec 2008 13:37:33 +0000 (14:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Dec 2008 02:44:16 +0000 (18:44 -0800)
When running:

p4 where //depot/SomePath/...

The result can in some situations look like:

//depot/SomePath/... //client/SomePath/... /home/user/p4root/SomePath/...
-//depot/SomePath/UndesiredSubdir/... //client/SomePath/UndesiredSubdir/... /home/user/p4root/SomePath/UndesiredSubdir/...

This depends on the users Client view. The current p4Where method will now
return /home/user/p4root/SomePath/UndesiredSubdir/... which is not what we
want. This patch loops through the results from "p4 where", and picks the one
where the depotFile exactly matches the given depotPath (//depot/SomePath/...
in this example).

Signed-off-by: Tor Arvid Lund <torarvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/fast-import/git-p4

index b44fbfc9b3988ba848aafe109682006254e46b21..ee504e90ed81720829f547d0a1bff41f368be18c 100755 (executable)
@@ -245,7 +245,15 @@ def p4Cmd(cmd):
 def p4Where(depotPath):
     if not depotPath.endswith("/"):
         depotPath += "/"
-    output = p4Cmd("where %s..." % depotPath)
+    depotPath = depotPath + "..."
+    outputList = p4CmdList("where %s" % depotPath)
+    output = None
+    for entry in outputList:
+        if entry["depotFile"] == depotPath:
+            output = entry
+            break
+    if output == None:
+        return ""
     if output["code"] == "error":
         return ""
     clientPath = ""