{"thread":{"id":"48623","subject":"[PATCH 0/1] git-p4: add options --commit and --disable-rebase","startedAt":"2018-06-01T07:46:43Z","lastAt":"2018-06-01T07:47:13Z","messageCount":2,"participants":["Romain Merland"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"348982","messageId":"20180601074614.7856-1-merlorom@yahoo.fr","threadId":"48623","inReplyTo":null,"subject":"[PATCH 0/1] git-p4: add options --commit and --disable-rebase","fromName":"Romain Merland","fromEmail":"merlorom@gmail.com","sentAt":"2018-06-01T07:46:13Z","receivedAt":"2018-06-01T07:46:43Z","isPatch":true,"sender":{"key":"merlorom@gmail.com","avatar":null},"body":"On a daily work with multiple local git branches, the usual way to submit only a\nspecified commit was to cherry-pick the commit on master then run git-p4 submit.\nIt can be very annoying to switch between local branches and master, only to\nsubmit one commit.\nThe proposed new way is to select directly the commit you want to submit.\n\nadd option --commit to command 'git-p4 submit' in order to submit only specified commit(s) in p4.\n\nOn a daily work developping software with big compilation time, one may not want\nto rebase on his local git tree, in order to avoid long recompilation.\n\nadd option --disable-rebase to command 'git-p4 submit' in order to disable rebase after submission.\n\nRomain Merland (1):\n  git-p4: add options --commit and --disable-rebase\n\n Documentation/git-p4.txt | 14 ++++++++++++++\n git-p4.py                | 29 +++++++++++++++++++++++------\n t/t9807-git-p4-submit.sh | 40 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 77 insertions(+), 6 deletions(-)\n\n-- \n2.17.0\n\n"},{"id":"348983","messageId":"20180601074614.7856-2-merlorom@yahoo.fr","threadId":"48623","inReplyTo":"20180601074614.7856-1-merlorom@yahoo.fr","subject":"[PATCH 1/1] git-p4: add options --commit and --disable-rebase","fromName":"Romain Merland","fromEmail":"merlorom@gmail.com","sentAt":"2018-06-01T07:46:14Z","receivedAt":"2018-06-01T07:47:13Z","isPatch":true,"sender":{"key":"merlorom@gmail.com","avatar":null},"body":"On a daily work with multiple local git branches, the usual way to submit only a\nspecified commit was to cherry-pick the commit on master then run git-p4 submit.\nIt can be very annoying to switch between local branches and master, only to\nsubmit one commit.\nThe proposed new way is to select directly the commit you want to submit.\n\nadd option --commit to command 'git-p4 submit' in order to submit only specified commit(s) in p4.\n\nOn a daily work developping software with big compilation time, one may not want\nto rebase on his local git tree, in order to avoid long recompilation.\n\nadd option --disable-rebase to command 'git-p4 submit' in order to disable rebase after submission.\n\nThanks-to: Cedric Borgese <cedric.borgese@gmail.com>\nReviewed-by: Luke Diamand <luke@diamand.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Romain Merland <merlorom@yahoo.fr>\n---\n Documentation/git-p4.txt | 14 ++++++++++++++\n git-p4.py                | 29 +++++++++++++++++++++++------\n t/t9807-git-p4-submit.sh | 40 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 77 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt\nindex d8c8f11c9..88d109deb 100644\n--- a/Documentation/git-p4.txt\n+++ b/Documentation/git-p4.txt\n@@ -149,6 +149,12 @@ To specify a branch other than the current one, use:\n $ git p4 submit topicbranch\n ------------\n \n+To specify a single commit or a range of commits, use:\n+------------\n+$ git p4 submit --commit <sha1>\n+$ git p4 submit --commit <sha1..sha1>\n+------------\n+\n The upstream reference is generally 'refs/remotes/p4/master', but can\n be overridden using the `--origin=` command-line option.\n \n@@ -330,6 +336,14 @@ These options can be used to modify 'git p4 submit' behavior.\n \tp4/master.  See the \"Sync options\" section above for more\n \tinformation.\n \n+--commit <sha1>|<sha1..sha1>::\n+    Submit only the specified commit or range of commits, instead of the full\n+    list of changes that are in the current Git branch.\n+\n+--disable-rebase::\n+    Disable the automatic rebase after all commits have been successfully\n+    submitted.\n+\n Rebase options\n ~~~~~~~~~~~~~~\n These options can be used to modify 'git p4 rebase' behavior.\ndiff --git a/git-p4.py b/git-p4.py\nindex 7bb9cadc6..f4a6f3b4c 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1352,7 +1352,12 @@ class P4Submit(Command, P4UserMap):\n                 optparse.make_option(\"--update-shelve\", dest=\"update_shelve\", action=\"append\", type=\"int\",\n                                      metavar=\"CHANGELIST\",\n                                      help=\"update an existing shelved changelist, implies --shelve, \"\n-                                           \"repeat in-order for multiple shelved changelists\")\n+                                           \"repeat in-order for multiple shelved changelists\"),\n+                optparse.make_option(\"--commit\", dest=\"commit\", metavar=\"COMMIT\",\n+                                     help=\"submit only the specified commit(s), one commit or xxx..xxx\"),\n+                optparse.make_option(\"--disable-rebase\", dest=\"disable_rebase\", action=\"store_true\",\n+                                     help=\"Disable rebase after submit is completed. Can be useful if you \"\n+                                     \"work from a local git branch that is not master\")\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@@ -1362,6 +1367,8 @@ class P4Submit(Command, P4UserMap):\n         self.dry_run = False\n         self.shelve = False\n         self.update_shelve = list()\n+        self.commit = \"\"\n+        self.disable_rebase = False\n         self.prepare_p4_only = False\n         self.conflict_behavior = None\n         self.isWindows = (platform.system() == \"Windows\")\n@@ -2103,9 +2110,18 @@ class P4Submit(Command, P4UserMap):\n         else:\n             commitish = 'HEAD'\n \n-        for line in read_pipe_lines([\"git\", \"rev-list\", \"--no-merges\", \"%s..%s\" % (self.origin, commitish)]):\n-            commits.append(line.strip())\n-        commits.reverse()\n+        if self.commit != \"\":\n+            if self.commit.find(\"..\") != -1:\n+                limits_ish = self.commit.split(\"..\")\n+                for line in read_pipe_lines([\"git\", \"rev-list\", \"--no-merges\", \"%s..%s\" % (limits_ish[0], limits_ish[1])]):\n+                    commits.append(line.strip())\n+                commits.reverse()\n+            else:\n+                commits.append(self.commit)\n+        else:\n+            for line in read_pipe_lines([\"git\", \"rev-list\", \"--no-merges\", \"%s..%s\" % (self.origin, commitish)]):\n+                commits.append(line.strip())\n+            commits.reverse()\n \n         if self.preserveUser or gitConfigBool(\"git-p4.skipUserNameCheck\"):\n             self.checkAuthorship = False\n@@ -2215,8 +2231,9 @@ class P4Submit(Command, P4UserMap):\n                 sync.branch = self.branch\n             sync.run([])\n \n-            rebase = P4Rebase()\n-            rebase.rebase()\n+            if self.disable_rebase is False:\n+                rebase = P4Rebase()\n+                rebase.rebase()\n \n         else:\n             if len(applied) == 0:\ndiff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh\nindex 71cae2874..2325599ee 100755\n--- a/t/t9807-git-p4-submit.sh\n+++ b/t/t9807-git-p4-submit.sh\n@@ -155,6 +155,46 @@ test_expect_success 'allow submit from branch with same revision but different n\n \t)\n '\n \n+# make two commits, but tell it to apply only one\n+\n+test_expect_success 'submit --commit one' '\n+\ttest_when_finished cleanup_git &&\n+\tgit p4 clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\ttest_commit \"file9\" &&\n+\t\ttest_commit \"file10\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit p4 submit --commit HEAD\n+\t) &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\ttest_path_is_missing \"file9.t\" &&\n+\t\ttest_path_is_file \"file10.t\"\n+\t)\n+'\n+\n+# make three commits, but tell it to apply only range\n+\n+test_expect_success 'submit --commit range' '\n+\ttest_when_finished cleanup_git &&\n+\tgit p4 clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\ttest_commit \"file11\" &&\n+\t\ttest_commit \"file12\" &&\n+\t\ttest_commit \"file13\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit p4 submit --commit HEAD~2..HEAD\n+\t) &&\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\ttest_path_is_missing \"file11.t\" &&\n+\t\ttest_path_is_file \"file12.t\" &&\n+\t\ttest_path_is_file \"file13.t\"\n+\t)\n+'\n+\n #\n # Basic submit tests, the five handled cases\n #\n-- \n2.17.0\n\n"}]}