Skip to content

Commit e63231e

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1951635 commit e63231e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

git-p4.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,10 +2041,9 @@ def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
20412041
gitStream.write(description)
20422042
gitStream.write("\n")
20432043

2044-
def commit(self, details, files, branch, branchPrefixes, parent = ""):
2044+
def commit(self, details, files, branch, parent = ""):
20452045
epoch = details["time"]
20462046
author = details["user"]
2047-
self.branchPrefixes = branchPrefixes
20482047

20492048
if self.verbose:
20502049
print "commit into %s" % branch
@@ -2053,7 +2052,7 @@ def commit(self, details, files, branch, branchPrefixes, parent = ""):
20532052
# create a commit.
20542053
new_files = []
20552054
for f in files:
2056-
if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]:
2055+
if [p for p in self.branchPrefixes if p4PathStartsWith(f['path'], p)]:
20572056
new_files.append (f)
20582057
else:
20592058
sys.stderr.write("Ignoring file outside of prefix: %s\n" % f['path'])
@@ -2070,8 +2069,8 @@ def commit(self, details, files, branch, branchPrefixes, parent = ""):
20702069

20712070
self.gitStream.write("data <<EOT\n")
20722071
self.gitStream.write(details["desc"])
2073-
self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s"
2074-
% (','.join (branchPrefixes), details["change"]))
2072+
self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s" %
2073+
(','.join(self.branchPrefixes), details["change"]))
20752074
if len(details['options']) > 0:
20762075
self.gitStream.write(": options = %s" % details['options'])
20772076
self.gitStream.write("]\nEOT\n\n")
@@ -2094,7 +2093,7 @@ def commit(self, details, files, branch, branchPrefixes, parent = ""):
20942093
print "Change %s is labelled %s" % (change, labelDetails)
20952094

20962095
files = p4CmdList(["files"] + ["%s...@%s" % (p, change)
2097-
for p in branchPrefixes])
2096+
for p in self.branchPrefixes])
20982097

20992098
if len(files) == len(labelRevisions):
21002099

@@ -2405,6 +2404,7 @@ def importChanges(self, changes):
24052404
for branch in branches.keys():
24062405
## HACK --hwn
24072406
branchPrefix = self.depotPaths[0] + branch + "/"
2407+
self.branchPrefixes = [ branchPrefix ]
24082408

24092409
parent = ""
24102410

@@ -2449,19 +2449,19 @@ def importChanges(self, changes):
24492449
tempBranch = os.path.join(self.tempBranchLocation, "%d" % (change))
24502450
if self.verbose:
24512451
print "Creating temporary branch: " + tempBranch
2452-
self.commit(description, filesForCommit, tempBranch, [branchPrefix])
2452+
self.commit(description, filesForCommit, tempBranch)
24532453
self.tempBranches.append(tempBranch)
24542454
self.checkpoint()
24552455
blob = self.searchParent(parent, branch, tempBranch)
24562456
if blob:
2457-
self.commit(description, filesForCommit, branch, [branchPrefix], blob)
2457+
self.commit(description, filesForCommit, branch, blob)
24582458
else:
24592459
if self.verbose:
24602460
print "Parent of %s not found. Committing into head of %s" % (branch, parent)
2461-
self.commit(description, filesForCommit, branch, [branchPrefix], parent)
2461+
self.commit(description, filesForCommit, branch, parent)
24622462
else:
24632463
files = self.extractFilesFromCommit(description)
2464-
self.commit(description, files, self.branch, self.depotPaths,
2464+
self.commit(description, files, self.branch,
24652465
self.initialParent)
24662466
self.initialParent = ""
24672467
except IOError:
@@ -2525,7 +2525,7 @@ def importHeadRevision(self, revision):
25252525

25262526
self.updateOptionDict(details)
25272527
try:
2528-
self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths)
2528+
self.commit(details, self.extractFilesFromCommit(details), self.branch)
25292529
except IOError:
25302530
print "IO error with git fast-import. Is your git version recent enough?"
25312531
print self.gitError.read()
@@ -2683,6 +2683,9 @@ def run(self, args):
26832683

26842684
self.depotPaths = newPaths
26852685

2686+
# --detect-branches may change this for each branch
2687+
self.branchPrefixes = self.depotPaths
2688+
26862689
self.loadUserMapFromCache()
26872690
self.labels = {}
26882691
if self.detectLabels:

0 commit comments

Comments
 (0)