Skip to content

Commit

Permalink
git-p4: Allow branch definition with git config
Browse files Browse the repository at this point in the history
Perforce does not strictly require the usage of branch specifications to create
branches. In these cases the branch detection code of git-p4 will not be able to
import them.
This patch adds support for git-p4.branchList configuration option, allowing
branches to be defined in git config.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Vitor Antunes authored and Junio C Hamano committed Aug 23, 2011
1 parent 8ace74c commit 7199cf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions contrib/fast-import/git-p4
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ def gitConfig(key, args = None): # set args to "--bool", for instance
_gitConfig[key] = read_pipe(cmd, ignore_error=True).strip()
return _gitConfig[key]

def gitConfigList(key):
if not _gitConfig.has_key(key):
_gitConfig[key] = read_pipe("git config --get-all %s" % key, ignore_error=True).strip().split(os.linesep)
return _gitConfig[key]

def p4BranchesInGit(branchesAreInRemotes = True):
branches = {}

Expand Down Expand Up @@ -1490,6 +1495,25 @@ class P4Sync(Command, P4UserMap):
if source not in self.knownBranches:
lostAndFoundBranches.add(source)

# Perforce does not strictly require branches to be defined, so we also
# check git config for a branch list.
#
# Example of branch definition in git config file:
# [git-p4]
# branchList=main:branchA
# branchList=main:branchB
# branchList=branchA:branchC
configBranches = gitConfigList("git-p4.branchList")
for branch in configBranches:
if branch:
(source, destination) = branch.split(":")
self.knownBranches[destination] = source

lostAndFoundBranches.discard(destination)

if source not in self.knownBranches:
lostAndFoundBranches.add(source)


for branch in lostAndFoundBranches:
self.knownBranches[branch] = branch
Expand Down
7 changes: 7 additions & 0 deletions contrib/fast-import/git-p4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ Only use branch specifications defined by the selected username.

git config [--global] git-p4.branchUser username

git-p4.branchList

List of branches to be imported when branch detection is enabled.

git config [--global] git-p4.branchList main:branchA
git config [--global] --add git-p4.branchList main:branchB

Implementation Details...
=========================

Expand Down

0 comments on commit 7199cf1

Please sign in to comment.