git-p4: Correct branch base depot path detection

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> Acked-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vitor Antunes committed Aug 19, 2011 at 00:44 UTC 04d277b39e3e40f939fd7935c30beb48452015ec
1 file changed +5 -3
contrib/fast-import/git-p4
+5 -3
@@ -1829,12 +1829,14 @@ class P4Sync(Command, P4UserMap):
1829 else:
1830 paths = []
1831 for (prev, cur) in zip(self.previousDepotPaths, depotPaths):
1832 - for i in range(0, min(len(cur), len(prev))):
1833 - if cur[i] <> prev[i]:
1832 + prev_list = prev.split("/")
1833 + cur_list = cur.split("/")
1834 + for i in range(0, min(len(cur_list), len(prev_list))):
1835 + if cur_list[i] <> prev_list[i]:
1836 i = i - 1
1837 break
1838
1837 - paths.append (cur[:i + 1])
1839 + paths.append ("/".join(cur_list[:i + 1]))
1840
1841 self.previousDepotPaths = paths
1842