{"thread":{"id":"40205","subject":"[PATCH v9] git-p4: Obey core.ignorecase when using P4 client specs","startedAt":"2015-08-28T12:00:33Z","lastAt":"2015-08-28T12:00:34Z","messageCount":2,"participants":["larsxschneider@gmail.com"],"isPatch":true,"patchVersion":9,"patchTotal":null},"messages":[{"id":"268836","messageId":"1440763234-60172-1-git-send-email-larsxschneider@gmail.com","threadId":"40205","inReplyTo":null,"subject":"[PATCH v9] git-p4: Obey core.ignorecase when using P4 client specs","fromName":"","fromEmail":"larsxschneider@gmail.com","sentAt":"2015-08-28T12:00:33Z","receivedAt":"2015-08-28T12:00:33Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"From: Lars Schneider <larsxschneider@gmail.com>\n\nI fixed a commit message typo discover by Remi in v8.\n\nThanks,\nLars\n\nLars Schneider (1):\n  git-p4: Obey core.ignorecase when using P4 client specs\n\n git-p4.py                         |   7 ++\n t/t9821-git-p4-path-variations.sh | 200 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 207 insertions(+)\n create mode 100755 t/t9821-git-p4-path-variations.sh\n\n--\n1.9.5 (Apple Git-50.3)\n"},{"id":"268835","messageId":"1440763234-60172-2-git-send-email-larsxschneider@gmail.com","threadId":"40205","inReplyTo":"1440763234-60172-1-git-send-email-larsxschneider@gmail.com","subject":"[PATCH v9] git-p4: Obey core.ignorecase when using P4 client specs","fromName":"","fromEmail":"larsxschneider@gmail.com","sentAt":"2015-08-28T12:00:34Z","receivedAt":"2015-08-28T12:00:34Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"From: Lars Schneider <larsxschneider@gmail.com>\n\nPerforce depot may record paths in mixed cases, e.g. \"p4 files\" may\nshow that there are these two paths:\n\n   //depot/Path/to/file1\n   //depot/pATH/to/file2\n\nand with \"p4\" or \"p4v\", these end up in the same directory, e.g.\n\n   //depot/Path/to/file1\n   //depot/Path/to/file2\n\nwhich is the desired outcome on case insensitive systems.\n\nIf git-p4 is used with client spec \"//depot/Path/...\", however, then\nall files not matching the case in the client spec are ignored (in\nthe example above \"//depot/pATH/to/file2\").\n\nFix this by using the path case that appears first in lexicographical\norder when core.ignorecase is set to true. This behavior is consistent\nwith \"p4\" and \"p4v\".\n\nSigned-off-by: Lars Schneider <larsxschneider@gmail.com>\nAcked-by: Luke Diamand <luke@diamand.org>\n---\n git-p4.py                         |   7 ++\n t/t9821-git-p4-path-variations.sh | 200 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 207 insertions(+)\n create mode 100755 t/t9821-git-p4-path-variations.sh\n\ndiff --git a/git-p4.py b/git-p4.py\nindex 073f87b..0093fa3 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1950,10 +1950,14 @@ class View(object):\n             if \"unmap\" in res:\n                 # it will list all of them, but only one not unmap-ped\n                 continue\n+            if gitConfigBool(\"core.ignorecase\"):\n+                res['depotFile'] = res['depotFile'].lower()\n             self.client_spec_path_cache[res['depotFile']] = self.convert_client_path(res[\"clientFile\"])\n \n         # not found files or unmap files set to \"\"\n         for depotFile in fileArgs:\n+            if gitConfigBool(\"core.ignorecase\"):\n+                depotFile = depotFile.lower()\n             if depotFile not in self.client_spec_path_cache:\n                 self.client_spec_path_cache[depotFile] = \"\"\n \n@@ -1962,6 +1966,9 @@ class View(object):\n            depot file should live.  Returns \"\" if the file should\n            not be mapped in the client.\"\"\"\n \n+        if gitConfigBool(\"core.ignorecase\"):\n+            depot_path = depot_path.lower()\n+\n         if depot_path in self.client_spec_path_cache:\n             return self.client_spec_path_cache[depot_path]\n \ndiff --git a/t/t9821-git-p4-path-variations.sh b/t/t9821-git-p4-path-variations.sh\nnew file mode 100755\nindex 0000000..81e46ac\n--- /dev/null\n+++ b/t/t9821-git-p4-path-variations.sh\n@@ -0,0 +1,200 @@\n+#!/bin/sh\n+\n+test_description='Clone repositories with path case variations'\n+\n+. ./lib-git-p4.sh\n+\n+test_expect_success 'start p4d with case folding enabled' '\n+\tstart_p4d -C1\n+'\n+\n+test_expect_success 'Create a repo with path case variations' '\n+\tclient_view \"//depot/... //client/...\" &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\n+\t\tmkdir -p Path/to &&\n+\t\t>Path/to/File2.txt &&\n+\t\tp4 add Path/to/File2.txt &&\n+\t\tp4 submit -d \"Add file2\" &&\n+\t\trm -rf Path &&\n+\n+\t\tmkdir -p path/TO &&\n+\t\t>path/TO/file1.txt &&\n+\t\tp4 add path/TO/file1.txt &&\n+\t\tp4 submit -d \"Add file1\" &&\n+\t\trm -rf path &&\n+\n+\t\tmkdir -p path/to &&\n+\t\t>path/to/file3.txt &&\n+\t\tp4 add path/to/file3.txt &&\n+\t\tp4 submit -d \"Add file3\" &&\n+\t\trm -rf path &&\n+\n+\t\tmkdir -p x-outside-spec &&\n+\t\t>x-outside-spec/file4.txt &&\n+\t\tp4 add x-outside-spec/file4.txt &&\n+\t\tp4 submit -d \"Add file4\" &&\n+\t\trm -rf x-outside-spec\n+\t)\n+'\n+\n+test_expect_success 'Clone root' '\n+\tclient_view \"//depot/... //client/...\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase false &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\t# This method is used instead of \"test -f\" to ensure the case is\n+\t\t# checked even if the test is executed on case-insensitive file systems.\n+\t\t# All files are there as expected although the path cases look random.\n+\t\tcat >expect <<-\\EOF &&\n+\t\tPath/to/File2.txt\n+\t\tpath/TO/file1.txt\n+\t\tpath/to/file3.txt\n+\t\tx-outside-spec/file4.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'Clone root (ignorecase)' '\n+\tclient_view \"//depot/... //client/...\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase true &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\t# This method is used instead of \"test -f\" to ensure the case is\n+\t\t# checked even if the test is executed on case-insensitive file systems.\n+\t\t# All files are there as expected although the path cases look random.\n+\t\tcat >expect <<-\\EOF &&\n+\t\tpath/TO/File2.txt\n+\t\tpath/TO/file1.txt\n+\t\tpath/TO/file3.txt\n+\t\tx-outside-spec/file4.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'Clone root and ignore one file' '\n+\tclient_view \\\n+\t\t\"//depot/... //client/...\" \\\n+\t\t\"-//depot/path/TO/file1.txt //client/path/TO/file1.txt\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase false &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\t# We ignore one file in the client spec and all path cases change from\n+\t\t# \"TO\" to \"to\"!\n+\t\tcat >expect <<-\\EOF &&\n+\t\tPath/to/File2.txt\n+\t\tpath/to/file3.txt\n+\t\tx-outside-spec/file4.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'Clone root and ignore one file (ignorecase)' '\n+\tclient_view \\\n+\t\t\"//depot/... //client/...\" \\\n+\t\t\"-//depot/path/TO/file1.txt //client/path/TO/file1.txt\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase true &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\t# We ignore one file in the client spec and all path cases change from\n+\t\t# \"TO\" to \"to\"!\n+\t\tcat >expect <<-\\EOF &&\n+\t\tPath/to/File2.txt\n+\t\tPath/to/file3.txt\n+\t\tx-outside-spec/file4.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'Clone path' '\n+\tclient_view \"//depot/Path/... //client/...\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase false &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tto/File2.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'Clone path (ignorecase)' '\n+\tclient_view \"//depot/Path/... //client/...\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase true &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tTO/File2.txt\n+\t\tTO/file1.txt\n+\t\tTO/file3.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+# It looks like P4 determines the path case based on the first file in\n+# lexicographical order. Please note the lower case \"to\" directory for all\n+# files triggered through the addition of \"File0.txt\".\n+test_expect_success 'Add a new file and clone path with new file (ignorecase)' '\n+\tclient_view \"//depot/... //client/...\" &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tmkdir -p Path/to &&\n+\t\t>Path/to/File0.txt &&\n+\t\tp4 add Path/to/File0.txt &&\n+\t\tp4 submit -d \"Add file\" &&\n+\t\trm -rf Path\n+\t) &&\n+\n+\tclient_view \"//depot/Path/... //client/...\" &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit init . &&\n+\t\tgit config core.ignorecase true &&\n+\t\tgit p4 clone --use-client-spec --destination=\"$git\" //depot &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tto/File0.txt\n+\t\tto/File2.txt\n+\t\tto/file1.txt\n+\t\tto/file3.txt\n+\t\tEOF\n+\t\tgit ls-files >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'kill p4d' '\n+\tkill_p4d\n+'\n+\n+test_done\n-- \n1.9.5 (Apple Git-50.3)\n"}]}