git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill Frolov via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Joel Holdsworth <jholdsworth@nvidia.com>,
	Ben Keene <seraphire@gmail.com>, Luke Diamand <luke@diamand.org>,
	Yang Zhao <yang.zhao@skyboxlabs.com>,
	Kirill Frolov <k.frolov@samsung.com>,
	Kirill Frolov <k.frolov@samsung.com>
Subject: [PATCH] git-p4: fix issue with multiple perforce remotes
Date: Mon, 21 Mar 2022 12:43:22 +0000	[thread overview]
Message-ID: <pull.1180.git.1647866603032.gitgitgadget@gmail.com> (raw)

From: Kirill Frolov <k.frolov@samsung.com>

Single perforce branch might be sync'ed multiple times with different
revision numbers, so it will be seen to Git as complete different
commits. This can be done by the following command:

  git p4 sync --branch=NAME //perforce/path...

It is assumed, that this command applied multiple times and
peforce repository changes between command invocations.

In such situation, git p4 will see multiple perforce branches with
same name and different revision numbers. The problem is that to make
a shelve, git-p4 script will try to find "origin" branch, if not
specified in command line explicitly. And previously script selected
any branch with same name and don't mention particular revision number.
Later this may cause failure of the command "git diff-tree -r $rev^ $rev",
so shelve can't be created (due to wrong origin branch/commit).

This commit fixes the heuristic by which git p4 selects origin branch:
first it tries to select branch with same perforce path and perforce
revision, and if it fails, then selects branch with only same perforce
path (ignoring perforce revision number).

Signed-off-by: Kirill Frolov <k.frolov@samsung.com>
---
    git-p4: fix issue with perforce branch synchronized multiple times.
    
    Perforce branch might be sync'ed multiple times with different revision
    numbers (by the command "git p4 sync --branch=NAME //perforce/path...")
    
    In such situation, git p4 will see multiple perforce branches with same
    name and different revision numbers. The problem is that to make a
    shelve, git-p4 script will try to find "origin" branch, if not specified
    in command line explicitly. And previously script selected any branch
    with same name and don't mention particular revision number. Later this
    may cause failure of the command "git diff-tree -r $rev^ $rev", so
    shelve can't be created (due to wrong origin branch/commit).
    
    This commit fixes the heuristic by which git p4 selects origin branch:
    first it tries to select branch with same perforce path and perforce
    revision, and if it fails, then selects branch with only same perforce
    path (ignoring perforce revision number).
    
    Signed-off-by: Kirill Frolov k.frolov@samsung.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1180%2Fkfrolov%2Fperforce_multi_fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1180/kfrolov/perforce_multi_fix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1180

 git-p4.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/git-p4.py b/git-p4.py
index a9b1f904410..4903e86351d 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -946,8 +946,12 @@ def findUpstreamBranchPoint(head = "HEAD"):
         log = extractLogMessageFromGitCommit(tip)
         settings = extractSettingsGitLog(log)
         if "depot-paths" in settings:
+            git_branch = "remotes/p4/" + branch
             paths = ",".join(settings["depot-paths"])
-            branchByDepotPath[paths] = "remotes/p4/" + branch
+            branchByDepotPath[paths] = git_branch
+            if "change" in settings:
+                paths = paths + ";" + settings["change"]
+                branchByDepotPath[paths] = git_branch
 
     settings = None
     parent = 0
@@ -957,6 +961,10 @@ def findUpstreamBranchPoint(head = "HEAD"):
         settings = extractSettingsGitLog(log)
         if "depot-paths" in settings:
             paths = ",".join(settings["depot-paths"])
+            if "change" in settings:
+                expaths = paths + ";" + settings["change"]
+                if expaths in branchByDepotPath:
+                    return [branchByDepotPath[expaths], settings]
             if paths in branchByDepotPath:
                 return [branchByDepotPath[paths], settings]
 

base-commit: 74cc1aa55f30ed76424a0e7226ab519aa6265061
-- 
gitgitgadget

                 reply	other threads:[~2022-03-21 12:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1180.git.1647866603032.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jholdsworth@nvidia.com \
    --cc=k.frolov@samsung.com \
    --cc=luke@diamand.org \
    --cc=seraphire@gmail.com \
    --cc=yang.zhao@skyboxlabs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).