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

[PATCH 1/1] git-p4: unshelve: use action==add instead of rev==none

From
Luke Diamand <luke@diamand.org>
Date
May 22, 2018, 08:41 UTC
Message-ID
<20180522084109.29787-2-luke@diamand.org>
In-Reply-To
<20180522084109.29787-1-luke@diamand.org>

SZEDER Gábor found that the unshelve tests fail with newer versions of Perforce (2016 vs 2015).

The problem arises because when a file is added in a P4 shelved changelist, the depot revision is shown as "none" if using the older p4d (which makes sense - the file doesn't yet exist, so can't have a revision), but as "1" in the newer versions of p4d.

For example, adding a file called "new" with 2015.1 and then shelving that change gives this from "p4 describe" :

    ... //depot/new#none add
Using the 2018.1 server gives this:
    ... //depot/new#1 add

We can detect that a file has been added simply by using the file status ("add") instead, rather than the depot revision, which is what this change does.

This also fixes a few verbose prints used for debugging this to be more friendly.

Signed-off-by: Luke Diamand <luke@diamand.org>
---
 git-p4.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 364d86dbcc..c80d85af89 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -2463,7 +2463,7 @@ class P4Sync(Command, P4UserMap):
         """
         ret = p4Cmd(["diff2", "{0}#{1}".format(path, filerev), "{0}@{1}".format(path, revision)])
         if verbose:
-            print("p4 diff2 %s %s %s => %s" % (path, filerev, revision, ret))
+            print("p4 diff2 path %s filerev %s revision %s => %s" % (path, filerev, revision, ret))
         return ret["status"] == "identical"
 
     def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_revision = 0):
@@ -2492,7 +2492,12 @@ class P4Sync(Command, P4UserMap):
             if shelved:
                 file["shelved_cl"] = int(shelved_cl)
 
-                if file["rev"] != "none" and \
+                # For shelved changelists, check that the revision of each file that the
+                # shelve was based on matches the revision that we are using for the
+                # starting point for git-fast-import (self.initialParent). Otherwise
+                # the resulting diff will contain deltas from multiple commits.
+
+                if file["action"] != "add" and \
                     not self.cmp_shelved(path, file["rev"], origin_revision):
                     sys.exit("change {0} not based on {1} for {2}, cannot unshelve".format(
                         commit["change"], self.initialParent, path))
@@ -2610,7 +2615,7 @@ class P4Sync(Command, P4UserMap):
     def streamOneP4File(self, file, contents):
         relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
         relPath = self.encodeWithUTF8(relPath)
-        if verbose:
+        if verbose and 'fileSize' in self.stream_file:
             size = int(self.stream_file['fileSize'])
             sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
             sys.stdout.flush()
-- 
2.17.0.392.gdeb1a6e9b7
Previous: Luke DiamandNext: SZEDER Gábor
Message 2 of 10 in “git-p4: unshelving: fix problem with newer P4”
  1. 0/1 git-p4: unshelving: fix problem with newer P4Luke Diamand, May 22, 2018
  2. 1/1 git-p4: unshelve: use action==add instead of rev==noneLuke Diamand, May 22, 2018
  3. SZEDER GáborMay 22, 2018
  4. Luke DiamandMay 22, 2018
  5. Junio C HamanoMay 23, 2018
  6. 0/1 git-p4: unshelve: fix problem with newer p4dLuke Diamand, May 23, 2018
  7. 1/1 git-p4: add unshelve commandLuke Diamand, May 23, 2018
  8. Mazo, AndreyMay 23, 2018
  9. Luke DiamandMay 23, 2018
  10. Mazo, AndreyMay 23, 2018

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.