git-p4: match branches case insensitively if configured
authorMazo, Andrey <amazo@checkvideo.com>
Mon, 1 Apr 2019 18:02:24 +0000 (18:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Apr 2019 02:25:41 +0000 (11:25 +0900)
git-p4 knows how to handle case insensitivity in file paths
if core.ignorecase is set.
However, when determining a branch for a file,
it still does a case-sensitive prefix match.
This may result in some file changes to be lost on import.

For example, given the following commits
1. add //depot/main/file1
2. add //depot/DirA/file2
3. add //depot/dira/file3
4. add //depot/DirA/file4
and "branchList = main:DirA" branch mapping,
commit 3 will be lost.

So, do branch search case insensitively if running with core.ignorecase set.
Teach splitFilesIntoBranches() to use the p4PathStartsWith() function
for path prefix matches instead of always case-sensitive match.

Signed-off-by: Andrey Mazo <amazo@checkvideo.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-p4.py
t/t9801-git-p4-branch.sh
index c0a3068b6f3994a0389f5458f7b35e06ee589519..f3e5ccb7af4c7e2e77e5f278e73ddd3d13230fff 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -2668,7 +2668,7 @@ def stripRepoPath(self, path, prefixes):
             path = self.clientSpecDirs.map_in_client(path)
             if self.detectBranches:
                 for b in self.knownBranches:
             path = self.clientSpecDirs.map_in_client(path)
             if self.detectBranches:
                 for b in self.knownBranches:
-                    if path.startswith(b + "/"):
+                    if p4PathStartsWith(path, b + "/"):
                         path = path[len(b)+1:]
 
         elif self.keepRepoPath:
                         path = path[len(b)+1:]
 
         elif self.keepRepoPath:
@@ -2723,7 +2723,7 @@ def splitFilesIntoBranches(self, commit):
             for branch in self.knownBranches.keys():
                 # add a trailing slash so that a commit into qt/4.2foo
                 # doesn't end up in qt/4.2, e.g.
             for branch in self.knownBranches.keys():
                 # add a trailing slash so that a commit into qt/4.2foo
                 # doesn't end up in qt/4.2, e.g.
-                if relPath.startswith(branch + "/"):
+                if p4PathStartsWith(relPath, branch + "/"):
                     if branch not in branches:
                         branches[branch] = []
                     branches[branch].append(file)
                     if branch not in branches:
                         branches[branch] = []
                     branches[branch].append(file)
index c48532e12b29ec310565028fbe47e9aa5a68504f..4779448b4c8a1a88c25b2b68a6c86b25feb7ef45 100755 (executable)
@@ -650,7 +650,7 @@ test_expect_success !CASE_INSENSITIVE_FS 'basic p4 branches for case folding' '
 '
 
 # Check that files are properly split across branches when ignorecase is set
 '
 
 # Check that files are properly split across branches when ignorecase is set
-test_expect_failure !CASE_INSENSITIVE_FS 'git p4 clone, branchList branch definition, ignorecase' '
+test_expect_success !CASE_INSENSITIVE_FS 'git p4 clone, branchList branch definition, ignorecase' '
        test_when_finished cleanup_git &&
        test_create_repo "$git" &&
        (
        test_when_finished cleanup_git &&
        test_create_repo "$git" &&
        (
@@ -676,7 +676,7 @@ test_expect_failure !CASE_INSENSITIVE_FS 'git p4 clone, branchList branch defini
 '
 
 # Check that files are properly split across branches when ignorecase is set, use-client-spec case
 '
 
 # Check that files are properly split across branches when ignorecase is set, use-client-spec case
-test_expect_failure !CASE_INSENSITIVE_FS 'git p4 clone with client-spec, branchList branch definition, ignorecase' '
+test_expect_success !CASE_INSENSITIVE_FS 'git p4 clone with client-spec, branchList branch definition, ignorecase' '
        client_view "//depot/... //client/..." &&
        test_when_finished cleanup_git &&
        test_create_repo "$git" &&
        client_view "//depot/... //client/..." &&
        test_when_finished cleanup_git &&
        test_create_repo "$git" &&