{"thread":{"id":"48433","subject":"Re: [PATCH] git-p4: add options --commit and --disable-rebase","startedAt":"2018-05-09T08:20:19Z","lastAt":"2018-05-09T08:20:19Z","messageCount":1,"participants":["Luke Diamand"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"347058","messageId":"CAE5ih7_u+7BzCRe4X9HjTgp9GxK34Co1v1kY=W=7Wa65inbkEg@mail.gmail.com","threadId":"48433","inReplyTo":"569077545.8373111.1525739857273@mail.yahoo.com","subject":"Re: [PATCH] git-p4: add options --commit and --disable-rebase","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2018-05-09T08:20:12Z","receivedAt":"2018-05-09T08:20:19Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 8 May 2018 at 01:37, Merland Romain <merlorom@yahoo.fr> wrote:\n> From f5229be8e2a3340af853227929818940323a8062 Mon Sep 17 00:00:00 2001\n> From: Romain Merland <merlorom@yahoo.fr>\n> Date: Tue, 8 May 2018 02:03:11 +0200\n> Subject: [PATCH] git-p4: add options --commit and --disable-rebase\n> To: git@vger.kernel.org\n> Cc: Luke Diamand <luke@diamand.org>,\n>     Junio C Hamano <gitster@pobox.com>,\n>     Matthieu Moy <Matthieu.Moy@imag.fr>,\n>     Vinicius Kursancew <viniciusalexandre@gmail.com>,\n>     Jeff King <peff@peff.net>,\n>     Cedric Borgese <cedric.borgese@pdgm.com>,\n>     Fabien Boutantin <fabien.boutantin@pdgm.com>\n> Thanks-to: Cedric Borgese\n> Signed-off-by: Romain Merland\n>\n> On a daily work with multiple local git branches, the usual way to submit\n> only a\n> specified commit was to cherry-pick the commit on master then run git-p4\n> 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\n> specified commit(s) in p4.\n>\n> On a daily work developping software with big compilation time, one may not\n> 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\n> rebase after submission.\n\nLooks good to me.\n\nI just tried it (shelving a change about 3 commits down) and it works\nlike a charm!\n\nThe \"--disable-rebase\" will also be very useful (I wonder whether a\ngit-config option might be a useful addition at a later date).\n\n(You might need to resubmit your change as plain text via \"git\nformat-patch\" and \"git send-email\" as I'm not sure if Junio will\naccept a mime-encoded patch).\n\nThanks\nLuke\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'\n> 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\n> 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\",\n> dest=\"update_shelve\", action=\"append\", type=\"int\",\n>                                       metavar=\"CHANGELIST\",\n>                                       help=\"update an existing shelved\n> changelist, implies --shelve, \"\n> -                                           \"repeat in-order for multiple\n> shelved changelists\")\n> +                                           \"repeat in-order for multiple\n> shelved changelists\"),\n> +                optparse.make_option(\"--commit\", dest=\"commit\",\n> metavar=\"COMMIT\",\n> +                                     help=\"submit only the specified\n> commit(s), one commit or xxx..xxx\"),\n> +                optparse.make_option(\"--disable-rebase\",\n> dest=\"disable_rebase\", action=\"store_true\",\n> +                                     help=\"Disable rebase after submit is\n> completed. Can be useful if you \"\n> +                                     \"work from a local git branch that is\n> 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\",\n> \"%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\",\n> \"--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\",\n> \"%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\n> 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>\n"}]}