Skip to contentSkip to conversation

git-p4: improved unshelving - small fixes

PATCH In review Luke Diamand 2 participants 6 messages Oct 15, 2018 – Oct 24, 2018 Documentation

lore
Share & tools
lore
#0 lore raw

v2 cover git-p4: improved unshelving - small fixes

This is the same as my earlier patch other than fixing the documentation to reflect the change to the destination branch, as noticed by Junio.

Luke Diamand (3):
git-p4: do not fail in verbose mode for missing 'fileSize' key
git-p4: unshelve into refs/remotes/p4-unshelved, not
refs/remotes/p4/unshelved
git-p4: fully support unshelving changelists

 Documentation/git-p4.txt | 10 ++---
 git-p4.py                | 90 +++++++++++++++++++++++-----------------
 t/t9832-unshelve.sh      | 75 ++++++++++++++++++++++++++-------
 3 files changed, 117 insertions(+), 58 deletions(-)
Signature · 1 line
2.19.1.331.gae0ed827e6
#1 lore raw

PATCH v2 1/3 git-p4: do not fail in verbose mode for missing 'fileSize' key

If deleting or moving a file, sometimes P4 doesn't report the file size.

The code handles this just fine but some logging crashes. Stop this happening.

There was some earlier discussion on the list about this:

https://public-inbox.org/git/[email protected]/

---
 git-p4.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
git-p4.py +4 -1
index 7fab255584..5701bad06a 100755
@@ -2775,7 +2775,10 @@ def streamOneP4File(self, file, contents):
         relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes)
         relPath = self.encodeWithUTF8(relPath)
         if verbose:
-            size = int(self.stream_file['fileSize'])
+            if 'fileSize' in self.stream_file:
+                size = int(self.stream_file['fileSize'])
+            else:
+                size = 0 # deleted files don't get a fileSize apparently
             sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024))
             sys.stdout.flush()
 
Signature · 1 line
2.19.1.331.gae0ed827e6
#2 lore raw

PATCH v2 2/3 git-p4: unshelve into refs/remotes/p4-unshelved, not refs/remotes/p4/unshelved

In reply to Luke Diamand

The branch detection code looks for branches under refs/remotes/p4/... and can end up getting confused if there are unshelved changes in there as well. This happens in the function p4BranchesInGit().

Instead, put the unshelved changes into refs/remotes/p4-unshelved/<N>.

---
 Documentation/git-p4.txt | 6 +++---
 git-p4.py                | 3 ++-
 t/t9832-unshelve.sh      | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)
Documentation/git-p4.txt +3 -3
index 41780a5aa9..6c0017e36e 100644
@@ -174,7 +174,7 @@ $ git p4 submit --update-shelve 1234 --update-shelve 2345
 Unshelve
 ~~~~~~~~
 Unshelving will take a shelved P4 changelist, and produce the equivalent git commit
-in the branch refs/remotes/p4/unshelved/<changelist>.
+in the branch refs/remotes/p4-unshelved/<changelist>.
 
 The git commit is created relative to the current origin revision (HEAD by default).
 If the shelved changelist's parent revisions differ, git-p4 will refuse to unshelve;
@@ -182,13 +182,13 @@ you need to be unshelving onto an equivalent tree.
 
 The origin revision can be changed with the "--origin" option.
 
-If the target branch in refs/remotes/p4/unshelved already exists, the old one will
+If the target branch in refs/remotes/p4-unshelved already exists, the old one will
 be renamed.
 
 ----
 $ git p4 sync
 $ git p4 unshelve 12345
-$ git show refs/remotes/p4/unshelved/12345
+$ git show p4-unshelved/12345
 <submit more changes via p4 to the same files>
 $ git p4 unshelve 12345
 <refuses to unshelve until git is in sync with p4 again>
git-p4.py +2 -1
index 5701bad06a..76c18a22e9 100755
@@ -3956,7 +3956,8 @@ def __init__(self):
         ]
         self.verbose = False
         self.noCommit = False
-        self.destbranch = "refs/remotes/p4/unshelved"
+        self.destbranch = "refs/remotes/p4-unshelved"
+        self.origin = "p4/master"
 
     def renameBranch(self, branch_name):
         """ Rename the existing branch to branch_name.N
t/t9832-unshelve.sh +3 -3
index 48ec7679b8..c3d15ceea8 100755
@@ -54,8 +54,8 @@ EOF
 		cd "$git" &&
 		change=$(last_shelved_change) &&
 		git p4 unshelve $change &&
-		git show refs/remotes/p4/unshelved/$change | grep -q "Further description" &&
-		git cherry-pick refs/remotes/p4/unshelved/$change &&
+		git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
+		git cherry-pick refs/remotes/p4-unshelved/$change &&
 		test_path_is_file file2 &&
 		test_cmp file1 "$cli"/file1 &&
 		test_cmp file2 "$cli"/file2 &&
@@ -88,7 +88,7 @@ EOF
 		cd "$git" &&
 		change=$(last_shelved_change) &&
 		git p4 unshelve $change &&
-		git diff refs/remotes/p4/unshelved/$change.0 refs/remotes/p4/unshelved/$change | grep -q file3
+		git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3
 	)
 '
 
Signature · 1 line
2.19.1.331.gae0ed827e6
#3 lore raw

PATCH v2 3/3 git-p4: fully support unshelving changelists

In reply to Luke Diamand

The previous git-p4 unshelve support would check for changes in Perforce to the files being unshelved since the original shelve, and would complain if any were found.

This was to ensure that the user wouldn't end up with both the shelved change delta, and some deltas from other changes in their git commit.

e.g. given fileA:
the
quick
brown
fox

  change1: s/the/The/   <- p4 shelve this change
  change2: s/fox/Fox/   <- p4 submit this change
  git p4 unshelve 1     <- FAIL

This change teaches the P4Unshelve class to always create a parent commit which matches the P4 tree (for the files being unshelved) at the point prior to the P4 shelve being created (which is reported in the p4 description for a shelved changelist).

That then means git-p4 can always create a git commit matching the P4 shelve that was originally created, without any extra deltas.

The user might still need to use the --origin option though - there is no way for git-p4 to work out the versions of all of the other *unchanged* files in the shelve, since this information is not recorded by Perforce.

Additionally this fixes handling of shelved 'move' operations.

---
 Documentation/git-p4.txt |  4 +-
 git-p4.py                | 84 +++++++++++++++++++++++-----------------
 t/t9832-unshelve.sh      | 69 ++++++++++++++++++++++++++-------
 3 files changed, 106 insertions(+), 51 deletions(-)
Documentation/git-p4.txt +2 -2
index 6c0017e36e..f0a0280954 100644
@@ -177,8 +177,8 @@ Unshelving will take a shelved P4 changelist, and produce the equivalent git com
 in the branch refs/remotes/p4-unshelved/<changelist>.
 
 The git commit is created relative to the current origin revision (HEAD by default).
-If the shelved changelist's parent revisions differ, git-p4 will refuse to unshelve;
-you need to be unshelving onto an equivalent tree.
+A parent commit is created based on the origin, and then the unshelve commit is
+created based on that.
 
 The origin revision can be changed with the "--origin" option.
 
git-p4.py +48 -36

165 lines not on this page · raw message

t/t9832-unshelve.sh +56 -13

118 lines not on this page · raw message

Signature · 1 line
2.19.1.331.gae0ed827e6
#4 lore raw
In reply to Luke Diamand
Quoted 3 lines · Luke Diamand

This is the same as my earlier patch other than fixing the documentation to reflect the change to the destination branch, as noticed by Junio.

Also you set up when-finished driver for clean-up before running clone, which I think is a good change, too.

Will replace. Thanks.

Quoted 11 lines

Luke Diamand (3):
git-p4: do not fail in verbose mode for missing 'fileSize' key
git-p4: unshelve into refs/remotes/p4-unshelved, not
refs/remotes/p4/unshelved
git-p4: fully support unshelving changelists

 Documentation/git-p4.txt | 10 ++---
 git-p4.py                | 90 +++++++++++++++++++++++-----------------
 t/t9832-unshelve.sh      | 75 ++++++++++++++++++++++++++-------
 3 files changed, 117 insertions(+), 58 deletions(-)
#5 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Luke Diamand

This is the same as my earlier patch other than fixing the documentation to reflect the change to the destination branch, as noticed by Junio.

Also you set up when-finished driver for clean-up before running clone, which I think is a good change, too.

Will replace. Thanks.

At the moment the parent commit file revisions are constructed by p4-printing the relevant files at the required version. That's because it's easy to do - I can just make use of the existing infrastructure for grabbing P4 changes.

However, in most cases we will already have these files present in the git repo - it's just that we don't know where. I think it ought to be possible to look at the revisions of each file, and then search through the git revision history for that file to find the magic comment marker that git-p4 inserts (which has the P4 changelist embedded in it) and then use that - rather than going back to the Perforce depot.

In most cases that ought to be quite a bit faster, especially for large files.

For now I'm not proposing to do this as it's quite a bit more work (this isn't really my day job!) and for the typical use case (at least the ones I encounter) the performance of unshelving isn't really that important - the fact that it does it at all is quite amazing.

But anyway, if someone somewhere finds that git-p4 unshelve performance is too slow, then that's the change to make.

Luke