MCPcopy Create free account
hub / github.com/git/git / getBranchMapping

Method getBranchMapping

git-p4.py:3647–3702  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3645 return p
3646
3647 def getBranchMapping(self):
3648 lostAndFoundBranches = set()
3649
3650 user = gitConfig("git-p4.branchUser")
3651
3652 for info in p4CmdList(
3653 ["branches"] + (["-u", user] if len(user) > 0 else [])):
3654 details = p4Cmd(["branch", "-o", info["branch"]])
3655 viewIdx = 0
3656 while "View%s" % viewIdx in details:
3657 paths = details["View%s" % viewIdx].split(" ")
3658 viewIdx = viewIdx + 1
3659 # require standard //depot/foo/... //depot/bar/... mapping
3660 if len(paths) != 2 or not paths[0].endswith("/...") or not paths[1].endswith("/..."):
3661 continue
3662 source = paths[0]
3663 destination = paths[1]
3664 # HACK
3665 if p4PathStartsWith(source, self.depotPaths[0]) and p4PathStartsWith(destination, self.depotPaths[0]):
3666 source = source[len(self.depotPaths[0]):-4]
3667 destination = destination[len(self.depotPaths[0]):-4]
3668
3669 if destination in self.knownBranches:
3670 if not self.silent:
3671 print("p4 branch %s defines a mapping from %s to %s" % (info["branch"], source, destination))
3672 print("but there exists another mapping from %s to %s already!" % (self.knownBranches[destination], destination))
3673 continue
3674
3675 self.knownBranches[destination] = source
3676
3677 lostAndFoundBranches.discard(destination)
3678
3679 if source not in self.knownBranches:
3680 lostAndFoundBranches.add(source)
3681
3682 # Perforce does not strictly require branches to be defined, so we also
3683 # check git config for a branch list.
3684 #
3685 # Example of branch definition in git config file:
3686 # [git-p4]
3687 # branchList=main:branchA
3688 # branchList=main:branchB
3689 # branchList=branchA:branchC
3690 configBranches = gitConfigList("git-p4.branchList")
3691 for branch in configBranches:
3692 if branch:
3693 source, destination = branch.split(":")
3694 self.knownBranches[destination] = source
3695
3696 lostAndFoundBranches.discard(destination)
3697
3698 if source not in self.knownBranches:
3699 lostAndFoundBranches.add(source)
3700
3701 for branch in lostAndFoundBranches:
3702 self.knownBranches[branch] = branch
3703
3704 def getBranchMappingFromGitBranches(self):

Callers 1

runMethod · 0.95

Calls 5

gitConfigFunction · 0.85
p4CmdListFunction · 0.85
p4CmdFunction · 0.85
p4PathStartsWithFunction · 0.85
gitConfigListFunction · 0.85

Tested by

no test coverage detected