{"thread":{"id":"28243","subject":"[PATCH v4 0/4] git-p4: Improve branch support","startedAt":"2011-08-28T21:58:26Z","lastAt":"2011-08-29T09:33:39Z","messageCount":7,"participants":["Vitor Antunes","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":4},"messages":[{"id":"174429","messageId":"1314568710-6472-1-git-send-email-vitor.hda@gmail.com","threadId":"28243","inReplyTo":null,"subject":"[PATCH v4 0/4] git-p4: Improve branch support","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-08-28T21:58:26Z","receivedAt":"2011-08-28T21:58:26Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"Include test case patches from Pete Wyckoff.\n\nVitor Antunes (4):\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  git-p4: Add simple test case for branch import\n\n contrib/fast-import/git-p4     |   40 +++++++++++++++++++++++--\n contrib/fast-import/git-p4.txt |   13 ++++++++\n t/t9800-git-p4.sh              |   61 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 110 insertions(+), 4 deletions(-)\n\n-- \n1.7.5.4\n"},{"id":"174430","messageId":"1314568710-6472-2-git-send-email-vitor.hda@gmail.com","threadId":"28243","inReplyTo":"1314568710-6472-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v4 1/4] git-p4: Correct branch base depot path detection","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-08-28T21:58:27Z","receivedAt":"2011-08-28T21:58:27Z","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 0db3e72..72a5b6c 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -1829,12 +1829,14 @@ class P4Sync(Command, P4UserMap):\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.5.4\n"},{"id":"174431","messageId":"1314568710-6472-3-git-send-email-vitor.hda@gmail.com","threadId":"28243","inReplyTo":"1314568710-6472-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v4 2/4] git-p4: Allow filtering Perforce branches by user","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-08-28T21:58:28Z","receivedAt":"2011-08-28T21:58:28Z","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 72a5b6c..6314c20 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -1455,7 +1455,13 @@ class P4Sync(Command, P4UserMap):\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 2ffbccc..97b66b9 100644\n--- a/contrib/fast-import/git-p4.txt\n+++ b/contrib/fast-import/git-p4.txt\n@@ -257,6 +257,12 @@ Perforce server. Will enable --find-copies-harder git argument.\n \n   git config [--global] git-p4.detectCopies true\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.5.4\n"},{"id":"174432","messageId":"1314568710-6472-4-git-send-email-vitor.hda@gmail.com","threadId":"28243","inReplyTo":"1314568710-6472-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v4 3/4] git-p4: Allow branch definition with git config","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-08-28T21:58:29Z","receivedAt":"2011-08-28T21:58:29Z","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 6314c20..2f7b270 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -342,6 +342,11 @@ def gitConfig(key, args = None): # set args to \"--bool\", for instance\n         _gitConfig[key] = read_pipe(cmd, 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@@ -1490,6 +1495,25 @@ class P4Sync(Command, P4UserMap):\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 97b66b9..52003ae 100644\n--- a/contrib/fast-import/git-p4.txt\n+++ b/contrib/fast-import/git-p4.txt\n@@ -263,6 +263,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.5.4\n"},{"id":"174433","messageId":"1314568710-6472-5-git-send-email-vitor.hda@gmail.com","threadId":"28243","inReplyTo":"1314568710-6472-1-git-send-email-vitor.hda@gmail.com","subject":"[PATCH v4 4/4] git-p4: Add simple test case for branch import","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-08-28T21:58:30Z","receivedAt":"2011-08-28T21:58:30Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"Create a basic branch structure in P4 and clone it with git-p4.\nAlso, make an update on P4 side and check if git-p4 imports it correctly.\nThe branch structure is created in such a way that git-p4 will fail to import\nupdates if patch \"git-p4: Correct branch base depot path detection\" is not\napplied.\n\nSigned-off-by: Vitor Antunes <vitor.hda@gmail.com>\nSigned-off-by: Pete Wyckoff <pw@padd.com>\n---\n t/t9800-git-p4.sh |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 61 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh\nindex 9d4d4bf..01ba041 100755\n--- a/t/t9800-git-p4.sh\n+++ b/t/t9800-git-p4.sh\n@@ -405,6 +405,67 @@ test_expect_success 'detect copies' '\n \tp4 filelog //depot/file13 | grep -q \"branch from //depot/file\"\n '\n \n+# Create a simple branch structure in P4 depot to check if it is correctly\n+# cloned.\n+test_expect_success 'add simple p4 branches' '\n+\tcd \"$cli\" &&\n+\tmkdir branch1 &&\n+\tcd branch1 &&\n+\techo file1 >file1 &&\n+\techo file2 >file2 &&\n+\tp4 add file1 file2 &&\n+\tp4 submit -d \"branch1\" &&\n+\tp4 integrate //depot/branch1/... //depot/branch2/... &&\n+\tp4 submit -d \"branch2\" &&\n+\techo file3 >file3 &&\n+\tp4 add file3 &&\n+\tp4 submit -d \"add file3 in branch1\" &&\n+\tp4 open file2 &&\n+\techo update >>file2 &&\n+\tp4 submit -d \"update file2 in branch1\" &&\n+\tp4 integrate //depot/branch1/... //depot/branch3/... &&\n+\tp4 submit -d \"branch3\" &&\n+\tcd \"$TRASH_DIRECTORY\"\n+'\n+\n+# Configure branches through git-config and clone them.\n+# All files are tested to make sure branches were cloned correctly.\n+# Finally, make an update to branch1 on P4 side to check if it is imported\n+# correctly by git-p4.\n+test_expect_success 'git-p4 clone simple branches' '\n+\ttest_when_finished cleanup_git &&\n+\ttest_create_repo \"$git\" &&\n+\tcd \"$git\" &&\n+\tgit config git-p4.branchList branch1:branch2 &&\n+\tgit config --add git-p4.branchList branch1:branch3 &&\n+\t\"$GITP4\" clone --dest=. --detect-branches //depot@all &&\n+\tgit log --all --graph --decorate --stat &&\n+\tgit reset --hard p4/depot/branch1 &&\n+\ttest -f file1 &&\n+\ttest -f file2 &&\n+\ttest -f file3 &&\n+\tgrep -q update file2 &&\n+\tgit reset --hard p4/depot/branch2 &&\n+\ttest -f file1 &&\n+\ttest -f file2 &&\n+\ttest ! -f file3 &&\n+\t! grep -q update file2 &&\n+\tgit reset --hard p4/depot/branch3 &&\n+\ttest -f file1 &&\n+\ttest -f file2 &&\n+\ttest -f file3 &&\n+\tgrep -q update file2 &&\n+\tcd \"$cli\" &&\n+\tcd branch1 &&\n+\tp4 edit file2 &&\n+\techo file2_ >>file2 &&\n+\tp4 submit -d \"update file2 in branch1\" &&\n+\tcd \"$git\" &&\n+\tgit reset --hard p4/depot/branch1 &&\n+\t\"$GITP4\" rebase &&\n+\tgrep -q file2_ file2\n+'\n+\n test_expect_success 'shutdown' '\n \tpid=`pgrep -f p4d` &&\n \ttest -n \"$pid\" &&\n-- \n1.7.5.4\n"},{"id":"174446","messageId":"7vmxes7nu2.fsf@alter.siamese.dyndns.org","threadId":"28243","inReplyTo":"1314568710-6472-1-git-send-email-vitor.hda@gmail.com","subject":"Re: [PATCH v4 0/4] git-p4: Improve branch support","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-08-29T06:07:17Z","receivedAt":"2011-08-29T06:07:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Could you make this an incremental patch relative to what is already in\nnext?\n\n\n\t\n"},{"id":"174454","messageId":"20110829103339.4ee9282d@fenix.utopia.dhis.org","threadId":"28243","inReplyTo":"7vmxes7nu2.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v4 0/4] git-p4: Improve branch support","fromName":"Vitor Antunes","fromEmail":"vitor.hda@gmail.com","sentAt":"2011-08-29T09:33:39Z","receivedAt":"2011-08-29T09:33:39Z","isPatch":true,"sender":{"key":"vitor.hda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/606876?v=4"},"body":"On Sun, 28 Aug 2011 23:07:17 -0700\nJunio C Hamano <gitster@pobox.com> wrote:\n\n> Could you make this an incremental patch relative to what is already in\n> next?\n\nDone.\n-- \nVitor Antunes\n"}]}