43
# Only labels/tags matching this will be imported/exported
44
defaultLabelRegexp = r'[a-zA-Z0-9_\-.]+$'
45
46
+# Grab changes in blocks of this many revisions, unless otherwise requested
47
+defaultBlockSize = 512
48
+
49
def p4_build_cmd(cmd):
50
"""Build a suitable p4 command line.
51
252
def p4_move(src, dest):
253
p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])
254
255
+def p4_last_change():
256
+ results = p4CmdList(["changes", "-m", "1"])
257
+ return int(results[0]['change'])
258
+
259
def p4_describe(change):
260
"""Make sure it returns a valid result by checking for
261
the presence of field "time". Return a dict of the
749
def originP4BranchesExist():
750
return gitBranchExists("origin") or gitBranchExists("origin/p4") or gitBranchExists("origin/p4/master")
751
745
-def p4ChangesForPaths(depotPaths, changeRange, block_size):
752
+
753
+def p4ParseNumericChangeRange(parts):
754
+ changeStart = int(parts[0][1:])
755
+ if parts[1] == '#head':
756
+ changeEnd = p4_last_change()
757
+ else:
758
+ changeEnd = int(parts[1])
759
+
760
+ return (changeStart, changeEnd)
761
+
762
+def chooseBlockSize(blockSize):
763
+ if blockSize:
764
+ return blockSize
765
+ else:
766
+ return defaultBlockSize
767
+
768
+def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
769
assert depotPaths
747
- assert block_size
770
749
- # Parse the change range into start and end
771
+ # Parse the change range into start and end. Try to find integer
772
+ # revision ranges as these can be broken up into blocks to avoid
773
+ # hitting server-side limits (maxrows, maxscanresults). But if
774
+ # that doesn't work, fall back to using the raw revision specifier
775
+ # strings, without using block mode.
776
+
777
if changeRange is None or changeRange == '':
751
- changeStart = '@1'
752
- changeEnd = '#head'
778
+ changeStart = 1
779
+ changeEnd = p4_last_change()
780
+ block_size = chooseBlockSize(requestedBlockSize)
781
else:
782
parts = changeRange.split(',')
783
assert len(parts) == 2
756
- changeStart = parts[0]
757
- changeEnd = parts[1]
784
+ try:
785
+ (changeStart, changeEnd) = p4ParseNumericChangeRange(parts)
786
+ block_size = chooseBlockSize(requestedBlockSize)
787
+ except:
788
+ changeStart = parts[0][1:]
789
+ changeEnd = parts[1]
790
+ if requestedBlockSize:
791
+ die("cannot use --changes-block-size with non-numeric revisions")
792
+ block_size = None
793
794
# Accumulate change numbers in a dictionary to avoid duplicates
795
changes = {}
796
797
for p in depotPaths:
798
# Retrieve changes a block at a time, to prevent running
764
- # into a MaxScanRows error from the server.
765
- start = changeStart
766
- end = changeEnd
767
- get_another_block = True
768
- while get_another_block:
769
- new_changes = []
799
+ # into a MaxResults/MaxScanRows error from the server.
800
+
801
+ while True:
802
cmd = ['changes']
771
- cmd += ['-m', str(block_size)]
772
- cmd += ["%s...%s,%s" % (p, start, end)]
803
+
804
+ if block_size:
805
+ end = min(changeEnd, changeStart + block_size)
806
+ revisionRange = "%d,%d" % (changeStart, end)
807
+ else:
808
+ revisionRange = "%s,%s" % (changeStart, changeEnd)
809
+
810
+ cmd += ["%s...@%s" % (p, revisionRange)]
811
+
812
for line in p4_read_pipe_lines(cmd):
813
changeNum = int(line.split(" ")[1])
775
- new_changes.append(changeNum)
814
changes[changeNum] = True
777
- if len(new_changes) == block_size:
778
- get_another_block = True
779
- end = '@' + str(min(new_changes))
780
- else:
781
- get_another_block = False
815
+
816
+ if not block_size:
817
+ break
818
+
819
+ if end >= changeEnd:
820
+ break
821
+
822
+ changeStart = end + 1
823
824
changelist = changes.keys()
825
changelist.sort()
2015
self.syncWithOrigin = True
2016
self.importIntoRemotes = True
2017
self.maxChanges = ""
1977
- self.changes_block_size = 500
2018
+ self.changes_block_size = None
2019
self.keepRepoPath = False
2020
self.depotPaths = None
2021
self.p4BranchesInGit = []