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 <vitor.hda@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vitor Antunes committed Aug 19, 2011 at 00:44 UTC 7199cf131c5420b631f8402498f17ec42cdb3b3a
2 files changed +31
contrib/fast-import/git-p4
+24
@@ -342,6 +342,11 @@ def gitConfig(key, args = None): # set args to "--bool", for instance
342 _gitConfig[key] = read_pipe(cmd, ignore_error=True).strip()
343 return _gitConfig[key]
344
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 +
350 def p4BranchesInGit(branchesAreInRemotes = True):
351 branches = {}
352
@@ -1490,6 +1495,25 @@ class P4Sync(Command, P4UserMap):
1495 if source not in self.knownBranches:
1496 lostAndFoundBranches.add(source)
1497
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 +
1517
1518 for branch in lostAndFoundBranches:
1519 self.knownBranches[branch] = branch
contrib/fast-import/git-p4.txt
+7
@@ -263,6 +263,13 @@ Only use branch specifications defined by the selected username.
263
264 git config [--global] git-p4.branchUser username
265
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 +
273 Implementation Details...
274 =========================
275