threads / patch / 48401

patchRe: [PATCH] git-p4 - Add option --sha1 to submit in p4

Subject: Re: [PATCH] git-p4 - Add option --sha1 to submit in p4

## tl;dr

2 messages between May 2, 2018 and May 2, 2018. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Luke Diamand· May 2, 2018, 14:55 UTC · lore
On 2 May 2018 at 15:32, Merland Romain <merlorom@yahoo.fr> wrote:
Show 12 quoted lines
> From 4867808cad2b759ebf31c275356e602b72c5659f Mon Sep 17 00:00:00 2001
> From: Romain Merland <merlorom@yahoo.fr>
> To: git@vger.kernel.org
> Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>, Luke
> Diamand <luke@diamand.org>, Vinicius Kursancew <viniciusalexandre@gmail.com>
> Date: Wed, 2 May 2018 15:02:11 +0200
> Subject: [PATCH] git-p4 - Add option --sha1 to submit in p4
>
> Add option --sha1 to command 'git-p4 submit' in order to submit in p4 a
> commit
> that is not necessarily on master.
> In that case, don't rebase the submitted changes.

That could be very useful, I often find the commit I want to submit is half-way down a long list of other commits.

Currently I end up cherry-picking the one I want into a clean repo, but that's much more awkward than your --sha1 change.

A few comments inline:
Show 22 quoted lines
> Signed-off-by: Romain Merland <merlorom@yahoo.fr>
> ---
>  git-p4.py | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 7bb9cadc6..d64ff79dd 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1352,7 +1352,9 @@ class P4Submit(Command, P4UserMap):
>                  optparse.make_option("--update-shelve",
> dest="update_shelve", action="append", type="int",
>                                       metavar="CHANGELIST",
>                                       help="update an existing shelved
> changelist, implies --shelve, "
> -                                           "repeat in-order for multiple
> shelved changelists")
> +                                           "repeat in-order for multiple
> shelved changelists"),
> +                optparse.make_option("--sha1", dest="sha1", metavar="SHA1",
> +                                     help="submit only the specified
> commit, don't rebase afterwards")

Is there a better name than "sha1" ? If git ever changes its hash to something else will this still make sense?

I wonder why you wouldn't rebase afterwards?
Perhaps an additional option to skip the rebase?
Show 36 quoted lines
>          ]
>          self.description = "Submit changes from git to the perforce depot."
>          self.usage += " [name of git branch to submit into perforce depot]"
> @@ -1362,6 +1364,7 @@ class P4Submit(Command, P4UserMap):
>          self.dry_run = False
>          self.shelve = False
>          self.update_shelve = list()
> +        self.sha1 = ""
>          self.prepare_p4_only = False
>          self.conflict_behavior = None
>          self.isWindows = (platform.system() == "Windows")
> @@ -2103,9 +2106,12 @@ class P4Submit(Command, P4UserMap):
>          else:
>              commitish = 'HEAD'
>
> -        for line in read_pipe_lines(["git", "rev-list", "--no-merges",
> "%s..%s" % (self.origin, commitish)]):
> -            commits.append(line.strip())
> -        commits.reverse()
> +        if self.sha1 != "":
> +            commits.append(self.sha1)
> +        else:
> +            for line in read_pipe_lines(["git", "rev-list", "--no-merges",
> "%s..%s" % (self.origin, commitish)]):
> +                commits.append(line.strip())
> +            commits.reverse()
>
>          if self.preserveUser or gitConfigBool("git-p4.skipUserNameCheck"):
>              self.checkAuthorship = False
> @@ -2215,8 +2221,11 @@ class P4Submit(Command, P4UserMap):
>                  sync.branch = self.branch
>              sync.run([])
>
> -            rebase = P4Rebase()
> -            rebase.rebase()
> +            if self.sha1 == "":
if not self.skip_rebase:
Show 11 quoted lines
> +                rebase = P4Rebase()
> +                rebase.rebase()
> +            else:
> +                print "You will have to do 'git p4 sync' and rebase."
>
>          else:
>              if len(applied) == 0:
> --
> 2.17.0
>
>
This would be better with some documentation in git-p4.txt and a test case!

Regards! Luke

Luke Diamand· May 2, 2018, 18:53 UTC · lore
On 2 May 2018 at 16:51, Merland Romain <merlorom@yahoo.fr> wrote:
> Thanks Luke,
>
> Following your comments, I will:
> - change the option name to --commit if it suits you
Seems like a good name.
> - add an option --force-rebase which defaults to false. Setting it to true
> will rebase even with --commit option used.

Or "--disable-rebase" ? I think there's no reason you couldn't rebase after doing a commit like this is there?

And "--disable-rebase" would be useful generally, not just with the --commit option, but also with the regular options.

"--force-rebase" is a bit confusing since for the normal flow, it always rebases anyway, and there's no need to force!

But you're the one who is using this in anger, so your opinion likely counts for more than mine!

> it can be useful too if some commits have been skipped and user wants to
> rebase anyway
> - add an entry in the documentation
> - (learn how to create a test and) add tests for these specific cases

To create a test just look in t/ for the t98*.sh files. Cut-n-paste one or add to an existing one. Send an email here if you get stuck (but it's pretty straightforward).

You can run only the git-p4 tests with:
$ (cd t && make T=t98* -j)
>
> What is the best practice ? to send a new email with the new diff ? to
> continue this discussion ?

I think either, probably a new email is easiest. See Documentation/SubmittingPatches for the general process.

Regards! Luke

← back to recent threads