@@ -740,17 +740,43 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
740
740
def originP4BranchesExist ():
741
741
return gitBranchExists ("origin" ) or gitBranchExists ("origin/p4" ) or gitBranchExists ("origin/p4/master" )
742
742
743
- def p4ChangesForPaths (depotPaths , changeRange ):
743
+ def p4ChangesForPaths (depotPaths , changeRange , block_size ):
744
744
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 ]
749
756
757
+ # Accumulate change numbers in a dictionary to avoid duplicates
750
758
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
754
780
755
781
changelist = changes .keys ()
756
782
changelist .sort ()
@@ -1911,7 +1937,10 @@ def __init__(self):
1911
1937
optparse .make_option ("--import-labels" , dest = "importLabels" , action = "store_true" ),
1912
1938
optparse .make_option ("--import-local" , dest = "importIntoRemotes" , action = "store_false" ,
1913
1939
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" ),
1915
1944
optparse .make_option ("--keep-path" , dest = "keepRepoPath" , action = 'store_true' ,
1916
1945
help = "Keep entire BRANCH/DIR/SUBDIR prefix during import" ),
1917
1946
optparse .make_option ("--use-client-spec" , dest = "useClientSpec" , action = 'store_true' ,
@@ -1940,6 +1969,7 @@ def __init__(self):
1940
1969
self .syncWithOrigin = True
1941
1970
self .importIntoRemotes = True
1942
1971
self .maxChanges = ""
1972
+ self .changes_block_size = 500
1943
1973
self .keepRepoPath = False
1944
1974
self .depotPaths = None
1945
1975
self .p4BranchesInGit = []
@@ -2586,7 +2616,7 @@ def importNewBranch(self, branch, maxChange):
2586
2616
branchPrefix = self .depotPaths [0 ] + branch + "/"
2587
2617
range = "@1,%s" % maxChange
2588
2618
#print "prefix" + branchPrefix
2589
- changes = p4ChangesForPaths ([branchPrefix ], range )
2619
+ changes = p4ChangesForPaths ([branchPrefix ], range , self . changes_block_size )
2590
2620
if len (changes ) <= 0 :
2591
2621
return False
2592
2622
firstChange = changes [0 ]
@@ -3002,7 +3032,7 @@ def run(self, args):
3002
3032
if self .verbose :
3003
3033
print "Getting p4 changes for %s...%s" % (', ' .join (self .depotPaths ),
3004
3034
self .changeRange )
3005
- changes = p4ChangesForPaths (self .depotPaths , self .changeRange )
3035
+ changes = p4ChangesForPaths (self .depotPaths , self .changeRange , self . changes_block_size )
3006
3036
3007
3037
if len (self .maxChanges ) > 0 :
3008
3038
changes = changes [:min (int (self .maxChanges ), len (changes ))]
0 commit comments