git-p4: Fix upstream branch detection for submit/rebase with multiple branches.
Don't use git name-rev to locate the upstream git-p4 branch for rebase and submit but instead locate the branch by comparing the depot paths. name-rev may produce results like wrongbranch~12 as it uses the first match. Signed-off-by: Simon Hausmann <simon@lst.de> Signed-off-by: Marius Storm-Olsen <marius@trolltech.com>
Simon Hausmann committed
Jul 18, 2007 at 12:40 UTC
86506fe54c8e9e5f75a73956840497e3e5744f86
1 file changed
+17
-12
contrib/fast-import/git-p4
+17
-12
@@ -205,26 +205,31 @@ def p4BranchesInGit(branchesAreInRemotes = True):
205
return branches
206
207
def findUpstreamBranchPoint(head = "HEAD"):
208
+ branches = p4BranchesInGit()
209
+ # map from depot-path to branch name
210
+ branchByDepotPath = {}
211
+ for branch in branches.keys():
212
+ tip = branches[branch]
213
+ log = extractLogMessageFromGitCommit(tip)
214
+ settings = extractSettingsGitLog(log)
215
+ if settings.has_key("depot-paths"):
216
+ paths = ",".join(settings["depot-paths"])
217
+ branchByDepotPath[paths] = "remotes/p4/" + branch
218
+
219
settings = None
209
- branchPoint = ""
220
parent = 0
221
while parent < 65535:
222
commit = head + "~%s" % parent
223
log = extractLogMessageFromGitCommit(commit)
224
settings = extractSettingsGitLog(log)
215
- if not settings.has_key("depot-paths"):
216
- parent = parent + 1
217
- continue
218
-
219
- names = read_pipe_lines("git name-rev \"--refs=refs/remotes/p4/*\" \"%s\"" % commit)
220
- if len(names) <= 0:
221
- continue
225
+ if settings.has_key("depot-paths"):
226
+ paths = ",".join(settings["depot-paths"])
227
+ if branchByDepotPath.has_key(paths):
228
+ return [branchByDepotPath[paths], settings]
229
223
- # strip away the beginning of 'HEAD~42 refs/remotes/p4/foo'
224
- branchPoint = names[0].strip()[len(commit) + 1:]
225
- break
230
+ parent = parent + 1
231
227
- return [branchPoint, settings]
232
+ return ["", settings]
233
234
class Command:
235
def __init__(self):