Skip to content

Commit aecb997

Browse files
committed
Merge branch 'sh/p4-multi-depot'
"git p4" when interacting with multiple depots at the same time used to incorrectly drop changes. * sh/p4-multi-depot: git-p4: reduce number of server queries for fetches git-p4: support multiple depot paths in p4 submit git-p4: failing test case for skipping changes with multiple depots
2 parents 7195733 + 1f90a64 commit aecb997

File tree

2 files changed

+57
-26
lines changed

2 files changed

+57
-26
lines changed

git-p4.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -822,39 +822,37 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
822822
die("cannot use --changes-block-size with non-numeric revisions")
823823
block_size = None
824824

825-
# Accumulate change numbers in a dictionary to avoid duplicates
826-
changes = {}
825+
changes = []
827826

828-
for p in depotPaths:
829-
# Retrieve changes a block at a time, to prevent running
830-
# into a MaxResults/MaxScanRows error from the server.
827+
# Retrieve changes a block at a time, to prevent running
828+
# into a MaxResults/MaxScanRows error from the server.
831829

832-
while True:
833-
cmd = ['changes']
830+
while True:
831+
cmd = ['changes']
834832

835-
if block_size:
836-
end = min(changeEnd, changeStart + block_size)
837-
revisionRange = "%d,%d" % (changeStart, end)
838-
else:
839-
revisionRange = "%s,%s" % (changeStart, changeEnd)
833+
if block_size:
834+
end = min(changeEnd, changeStart + block_size)
835+
revisionRange = "%d,%d" % (changeStart, end)
836+
else:
837+
revisionRange = "%s,%s" % (changeStart, changeEnd)
840838

839+
for p in depotPaths:
841840
cmd += ["%s...@%s" % (p, revisionRange)]
842841

843-
for line in p4_read_pipe_lines(cmd):
844-
changeNum = int(line.split(" ")[1])
845-
changes[changeNum] = True
842+
# Insert changes in chronological order
843+
for line in reversed(p4_read_pipe_lines(cmd)):
844+
changes.append(int(line.split(" ")[1]))
846845

847-
if not block_size:
848-
break
846+
if not block_size:
847+
break
849848

850-
if end >= changeEnd:
851-
break
849+
if end >= changeEnd:
850+
break
852851

853-
changeStart = end + 1
852+
changeStart = end + 1
854853

855-
changelist = changes.keys()
856-
changelist.sort()
857-
return changelist
854+
changes = sorted(changes)
855+
return changes
858856

859857
def p4PathStartsWith(path, prefix):
860858
# This method tries to remedy a potential mixed-case issue:
@@ -1458,6 +1456,8 @@ def prepareSubmitTemplate(self):
14581456
Remove lines in the Files section that show changes to files
14591457
outside the depot path we're committing into."""
14601458

1459+
[upstream, settings] = findUpstreamBranchPoint()
1460+
14611461
template = ""
14621462
inFilesSection = False
14631463
for line in p4_read_pipe_lines(['change', '-o']):
@@ -1470,8 +1470,13 @@ def prepareSubmitTemplate(self):
14701470
lastTab = path.rfind("\t")
14711471
if lastTab != -1:
14721472
path = path[:lastTab]
1473-
if not p4PathStartsWith(path, self.depotPath):
1474-
continue
1473+
if settings.has_key('depot-paths'):
1474+
if not [p for p in settings['depot-paths']
1475+
if p4PathStartsWith(path, p)]:
1476+
continue
1477+
else:
1478+
if not p4PathStartsWith(path, self.depotPath):
1479+
continue
14751480
else:
14761481
inFilesSection = False
14771482
else:

t/t9818-git-p4-block.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ p4_add_file() {
8484
(cd "$cli" &&
8585
>$1 &&
8686
p4 add $1 &&
87-
p4 submit -d "Added a file" $1
87+
p4 submit -d "Added file $1" $1
8888
)
8989
}
9090

@@ -112,6 +112,32 @@ test_expect_success 'Syncing files' '
112112
)
113113
'
114114

115+
# Handling of multiple depot paths:
116+
# git p4 clone //depot/pathA //depot/pathB
117+
#
118+
test_expect_success 'Create a repo with multiple depot paths' '
119+
client_view "//depot/pathA/... //client/pathA/..." \
120+
"//depot/pathB/... //client/pathB/..." &&
121+
mkdir -p "$cli/pathA" "$cli/pathB" &&
122+
for p in pathA pathB
123+
do
124+
for i in $(test_seq 1 10)
125+
do
126+
p4_add_file "$p/file$p$i"
127+
done
128+
done
129+
'
130+
131+
test_expect_success 'Clone repo with multiple depot paths' '
132+
(
133+
cd "$git" &&
134+
git p4 clone --changes-block-size=4 //depot/pathA@all //depot/pathB@all \
135+
--destination=dest &&
136+
ls -1 dest >log &&
137+
test_line_count = 20 log
138+
)
139+
'
140+
115141
test_expect_success 'kill p4d' '
116142
kill_p4d
117143
'

0 commit comments

Comments
 (0)