{"thread":{"id":"44554","subject":"[PATCH] git-p4: allow submit to create shelved changelists.","startedAt":"2016-11-28T09:34:03Z","lastAt":"2016-11-29T18:59:19Z","messageCount":5,"participants":["Vinicius Kursancew","Junio C Hamano","Luke Diamand"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"306472","messageId":"1480325598-12344-2-git-send-email-viniciusalexandre@gmail.com","threadId":"44554","inReplyTo":"1480325598-12344-1-git-send-email-viniciusalexandre@gmail.com","subject":"[PATCH] git-p4: allow submit to create shelved changelists.","fromName":"Vinicius Kursancew","fromEmail":"viniciusalexandre@gmail.com","sentAt":"2016-11-28T09:33:18Z","receivedAt":"2016-11-28T09:34:03Z","isPatch":true,"sender":{"key":"viniciusalexandre@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6376185?v=4"},"body":"Add a --shelve command line argument which invokes p4 shelve instead\nof submitting changes. After shelving the changes are reverted from the\np4 workspace.\n\nSigned-off-by: Vinicius Kursancew <viniciusalexandre@gmail.com>\n---\n Documentation/git-p4.txt |  5 +++++\n git-p4.py                | 36 ++++++++++++++++++++++--------------\n t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++\n 3 files changed, 58 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt\nindex c83aaf3..1bbf43d 100644\n--- a/Documentation/git-p4.txt\n+++ b/Documentation/git-p4.txt\n@@ -303,6 +303,11 @@ These options can be used to modify 'git p4 submit' behavior.\n \tsubmit manually or revert.  This option always stops after the\n \tfirst (oldest) commit.  Git tags are not exported to p4.\n \n+--shelve::\n+\tInstead of submitting create a series of shelved changelists.\n+\tAfter creating each shelve, the relevant files are reverted/deleted.\n+\tIf you have multiple commits pending multiple shelves will be created.\n+\n --conflict=(ask|skip|quit)::\n \tConflicts can occur when applying a commit to p4.  When this\n \thappens, the default behavior (\"ask\") is to prompt whether to\ndiff --git a/git-p4.py b/git-p4.py\nindex fd5ca52..0c4f2af 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1289,6 +1289,9 @@ class P4Submit(Command, P4UserMap):\n                 optparse.make_option(\"--conflict\", dest=\"conflict_behavior\",\n                                      choices=self.conflict_behavior_choices),\n                 optparse.make_option(\"--branch\", dest=\"branch\"),\n+                optparse.make_option(\"--shelve\", dest=\"shelve\", action=\"store_true\",\n+                                     help=\"Shelve instead of submit. Shelved files are reverted, \"\n+                                     \"restoring the workspace to the state before the shelve\"),\n         ]\n         self.description = \"Submit changes from git to the perforce depot.\"\n         self.usage += \" [name of git branch to submit into perforce depot]\"\n@@ -1296,6 +1299,7 @@ class P4Submit(Command, P4UserMap):\n         self.detectRenames = False\n         self.preserveUser = gitConfigBool(\"git-p4.preserveUser\")\n         self.dry_run = False\n+        self.shelve = False\n         self.prepare_p4_only = False\n         self.conflict_behavior = None\n         self.isWindows = (platform.system() == \"Windows\")\n@@ -1785,7 +1789,14 @@ class P4Submit(Command, P4UserMap):\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+                if self.shelve:\n+                    p4_write_pipe(['shelve', '-i'], submitTemplate)\n+                else:\n+                    p4_write_pipe(['submit', '-i'], submitTemplate)\n+                    # The rename/copy happened by applying a patch that created a\n+                    # new file.  This leaves it writable, which confuses p4.\n+                    for f in pureRenameCopy:\n+                        p4_sync(f, \"-f\")\n \n                 if self.preserveUser:\n                     if p4User:\n@@ -1795,23 +1806,20 @@ class P4Submit(Command, P4UserMap):\n                         changelist = self.lastP4Changelist()\n                         self.modifyChangelistUser(changelist, p4User)\n \n-                # The rename/copy happened by applying a patch that created a\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         finally:\n             # skip this patch\n-            if not submitted:\n-                print \"Submission cancelled, undoing p4 changes.\"\n-                for f in editedFiles:\n+            if not submitted or self.shelve:\n+                if self.shelve:\n+                    print (\"Reverting shelved files.\")\n+                else:\n+                    print (\"Submission cancelled, undoing p4 changes.\")\n+                for f in editedFiles | filesToDelete:\n                     p4_revert(f)\n                 for f in filesToAdd:\n                     p4_revert(f)\n                     os.remove(f)\n-                for f in filesToDelete:\n-                    p4_revert(f)\n \n         os.remove(fileName)\n         return submitted\n@@ -2067,13 +2075,13 @@ class P4Submit(Command, P4UserMap):\n                         break\n \n         chdir(self.oldWorkingDirectory)\n-\n+        shelved_applied = \"shelved\" if self.shelve else \"applied\"\n         if self.dry_run:\n             pass\n         elif self.prepare_p4_only:\n             pass\n         elif len(commits) == len(applied):\n-            print \"All commits applied!\"\n+            print (\"All commits {0}!\".format(shelved_applied))\n \n             sync = P4Sync()\n             if self.branch:\n@@ -2085,9 +2093,9 @@ class P4Submit(Command, P4UserMap):\n \n         else:\n             if len(applied) == 0:\n-                print \"No commits applied.\"\n+                print (\"No commits {0}.\".format(shelved_applied))\n             else:\n-                print \"Applied only the commits marked with '*':\"\n+                print (\"{0} only the commits marked with '*':\".format(shelved_applied.capitalize()))\n                 for c in commits:\n                     if c in applied:\n                         star = \"*\"\ndiff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh\nindex 5931528..42a5fad 100755\n--- a/t/t9807-git-p4-submit.sh\n+++ b/t/t9807-git-p4-submit.sh\n@@ -413,6 +413,37 @@ test_expect_success 'submit --prepare-p4-only' '\n \t)\n '\n \n+test_expect_success 'submit --shelve' '\n+\ttest_when_finished cleanup_git &&\n+\tgit p4 clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tp4 revert ... &&\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\ttest_commit \"shelveme1\" &&\n+\t\tgit p4 submit --origin=HEAD^ &&\n+\n+\t\techo 654321 >shelveme2.t &&\n+\t\techo 123456 >>shelveme1.t &&\n+\t\tgit add shelveme* &&\n+\t\tgit commit -m\"shelvetest\" &&\n+\t\tgit p4 submit --shelve --origin=HEAD^ &&\n+\n+\t\ttest_path_is_file shelveme1.t &&\n+\t\ttest_path_is_file shelveme2.t\n+\t) &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tchange=$(p4 -G changes -s shelved -m 1 //depot/... | \\\n+\t\t\t marshal_dump change) &&\n+\t\tp4 describe -S $change | grep shelveme2 &&\n+\t\tp4 describe -S $change | grep 123456 &&\n+\t\ttest_path_is_file shelveme1.t &&\n+\t\ttest_path_is_missing shelveme2.t\n+\t)\n+'\n+\n test_expect_success 'kill p4d' '\n \tkill_p4d\n '\n-- \n2.6.0-rc1\n\n"},{"id":"306473","messageId":"1480325598-12344-1-git-send-email-viniciusalexandre@gmail.com","threadId":"44554","inReplyTo":null,"subject":"[PATCH] allow git-p4 to create shelved changelists","fromName":"Vinicius Kursancew","fromEmail":"viniciusalexandre@gmail.com","sentAt":"2016-11-28T09:33:17Z","receivedAt":"2016-11-28T09:34:11Z","isPatch":true,"sender":{"key":"viniciusalexandre@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6376185?v=4"},"body":"This patch adds a \"--shelve\" option to the submit subcommand, it will\nsave the changes to a perforce shelve instead of commiting them.\n\nVinicius Kursancew (1):\n  git-p4: allow submit to create shelved changelists.\n\n Documentation/git-p4.txt |  5 +++++\n git-p4.py                | 36 ++++++++++++++++++++++--------------\n t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++\n 3 files changed, 58 insertions(+), 14 deletions(-)\n\n-- \n2.6.0-rc1\n\n"},{"id":"306511","messageId":"xmqqeg1vjug2.fsf@gitster.mtv.corp.google.com","threadId":"44554","inReplyTo":"1480325598-12344-1-git-send-email-viniciusalexandre@gmail.com","subject":"Re: [PATCH] allow git-p4 to create shelved changelists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-11-28T19:06:05Z","receivedAt":"2016-11-28T19:06:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vinicius Kursancew <viniciusalexandre@gmail.com> writes:\n\n> This patch adds a \"--shelve\" option to the submit subcommand, it will\n> save the changes to a perforce shelve instead of commiting them.\n>\n> Vinicius Kursancew (1):\n>   git-p4: allow submit to create shelved changelists.\n>\n>  Documentation/git-p4.txt |  5 +++++\n>  git-p4.py                | 36 ++++++++++++++++++++++--------------\n>  t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++\n>  3 files changed, 58 insertions(+), 14 deletions(-)\n\nThanks, but I am a wrong person to review this change, so I'll\nsummon two people who appear in \"git shortlog --since=18.months\"\noutput to help review it.\n\n\n"},{"id":"306543","messageId":"CAE5ih78+br88ST3Hkiw744V62AZ9iYWZ4nD5EYjewfmQRWvsiw@mail.gmail.com","threadId":"44554","inReplyTo":"xmqqeg1vjug2.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] allow git-p4 to create shelved changelists","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2016-11-29T12:47:04Z","receivedAt":"2016-11-29T12:47:29Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 28 November 2016 at 19:06, Junio C Hamano <gitster@pobox.com> wrote:\n> Vinicius Kursancew <viniciusalexandre@gmail.com> writes:\n>\n>> This patch adds a \"--shelve\" option to the submit subcommand, it will\n>> save the changes to a perforce shelve instead of commiting them.\n\nLooks good to me, thanks!\n\nWorks a treat.\n\nAck.\n\n>>\n>> Vinicius Kursancew (1):\n>>   git-p4: allow submit to create shelved changelists.\n>>\n>>  Documentation/git-p4.txt |  5 +++++\n>>  git-p4.py                | 36 ++++++++++++++++++++++--------------\n>>  t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++\n>>  3 files changed, 58 insertions(+), 14 deletions(-)\n>\n> Thanks, but I am a wrong person to review this change, so I'll\n> summon two people who appear in \"git shortlog --since=18.months\"\n> output to help review it.\n>\n>\n"},{"id":"306557","messageId":"xmqqy402f6yp.fsf@gitster.mtv.corp.google.com","threadId":"44554","inReplyTo":"CAE5ih78+br88ST3Hkiw744V62AZ9iYWZ4nD5EYjewfmQRWvsiw@mail.gmail.com","subject":"Re: [PATCH] allow git-p4 to create shelved changelists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-11-29T18:59:10Z","receivedAt":"2016-11-29T18:59:19Z","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 28 November 2016 at 19:06, Junio C Hamano <gitster@pobox.com> wrote:\n>> Vinicius Kursancew <viniciusalexandre@gmail.com> writes:\n>>\n>>> This patch adds a \"--shelve\" option to the submit subcommand, it will\n>>> save the changes to a perforce shelve instead of commiting them.\n>\n> Looks good to me, thanks!\n>\n> Works a treat.\n\nThanks.\n"}]}