fnum = fnum + 1
return files
- def branchesForCommit(self, files):
- branches = Set()
+ def splitFilesIntoBranches(self, commit):
+ branches = {}
- for file in files:
- path = file["path"][len(self.depotPath):]
+ fnum = 0
+ while commit.has_key("depotFile%s" % fnum):
+ path = commit["depotFile%s" % fnum]
+ if not path.startswith(self.depotPath):
+ # if not self.silent:
+ # print "\nchanged files: ignoring path %s outside of %s in change %s" % (path, self.depotPath, change)
+ fnum = fnum + 1
+ continue
+
+ file = {}
+ file["path"] = path
+ file["rev"] = commit["rev%s" % fnum]
+ file["action"] = commit["action%s" % fnum]
+ file["type"] = commit["type%s" % fnum]
+ fnum = fnum + 1
+
+ relPath = path[len(self.depotPath):]
for branch in self.knownBranches.keys():
- if path.startswith(branch):
- branches.add(branch)
+ if relPath.startswith(branch):
+ if branch not in branches:
+ branches[branch] = []
+ branches[branch].append(file)
return branches
change = int(details["change"])
- self.lastChange = change
-
- if change in self.labels:
+ if self.labels.has_key(change):
label = self.labels[change]
labelDetails = label[0]
labelRevisions = label[1]
+ if self.verbose:
+ print "Change %s is labelled %s" % (change, labelDetails)
files = p4CmdList("files %s...@%s" % (branchPrefix, change))
if not self.silent:
print "Tag %s does not match with change %s: file count is different." % (labelDetails["label"], change)
- def extractFilesInCommitToBranch(self, files, branchPrefix):
- newFiles = []
-
- for file in files:
- path = file["path"]
- if path.startswith(branchPrefix):
- newFiles.append(file)
-
- return newFiles
-
def getUserMap(self):
self.users = {}
label = output["label"]
revisions = {}
newestChange = 0
- for file in p4CmdList("files //...@%s" % label):
+ if self.verbose:
+ print "Querying files for label %s" % label
+ for file in p4CmdList("files %s...@%s" % (self.depotPath, label)):
revisions[file["depotFile"]] = file["rev"]
change = int(file["change"])
if change > newestChange:
self.labels[newestChange] = [output, revisions]
+ if self.verbose:
+ print "Label changes: %s" % self.labels.keys()
+
def getBranchMapping(self):
self.projectName = self.depotPath[self.depotPath[:-1].rfind("/") + 1:]
if p4Change > 0:
self.depotPath = self.previousDepotPath
- #self.changeRange = "@%s,#head" % p4Change
- self.changeRange = "@%s,%s" % (p4Change, p4Change + 10)
+ self.changeRange = "@%s,#head" % p4Change
self.initialParent = parseRevision(self.branch)
if not self.silent:
print "Performing incremental import into %s git branch" % self.branch
self.revision = ""
self.users = {}
- self.lastChange = 0
if self.depotPath.find("@") != -1:
atIdx = self.depotPath.index("@")
cnt = cnt + 1
try:
- files = self.extractFilesFromCommit(description)
if self.detectBranches:
- for branch in self.branchesForCommit(files):
+ branches = self.splitFilesIntoBranches(description)
+ for branch in branches.keys():
branchPrefix = self.depotPath + branch + "/"
parent = ""
- filesForCommit = self.extractFilesInCommitToBranch(files, branch)
+ filesForCommit = branches[branch]
if self.verbose:
print "branch is %s" % branch
parent = self.initialParents[branch]
del self.initialParents[branch]
- self.commit(description, files, branch, branchPrefix, parent)
+ self.commit(description, filesForCommit, branch, branchPrefix, parent)
else:
+ files = self.extractFilesFromCommit(description)
self.commit(description, files, self.branch, self.depotPath, self.initialParent)
self.initialParent = ""
except IOError: