{"thread":{"id":"57592","subject":"[PATCH] git-p4: fix issue with multiple perforce remotes","startedAt":"2022-03-21T12:43:29Z","lastAt":"2022-03-21T12:43:29Z","messageCount":1,"participants":["Kirill Frolov via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"451724","messageId":"pull.1180.git.1647866603032.gitgitgadget@gmail.com","threadId":"57592","inReplyTo":null,"subject":"[PATCH] git-p4: fix issue with multiple perforce remotes","fromName":"Kirill Frolov via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-03-21T12:43:22Z","receivedAt":"2022-03-21T12:43:29Z","isPatch":true,"sender":{"key":"frolovkirill7@gmail.com","avatar":null},"body":"From: Kirill Frolov <k.frolov@samsung.com>\n\nSingle perforce branch might be sync'ed multiple times with different\nrevision numbers, so it will be seen to Git as complete different\ncommits. This can be done by the following command:\n\n  git p4 sync --branch=NAME //perforce/path...\n\nIt is assumed, that this command applied multiple times and\npeforce repository changes between command invocations.\n\nIn such situation, git p4 will see multiple perforce branches with\nsame name and different revision numbers. The problem is that to make\na shelve, git-p4 script will try to find \"origin\" branch, if not\nspecified in command line explicitly. And previously script selected\nany branch with same name and don't mention particular revision number.\nLater this may cause failure of the command \"git diff-tree -r $rev^ $rev\",\nso shelve can't be created (due to wrong origin branch/commit).\n\nThis commit fixes the heuristic by which git p4 selects origin branch:\nfirst it tries to select branch with same perforce path and perforce\nrevision, and if it fails, then selects branch with only same perforce\npath (ignoring perforce revision number).\n\nSigned-off-by: Kirill Frolov <k.frolov@samsung.com>\n---\n    git-p4: fix issue with perforce branch synchronized multiple times.\n    \n    Perforce branch might be sync'ed multiple times with different revision\n    numbers (by the command \"git p4 sync --branch=NAME //perforce/path...\")\n    \n    In such situation, git p4 will see multiple perforce branches with same\n    name and different revision numbers. The problem is that to make a\n    shelve, git-p4 script will try to find \"origin\" branch, if not specified\n    in command line explicitly. And previously script selected any branch\n    with same name and don't mention particular revision number. Later this\n    may cause failure of the command \"git diff-tree -r $rev^ $rev\", so\n    shelve can't be created (due to wrong origin branch/commit).\n    \n    This commit fixes the heuristic by which git p4 selects origin branch:\n    first it tries to select branch with same perforce path and perforce\n    revision, and if it fails, then selects branch with only same perforce\n    path (ignoring perforce revision number).\n    \n    Signed-off-by: Kirill Frolov k.frolov@samsung.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1180%2Fkfrolov%2Fperforce_multi_fix-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1180/kfrolov/perforce_multi_fix-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1180\n\n git-p4.py | 10 +++++++++-\n 1 file changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex a9b1f904410..4903e86351d 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -946,8 +946,12 @@ def findUpstreamBranchPoint(head = \"HEAD\"):\n         log = extractLogMessageFromGitCommit(tip)\n         settings = extractSettingsGitLog(log)\n         if \"depot-paths\" in settings:\n+            git_branch = \"remotes/p4/\" + branch\n             paths = \",\".join(settings[\"depot-paths\"])\n-            branchByDepotPath[paths] = \"remotes/p4/\" + branch\n+            branchByDepotPath[paths] = git_branch\n+            if \"change\" in settings:\n+                paths = paths + \";\" + settings[\"change\"]\n+                branchByDepotPath[paths] = git_branch\n \n     settings = None\n     parent = 0\n@@ -957,6 +961,10 @@ def findUpstreamBranchPoint(head = \"HEAD\"):\n         settings = extractSettingsGitLog(log)\n         if \"depot-paths\" in settings:\n             paths = \",\".join(settings[\"depot-paths\"])\n+            if \"change\" in settings:\n+                expaths = paths + \";\" + settings[\"change\"]\n+                if expaths in branchByDepotPath:\n+                    return [branchByDepotPath[expaths], settings]\n             if paths in branchByDepotPath:\n                 return [branchByDepotPath[paths], settings]\n \n\nbase-commit: 74cc1aa55f30ed76424a0e7226ab519aa6265061\n-- \ngitgitgadget\n"}]}