{"thread":{"id":"41114","subject":"[PATCH v2] git-p4.py: add support for filetype change","startedAt":"2016-01-04T10:52:44Z","lastAt":"2016-01-05T13:08:42Z","messageCount":4,"participants":["Romain Picard","Junio C Hamano","Luke Diamand"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"275297","messageId":"1451904764-338-1-git-send-email-romain.picard@oakbits.com","threadId":"41114","inReplyTo":null,"subject":"[PATCH v2] git-p4.py: add support for filetype change","fromName":"Romain Picard","fromEmail":"romain.picard@oakbits.com","sentAt":"2016-01-04T10:52:44Z","receivedAt":"2016-01-04T10:52:44Z","isPatch":true,"sender":{"key":"romain.picard@oakbits.com","avatar":"https://avatars.githubusercontent.com/u/814804?v=4"},"body":"After changing the type of a file in the git repository, it is not possible to\n\"git p4 publish\" the commit to perforce. This is due to the fact that the git\n\"T\" status is not handled in git-p4.py. This can typically occur when replacing\nan existing file with a symbolic link.\n\nThe \"T\" modifier is now supported in git-p4.py. When a file type has changed,\ninform perforce with the \"p4 edit -f auto\" command.\n\nSigned-off-by: Romain Picard <romain.picard@oakbits.com>\n---\n git-p4.py                         |  9 +++--\n t/t9827-git-p4-change-filetype.sh | 69 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 76 insertions(+), 2 deletions(-)\n create mode 100755 t/t9827-git-p4-change-filetype.sh\n\ndiff --git a/git-p4.py b/git-p4.py\nindex a7ec118..b7a3494 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -240,8 +240,8 @@ def p4_add(f):\n def p4_delete(f):\n     p4_system([\"delete\", wildcard_encode(f)])\n \n-def p4_edit(f):\n-    p4_system([\"edit\", wildcard_encode(f)])\n+def p4_edit(f, *options):\n+    p4_system([\"edit\"] + list(options) + [wildcard_encode(f)])\n \n def p4_revert(f):\n     p4_system([\"revert\", wildcard_encode(f)])\n@@ -1344,6 +1344,7 @@ class P4Submit(Command, P4UserMap):\n \n         diff = read_pipe_lines(\"git diff-tree -r %s \\\"%s^\\\" \\\"%s\\\"\" % (self.diffOpts, id, id))\n         filesToAdd = set()\n+        filesToChangeType = set()\n         filesToDelete = set()\n         editedFiles = set()\n         pureRenameCopy = set()\n@@ -1404,6 +1405,8 @@ class P4Submit(Command, P4UserMap):\n                     os.unlink(dest)\n                     filesToDelete.add(src)\n                 editedFiles.add(dest)\n+            elif modifier == \"T\":\n+                filesToChangeType.add(path)\n             else:\n                 die(\"unknown modifier %s for %s\" % (modifier, path))\n \n@@ -1463,6 +1466,8 @@ class P4Submit(Command, P4UserMap):\n         #\n         system(applyPatchCmd)\n \n+        for f in filesToChangeType:\n+            p4_edit(f, \"-t\", \"auto\")\n         for f in filesToAdd:\n             p4_add(f)\n         for f in filesToDelete:\ndiff --git a/t/t9827-git-p4-change-filetype.sh b/t/t9827-git-p4-change-filetype.sh\nnew file mode 100755\nindex 0000000..b0a9f62\n--- /dev/null\n+++ b/t/t9827-git-p4-change-filetype.sh\n@@ -0,0 +1,69 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2016 Romain Picard\n+#\n+\n+test_description='git p4 support for file type change'\n+\n+. ./lib-git-p4.sh\n+\n+test_expect_success 'start p4d' '\n+\tstart_p4d\n+'\n+\n+test_expect_success 'create files' '\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tp4 client -o | sed \"/LineEnd/s/:.*/:unix/\" | p4 client -i &&\n+\t\tcat >file1 <<-EOF &&\n+\t\tThis is a first file.\n+\t\tEOF\n+\t\tcat >file2 <<-EOF &&\n+\t\tThis is a second file whose type will change.\n+\t\tEOF\n+\t\tp4 add file1 file2 &&\n+\t\tp4 submit -d \"add files\"\n+\t)\n+'\n+\n+test_expect_success 'change file to symbolic link' '\n+\tgit p4 clone --dest=\"$git\" //depot@all &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\n+\t\trm file2 &&\n+\t\tln -s file1 file2 &&\n+\t\tgit add file2 &&\n+\t\tgit commit -m \"symlink file1 to file2\" &&\n+\t\tgit p4 submit &&\n+\t\tp4 filelog -m 1 //depot/file2 >filelog &&\n+\t\tgrep \"(symlink)\" filelog\n+\t)\n+'\n+\n+test_expect_success 'change symbolic link to file' '\n+\tgit p4 clone --dest=\"$git\" //depot@all &&\n+\ttest_when_finished cleanup_git &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\n+\t\trm file2 &&\n+\t\tcat >file2 <<-EOF &&\n+\t\tThis is another content for the second file.\n+\t\tEOF\n+\t\tgit add file2 &&\n+\t\tgit commit -m \"re-write file2\" &&\n+\t\tgit p4 submit &&\n+\t\tp4 filelog -m 1 //depot/file2 >filelog &&\n+\t\tgrep \"(text)\" filelog\n+\t)\n+'\n+\n+test_expect_success 'kill p4d' '\n+\tkill_p4d\n+'\n+\n+test_done\n-- \n2.6.4\n"},{"id":"275326","messageId":"xmqqtwmtm2m3.fsf@gitster.mtv.corp.google.com","threadId":"41114","inReplyTo":"1451904764-338-1-git-send-email-romain.picard@oakbits.com","subject":"Re: [PATCH v2] git-p4.py: add support for filetype change","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-04T21:55:16Z","receivedAt":"2016-01-04T21:55:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Romain Picard <romain.picard@oakbits.com> writes:\n\n> diff --git a/t/t9827-git-p4-change-filetype.sh b/t/t9827-git-p4-change-filetype.sh\n> new file mode 100755\n> index 0000000..b0a9f62\n> --- /dev/null\n> +++ b/t/t9827-git-p4-change-filetype.sh\n> @@ -0,0 +1,69 @@\n> +#!/bin/sh\n> +#\n> +# Copyright (c) 2016 Romain Picard\n> +#\n> +\n> +test_description='git p4 support for file type change'\n> +\n> +. ./lib-git-p4.sh\n> +\n> +test_expect_success 'start p4d' '\n> +\tstart_p4d\n> +'\n> +\n> +test_expect_success 'create files' '\n> +\t(\n> +\t\tcd \"$cli\" &&\n> +\t\tp4 client -o | sed \"/LineEnd/s/:.*/:unix/\" | p4 client -i &&\n> +\t\tcat >file1 <<-EOF &&\n> +\t\tThis is a first file.\n> +\t\tEOF\n> +\t\tcat >file2 <<-EOF &&\n> +\t\tThis is a second file whose type will change.\n> +\t\tEOF\n\nMicronit.  It would be nicer to the readers to make it clear that\nthere is no funny substitution to be worried about by quoting the\nend marker of these here document, i.e.\n\n\t\tcat >dest <<-\\EOF &&\n                text without any funny substitution business\n                EOF\n\n> +\t\tp4 add file1 file2 &&\n> +\t\tp4 submit -d \"add files\"\n> +\t)\n> +'\n> +\n> +test_expect_success 'change file to symbolic link' '\n\nThis needs a SYMLINKS prerequisite so that it is skipped on systems\nthat lack support for symbolic links, i.e.\n\n\ttest_expect_success SYMLINKS 'change file to symbolic link' '\n\nThe same for the next one.\n\nThanks.\n"},{"id":"275329","messageId":"CAE5ih78Jb9u8FKNd5hoWkWVFsZJBa2_dqaQ1G1SKtjm8Ec4J6Q@mail.gmail.com","threadId":"41114","inReplyTo":"1451904764-338-1-git-send-email-romain.picard@oakbits.com","subject":"Re: [PATCH v2] git-p4.py: add support for filetype change","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2016-01-04T22:16:03Z","receivedAt":"2016-01-04T22:16:03Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 4 January 2016 at 10:52, Romain Picard <romain.picard@oakbits.com> wrote:\n> After changing the type of a file in the git repository, it is not possible to\n> \"git p4 publish\" the commit to perforce. This is due to the fact that the git\n> \"T\" status is not handled in git-p4.py. This can typically occur when replacing\n> an existing file with a symbolic link.\n>\n> The \"T\" modifier is now supported in git-p4.py. When a file type has changed,\n> inform perforce with the \"p4 edit -f auto\" command.\n\nLooks good to me, thanks for adding the test. I think the test needs\nto say what the terms of the copyright are (GPL, etc) but other than\nthat it looks good.\n\nThanks\nLuke\n\n>\n> Signed-off-by: Romain Picard <romain.picard@oakbits.com>\n> ---\n>  git-p4.py                         |  9 +++--\n>  t/t9827-git-p4-change-filetype.sh | 69 +++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 76 insertions(+), 2 deletions(-)\n>  create mode 100755 t/t9827-git-p4-change-filetype.sh\n>\n> diff --git a/git-p4.py b/git-p4.py\n> index a7ec118..b7a3494 100755\n> --- a/git-p4.py\n> +++ b/git-p4.py\n> @@ -240,8 +240,8 @@ def p4_add(f):\n>  def p4_delete(f):\n>      p4_system([\"delete\", wildcard_encode(f)])\n>\n> -def p4_edit(f):\n> -    p4_system([\"edit\", wildcard_encode(f)])\n> +def p4_edit(f, *options):\n> +    p4_system([\"edit\"] + list(options) + [wildcard_encode(f)])\n>\n>  def p4_revert(f):\n>      p4_system([\"revert\", wildcard_encode(f)])\n> @@ -1344,6 +1344,7 @@ class P4Submit(Command, P4UserMap):\n>\n>          diff = read_pipe_lines(\"git diff-tree -r %s \\\"%s^\\\" \\\"%s\\\"\" % (self.diffOpts, id, id))\n>          filesToAdd = set()\n> +        filesToChangeType = set()\n>          filesToDelete = set()\n>          editedFiles = set()\n>          pureRenameCopy = set()\n> @@ -1404,6 +1405,8 @@ class P4Submit(Command, P4UserMap):\n>                      os.unlink(dest)\n>                      filesToDelete.add(src)\n>                  editedFiles.add(dest)\n> +            elif modifier == \"T\":\n> +                filesToChangeType.add(path)\n>              else:\n>                  die(\"unknown modifier %s for %s\" % (modifier, path))\n>\n> @@ -1463,6 +1466,8 @@ class P4Submit(Command, P4UserMap):\n>          #\n>          system(applyPatchCmd)\n>\n> +        for f in filesToChangeType:\n> +            p4_edit(f, \"-t\", \"auto\")\n>          for f in filesToAdd:\n>              p4_add(f)\n>          for f in filesToDelete:\n> diff --git a/t/t9827-git-p4-change-filetype.sh b/t/t9827-git-p4-change-filetype.sh\n> new file mode 100755\n> index 0000000..b0a9f62\n> --- /dev/null\n> +++ b/t/t9827-git-p4-change-filetype.sh\n> @@ -0,0 +1,69 @@\n> +#!/bin/sh\n> +#\n> +# Copyright (c) 2016 Romain Picard\n> +#\n> +\n> +test_description='git p4 support for file type change'\n> +\n> +. ./lib-git-p4.sh\n> +\n> +test_expect_success 'start p4d' '\n> +       start_p4d\n> +'\n> +\n> +test_expect_success 'create files' '\n> +       (\n> +               cd \"$cli\" &&\n> +               p4 client -o | sed \"/LineEnd/s/:.*/:unix/\" | p4 client -i &&\n> +               cat >file1 <<-EOF &&\n> +               This is a first file.\n> +               EOF\n> +               cat >file2 <<-EOF &&\n> +               This is a second file whose type will change.\n> +               EOF\n> +               p4 add file1 file2 &&\n> +               p4 submit -d \"add files\"\n> +       )\n> +'\n> +\n> +test_expect_success 'change file to symbolic link' '\n> +       git p4 clone --dest=\"$git\" //depot@all &&\n> +       test_when_finished cleanup_git &&\n> +       (\n> +               cd \"$git\" &&\n> +               git config git-p4.skipSubmitEdit true &&\n> +\n> +               rm file2 &&\n> +               ln -s file1 file2 &&\n> +               git add file2 &&\n> +               git commit -m \"symlink file1 to file2\" &&\n> +               git p4 submit &&\n> +               p4 filelog -m 1 //depot/file2 >filelog &&\n> +               grep \"(symlink)\" filelog\n> +       )\n> +'\n> +\n> +test_expect_success 'change symbolic link to file' '\n> +       git p4 clone --dest=\"$git\" //depot@all &&\n> +       test_when_finished cleanup_git &&\n> +       (\n> +               cd \"$git\" &&\n> +               git config git-p4.skipSubmitEdit true &&\n> +\n> +               rm file2 &&\n> +               cat >file2 <<-EOF &&\n> +               This is another content for the second file.\n> +               EOF\n> +               git add file2 &&\n> +               git commit -m \"re-write file2\" &&\n> +               git p4 submit &&\n> +               p4 filelog -m 1 //depot/file2 >filelog &&\n> +               grep \"(text)\" filelog\n> +       )\n> +'\n> +\n> +test_expect_success 'kill p4d' '\n> +       kill_p4d\n> +'\n> +\n> +test_done\n> --\n> 2.6.4\n>\n"},{"id":"275385","messageId":"011e31179a6b263636562de374102fd7@oakbits.com","threadId":"41114","inReplyTo":"CAE5ih78Jb9u8FKNd5hoWkWVFsZJBa2_dqaQ1G1SKtjm8Ec4J6Q@mail.gmail.com","subject":"Re: [PATCH v2] git-p4.py: add support for filetype change","fromName":"Romain Picard","fromEmail":"romain.picard@oakbits.com","sentAt":"2016-01-05T13:08:42Z","receivedAt":"2016-01-05T13:08:42Z","isPatch":true,"sender":{"key":"romain.picard@oakbits.com","avatar":"https://avatars.githubusercontent.com/u/814804?v=4"},"body":"Le 04.01.2016 23:16, Luke Diamand a écrit :\n> On 4 January 2016 at 10:52, Romain Picard <romain.picard@oakbits.com> \n> wrote:\n>> After changing the type of a file in the git repository, it is not \n>> possible to\n>> \"git p4 publish\" the commit to perforce. This is due to the fact that \n>> the git\n>> \"T\" status is not handled in git-p4.py. This can typically occur when \n>> replacing\n>> an existing file with a symbolic link.\n>> \n>> The \"T\" modifier is now supported in git-p4.py. When a file type has \n>> changed,\n>> inform perforce with the \"p4 edit -f auto\" command.\n> \n> Looks good to me, thanks for adding the test. I think the test needs\n> to say what the terms of the copyright are (GPL, etc) but other than\n> that it looks good.\n\nI copy/pasted the copyright present in \"t/README\" and other tests. Tell \nme if you\nwant an explicit reference to a license.\n\nHowever since many existing tests do not have any copyright I can just \nremove it.\n\n> \n> Thanks\n> Luke\n> \n>> \n>> Signed-off-by: Romain Picard <romain.picard@oakbits.com>\n>> ---\n>>  git-p4.py                         |  9 +++--\n>>  t/t9827-git-p4-change-filetype.sh | 69 \n>> +++++++++++++++++++++++++++++++++++++++\n>>  2 files changed, 76 insertions(+), 2 deletions(-)\n>>  create mode 100755 t/t9827-git-p4-change-filetype.sh\n>> \n>> diff --git a/git-p4.py b/git-p4.py\n>> index a7ec118..b7a3494 100755\n>> --- a/git-p4.py\n>> +++ b/git-p4.py\n>> @@ -240,8 +240,8 @@ def p4_add(f):\n>>  def p4_delete(f):\n>>      p4_system([\"delete\", wildcard_encode(f)])\n>> \n>> -def p4_edit(f):\n>> -    p4_system([\"edit\", wildcard_encode(f)])\n>> +def p4_edit(f, *options):\n>> +    p4_system([\"edit\"] + list(options) + [wildcard_encode(f)])\n>> \n>>  def p4_revert(f):\n>>      p4_system([\"revert\", wildcard_encode(f)])\n>> @@ -1344,6 +1344,7 @@ class P4Submit(Command, P4UserMap):\n>> \n>>          diff = read_pipe_lines(\"git diff-tree -r %s \\\"%s^\\\" \\\"%s\\\"\" % \n>> (self.diffOpts, id, id))\n>>          filesToAdd = set()\n>> +        filesToChangeType = set()\n>>          filesToDelete = set()\n>>          editedFiles = set()\n>>          pureRenameCopy = set()\n>> @@ -1404,6 +1405,8 @@ class P4Submit(Command, P4UserMap):\n>>                      os.unlink(dest)\n>>                      filesToDelete.add(src)\n>>                  editedFiles.add(dest)\n>> +            elif modifier == \"T\":\n>> +                filesToChangeType.add(path)\n>>              else:\n>>                  die(\"unknown modifier %s for %s\" % (modifier, path))\n>> \n>> @@ -1463,6 +1466,8 @@ class P4Submit(Command, P4UserMap):\n>>          #\n>>          system(applyPatchCmd)\n>> \n>> +        for f in filesToChangeType:\n>> +            p4_edit(f, \"-t\", \"auto\")\n>>          for f in filesToAdd:\n>>              p4_add(f)\n>>          for f in filesToDelete:\n>> diff --git a/t/t9827-git-p4-change-filetype.sh \n>> b/t/t9827-git-p4-change-filetype.sh\n>> new file mode 100755\n>> index 0000000..b0a9f62\n>> --- /dev/null\n>> +++ b/t/t9827-git-p4-change-filetype.sh\n>> @@ -0,0 +1,69 @@\n>> +#!/bin/sh\n>> +#\n>> +# Copyright (c) 2016 Romain Picard\n>> +#\n>> +\n>> +test_description='git p4 support for file type change'\n>> +\n>> +. ./lib-git-p4.sh\n>> +\n>> +test_expect_success 'start p4d' '\n>> +       start_p4d\n>> +'\n>> +\n>> +test_expect_success 'create files' '\n>> +       (\n>> +               cd \"$cli\" &&\n>> +               p4 client -o | sed \"/LineEnd/s/:.*/:unix/\" | p4 client \n>> -i &&\n>> +               cat >file1 <<-EOF &&\n>> +               This is a first file.\n>> +               EOF\n>> +               cat >file2 <<-EOF &&\n>> +               This is a second file whose type will change.\n>> +               EOF\n>> +               p4 add file1 file2 &&\n>> +               p4 submit -d \"add files\"\n>> +       )\n>> +'\n>> +\n>> +test_expect_success 'change file to symbolic link' '\n>> +       git p4 clone --dest=\"$git\" //depot@all &&\n>> +       test_when_finished cleanup_git &&\n>> +       (\n>> +               cd \"$git\" &&\n>> +               git config git-p4.skipSubmitEdit true &&\n>> +\n>> +               rm file2 &&\n>> +               ln -s file1 file2 &&\n>> +               git add file2 &&\n>> +               git commit -m \"symlink file1 to file2\" &&\n>> +               git p4 submit &&\n>> +               p4 filelog -m 1 //depot/file2 >filelog &&\n>> +               grep \"(symlink)\" filelog\n>> +       )\n>> +'\n>> +\n>> +test_expect_success 'change symbolic link to file' '\n>> +       git p4 clone --dest=\"$git\" //depot@all &&\n>> +       test_when_finished cleanup_git &&\n>> +       (\n>> +               cd \"$git\" &&\n>> +               git config git-p4.skipSubmitEdit true &&\n>> +\n>> +               rm file2 &&\n>> +               cat >file2 <<-EOF &&\n>> +               This is another content for the second file.\n>> +               EOF\n>> +               git add file2 &&\n>> +               git commit -m \"re-write file2\" &&\n>> +               git p4 submit &&\n>> +               p4 filelog -m 1 //depot/file2 >filelog &&\n>> +               grep \"(text)\" filelog\n>> +       )\n>> +'\n>> +\n>> +test_expect_success 'kill p4d' '\n>> +       kill_p4d\n>> +'\n>> +\n>> +test_done\n>> --\n>> 2.6.4\n>> \n"}]}