{"thread":{"id":"44628","subject":"[PATCH] git-p4: add p4 shelf support","startedAt":"2016-12-06T02:21:01Z","lastAt":"2016-12-07T11:09:19Z","messageCount":4,"participants":["Nuno Subtil","Luke Diamand","Vinicius Kursancew"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"306989","messageId":"01020158d1de0e71-ac079bb9-bc7d-4fb7-9ff7-60fd6955116b-000000@eu-west-1.amazonses.com","threadId":"44628","inReplyTo":null,"subject":"[PATCH] git-p4: add p4 shelf support","fromName":"Nuno Subtil","fromEmail":"subtil@gmail.com","sentAt":"2016-12-06T02:02:20Z","receivedAt":"2016-12-06T02:21:01Z","isPatch":true,"sender":{"key":"subtil@gmail.com","avatar":null},"body":"Extends the submit command to support shelving a commit instead of\nsubmitting it to p4 (similar to --prepare-p4-only).\n\nSigned-off-by: Nuno Subtil <subtil@gmail.com>\n---\n git-p4.py | 36 ++++++++++++++++++++++++++++++------\n 1 file changed, 30 insertions(+), 6 deletions(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex fd5ca52..3c4be22 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1286,6 +1286,8 @@ def __init__(self):\n                 optparse.make_option(\"--export-labels\", dest=\"exportLabels\", action=\"store_true\"),\n                 optparse.make_option(\"--dry-run\", \"-n\", dest=\"dry_run\", action=\"store_true\"),\n                 optparse.make_option(\"--prepare-p4-only\", dest=\"prepare_p4_only\", action=\"store_true\"),\n+                optparse.make_option(\"--shelve-only\", dest=\"shelve_only\", action=\"store_true\", help=\"Create P4 shelf for first change that would be submitted (using a new CL)\"),\n+                optparse.make_option(\"--shelve-cl\", dest=\"shelve_cl\", help=\"Replace shelf under existing CL number (previously shelved files will be deleted)\"),\n                 optparse.make_option(\"--conflict\", dest=\"conflict_behavior\",\n                                      choices=self.conflict_behavior_choices),\n                 optparse.make_option(\"--branch\", dest=\"branch\"),\n@@ -1297,6 +1299,8 @@ def __init__(self):\n         self.preserveUser = gitConfigBool(\"git-p4.preserveUser\")\n         self.dry_run = False\n         self.prepare_p4_only = False\n+        self.shelve_only = False\n+        self.shelve_cl = None\n         self.conflict_behavior = None\n         self.isWindows = (platform.system() == \"Windows\")\n         self.exportLabels = False\n@@ -1496,6 +1500,12 @@ def prepareSubmitTemplate(self):\n                 else:\n                     inFilesSection = False\n             else:\n+                if self.shelve_only and self.shelve_cl:\n+                    if line.startswith(\"Change:\"):\n+                        line = \"Change: %s\\n\" % self.shelve_cl\n+                    if line.startswith(\"Status:\"):\n+                        line = \"Status: pending\\n\"\n+\n                 if line.startswith(\"Files:\"):\n                     inFilesSection = True\n \n@@ -1785,7 +1795,11 @@ def applyCommit(self, id):\n                 if self.isWindows:\n                     message = message.replace(\"\\r\\n\", \"\\n\")\n                 submitTemplate = message[:message.index(separatorLine)]\n-                p4_write_pipe(['submit', '-i'], submitTemplate)\n+\n+                if self.shelve_only:\n+                    p4_write_pipe(['shelve', '-i', '-r'], submitTemplate)\n+                else:\n+                    p4_write_pipe(['submit', '-i'], submitTemplate)\n \n                 if self.preserveUser:\n                     if p4User:\n@@ -1799,12 +1813,17 @@ def applyCommit(self, id):\n                 # new file.  This leaves it writable, which confuses p4.\n                 for f in pureRenameCopy:\n                     p4_sync(f, \"-f\")\n-                submitted = True\n+\n+                if not self.shelve_only:\n+                    submitted = True\n \n         finally:\n             # skip this patch\n             if not submitted:\n-                print \"Submission cancelled, undoing p4 changes.\"\n+                if not self.shelve_only:\n+                    print \"Submission cancelled, undoing p4 changes.\"\n+                else:\n+                    print \"Change shelved, undoing p4 changes.\"\n                 for f in editedFiles:\n                     p4_revert(f)\n                 for f in filesToAdd:\n@@ -2034,9 +2053,13 @@ def run(self, args):\n             if ok:\n                 applied.append(commit)\n             else:\n-                if self.prepare_p4_only and i < last:\n-                    print \"Processing only the first commit due to option\" \\\n-                          \" --prepare-p4-only\"\n+                if (self.prepare_p4_only or self.shelve_only) and i < last:\n+                    if self.prepare_p4_only:\n+                        print \"Processing only the first commit due to option\" \\\n+                              \" --prepare-p4-only\"\n+                    else:\n+                        print \"Processing only the first commit due to option\" \\\n+                              \" --shelve-only\"\n                     break\n                 if i < last:\n                     quit = False\n@@ -3638,6 +3661,7 @@ def printUsage(commands):\n     \"debug\" : P4Debug,\n     \"submit\" : P4Submit,\n     \"commit\" : P4Submit,\n+    \"shelve\" : P4Submit,\n     \"sync\" : P4Sync,\n     \"rebase\" : P4Rebase,\n     \"clone\" : P4Clone,\n\n--\nhttps://github.com/git/git/pull/309\n"},{"id":"306991","messageId":"CAE5ih79S+SFt-fsQ_2c4eXMankoXvoSE3zhxw39Y4XeQqQ9nMg@mail.gmail.com","threadId":"44628","inReplyTo":"01020158d1de0e71-ac079bb9-bc7d-4fb7-9ff7-60fd6955116b-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] git-p4: add p4 shelf support","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2016-12-06T08:36:46Z","receivedAt":"2016-12-06T08:36:52Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 6 December 2016 at 02:02, Nuno Subtil <subtil@gmail.com> wrote:\n> Extends the submit command to support shelving a commit instead of\n> submitting it to p4 (similar to --prepare-p4-only).\n\nIs this just the same as these two changes?\n\nhttp://www.spinics.net/lists/git/msg290755.html\nhttp://www.spinics.net/lists/git/msg291103.html\n\nThanks,\nLuke\n\n>\n> Signed-off-by: Nuno Subtil <subtil@gmail.com>\n> ---\n>  git-p4.py | 36 ++++++++++++++++++++++++++++++------\n>  1 file changed, 30 insertions(+), 6 deletions(-)\n>\n> diff --git a/git-p4.py b/git-p4.py\n> index fd5ca52..3c4be22 100755\n> --- a/git-p4.py\n> +++ b/git-p4.py\n> @@ -1286,6 +1286,8 @@ def __init__(self):\n>                  optparse.make_option(\"--export-labels\", dest=\"exportLabels\", action=\"store_true\"),\n>                  optparse.make_option(\"--dry-run\", \"-n\", dest=\"dry_run\", action=\"store_true\"),\n>                  optparse.make_option(\"--prepare-p4-only\", dest=\"prepare_p4_only\", action=\"store_true\"),\n> +                optparse.make_option(\"--shelve-only\", dest=\"shelve_only\", action=\"store_true\", help=\"Create P4 shelf for first change that would be submitted (using a new CL)\"),\n> +                optparse.make_option(\"--shelve-cl\", dest=\"shelve_cl\", help=\"Replace shelf under existing CL number (previously shelved files will be deleted)\"),\n>                  optparse.make_option(\"--conflict\", dest=\"conflict_behavior\",\n>                                       choices=self.conflict_behavior_choices),\n>                  optparse.make_option(\"--branch\", dest=\"branch\"),\n> @@ -1297,6 +1299,8 @@ def __init__(self):\n>          self.preserveUser = gitConfigBool(\"git-p4.preserveUser\")\n>          self.dry_run = False\n>          self.prepare_p4_only = False\n> +        self.shelve_only = False\n> +        self.shelve_cl = None\n>          self.conflict_behavior = None\n>          self.isWindows = (platform.system() == \"Windows\")\n>          self.exportLabels = False\n> @@ -1496,6 +1500,12 @@ def prepareSubmitTemplate(self):\n>                  else:\n>                      inFilesSection = False\n>              else:\n> +                if self.shelve_only and self.shelve_cl:\n> +                    if line.startswith(\"Change:\"):\n> +                        line = \"Change: %s\\n\" % self.shelve_cl\n> +                    if line.startswith(\"Status:\"):\n> +                        line = \"Status: pending\\n\"\n> +\n>                  if line.startswith(\"Files:\"):\n>                      inFilesSection = True\n>\n> @@ -1785,7 +1795,11 @@ def applyCommit(self, id):\n>                  if self.isWindows:\n>                      message = message.replace(\"\\r\\n\", \"\\n\")\n>                  submitTemplate = message[:message.index(separatorLine)]\n> -                p4_write_pipe(['submit', '-i'], submitTemplate)\n> +\n> +                if self.shelve_only:\n> +                    p4_write_pipe(['shelve', '-i', '-r'], submitTemplate)\n> +                else:\n> +                    p4_write_pipe(['submit', '-i'], submitTemplate)\n>\n>                  if self.preserveUser:\n>                      if p4User:\n> @@ -1799,12 +1813,17 @@ def applyCommit(self, id):\n>                  # new file.  This leaves it writable, which confuses p4.\n>                  for f in pureRenameCopy:\n>                      p4_sync(f, \"-f\")\n> -                submitted = True\n> +\n> +                if not self.shelve_only:\n> +                    submitted = True\n>\n>          finally:\n>              # skip this patch\n>              if not submitted:\n> -                print \"Submission cancelled, undoing p4 changes.\"\n> +                if not self.shelve_only:\n> +                    print \"Submission cancelled, undoing p4 changes.\"\n> +                else:\n> +                    print \"Change shelved, undoing p4 changes.\"\n>                  for f in editedFiles:\n>                      p4_revert(f)\n>                  for f in filesToAdd:\n> @@ -2034,9 +2053,13 @@ def run(self, args):\n>              if ok:\n>                  applied.append(commit)\n>              else:\n> -                if self.prepare_p4_only and i < last:\n> -                    print \"Processing only the first commit due to option\" \\\n> -                          \" --prepare-p4-only\"\n> +                if (self.prepare_p4_only or self.shelve_only) and i < last:\n> +                    if self.prepare_p4_only:\n> +                        print \"Processing only the first commit due to option\" \\\n> +                              \" --prepare-p4-only\"\n> +                    else:\n> +                        print \"Processing only the first commit due to option\" \\\n> +                              \" --shelve-only\"\n>                      break\n>                  if i < last:\n>                      quit = False\n> @@ -3638,6 +3661,7 @@ def printUsage(commands):\n>      \"debug\" : P4Debug,\n>      \"submit\" : P4Submit,\n>      \"commit\" : P4Submit,\n> +    \"shelve\" : P4Submit,\n>      \"sync\" : P4Sync,\n>      \"rebase\" : P4Rebase,\n>      \"clone\" : P4Clone,\n>\n> --\n> https://github.com/git/git/pull/309\n"},{"id":"307015","messageId":"CAE-KjjE7UE19CfGQb=5BzJrz3Ji6mOXTT46_3v2056b_U8A+qw@mail.gmail.com","threadId":"44628","inReplyTo":"CAE5ih79S+SFt-fsQ_2c4eXMankoXvoSE3zhxw39Y4XeQqQ9nMg@mail.gmail.com","subject":"Re: [PATCH] git-p4: add p4 shelf support","fromName":"Vinicius Kursancew","fromEmail":"viniciusalexandre@gmail.com","sentAt":"2016-12-06T16:03:26Z","receivedAt":"2016-12-06T16:03:34Z","isPatch":true,"sender":{"key":"viniciusalexandre@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6376185?v=4"},"body":"It seems if you do shelve and then later submit the p4 workspace is\nleft dirty (just like --prepare-p4-only would've done).\nVinicius Alexandre Kursancew <viniciusalexandre@gmail.com>\n\n\n\nOn Tue, Dec 6, 2016 at 8:36 AM, Luke Diamand <luke@diamand.org> wrote:\n> On 6 December 2016 at 02:02, Nuno Subtil <subtil@gmail.com> wrote:\n>> Extends the submit command to support shelving a commit instead of\n>> submitting it to p4 (similar to --prepare-p4-only).\n>\n> Is this just the same as these two changes?\n>\n> http://www.spinics.net/lists/git/msg290755.html\n> http://www.spinics.net/lists/git/msg291103.html\n>\n> Thanks,\n> Luke\n>\n>>\n>> Signed-off-by: Nuno Subtil <subtil@gmail.com>\n>> ---\n>>  git-p4.py | 36 ++++++++++++++++++++++++++++++------\n>>  1 file changed, 30 insertions(+), 6 deletions(-)\n>>\n>> diff --git a/git-p4.py b/git-p4.py\n>> index fd5ca52..3c4be22 100755\n>> --- a/git-p4.py\n>> +++ b/git-p4.py\n>> @@ -1286,6 +1286,8 @@ def __init__(self):\n>>                  optparse.make_option(\"--export-labels\", dest=\"exportLabels\", action=\"store_true\"),\n>>                  optparse.make_option(\"--dry-run\", \"-n\", dest=\"dry_run\", action=\"store_true\"),\n>>                  optparse.make_option(\"--prepare-p4-only\", dest=\"prepare_p4_only\", action=\"store_true\"),\n>> +                optparse.make_option(\"--shelve-only\", dest=\"shelve_only\", action=\"store_true\", help=\"Create P4 shelf for first change that would be submitted (using a new CL)\"),\n>> +                optparse.make_option(\"--shelve-cl\", dest=\"shelve_cl\", help=\"Replace shelf under existing CL number (previously shelved files will be deleted)\"),\n>>                  optparse.make_option(\"--conflict\", dest=\"conflict_behavior\",\n>>                                       choices=self.conflict_behavior_choices),\n>>                  optparse.make_option(\"--branch\", dest=\"branch\"),\n>> @@ -1297,6 +1299,8 @@ def __init__(self):\n>>          self.preserveUser = gitConfigBool(\"git-p4.preserveUser\")\n>>          self.dry_run = False\n>>          self.prepare_p4_only = False\n>> +        self.shelve_only = False\n>> +        self.shelve_cl = None\n>>          self.conflict_behavior = None\n>>          self.isWindows = (platform.system() == \"Windows\")\n>>          self.exportLabels = False\n>> @@ -1496,6 +1500,12 @@ def prepareSubmitTemplate(self):\n>>                  else:\n>>                      inFilesSection = False\n>>              else:\n>> +                if self.shelve_only and self.shelve_cl:\n>> +                    if line.startswith(\"Change:\"):\n>> +                        line = \"Change: %s\\n\" % self.shelve_cl\n>> +                    if line.startswith(\"Status:\"):\n>> +                        line = \"Status: pending\\n\"\n>> +\n>>                  if line.startswith(\"Files:\"):\n>>                      inFilesSection = True\n>>\n>> @@ -1785,7 +1795,11 @@ def applyCommit(self, id):\n>>                  if self.isWindows:\n>>                      message = message.replace(\"\\r\\n\", \"\\n\")\n>>                  submitTemplate = message[:message.index(separatorLine)]\n>> -                p4_write_pipe(['submit', '-i'], submitTemplate)\n>> +\n>> +                if self.shelve_only:\n>> +                    p4_write_pipe(['shelve', '-i', '-r'], submitTemplate)\n>> +                else:\n>> +                    p4_write_pipe(['submit', '-i'], submitTemplate)\n>>\n>>                  if self.preserveUser:\n>>                      if p4User:\n>> @@ -1799,12 +1813,17 @@ def applyCommit(self, id):\n>>                  # new file.  This leaves it writable, which confuses p4.\n>>                  for f in pureRenameCopy:\n>>                      p4_sync(f, \"-f\")\n>> -                submitted = True\n>> +\n>> +                if not self.shelve_only:\n>> +                    submitted = True\n>>\n>>          finally:\n>>              # skip this patch\n>>              if not submitted:\n>> -                print \"Submission cancelled, undoing p4 changes.\"\n>> +                if not self.shelve_only:\n>> +                    print \"Submission cancelled, undoing p4 changes.\"\n>> +                else:\n>> +                    print \"Change shelved, undoing p4 changes.\"\n>>                  for f in editedFiles:\n>>                      p4_revert(f)\n>>                  for f in filesToAdd:\n>> @@ -2034,9 +2053,13 @@ def run(self, args):\n>>              if ok:\n>>                  applied.append(commit)\n>>              else:\n>> -                if self.prepare_p4_only and i < last:\n>> -                    print \"Processing only the first commit due to option\" \\\n>> -                          \" --prepare-p4-only\"\n>> +                if (self.prepare_p4_only or self.shelve_only) and i < last:\n>> +                    if self.prepare_p4_only:\n>> +                        print \"Processing only the first commit due to option\" \\\n>> +                              \" --prepare-p4-only\"\n>> +                    else:\n>> +                        print \"Processing only the first commit due to option\" \\\n>> +                              \" --shelve-only\"\n>>                      break\n>>                  if i < last:\n>>                      quit = False\n>> @@ -3638,6 +3661,7 @@ def printUsage(commands):\n>>      \"debug\" : P4Debug,\n>>      \"submit\" : P4Submit,\n>>      \"commit\" : P4Submit,\n>> +    \"shelve\" : P4Submit,\n>>      \"sync\" : P4Sync,\n>>      \"rebase\" : P4Rebase,\n>>      \"clone\" : P4Clone,\n>>\n>> --\n>> https://github.com/git/git/pull/309\n"},{"id":"307107","messageId":"CAE5ih79cW8DwtEJz_TWLS=xcGgE9ZjdMzfCs9HVoMkgVFMwiPg@mail.gmail.com","threadId":"44628","inReplyTo":"CALdXDfdXtc+FpePnGmE6_YDQ+8=wUZRqh4Xb65NJXUXaZnmELA@mail.gmail.com","subject":"Re: [PATCH] git-p4: add p4 shelf support","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2016-12-07T11:09:14Z","receivedAt":"2016-12-07T11:09:19Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 6 December 2016 at 16:12, Nuno Subtil <subtil@gmail.com> wrote:\n> Yeah, it looks similar. This change can be ignored if those have already\n> been accepted.\n\nThanks, that's appreciated!\n\nLuke\n"}]}