@@ -740,17 +740,43 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
740740def originP4BranchesExist ():
741741 return gitBranchExists ("origin" ) or gitBranchExists ("origin/p4" ) or gitBranchExists ("origin/p4/master" )
742742
743- def p4ChangesForPaths (depotPaths , changeRange ):
743+ def p4ChangesForPaths (depotPaths , changeRange , block_size ):
744744 assert depotPaths
745- cmd = ['changes' ]
746- for p in depotPaths :
747- cmd += ["%s...%s" % (p , changeRange )]
748- output = p4_read_pipe_lines (cmd )
745+ assert block_size
746+
747+ # Parse the change range into start and end
748+ if changeRange is None or changeRange == '' :
749+ changeStart = '@1'
750+ changeEnd = '#head'
751+ else :
752+ parts = changeRange .split (',' )
753+ assert len (parts ) == 2
754+ changeStart = parts [0 ]
755+ changeEnd = parts [1 ]
749756
757+ # Accumulate change numbers in a dictionary to avoid duplicates
750758 changes = {}
751- for line in output :
752- changeNum = int (line .split (" " )[1 ])
753- changes [changeNum ] = True
759+
760+ for p in depotPaths :
761+ # Retrieve changes a block at a time, to prevent running
762+ # into a MaxScanRows error from the server.
763+ start = changeStart
764+ end = changeEnd
765+ get_another_block = True
766+ while get_another_block :
767+ new_changes = []
768+ cmd = ['changes' ]
769+ cmd += ['-m' , str (block_size )]
770+ cmd += ["%s...%s,%s" % (p , start , end )]
771+ for line in p4_read_pipe_lines (cmd ):
772+ changeNum = int (line .split (" " )[1 ])
773+ new_changes .append (changeNum )
774+ changes [changeNum ] = True
775+ if len (new_changes ) == block_size :
776+ get_another_block = True
777+ end = '@' + str (min (new_changes ))
778+ else :
779+ get_another_block = False
754780
755781 changelist = changes .keys ()
756782 changelist .sort ()
@@ -1911,7 +1937,10 @@ def __init__(self):
19111937 optparse .make_option ("--import-labels" , dest = "importLabels" , action = "store_true" ),
19121938 optparse .make_option ("--import-local" , dest = "importIntoRemotes" , action = "store_false" ,
19131939 help = "Import into refs/heads/ , not refs/remotes" ),
1914- optparse .make_option ("--max-changes" , dest = "maxChanges" ),
1940+ optparse .make_option ("--max-changes" , dest = "maxChanges" ,
1941+ help = "Maximum number of changes to import" ),
1942+ optparse .make_option ("--changes-block-size" , dest = "changes_block_size" , type = "int" ,
1943+ help = "Internal block size to use when iteratively calling p4 changes" ),
19151944 optparse .make_option ("--keep-path" , dest = "keepRepoPath" , action = 'store_true' ,
19161945 help = "Keep entire BRANCH/DIR/SUBDIR prefix during import" ),
19171946 optparse .make_option ("--use-client-spec" , dest = "useClientSpec" , action = 'store_true' ,
@@ -1940,6 +1969,7 @@ def __init__(self):
19401969 self .syncWithOrigin = True
19411970 self .importIntoRemotes = True
19421971 self .maxChanges = ""
1972+ self .changes_block_size = 500
19431973 self .keepRepoPath = False
19441974 self .depotPaths = None
19451975 self .p4BranchesInGit = []
@@ -2586,7 +2616,7 @@ def importNewBranch(self, branch, maxChange):
25862616 branchPrefix = self .depotPaths [0 ] + branch + "/"
25872617 range = "@1,%s" % maxChange
25882618 #print "prefix" + branchPrefix
2589- changes = p4ChangesForPaths ([branchPrefix ], range )
2619+ changes = p4ChangesForPaths ([branchPrefix ], range , self . changes_block_size )
25902620 if len (changes ) <= 0 :
25912621 return False
25922622 firstChange = changes [0 ]
@@ -3002,7 +3032,7 @@ def run(self, args):
30023032 if self .verbose :
30033033 print "Getting p4 changes for %s...%s" % (', ' .join (self .depotPaths ),
30043034 self .changeRange )
3005- changes = p4ChangesForPaths (self .depotPaths , self .changeRange )
3035+ changes = p4ChangesForPaths (self .depotPaths , self .changeRange , self . changes_block_size )
30063036
30073037 if len (self .maxChanges ) > 0 :
30083038 changes = changes [:min (int (self .maxChanges ), len (changes ))]
0 commit comments