Skip to content

Commit a2bee10

Browse files
Mazo, Andreygitster
authored andcommitted
git-p4: don't exclude other files with same prefix
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d604520 commit a2bee10

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

git-p4.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,18 +2623,25 @@ def checkpoint(self):
26232623
if self.verbose:
26242624
print("checkpoint finished: " + out)
26252625

2626+
def isPathWanted(self, path):
2627+
for p in self.cloneExclude:
2628+
if p.endswith("/"):
2629+
if p4PathStartsWith(path, p):
2630+
return False
2631+
# "-//depot/file1" without a trailing "/" should only exclude "file1", but not "file111" or "file1_dir/file2"
2632+
elif path.lower() == p.lower():
2633+
return False
2634+
for p in self.depotPaths:
2635+
if p4PathStartsWith(path, p):
2636+
return True
2637+
return False
2638+
26262639
def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0):
26272640
files = []
26282641
fnum = 0
26292642
while "depotFile%s" % fnum in commit:
26302643
path = commit["depotFile%s" % fnum]
2631-
2632-
if [p for p in self.cloneExclude
2633-
if p4PathStartsWith(path, p)]:
2634-
found = False
2635-
else:
2636-
found = [p for p in self.depotPaths
2637-
if p4PathStartsWith(path, p)]
2644+
found = self.isPathWanted(path)
26382645
if not found:
26392646
fnum = fnum + 1
26402647
continue

t/t9817-git-p4-exclude.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test_expect_success 'clone, excluding part of repo' '
5353
)
5454
'
5555

56-
test_expect_failure 'clone, excluding single file, no trailing /' '
56+
test_expect_success 'clone, excluding single file, no trailing /' '
5757
test_when_finished cleanup_git &&
5858
git p4 clone -//depot/discard_file --dest="$git" //depot/...@all &&
5959
(
@@ -85,7 +85,7 @@ test_expect_success 'clone, then sync with exclude' '
8585
)
8686
'
8787

88-
test_expect_failure 'clone, then sync with exclude, no trailing /' '
88+
test_expect_success 'clone, then sync with exclude, no trailing /' '
8989
test_when_finished cleanup_git &&
9090
git p4 clone -//depot/discard/... -//depot/discard_file --dest="$git" //depot/...@all &&
9191
(

0 commit comments

Comments
 (0)