git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 3/4] git-p4: Allow branch definition with git config

From
Vitor Antunes <vitor.hda@gmail.com>
Date
Aug 18, 2011, 23:44 UTC
Message-ID
<1313711046-23489-4-git-send-email-vitor.hda@gmail.com>
In-Reply-To
<1313711046-23489-1-git-send-email-vitor.hda@gmail.com>

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>
---
 contrib/fast-import/git-p4     |   24 ++++++++++++++++++++++++
 contrib/fast-import/git-p4.txt |    7 +++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 8b88f97..f622a38 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -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 = {}
 
@@ -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
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index 97b66b9..52003ae 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -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...
 =========================
 
-- 
1.7.5.4
Previous: Vitor AntunesNext: Vitor Antunes
Message 4 of 12 in “git-p4: Improve branch support”
  1. 0/4 git-p4: Improve branch supportVitor Antunes, Aug 18, 2011
  2. 1/4 git-p4: Correct branch base depot path detectionVitor Antunes, Aug 18, 2011
  3. 2/4 git-p4: Allow filtering Perforce branches by userVitor Antunes, Aug 18, 2011
  4. 3/4 git-p4: Allow branch definition with git configVitor Antunes, Aug 18, 2011
  5. 4/4 git-p4: Add simple test case for branch importVitor Antunes, Aug 18, 2011
  6. Pete WyckoffAug 20, 2011
  7. Pete WyckoffAug 19, 2011
  8. Vitor AntunesAug 19, 2011
  9. Pete WyckoffAug 20, 2011
  10. Vitor AntunesAug 23, 2011
  11. Junio C HamanoAug 19, 2011
  12. Vitor AntunesAug 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.