{"thread":{"id":"48516","subject":"Re: [PATCH] git-p4: add options --commit and --disable-rebase","startedAt":"2018-05-18T11:54:26Z","lastAt":"2018-05-21T07:01:14Z","messageCount":2,"participants":["Luke Diamand","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"347981","messageId":"CAE5ih7_U_8TqsWQbCBrATkrOpyAkE2sdgj3KXdovLw7rsXtt6A@mail.gmail.com","threadId":"48516","inReplyTo":"20180509153212.2681-1-merlorom@yahoo.fr","subject":"Re: [PATCH] git-p4: add options --commit and --disable-rebase","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2018-05-18T11:54:22Z","receivedAt":"2018-05-18T11:54:26Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 9 May 2018 at 16:32, Romain Merland <merlorom@yahoo.fr> wrote:\n> On a daily work with multiple local git branches, the usual way to submit only a\n> specified commit was to cherry-pick the commit on master then run git-p4 submit.\n> It can be very annoying to switch between local branches and master, only to\n> submit one commit.\n> The proposed new way is to select directly the commit you want to submit.\n>\n> add option --commit to command 'git-p4 submit' in order to submit only specified commit(s) in p4.\n>\n> On a daily work developping software with big compilation time, one may not want\n> to rebase on his local git tree, in order to avoid long recompilation.\n>\n> add option --disable-rebase to command 'git-p4 submit' in order to disable rebase after submission.\n\nI've been using this for real and it works well for me. Ack.\n\nBecause of the way I'm using git-p4, the --disable-rebase option\ndoesn't really help me - I really need a --disable-sync option but\nthat's a different feature.\n\nThanks\nLuke\n\n\n\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> diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt\n> index 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>         p4/master.  See the \"Sync options\" section above for more\n>         information.\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.\n> diff --git a/git-p4.py b/git-p4.py\n> index 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:\n> diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh\n> index 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>         )\n>  '\n>\n> +# make two commits, but tell it to apply only one\n> +\n> +test_expect_success 'submit --commit one' '\n> +       test_when_finished cleanup_git &&\n> +       git p4 clone --dest=\"$git\" //depot &&\n> +       (\n> +               cd \"$git\" &&\n> +               test_commit \"file9\" &&\n> +               test_commit \"file10\" &&\n> +               git config git-p4.skipSubmitEdit true &&\n> +               git p4 submit --commit HEAD\n> +       ) &&\n> +       (\n> +               cd \"$cli\" &&\n> +               test_path_is_missing \"file9.t\" &&\n> +               test_path_is_file \"file10.t\"\n> +       )\n> +'\n> +\n> +# make three commits, but tell it to apply only range\n> +\n> +test_expect_success 'submit --commit range' '\n> +       test_when_finished cleanup_git &&\n> +       git p4 clone --dest=\"$git\" //depot &&\n> +       (\n> +               cd \"$git\" &&\n> +               test_commit \"file11\" &&\n> +               test_commit \"file12\" &&\n> +               test_commit \"file13\" &&\n> +               git config git-p4.skipSubmitEdit true &&\n> +               git p4 submit --commit HEAD~2..HEAD\n> +       ) &&\n> +       (\n> +               cd \"$cli\" &&\n> +               test_path_is_missing \"file11.t\" &&\n> +               test_path_is_file \"file12.t\" &&\n> +               test_path_is_file \"file13.t\"\n> +       )\n> +'\n> +\n>  #\n>  # Basic submit tests, the five handled cases\n>  #\n> --\n> 2.17.0\n>\n"},{"id":"348182","messageId":"xmqqh8n11oi3.fsf@gitster-ct.c.googlers.com","threadId":"48516","inReplyTo":"CAE5ih7_U_8TqsWQbCBrATkrOpyAkE2sdgj3KXdovLw7rsXtt6A@mail.gmail.com","subject":"Re: [PATCH] git-p4: add options --commit and --disable-rebase","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-21T07:01:08Z","receivedAt":"2018-05-21T07:01:14Z","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 9 May 2018 at 16:32, Romain Merland <merlorom@yahoo.fr> wrote:\n>> On a daily work with multiple local git branches, the usual way to submit only a\n>> specified commit was to cherry-pick the commit on master then run git-p4 submit.\n>> It can be very annoying to switch between local branches and master, only to\n>> submit one commit.\n>> The proposed new way is to select directly the commit you want to submit.\n>>\n>> add option --commit to command 'git-p4 submit' in order to submit only specified commit(s) in p4.\n>>\n>> On a daily work developping software with big compilation time, one may not want\n>> to rebase on his local git tree, in order to avoid long recompilation.\n>>\n>> add option --disable-rebase to command 'git-p4 submit' in order to disable rebase after submission.\n>\n> I've been using this for real and it works well for me. Ack.\n>\n> Because of the way I'm using git-p4, the --disable-rebase option\n> doesn't really help me - I really need a --disable-sync option but\n> that's a different feature.\n\nThese sound like two separate issues that deserve two separate\npatches, but I'll take it as-is with your Reviewed-by:\n\nThe original patch I couldn't find in the public inbox archive, so\nhere is based on what I saw in my spambox (where pieces of e-mail\naddressed to gitster@ but do not appear on the public archive are\nsent).\n\n    ... goes and notices the lack of sign-off\n\nOh, I take it back; I cannot use it as-is, as Romain's sign-off is\nmissing X-<.\n\nRomain, could you sign it off after understanding what it means by\nchecking\n\n    https://git.github.io/htmldocs/SubmittingPatches.html#sign-off\n\nThanks.\n\n-- >8 --\nFrom: Romain Merland <merlorom@yahoo.fr>\nDate: Wed, 9 May 2018 17:32:12 +0200\nSubject: [PATCH] git-p4: add options --commit and --disable-rebase\n\nOn a daily work with multiple local git branches, the usual way to\nsubmit only a specified commit was to cherry-pick the commit on\nmaster then run git-p4 submit.  It can be very annoying to switch\nbetween local branches and master, only to submit one commit.  The\nproposed new way is to select directly the commit you want to\nsubmit.\n\nAdd option --commit to command 'git-p4 submit' in order to submit\nonly specified commit(s) in p4.\n\nOn a daily work developping software with big compilation time, one\nmay not want to rebase on his local git tree, in order to avoid long\nrecompilation.\n\nAdd option --disable-rebase to command 'git-p4 submit' in order to\ndisable rebase after submission.\n\nReviewed-by: Luke Diamand <luke@diamand.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\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 d8c8f11c9f..88d109debb 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 7bb9cadc69..f4a6f3b4c3 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 71cae2874d..2325599ee6 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-582-gccdcbd54c4\n\n"}]}