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

[PATCH v2 1/3] git-p4: Correct branch base depot path detection

From
Vitor Antunes <vitor.hda@gmail.com>
Date
Feb 26, 2011, 23:46 UTC
Message-ID
<1298763971-20556-2-git-send-email-vitor.hda@gmail.com>
In-Reply-To
<1298763971-20556-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 a92beb6..fad3371 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1599,12 +1599,14 @@ class P4Sync(Command):
                     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.4.1
Previous: Vitor AntunesNext: Vitor Antunes
Message 2 of 4 in “git-p4: Improve branch support”
  1. 0/3 git-p4: Improve branch supportVitor Antunes, Feb 26, 2011
  2. 1/3 git-p4: Correct branch base depot path detectionVitor Antunes, Feb 26, 2011
  3. 2/3 git-p4: Allow filtering Perforce branches by userVitor Antunes, Feb 26, 2011
  4. 3/3 git-p4: Allow branch definition with git configVitor Antunes, Feb 26, 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.