From c75310e082a86f564d11bdd7bdfe3ca1365e0265 Mon Sep 17 00:00:00 2001 From: DogeBotZ <437569@gmail.com> Date: Mon, 4 Aug 2025 22:56:32 +0800 Subject: [PATCH] Support handling cases where multiple integration records found for the same file in source depot ## Issue: In case when source depot contains multiple integration records of the same depotfile, the original script only takes the first record. Such cases can be easily observed on dirty moves, that in **one CL**, file A is branched into file B and file A is deleted. Running `p4 filelog` with file B's path will add into the result the older integration record of A. ## Solution: Preprocess the filelog result so that only the latest record for each file as returned from `p4 filelog` is being processed. --- P4Transfer.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/P4Transfer.py b/P4Transfer.py index a7389ca..6071d83 100755 --- a/P4Transfer.py +++ b/P4Transfer.py @@ -1262,19 +1262,29 @@ def getChange(self, changeNum): fpaths = ['{}#{}'.format(x.depotFile, x.rev) for x in filesToLog.values()] filelogs = [] if fpaths: - processedRevs = {} # Get 2 filelogs per rev - saves time filelogs = self.p4.run_filelog('-i', '-m2', *fpaths) if len(filelogs) < 1000: self.logger.debug('filelogs: %s' % filelogs) else: self.logger.debug('filelogs count: %d' % len(filelogs)) + # Create a dictionary to track the highest revision per depotFile + max_revs = {} + # First pass: find the filelog from the maximum revision for each depotFile for flog in filelogs: + depot_file = flog.depotFile + current_rev = flog.revisions[0].rev + if depot_file not in max_revs or current_rev > max_revs[depot_file]: + max_revs[depot_file] = current_rev + # Second pass: filter the filelogs to keep only those with the max revision per depotFile + filtered_logs = [ + flog for flog in filelogs + if flog.revisions[0].rev == max_revs[flog.depotFile] + ] + + for flog in filtered_logs: if flog.depotFile in filesToLog: chRev = filesToLog[flog.depotFile] - if chRev.depotFile in processedRevs: # Only process once - continue - processedRevs[chRev.depotFile] = 1 revision = flog.revisions[0] if len(revision.integrations) > 0: if not self.options.historical_start_change or revision.change >= self.options.historical_start_change: