{"thread":{"id":"26612","subject":"[PATCH v2 0/3] git-p4: Improve branch support","startedAt":"2011-02-26T23:46:08Z","lastAt":"2011-02-26T23:46:11Z","messageCount":4,"participants":["Vitor Antunes"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"162328","messageId":"1298763971-20556-1-git-send-email-vitor.hda@gmail.com","threadId":"26612","inReplyTo":null,"subject":"[PATCH v2 0/3] git-p4: Improve branch support","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-02-26T23:46:08Z","receivedAt":"2011-02-26T23:46:08Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"In this second submission I've split the patch into 3 different commits, one for\neach individual update. I also added a description of the newly added config\noptions to git-p4.txt.\n\nVitor Antunes (3):\n  git-p4: Correct branch base depot path detection\n  git-p4: Allow filtering Perforce branches by user\n  git-p4: Allow branch definition with git config\n\n contrib/fast-import/git-p4     |   40 ++++++++++++++++++++++++++++++++++++----\n contrib/fast-import/git-p4.txt |   13 +++++++++++++\n 2 files changed, 49 insertions(+), 4 deletions(-)\n\n-- \n1.7.4.1\n"},{"id":"162329","messageId":"1298763971-20556-2-git-send-email-vitor.hda@gmail.com","threadId":"26612","inReplyTo":"1298763971-20556-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v2 1/3] git-p4: Correct branch base depot path detection","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-02-26T23:46:09Z","receivedAt":"2011-02-26T23:46:09Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"When branch detection is enabled each branch is named in git after their\nrelative depot path in Perforce. To do this the depot paths are compared against\neach other to find their common base path. The current algorithm makes this\ncomparison on a character by character basis.\nAssuming we have the following branches:\n\n//depot/branches/featureA\n//depot/branches/featureB\n\nThen the base depot path would be //depot/branches/feature, which is an invalid\ndepot path.\nThe current patch fixes this by splitting the path into a list and comparing the\nlist entries, making it choose correctly //depot/branches as the base path.\n\nSigned-off-by: Vitor Antunes <vitor.hda@gmail.com>\n---\n contrib/fast-import/git-p4 |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex a92beb6..fad3371 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -1599,12 +1599,14 @@ class P4Sync(Command):\n                     else:\n                         paths = []\n                         for (prev, cur) in zip(self.previousDepotPaths, depotPaths):\n-                            for i in range(0, min(len(cur), len(prev))):\n-                                if cur[i] <> prev[i]:\n+                            prev_list = prev.split(\"/\")\n+                            cur_list = cur.split(\"/\")\n+                            for i in range(0, min(len(cur_list), len(prev_list))):\n+                                if cur_list[i] <> prev_list[i]:\n                                     i = i - 1\n                                     break\n \n-                            paths.append (cur[:i + 1])\n+                            paths.append (\"/\".join(cur_list[:i + 1]))\n \n                         self.previousDepotPaths = paths\n \n-- \n1.7.4.1\n"},{"id":"162330","messageId":"1298763971-20556-3-git-send-email-vitor.hda@gmail.com","threadId":"26612","inReplyTo":"1298763971-20556-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v2 2/3] git-p4: Allow filtering Perforce branches by user","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-02-26T23:46:10Z","receivedAt":"2011-02-26T23:46:10Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"All branches in the Perforce server are downloaded to allow branch detection. If\nyou have a centralized server on a remote location and there is a big number of\nbranches this operation can take some time.\nThis patch adds the configuration option git-p4.branchUser to allow filtering\nthe branch list by user. Although this limits the branch maintenance in Perforce\nto be done by a single user, it might be an advantage when the number of\nbranches being used in a specific depot is very small when compared with the\nbranches available in the server.\n\nSigned-off-by: Vitor Antunes <vitor.hda@gmail.com>\n---\n contrib/fast-import/git-p4     |    8 +++++++-\n contrib/fast-import/git-p4.txt |    6 ++++++\n 2 files changed, 13 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex fad3371..646afc1 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -1245,7 +1245,13 @@ class P4Sync(Command):\n     def getBranchMapping(self):\n         lostAndFoundBranches = set()\n \n-        for info in p4CmdList(\"branches\"):\n+        user = gitConfig(\"git-p4.branchUser\")\n+        if len(user) > 0:\n+            command = \"branches -u %s\" % user\n+        else:\n+            command = \"branches\"\n+\n+        for info in p4CmdList(command):\n             details = p4Cmd(\"branch -o %s\" % info[\"branch\"])\n             viewIdx = 0\n             while details.has_key(\"View%s\" % viewIdx):\ndiff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt\nindex e09da44..5b85081 100644\n--- a/contrib/fast-import/git-p4.txt\n+++ b/contrib/fast-import/git-p4.txt\n@@ -196,6 +196,12 @@ able to find the relevant client.  This client spec will be used to\n both filter the files cloned by git and set the directory layout as\n specified in the client (this implies --keep-path style semantics).\n \n+git-p4.branchUser\n+\n+Only use branch specifications defined by the selected username.\n+\n+  git config [--global] git-p4.branchUser username\n+\n Implementation Details...\n =========================\n \n-- \n1.7.4.1\n"},{"id":"162331","messageId":"1298763971-20556-4-git-send-email-vitor.hda@gmail.com","threadId":"26612","inReplyTo":"1298763971-20556-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v2 3/3] git-p4: Allow branch definition with git config","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-02-26T23:46:11Z","receivedAt":"2011-02-26T23:46:11Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"Perforce does not strictly require the usage of branch specifications to create\nbranches. In these cases the branch detection code of git-p4 will not be able to\nimport them.\nThis patch adds support for git-p4.branchList configuration option, allowing\nbranches to be defined in git config.\n\nSigned-off-by: Vitor Antunes <vitor.hda@gmail.com>\n---\n contrib/fast-import/git-p4     |   24 ++++++++++++++++++++++++\n contrib/fast-import/git-p4.txt |    7 +++++++\n 2 files changed, 31 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 646afc1..3ad9600 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -338,6 +338,11 @@ def gitConfig(key):\n         _gitConfig[key] = read_pipe(\"git config %s\" % key, ignore_error=True).strip()\n     return _gitConfig[key]\n \n+def gitConfigList(key):\n+    if not _gitConfig.has_key(key):\n+        _gitConfig[key] = read_pipe(\"git config --get-all %s\" % key, ignore_error=True).strip().split(os.linesep)\n+    return _gitConfig[key]\n+\n def p4BranchesInGit(branchesAreInRemotes = True):\n     branches = {}\n \n@@ -1280,6 +1285,25 @@ class P4Sync(Command):\n                     if source not in self.knownBranches:\n                         lostAndFoundBranches.add(source)\n \n+        # Perforce does not strictly require branches to be defined, so we also\n+        # check git config for a branch list.\n+        #\n+        # Example of branch definition in git config file:\n+        # [git-p4]\n+        #   branchList=main:branchA\n+        #   branchList=main:branchB\n+        #   branchList=branchA:branchC\n+        configBranches = gitConfigList(\"git-p4.branchList\")\n+        for branch in configBranches:\n+            if branch:\n+                (source, destination) = branch.split(\":\")\n+                self.knownBranches[destination] = source\n+\n+                lostAndFoundBranches.discard(destination)\n+\n+                if source not in self.knownBranches:\n+                    lostAndFoundBranches.add(source)\n+\n \n         for branch in lostAndFoundBranches:\n             self.knownBranches[branch] = branch\ndiff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt\nindex 5b85081..3cc2309 100644\n--- a/contrib/fast-import/git-p4.txt\n+++ b/contrib/fast-import/git-p4.txt\n@@ -202,6 +202,13 @@ Only use branch specifications defined by the selected username.\n \n   git config [--global] git-p4.branchUser username\n \n+git-p4.branchList\n+\n+List of branches to be imported when branch detection is enabled.\n+\n+  git config [--global] git-p4.branchList main:branchA\n+  git config [--global] --add git-p4.branchList main:branchB\n+\n Implementation Details...\n =========================\n \n-- \n1.7.4.1\n"}]}