git-p4: match branches case insensitively if configured

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>

Mazo, Andrey committed Apr 1, 2019 at 18:02 UTC f2768cb343cb0320f79692625dea7f50af643759
2 files changed +4 -4
git-p4.py
+2 -2
@@ -2668,7 +2668,7 @@ class P4Sync(Command, P4UserMap):
2668 path = self.clientSpecDirs.map_in_client(path)
2669 if self.detectBranches:
2670 for b in self.knownBranches:
2671 - if path.startswith(b + "/"):
2671 + if p4PathStartsWith(path, b + "/"):
2672 path = path[len(b)+1:]
2673
2674 elif self.keepRepoPath:
@@ -2723,7 +2723,7 @@ class P4Sync(Command, P4UserMap):
2723 for branch in self.knownBranches.keys():
2724 # add a trailing slash so that a commit into qt/4.2foo
2725 # doesn't end up in qt/4.2, e.g.
2726 - if relPath.startswith(branch + "/"):
2726 + if p4PathStartsWith(relPath, branch + "/"):
2727 if branch not in branches:
2728 branches[branch] = []
2729 branches[branch].append(file)
t/t9801-git-p4-branch.sh
+2 -2
@@ -650,7 +650,7 @@ test_expect_success !CASE_INSENSITIVE_FS 'basic p4 branches for case folding' '
650 '
651
652 # Check that files are properly split across branches when ignorecase is set
653 -test_expect_failure !CASE_INSENSITIVE_FS 'git p4 clone, branchList branch definition, ignorecase' '
653 +test_expect_success !CASE_INSENSITIVE_FS 'git p4 clone, branchList branch definition, ignorecase' '
654 test_when_finished cleanup_git &&
655 test_create_repo "$git" &&
656 (
@@ -676,7 +676,7 @@ test_expect_failure !CASE_INSENSITIVE_FS 'git p4 clone, branchList branch defini
676 '
677
678 # Check that files are properly split across branches when ignorecase is set, use-client-spec case
679 -test_expect_failure !CASE_INSENSITIVE_FS 'git p4 clone with client-spec, branchList branch definition, ignorecase' '
679 +test_expect_success !CASE_INSENSITIVE_FS 'git p4 clone with client-spec, branchList branch definition, ignorecase' '
680 client_view "//depot/... //client/..." &&
681 test_when_finished cleanup_git &&
682 test_create_repo "$git" &&