git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 1/4] git-p4: Correct branch base depot path detection

From
Vitor Antunes <vitor.hda@gmail.com>
Date
Aug 28, 2011, 21:58 UTC
Message-ID
<1314568710-6472-2-git-send-email-vitor.hda@gmail.com>
In-Reply-To
<1314568710-6472-1-git-send-email-vitor.hda@gmail.com>

When branch detection is enabled each branch is named in git after their relative depot path in Perforce. To do this the depot paths are compared against each other to find their common base path. The current algorithm makes this comparison on a character by character basis. Assuming we have the following branches:

//depot/branches/featureA //depot/branches/featureB

Then the base depot path would be //depot/branches/feature, which is an invalid depot path. The current patch fixes this by splitting the path into a list and comparing the list entries, making it choose correctly //depot/branches as the base path.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 contrib/fast-import/git-p4 |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 0db3e72..72a5b6c 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1829,12 +1829,14 @@ class P4Sync(Command, P4UserMap):
                     else:
                         paths = []
                         for (prev, cur) in zip(self.previousDepotPaths, depotPaths):
-                            for i in range(0, min(len(cur), len(prev))):
-                                if cur[i] <> prev[i]:
+                            prev_list = prev.split("/")
+                            cur_list = cur.split("/")
+                            for i in range(0, min(len(cur_list), len(prev_list))):
+                                if cur_list[i] <> prev_list[i]:
                                     i = i - 1
                                     break
 
-                            paths.append (cur[:i + 1])
+                            paths.append ("/".join(cur_list[:i + 1]))
 
                         self.previousDepotPaths = paths
 
-- 
1.7.5.4
Previous: Vitor AntunesNext: Vitor Antunes
Message 2 of 7 in “git-p4: Improve branch support”
  1. 0/4 git-p4: Improve branch supportVitor Antunes, Aug 28, 2011
  2. 1/4 git-p4: Correct branch base depot path detectionVitor Antunes, Aug 28, 2011
  3. 2/4 git-p4: Allow filtering Perforce branches by userVitor Antunes, Aug 28, 2011
  4. 3/4 git-p4: Allow branch definition with git configVitor Antunes, Aug 28, 2011
  5. 4/4 git-p4: Add simple test case for branch importVitor Antunes, Aug 28, 2011
  6. Junio C HamanoAug 29, 2011
  7. Vitor AntunesAug 29, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.