Skip to contentSkip to conversation

git-p4: fix submit regression with --use-client-spec

PATCH In review Pete Wyckoff 2 participants 5 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover git-p4: fix submit regression with --use-client-spec

This pair of patches fixes a regression that happened with ecb7cf9 (git-p4: rewrite view handling, 2012-01-02). There are two factors that affect where files go in the client when submitting: the cilent spec, and the depot path. When the depot path was not exactly the root of the client, submit fails.

Fix this by always using the true client root. And also notice that somebody has to tell the submit path that it should be looking at the cilent spec. Save useClientSpec in a configuration variable if it was specified as an option on the command line.

Junio: can you put this on maint to go out with the next 1.9.x?

Pete Wyckoff (2):
git-p4: set useClientSpec variable on initial clone
git-p4: fix submit regression with clientSpec and subdir clone

 Documentation/git-p4.txt      |   10 ++-
 contrib/fast-import/git-p4    |   97 ++++++++++++++++---------
 t/t9809-git-p4-client-view.sh |  159 ++++++++++++++++++++++++++++++++++++++---
 3 files changed, 219 insertions(+), 47 deletions(-)
Signature · 1 line
1.7.9.219.g1d56c.dirty
#1 lore raw

PATCH 1/2 git-p4: set useClientSpec variable on initial clone

If --use-client-spec was given, set the matching configuration variable. This is necessary to ensure that future submits work properly.

The alternatives of requiring the user to set it, or providing a command-line option on every submit, are error prone.

---
 Documentation/git-p4.txt      |   10 +++++++---
 contrib/fast-import/git-p4    |   11 ++++++++++-
 t/t9809-git-p4-client-view.sh |   17 +++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)
Documentation/git-p4.txt +7 -3
index 78938b2..ed82790 100644
@@ -303,9 +303,13 @@ CLIENT SPEC
 -----------
 The p4 client specification is maintained with the 'p4 client' command
 and contains among other fields, a View that specifies how the depot
-is mapped into the client repository.  Git-p4 can consult the client
-spec when given the '--use-client-spec' option or useClientSpec
-variable.
+is mapped into the client repository.  The 'clone' and 'sync' commands
+can consult the client spec when given the '--use-client-spec' option or
+when the useClientSpec variable is true.  After 'git p4 clone', the
+useClientSpec variable is automatically set in the repository
+configuration file.  This allows future 'git p4 submit' commands to
+work properly; the submit command looks only at the variable and does
+not have a command-line option.
 
 The full syntax for a p4 view is documented in 'p4 help views'.  Git-p4
 knows only a subset of the view syntax.  It understands multi-line
contrib/fast-import/git-p4 +10 -1
index 3e1aa27..94f0a12 100755
@@ -1428,6 +1428,7 @@ class P4Sync(Command, P4UserMap):
         self.p4BranchesInGit = []
         self.cloneExclude = []
         self.useClientSpec = False
+        self.useClientSpec_from_options = False
         self.clientSpecDirs = None
 
         if gitConfig("git-p4.syncFromOrigin") == "false":
@@ -2136,7 +2137,11 @@ class P4Sync(Command, P4UserMap):
             if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch):
                 system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
 
-        if not self.useClientSpec:
+        # accept either the command-line option, or the configuration variable
+        if self.useClientSpec:
+            # will use this after clone to set the variable
+            self.useClientSpec_from_options = True
+        else:
             if gitConfig("git-p4.useclientspec", "--bool") == "true":
                 self.useClientSpec = True
         if self.useClientSpec:
@@ -2455,6 +2460,10 @@ class P4Clone(P4Sync):
             else:
                 print "Could not detect main branch. No checkout/master branch created."
 
+        # auto-set this variable if invoked with --use-client-spec
+        if self.useClientSpec_from_options:
+            system("git config --bool git-p4.useclientspec true")
+
         return True
 
 class P4Branches(Command):
t/t9809-git-p4-client-view.sh +17 -0
index c9471d5..25e01a4 100755
@@ -241,6 +241,23 @@ test_expect_success 'quotes on rhs only' '
 '
 
 #
+# Submit tests
+#
+
+# clone sets variable
+test_expect_success 'clone --use-client-spec sets useClientSpec' '
+	client_view "//depot/... //client/..." &&
+	test_when_finished cleanup_git &&
+	"$GITP4" clone --use-client-spec --dest="$git" //depot &&
+	(
+		cd "$git" &&
+		git config --bool git-p4.useClientSpec >actual &&
+		echo true >true &&
+		test_cmp actual true
+	)
+'
+
+#
 # Rename directories to test quoting in depot-side mappings
 # //depot
 #    - "dir 1"
Signature · 1 line
1.7.9.219.g1d56c.dirty
#2 lore raw

PATCH 2/2 git-p4: fix submit regression with clientSpec and subdir clone

In reply to Pete Wyckoff

When the --use-client-spec is given to clone, and the clone path is a subset of the full tree as specified in the client, future submits will go to the wrong place.

Factor out getClientSpec() so both clone/sync and submit can use it. Introduce getClientRoot() that is needed for the client spec case, and use it instead of p4Where().

Test the five possible submit behaviors (add, modify, rename, copy, delete).

---
 contrib/fast-import/git-p4    |   86 ++++++++++++++++---------
 t/t9809-git-p4-client-view.sh |  142 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 185 insertions(+), 43 deletions(-)
contrib/fast-import/git-p4 +54 -32
index 94f0a12..9ccc87b 100755
@@ -555,6 +555,46 @@ def p4PathStartsWith(path, prefix):
         return path.lower().startswith(prefix.lower())
     return path.startswith(prefix)
 
+def getClientSpec():
+    """Look at the p4 client spec, create a View() object that contains
+       all the mappings, and return it."""
+
+    specList = p4CmdList("client -o")
+    if len(specList) != 1:
+        die('Output from "client -o" is %d lines, expecting 1' %
+            len(specList))
+
+    # dictionary of all client parameters
+    entry = specList[0]
+
+    # just the keys that start with "View"
+    view_keys = [ k for k in entry.keys() if k.startswith("View") ]
+
+    # hold this new View
+    view = View()
+
+    # append the lines, in order, to the view
+    for view_num in range(len(view_keys)):
+        k = "View%d" % view_num
+        if k not in view_keys:
+            die("Expected view key %s missing" % k)
+        view.append(entry[k])
+
+    return view
+
+def getClientRoot():
+    """Grab the client directory."""
+
+    output = p4CmdList("client -o")
+    if len(output) != 1:
+        die('Output from "client -o" is %d lines, expecting 1' % len(output))
+
+    entry = output[0]
+    if "Root" not in entry:
+        die('Client has no "Root"')
+
+    return entry["Root"]
+
 class Command:
     def __init__(self):
         self.usage = "usage: %prog [options]"
@@ -1119,11 +1159,20 @@ class P4Submit(Command, P4UserMap):
             print "Internal error: cannot locate perforce depot path from existing branches"
             sys.exit(128)
 
-        self.clientPath = p4Where(self.depotPath)
+        self.useClientSpec = False
+        if gitConfig("git-p4.useclientspec", "--bool") == "true":
+            self.useClientSpec = True
+        if self.useClientSpec:
+            self.clientSpecDirs = getClientSpec()
+
+        if self.useClientSpec:
+            # all files are relative to the client spec
+            self.clientPath = getClientRoot()
+        else:
+            self.clientPath = p4Where(self.depotPath)
 
-        if len(self.clientPath) == 0:
-            print "Error: Cannot locate perforce checkout of %s in client view" % self.depotPath
-            sys.exit(128)
+        if self.clientPath == "":
+            die("Error: Cannot locate perforce checkout of %s in client view" % self.depotPath)
 
         print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath)
         self.oldWorkingDirectory = os.getcwd()
@@ -2078,33 +2127,6 @@ class P4Sync(Command, P4UserMap):
             print self.gitError.read()
 
 
-    def getClientSpec(self):
-        specList = p4CmdList("client -o")
-        if len(specList) != 1:
-            die('Output from "client -o" is %d lines, expecting 1' %
-                len(specList))
-
-        # dictionary of all client parameters
-        entry = specList[0]
-
-        # just the keys that start with "View"
-        view_keys = [ k for k in entry.keys() if k.startswith("View") ]
-
-        # hold this new View
-        view = View()
-
-        # append the lines, in order, to the view
-        for view_num in range(len(view_keys)):
-            k = "View%d" % view_num
-            if k not in view_keys:
-                die("Expected view key %s missing" % k)
-            view.append(entry[k])
-
-        self.clientSpecDirs = view
-        if self.verbose:
-            for i, m in enumerate(self.clientSpecDirs.mappings):
-                    print "clientSpecDirs %d: %s" % (i, str(m))
-
     def run(self, args):
         self.depotPaths = []
         self.changeRange = ""
@@ -2145,7 +2167,7 @@ class P4Sync(Command, P4UserMap):
             if gitConfig("git-p4.useclientspec", "--bool") == "true":
                 self.useClientSpec = True
         if self.useClientSpec:
-            self.getClientSpec()
+            self.clientSpecDirs = getClientSpec()
 
         # TODO: should always look at previous commits,
         # merge with previous imports, if possible.
t/t9809-git-p4-client-view.sh +131 -11

157 lines not on this page · raw message

Signature · 1 line
1.7.9.219.g1d56c.dirty
#3 lore raw
In reply to Pete Wyckoff
Quoted 6 lines · Pete Wyckoff

This pair of patches fixes a regression that happened with ecb7cf9 (git-p4: rewrite view handling, 2012-01-02). There are two factors that affect where files go in the client when submitting: the cilent spec, and the depot path. When the depot path was not exactly the root of the client, submit fails.

Quoted 6 lines

Fix this by always using the true client root. And also notice that somebody has to tell the submit path that it should be looking at the cilent spec. Save useClientSpec in a configuration variable if it was specified as an option on the command line.

Junio: can you put this on maint to go out with the next 1.9.x?

Surely and thanks.

Your "p4: submit with wildcards" seems to conflict with this change and may need to be rebased, though.

Quoted 9 lines

Pete Wyckoff (2):
git-p4: set useClientSpec variable on initial clone
git-p4: fix submit regression with clientSpec and subdir clone

 Documentation/git-p4.txt      |   10 ++-
 contrib/fast-import/git-p4    |   97 ++++++++++++++++---------
 t/t9809-git-p4-client-view.sh |  159 ++++++++++++++++++++++++++++++++++++++---
 3 files changed, 219 insertions(+), 47 deletions(-)
#4 lore raw

[email protected] wrote on Sun, 26 Feb 2012 16:18 -0800:

Quoted 13 lines
Quoted 11 lines · Pete Wyckoff

This pair of patches fixes a regression that happened with ecb7cf9 (git-p4: rewrite view handling, 2012-01-02). There are two factors that affect where files go in the client when submitting: the cilent spec, and the depot path. When the depot path was not exactly the root of the client, submit fails.

Fix this by always using the true client root. And also notice that somebody has to tell the submit path that it should be looking at the cilent spec. Save useClientSpec in a configuration variable if it was specified as an option on the command line.

Quoted 6 lines
Quoted 1 line

Junio: can you put this on maint to go out with the next 1.9.x?

Surely and thanks.

Your "p4: submit with wildcards" seems to conflict with this change and may need to be rebased, though.

Ah, yes. The conflicting chunks can be added in any order above class P4Command. I'll rebase and resend in a few days, after waiting for review comments.

		-- Pete