{"thread":{"id":"38393","subject":"[PATCH] git-p4: support exclude in 'git p4 sync'","startedAt":"2015-01-17T20:56:37Z","lastAt":"2015-01-18T14:02:55Z","messageCount":3,"participants":["Luke Diamand","Pete Wyckoff"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"254856","messageId":"1421528198-16749-1-git-send-email-luke@diamand.org","threadId":"38393","inReplyTo":null,"subject":"[PATCH] git-p4: support exclude in 'git p4 sync'","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2015-01-17T20:56:37Z","receivedAt":"2015-01-17T20:56:37Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"The git-p4 'clone' subcommand has long had the option to specify\nparts of the repo to be excluded, on the command line. But this has\nnot been present in 'sync', which makes it less than useful: as\nsoon as you do a sync, the excluded parts start being repopulated\nas those directories are changed.\n\n(You can achieve the same effect by using a client specification to\ndo the exclusion, but that's then an extra step).\n\nThe code for doing the exclusion is actually all present in the base\n'P4Sync' class: this change turns that on by moving the definition\nof the command-line switch.\n\nIt also updates the documentation and adds a test-case.\n\nThanks,\nLuke\n\nAnd yes, I'm back to using version control systems other than git :-(\n\nLuke Diamand (1):\n  git-p4: support excluding paths on sync\n\n Documentation/git-p4.txt  |    6 ++--\n git-p4.py                 |   18 ++++++------\n t/t9817-git-p4-exclude.sh |   71 +++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 83 insertions(+), 12 deletions(-)\n create mode 100755 t/t9817-git-p4-exclude.sh\n\n-- \n1.7.10.4\n"},{"id":"254857","messageId":"1421528198-16749-2-git-send-email-luke@diamand.org","threadId":"38393","inReplyTo":"1421528198-16749-1-git-send-email-luke@diamand.org","subject":"[PATCH] git-p4: support excluding paths on sync","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2015-01-17T20:56:38Z","receivedAt":"2015-01-17T20:56:38Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"The clone subcommand has long had support for excluding\nsubdirectories, but sync has not. This is a nuisance,\nsince as soon as you do a sync, any changed files that\nwere initially excluded start showing up.\n\nMove the \"exclude\" command-line option into the parent\nclass; the actual behavior was already present there so\nit simply had to be exposed.\n\nSigned-off-by: Luke Diamand <luke@diamand.org>\n---\n Documentation/git-p4.txt  |    6 ++--\n git-p4.py                 |   18 ++++++------\n t/t9817-git-p4-exclude.sh |   71 +++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 83 insertions(+), 12 deletions(-)\n create mode 100755 t/t9817-git-p4-exclude.sh\n\ndiff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt\nindex 6ab5f94..a1664b9 100644\n--- a/Documentation/git-p4.txt\n+++ b/Documentation/git-p4.txt\n@@ -241,6 +241,9 @@ Git repository:\n \tUse a client spec to find the list of interesting files in p4.\n \tSee the \"CLIENT SPEC\" section below.\n \n+-/ <path>::\n+\tExclude selected depot paths when cloning or syncing.\n+\n Clone options\n ~~~~~~~~~~~~~\n These options can be used in an initial 'clone', along with the 'sync'\n@@ -254,9 +257,6 @@ options described above.\n --bare::\n \tPerform a bare clone.  See linkgit:git-clone[1].\n \n--/ <path>::\n-\tExclude selected depot paths when cloning.\n-\n Submit options\n ~~~~~~~~~~~~~~\n These options can be used to modify 'git p4 submit' behavior.\ndiff --git a/git-p4.py b/git-p4.py\nindex ff132b2..38029a4 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1916,6 +1916,9 @@ class P4Sync(Command, P4UserMap):\n                                      help=\"Keep entire BRANCH/DIR/SUBDIR prefix during import\"),\n                 optparse.make_option(\"--use-client-spec\", dest=\"useClientSpec\", action='store_true',\n                                      help=\"Only sync files that are included in the Perforce Client Spec\")\n+                optparse.make_option(\"-/\", dest=\"cloneExclude\",\n+                                     action=\"append\", type=\"string\",\n+                                     help=\"exclude depot path\"),\n         ]\n         self.description = \"\"\"Imports from Perforce into a git repository.\\n\n     example:\n@@ -1950,6 +1953,12 @@ class P4Sync(Command, P4UserMap):\n         if gitConfig(\"git-p4.syncFromOrigin\") == \"false\":\n             self.syncWithOrigin = False\n \n+    # This is required for the \"append\" cloneExclude action\n+    def ensure_value(self, attr, value):\n+        if not hasattr(self, attr) or getattr(self, attr) is None:\n+            setattr(self, attr, value)\n+        return getattr(self, attr)\n+\n     # Force a checkpoint in fast-import and wait for it to finish\n     def checkpoint(self):\n         self.gitStream.write(\"checkpoint\\n\\n\")\n@@ -3101,9 +3110,6 @@ class P4Clone(P4Sync):\n             optparse.make_option(\"--destination\", dest=\"cloneDestination\",\n                                  action='store', default=None,\n                                  help=\"where to leave result of the clone\"),\n-            optparse.make_option(\"-/\", dest=\"cloneExclude\",\n-                                 action=\"append\", type=\"string\",\n-                                 help=\"exclude depot path\"),\n             optparse.make_option(\"--bare\", dest=\"cloneBare\",\n                                  action=\"store_true\", default=False),\n         ]\n@@ -3111,12 +3117,6 @@ class P4Clone(P4Sync):\n         self.needsGit = False\n         self.cloneBare = False\n \n-    # This is required for the \"append\" cloneExclude action\n-    def ensure_value(self, attr, value):\n-        if not hasattr(self, attr) or getattr(self, attr) is None:\n-            setattr(self, attr, value)\n-        return getattr(self, attr)\n-\n     def defaultDestination(self, args):\n         ## TODO: use common prefix of args?\n         depotPath = args[0]\ndiff --git a/t/t9817-git-p4-exclude.sh b/t/t9817-git-p4-exclude.sh\nnew file mode 100755\nindex 0000000..aac568e\n--- /dev/null\n+++ b/t/t9817-git-p4-exclude.sh\n@@ -0,0 +1,71 @@\n+#!/bin/sh\n+\n+test_description='git p4 tests for excluded paths during clone and sync'\n+\n+. ./lib-git-p4.sh\n+\n+test_expect_success 'start p4d' '\n+\tstart_p4d\n+'\n+\n+# Create a repo with the structure:\n+#\n+#    //depot/wanted/foo\n+#    //depot/discard/foo\n+#\n+# Check that we can exclude a subdirectory with both\n+# clone and sync operations.\n+\n+test_expect_success 'create exclude repo' '\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tmkdir -p wanted discard &&\n+\t\techo wanted >wanted/foo &&\n+\t\techo discard >discard/foo &&\n+\t\tp4 add wanted/foo discard/foo &&\n+\t\tp4 submit -d \"initial revision\"\n+\t)\n+'\n+\n+test_expect_success 'check the repo was created correctly' '\n+\ttest_when_finished cleanup_git &&\n+\tgit p4 clone --dest=\"$git\" //depot/...@all &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\ttest_path_is_file wanted/foo &&\n+\t\ttest_path_is_file discard/foo\n+\t)\n+'\n+\n+test_expect_success 'clone, excluding part of repo' '\n+\ttest_when_finished cleanup_git &&\n+\tgit p4 clone -//depot/discard/... --dest=\"$git\" //depot/...@all &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\ttest_path_is_file wanted/foo &&\n+\t\ttest_path_is_missing discard/foo\n+\t)\n+'\n+\n+test_expect_success 'clone, then sync with exclude' '\n+\ttest_when_finished cleanup_git &&\n+\tgit p4 clone -//depot/discard/... --dest=\"$git\" //depot/...@all &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tp4 edit wanted/foo discard/foo &&\n+\t\tdate >>wanted/foo &&\n+\t\tdate >>discard/foo &&\n+\t\tp4 submit -d \"updating\" &&\n+\n+\t\tcd \"$git\" &&\n+\t\tgit p4 sync -//depot/discard/... &&\n+\t\ttest_path_is_file wanted/foo &&\n+\t\ttest_path_is_missing discard/foo\n+\t)\n+'\n+\n+test_expect_success 'kill p4d' '\n+\tkill_p4d\n+'\n+\n+test_done\n-- \n1.7.10.4\n"},{"id":"254865","messageId":"20150118140255.GA18490@padd.com","threadId":"38393","inReplyTo":"1421528198-16749-1-git-send-email-luke@diamand.org","subject":"Re: [PATCH] git-p4: support exclude in 'git p4 sync'","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2015-01-18T14:02:55Z","receivedAt":"2015-01-18T14:02:55Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"luke@diamand.org wrote on Sat, 17 Jan 2015 20:56 +0000:\n> The git-p4 'clone' subcommand has long had the option to specify\n> parts of the repo to be excluded, on the command line. But this has\n> not been present in 'sync', which makes it less than useful: as\n> soon as you do a sync, the excluded parts start being repopulated\n> as those directories are changed.\n> \n> (You can achieve the same effect by using a client specification to\n> do the exclusion, but that's then an extra step).\n> \n> The code for doing the exclusion is actually all present in the base\n> 'P4Sync' class: this change turns that on by moving the definition\n> of the command-line switch.\n> \n> It also updates the documentation and adds a test-case.\n> \n> Thanks,\n> Luke\n> \n> And yes, I'm back to using version control systems other than git :-(\n\nSo sorry. I on the other hand have been fortunate enough to\nswitch to using only git.\n\nNevertheless, I read through the patch and it looks good and\nmakes sense. You've got my ack on this for what it's worth.\nHopefully someone else starts picking up the git-p4 maintenance\nwork. Hint.\n\n\t\t-- Pete\n"}]}