Skip to content

Commit

Permalink
git-p4: Fix upstream branch detection for submit/rebase with multiple…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
Simon Hausmann committed Jul 18, 2007
1 parent 062410b commit 86506fe
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions contrib/fast-import/git-p4
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,31 @@ def p4BranchesInGit(branchesAreInRemotes = True):
return branches

def findUpstreamBranchPoint(head = "HEAD"):
branches = p4BranchesInGit()
# map from depot-path to branch name
branchByDepotPath = {}
for branch in branches.keys():
tip = branches[branch]
log = extractLogMessageFromGitCommit(tip)
settings = extractSettingsGitLog(log)
if settings.has_key("depot-paths"):
paths = ",".join(settings["depot-paths"])
branchByDepotPath[paths] = "remotes/p4/" + branch

settings = None
branchPoint = ""
parent = 0
while parent < 65535:
commit = head + "~%s" % parent
log = extractLogMessageFromGitCommit(commit)
settings = extractSettingsGitLog(log)
if not settings.has_key("depot-paths"):
parent = parent + 1
continue

names = read_pipe_lines("git name-rev \"--refs=refs/remotes/p4/*\" \"%s\"" % commit)
if len(names) <= 0:
continue
if settings.has_key("depot-paths"):
paths = ",".join(settings["depot-paths"])
if branchByDepotPath.has_key(paths):
return [branchByDepotPath[paths], settings]

# strip away the beginning of 'HEAD~42 refs/remotes/p4/foo'
branchPoint = names[0].strip()[len(commit) + 1:]
break
parent = parent + 1

return [branchPoint, settings]
return ["", settings]

class Command:
def __init__(self):
Expand Down

0 comments on commit 86506fe

Please sign in to comment.