Skip to content

Commit 1f90a64

Browse files
samhocevargitster
authored andcommitted
git-p4: reduce number of server queries for fetches
When fetching changes from a depot using a full client spec, there is no need to perform as many queries as there are top-level paths in the client spec. Instead we query all changes in chronological order, also getting rid of the need to sort the results and remove duplicates. Signed-off-by: Sam Hocevar <[email protected]> Signed-off-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbc6924 commit 1f90a64

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

git-p4.py

Lines changed: 21 additions & 23 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:

t/t9818-git-p4-block.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ test_expect_success 'Create a repo with multiple depot paths' '
128128
done
129129
'
130130

131-
test_expect_failure 'Clone repo with multiple depot paths' '
131+
test_expect_success 'Clone repo with multiple depot paths' '
132132
(
133133
cd "$git" &&
134134
git p4 clone --changes-block-size=4 //depot/pathA@all //depot/pathB@all \

0 commit comments

Comments
 (0)