{"thread":{"id":"41173","subject":"[PATCH v3] git-p4.py: add support for filetype change","startedAt":"2016-01-12T12:43:47Z","lastAt":"2016-01-13T17:07:25Z","messageCount":3,"participants":["Romain Picard","Luke Diamand","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"275804","messageId":"1452602627-8402-1-git-send-email-romain.picard@oakbits.com","threadId":"41173","inReplyTo":null,"subject":"[PATCH v3] git-p4.py: add support for filetype change","fromName":"Romain Picard","fromEmail":"romain.picard@oakbits.com","sentAt":"2016-01-12T12:43:47Z","receivedAt":"2016-01-12T12:43:47Z","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 | 66 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 73 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..7433998\n--- /dev/null\n+++ b/t/t9827-git-p4-change-filetype.sh\n@@ -0,0 +1,66 @@\n+#!/bin/sh\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\ttext without any funny substitution business\n+\t\tEOF\n+\t\tcat >file2 <<-EOF &&\n+\t\tsecond 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 SYMLINKS '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 SYMLINKS '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":"275878","messageId":"CAE5ih78XSq5kFmmOYKCw0zF-NEgWH8+HS-0cHse_-mGR8r355A@mail.gmail.com","threadId":"41173","inReplyTo":"1452602627-8402-1-git-send-email-romain.picard@oakbits.com","subject":"Re: [PATCH v3] git-p4.py: add support for filetype change","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2016-01-13T07:02:57Z","receivedAt":"2016-01-13T07:02:57Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 12 January 2016 at 12:43, 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.\n\nAck.\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 | 66 +++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 73 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..7433998\n> --- /dev/null\n> +++ b/t/t9827-git-p4-change-filetype.sh\n> @@ -0,0 +1,66 @@\n> +#!/bin/sh\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> +               text without any funny substitution business\n> +               EOF\n> +               cat >file2 <<-EOF &&\n> +               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 SYMLINKS '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 SYMLINKS '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":"275926","messageId":"xmqqpox5pfw2.fsf@gitster.mtv.corp.google.com","threadId":"41173","inReplyTo":"CAE5ih78XSq5kFmmOYKCw0zF-NEgWH8+HS-0cHse_-mGR8r355A@mail.gmail.com","subject":"Re: [PATCH v3] git-p4.py: add support for filetype change","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-13T17:07:25Z","receivedAt":"2016-01-13T17:07:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luke Diamand <luke@diamand.org> writes:\n\n> On 12 January 2016 at 12:43, 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>\n> Looks good to me, thanks.\n>\n> Ack.\n\nThanks, both.  Will queue.\n"}]}