]> granicus.if.org Git - git/commitdiff
git-p4: don't exclude other files with same prefix
authorMazo, Andrey <amazo@checkvideo.com>
Mon, 1 Apr 2019 18:02:32 +0000 (18:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Apr 2019 02:25:41 +0000 (11:25 +0900)
Make sure not to exclude files unintentionally
if exclude paths are specified without a trailing /.
I.e., don't exclude "//depot/file_dont_exclude" if run with "-//depot/file".

Do this by ensuring that paths without a trailing "/" are only matched completely.

Also, abort path search on the first match as a micro-optimization.

Signed-off-by: Andrey Mazo <amazo@checkvideo.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-p4.py
t/t9817-git-p4-exclude.sh

index 7edcbad05550e7d091957a984f7541d084d097b9..c47bd8c4d899a09d0693d7f169da12d8d0028a74 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -2623,18 +2623,25 @@ class P4Sync(Command, P4UserMap):
         if self.verbose:
             print("checkpoint finished: " + out)
 
+    def isPathWanted(self, path):
+        for p in self.cloneExclude:
+            if p.endswith("/"):
+                if p4PathStartsWith(path, p):
+                    return False
+            # "-//depot/file1" without a trailing "/" should only exclude "file1", but not "file111" or "file1_dir/file2"
+            elif path.lower() == p.lower():
+                return False
+        for p in self.depotPaths:
+            if p4PathStartsWith(path, p):
+                return True
+        return False
+
     def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0):
         files = []
         fnum = 0
         while "depotFile%s" % fnum in commit:
             path =  commit["depotFile%s" % fnum]
-
-            if [p for p in self.cloneExclude
-                if p4PathStartsWith(path, p)]:
-                found = False
-            else:
-                found = [p for p in self.depotPaths
-                         if p4PathStartsWith(path, p)]
+            found = self.isPathWanted(path)
             if not found:
                 fnum = fnum + 1
                 continue
index 1c225707976d215426bdddffe76583d63a44e885..275dd304258311703ed596ce25a1b67ef3bcc110 100755 (executable)
@@ -53,7 +53,7 @@ test_expect_success 'clone, excluding part of repo' '
        )
 '
 
-test_expect_failure 'clone, excluding single file, no trailing /' '
+test_expect_success 'clone, excluding single file, no trailing /' '
        test_when_finished cleanup_git &&
        git p4 clone -//depot/discard_file --dest="$git" //depot/...@all &&
        (
@@ -85,7 +85,7 @@ test_expect_success 'clone, then sync with exclude' '
        )
 '
 
-test_expect_failure 'clone, then sync with exclude, no trailing /' '
+test_expect_success 'clone, then sync with exclude, no trailing /' '
        test_when_finished cleanup_git &&
        git p4 clone -//depot/discard/... -//depot/discard_file --dest="$git" //depot/...@all &&
        (