git p4: set self.branchPrefixes in initialization

This instance variable is needed during commit() to map
files from p4 to their relative locations in git.  Set
it when initializing P4Sync to avoid passing it to every
commit() call.

Signed-off-by: Pete Wyckoff <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pete Wyckoff 2012-08-11 12:55:02 -04:00 committed by Junio C Hamano
parent 19516356b2
commit e63231e566

View File

@ -2041,10 +2041,9 @@ class P4Sync(Command, P4UserMap):
gitStream.write(description) gitStream.write(description)
gitStream.write("\n") gitStream.write("\n")
def commit(self, details, files, branch, branchPrefixes, parent = ""): def commit(self, details, files, branch, parent = ""):
epoch = details["time"] epoch = details["time"]
author = details["user"] author = details["user"]
self.branchPrefixes = branchPrefixes
if self.verbose: if self.verbose:
print "commit into %s" % branch print "commit into %s" % branch
@ -2053,7 +2052,7 @@ class P4Sync(Command, P4UserMap):
# create a commit. # create a commit.
new_files = [] new_files = []
for f in files: for f in files:
if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]: if [p for p in self.branchPrefixes if p4PathStartsWith(f['path'], p)]:
new_files.append (f) new_files.append (f)
else: else:
sys.stderr.write("Ignoring file outside of prefix: %s\n" % f['path']) sys.stderr.write("Ignoring file outside of prefix: %s\n" % f['path'])
@ -2070,8 +2069,8 @@ class P4Sync(Command, P4UserMap):
self.gitStream.write("data <<EOT\n") self.gitStream.write("data <<EOT\n")
self.gitStream.write(details["desc"]) self.gitStream.write(details["desc"])
self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s" self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s" %
% (','.join (branchPrefixes), details["change"])) (','.join(self.branchPrefixes), details["change"]))
if len(details['options']) > 0: if len(details['options']) > 0:
self.gitStream.write(": options = %s" % details['options']) self.gitStream.write(": options = %s" % details['options'])
self.gitStream.write("]\nEOT\n\n") self.gitStream.write("]\nEOT\n\n")
@ -2094,7 +2093,7 @@ class P4Sync(Command, P4UserMap):
print "Change %s is labelled %s" % (change, labelDetails) print "Change %s is labelled %s" % (change, labelDetails)
files = p4CmdList(["files"] + ["%s...@%s" % (p, change) files = p4CmdList(["files"] + ["%s...@%s" % (p, change)
for p in branchPrefixes]) for p in self.branchPrefixes])
if len(files) == len(labelRevisions): if len(files) == len(labelRevisions):
@ -2405,6 +2404,7 @@ class P4Sync(Command, P4UserMap):
for branch in branches.keys(): for branch in branches.keys():
## HACK --hwn ## HACK --hwn
branchPrefix = self.depotPaths[0] + branch + "/" branchPrefix = self.depotPaths[0] + branch + "/"
self.branchPrefixes = [ branchPrefix ]
parent = "" parent = ""
@ -2449,19 +2449,19 @@ class P4Sync(Command, P4UserMap):
tempBranch = os.path.join(self.tempBranchLocation, "%d" % (change)) tempBranch = os.path.join(self.tempBranchLocation, "%d" % (change))
if self.verbose: if self.verbose:
print "Creating temporary branch: " + tempBranch print "Creating temporary branch: " + tempBranch
self.commit(description, filesForCommit, tempBranch, [branchPrefix]) self.commit(description, filesForCommit, tempBranch)
self.tempBranches.append(tempBranch) self.tempBranches.append(tempBranch)
self.checkpoint() self.checkpoint()
blob = self.searchParent(parent, branch, tempBranch) blob = self.searchParent(parent, branch, tempBranch)
if blob: if blob:
self.commit(description, filesForCommit, branch, [branchPrefix], blob) self.commit(description, filesForCommit, branch, blob)
else: else:
if self.verbose: if self.verbose:
print "Parent of %s not found. Committing into head of %s" % (branch, parent) print "Parent of %s not found. Committing into head of %s" % (branch, parent)
self.commit(description, filesForCommit, branch, [branchPrefix], parent) self.commit(description, filesForCommit, branch, parent)
else: else:
files = self.extractFilesFromCommit(description) files = self.extractFilesFromCommit(description)
self.commit(description, files, self.branch, self.depotPaths, self.commit(description, files, self.branch,
self.initialParent) self.initialParent)
self.initialParent = "" self.initialParent = ""
except IOError: except IOError:
@ -2525,7 +2525,7 @@ class P4Sync(Command, P4UserMap):
self.updateOptionDict(details) self.updateOptionDict(details)
try: try:
self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths) self.commit(details, self.extractFilesFromCommit(details), self.branch)
except IOError: except IOError:
print "IO error with git fast-import. Is your git version recent enough?" print "IO error with git fast-import. Is your git version recent enough?"
print self.gitError.read() print self.gitError.read()
@ -2683,6 +2683,9 @@ class P4Sync(Command, P4UserMap):
self.depotPaths = newPaths self.depotPaths = newPaths
# --detect-branches may change this for each branch
self.branchPrefixes = self.depotPaths
self.loadUserMapFromCache() self.loadUserMapFromCache()
self.labels = {} self.labels = {}
if self.detectLabels: if self.detectLabels: