threads / patch / 38393

patchgit-p4: support exclude in 'git p4 sync'

Subject: [PATCH] git-p4: support exclude in 'git p4 sync'

## tl;dr

3 messages between Jan 17, 2015 and Jan 18, 2015. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Luke Diamand· Jan 17, 2015, 20:56 UTC · lore

The git-p4 'clone' subcommand has long had the option to specify parts of the repo to be excluded, on the command line. But this has not been present in 'sync', which makes it less than useful: as soon as you do a sync, the excluded parts start being repopulated as those directories are changed.

(You can achieve the same effect by using a client specification to do the exclusion, but that's then an extra step).

The code for doing the exclusion is actually all present in the base 'P4Sync' class: this change turns that on by moving the definition of the command-line switch.

It also updates the documentation and adds a test-case.

Thanks, Luke

And yes, I'm back to using version control systems other than git :-(
Luke Diamand (1):
  git-p4: support excluding paths on sync
 Documentation/git-p4.txt  |    6 ++--
 git-p4.py                 |   18 ++++++------
 t/t9817-git-p4-exclude.sh |   71 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 12 deletions(-)
 create mode 100755 t/t9817-git-p4-exclude.sh
-- 
1.7.10.4
Luke Diamand· Jan 17, 2015, 20:56 UTC · re: Luke Diamand · lore

[PATCH] git-p4: support excluding paths on sync

The clone subcommand has long had support for excluding subdirectories, but sync has not. This is a nuisance, since as soon as you do a sync, any changed files that were initially excluded start showing up.

Move the "exclude" command-line option into the parent class; the actual behavior was already present there so it simply had to be exposed.

Signed-off-by: Luke Diamand <luke@diamand.org>
---
 Documentation/git-p4.txt  |    6 ++--
 git-p4.py                 |   18 ++++++------
 t/t9817-git-p4-exclude.sh |   71 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 12 deletions(-)
 create mode 100755 t/t9817-git-p4-exclude.sh
Show changes to 3 files +83 −12

Documentation/git-p4.txt, git-p4.py, t/t9817-git-p4-exclude.sh

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index 6ab5f94..a1664b9 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -241,6 +241,9 @@ Git repository:
 	Use a client spec to find the list of interesting files in p4.
 	See the "CLIENT SPEC" section below.
 
+-/ <path>::
+	Exclude selected depot paths when cloning or syncing.
+
 Clone options
 ~~~~~~~~~~~~~
 These options can be used in an initial 'clone', along with the 'sync'
@@ -254,9 +257,6 @@ options described above.
 --bare::
 	Perform a bare clone.  See linkgit:git-clone[1].
 
--/ <path>::
-	Exclude selected depot paths when cloning.
-
 Submit options
 ~~~~~~~~~~~~~~
 These options can be used to modify 'git p4 submit' behavior.
diff --git a/git-p4.py b/git-p4.py
index ff132b2..38029a4 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1916,6 +1916,9 @@ class P4Sync(Command, P4UserMap):
                                      help="Keep entire BRANCH/DIR/SUBDIR prefix during import"),
                 optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
                                      help="Only sync files that are included in the Perforce Client Spec")
+                optparse.make_option("-/", dest="cloneExclude",
+                                     action="append", type="string",
+                                     help="exclude depot path"),
         ]
         self.description = """Imports from Perforce into a git repository.\n
     example:
@@ -1950,6 +1953,12 @@ class P4Sync(Command, P4UserMap):
         if gitConfig("git-p4.syncFromOrigin") == "false":
             self.syncWithOrigin = False
 
+    # This is required for the "append" cloneExclude action
+    def ensure_value(self, attr, value):
+        if not hasattr(self, attr) or getattr(self, attr) is None:
+            setattr(self, attr, value)
+        return getattr(self, attr)
+
     # Force a checkpoint in fast-import and wait for it to finish
     def checkpoint(self):
         self.gitStream.write("checkpoint\n\n")
@@ -3101,9 +3110,6 @@ class P4Clone(P4Sync):
             optparse.make_option("--destination", dest="cloneDestination",
                                  action='store', default=None,
                                  help="where to leave result of the clone"),
-            optparse.make_option("-/", dest="cloneExclude",
-                                 action="append", type="string",
-                                 help="exclude depot path"),
             optparse.make_option("--bare", dest="cloneBare",
                                  action="store_true", default=False),
         ]
@@ -3111,12 +3117,6 @@ class P4Clone(P4Sync):
         self.needsGit = False
         self.cloneBare = False
 
-    # This is required for the "append" cloneExclude action
-    def ensure_value(self, attr, value):
-        if not hasattr(self, attr) or getattr(self, attr) is None:
-            setattr(self, attr, value)
-        return getattr(self, attr)
-
     def defaultDestination(self, args):
         ## TODO: use common prefix of args?
         depotPath = args[0]
diff --git a/t/t9817-git-p4-exclude.sh b/t/t9817-git-p4-exclude.sh
new file mode 100755
index 0000000..aac568e
--- /dev/null
+++ b/t/t9817-git-p4-exclude.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+test_description='git p4 tests for excluded paths during clone and sync'
+
+. ./lib-git-p4.sh
+
+test_expect_success 'start p4d' '
+	start_p4d
+'
+
+# Create a repo with the structure:
+#
+#    //depot/wanted/foo
+#    //depot/discard/foo
+#
+# Check that we can exclude a subdirectory with both
+# clone and sync operations.
+
+test_expect_success 'create exclude repo' '
+	(
+		cd "$cli" &&
+		mkdir -p wanted discard &&
+		echo wanted >wanted/foo &&
+		echo discard >discard/foo &&
+		p4 add wanted/foo discard/foo &&
+		p4 submit -d "initial revision"
+	)
+'
+
+test_expect_success 'check the repo was created correctly' '
+	test_when_finished cleanup_git &&
+	git p4 clone --dest="$git" //depot/...@all &&
+	(
+		cd "$git" &&
+		test_path_is_file wanted/foo &&
+		test_path_is_file discard/foo
+	)
+'
+
+test_expect_success 'clone, excluding part of repo' '
+	test_when_finished cleanup_git &&
+	git p4 clone -//depot/discard/... --dest="$git" //depot/...@all &&
+	(
+		cd "$git" &&
+		test_path_is_file wanted/foo &&
+		test_path_is_missing discard/foo
+	)
+'
+
+test_expect_success 'clone, then sync with exclude' '
+	test_when_finished cleanup_git &&
+	git p4 clone -//depot/discard/... --dest="$git" //depot/...@all &&
+	(
+		cd "$cli" &&
+		p4 edit wanted/foo discard/foo &&
+		date >>wanted/foo &&
+		date >>discard/foo &&
+		p4 submit -d "updating" &&
+
+		cd "$git" &&
+		git p4 sync -//depot/discard/... &&
+		test_path_is_file wanted/foo &&
+		test_path_is_missing discard/foo
+	)
+'
+
+test_expect_success 'kill p4d' '
+	kill_p4d
+'
+
+test_done
-- 
1.7.10.4
Pete Wyckoff· Jan 18, 2015, 14:02 UTC · re: Luke Diamand · lore

Re: [PATCH] git-p4: support exclude in 'git p4 sync'

luke@diamand.org wrote on Sat, 17 Jan 2015 20:56 +0000:
Show 19 quoted lines
> The git-p4 'clone' subcommand has long had the option to specify
> parts of the repo to be excluded, on the command line. But this has
> not been present in 'sync', which makes it less than useful: as
> soon as you do a sync, the excluded parts start being repopulated
> as those directories are changed.
> 
> (You can achieve the same effect by using a client specification to
> do the exclusion, but that's then an extra step).
> 
> The code for doing the exclusion is actually all present in the base
> 'P4Sync' class: this change turns that on by moving the definition
> of the command-line switch.
> 
> It also updates the documentation and adds a test-case.
> 
> Thanks,
> Luke
> 
> And yes, I'm back to using version control systems other than git :-(

So sorry. I on the other hand have been fortunate enough to switch to using only git.

Nevertheless, I read through the patch and it looks good and makes sense. You've got my ack on this for what it's worth. Hopefully someone else starts picking up the git-p4 maintenance work. Hint.

		-- Pete

← back to recent threads