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>
Pete Wyckoff committed
Aug 11, 2012 at 12:55 UTC
e63231e566e2ac063e9f2aca18f5e3dca29dbc8f
1 file changed
+14
-11
git-p4.py
+14
-11
@@ -2041,10 +2041,9 @@ class P4Sync(Command, P4UserMap):
2041
gitStream.write(description)
2042
gitStream.write("\n")
2043
2044
- def commit(self, details, files, branch, branchPrefixes, parent = ""):
2044
+ def commit(self, details, files, branch, parent = ""):
2045
epoch = details["time"]
2046
author = details["user"]
2047
- self.branchPrefixes = branchPrefixes
2047
2048
if self.verbose:
2049
print "commit into %s" % branch
@@ -2053,7 +2052,7 @@ class P4Sync(Command, P4UserMap):
2052
# create a commit.
2053
new_files = []
2054
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)]:
2056
new_files.append (f)
2057
else:
2058
sys.stderr.write("Ignoring file outside of prefix: %s\n" % f['path'])
@@ -2070,8 +2069,8 @@ class P4Sync(Command, P4UserMap):
2069
2070
self.gitStream.write("data <<EOT\n")
2071
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"]))
2074
if len(details['options']) > 0:
2075
self.gitStream.write(": options = %s" % details['options'])
2076
self.gitStream.write("]\nEOT\n\n")
@@ -2094,7 +2093,7 @@ class P4Sync(Command, P4UserMap):
2093
print "Change %s is labelled %s" % (change, labelDetails)
2094
2095
files = p4CmdList(["files"] + ["%s...@%s" % (p, change)
2097
- for p in branchPrefixes])
2096
+ for p in self.branchPrefixes])
2097
2098
if len(files) == len(labelRevisions):
2099
@@ -2405,6 +2404,7 @@ class P4Sync(Command, P4UserMap):
2404
for branch in branches.keys():
2405
## HACK --hwn
2406
branchPrefix = self.depotPaths[0] + branch + "/"
2407
+ self.branchPrefixes = [ branchPrefix ]
2408
2409
parent = ""
2410
@@ -2449,19 +2449,19 @@ class P4Sync(Command, P4UserMap):
2449
tempBranch = os.path.join(self.tempBranchLocation, "%d" % (change))
2450
if self.verbose:
2451
print "Creating temporary branch: " + tempBranch
2452
- self.commit(description, filesForCommit, tempBranch, [branchPrefix])
2452
+ self.commit(description, filesForCommit, tempBranch)
2453
self.tempBranches.append(tempBranch)
2454
self.checkpoint()
2455
blob = self.searchParent(parent, branch, tempBranch)
2456
if blob:
2457
- self.commit(description, filesForCommit, branch, [branchPrefix], blob)
2457
+ self.commit(description, filesForCommit, branch, blob)
2458
else:
2459
if self.verbose:
2460
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)
2462
else:
2463
files = self.extractFilesFromCommit(description)
2464
- self.commit(description, files, self.branch, self.depotPaths,
2464
+ self.commit(description, files, self.branch,
2465
self.initialParent)
2466
self.initialParent = ""
2467
except IOError:
@@ -2525,7 +2525,7 @@ class P4Sync(Command, P4UserMap):
2525
2526
self.updateOptionDict(details)
2527
try:
2528
- self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths)
2528
+ self.commit(details, self.extractFilesFromCommit(details), self.branch)
2529
except IOError:
2530
print "IO error with git fast-import. Is your git version recent enough?"
2531
print self.gitError.read()
@@ -2683,6 +2683,9 @@ class P4Sync(Command, P4UserMap):
2683
2684
self.depotPaths = newPaths
2685
2686
+ # --detect-branches may change this for each branch
2687
+ self.branchPrefixes = self.depotPaths
2688
+
2689
self.loadUserMapFromCache()
2690
self.labels = {}
2691
if self.detectLabels: