Skip to content

Commit 7199cf1

Browse files
vhdagitster
authored andcommitted
git-p4: Allow branch definition with git config
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ace74c commit 7199cf1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

contrib/fast-import/git-p4

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ def gitConfig(key, args = None): # set args to "--bool", for instance
342342
_gitConfig[key] = read_pipe(cmd, ignore_error=True).strip()
343343
return _gitConfig[key]
344344

345+
def gitConfigList(key):
346+
if not _gitConfig.has_key(key):
347+
_gitConfig[key] = read_pipe("git config --get-all %s" % key, ignore_error=True).strip().split(os.linesep)
348+
return _gitConfig[key]
349+
345350
def p4BranchesInGit(branchesAreInRemotes = True):
346351
branches = {}
347352

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

1498+
# Perforce does not strictly require branches to be defined, so we also
1499+
# check git config for a branch list.
1500+
#
1501+
# Example of branch definition in git config file:
1502+
# [git-p4]
1503+
# branchList=main:branchA
1504+
# branchList=main:branchB
1505+
# branchList=branchA:branchC
1506+
configBranches = gitConfigList("git-p4.branchList")
1507+
for branch in configBranches:
1508+
if branch:
1509+
(source, destination) = branch.split(":")
1510+
self.knownBranches[destination] = source
1511+
1512+
lostAndFoundBranches.discard(destination)
1513+
1514+
if source not in self.knownBranches:
1515+
lostAndFoundBranches.add(source)
1516+
14931517

14941518
for branch in lostAndFoundBranches:
14951519
self.knownBranches[branch] = branch

contrib/fast-import/git-p4.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ Only use branch specifications defined by the selected username.
263263

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

266+
git-p4.branchList
267+
268+
List of branches to be imported when branch detection is enabled.
269+
270+
git config [--global] git-p4.branchList main:branchA
271+
git config [--global] --add git-p4.branchList main:branchB
272+
266273
Implementation Details...
267274
=========================
268275

0 commit comments

Comments
 (0)