git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-p4: Add hook p4-pre-pedit-changelist

From
Ben Keene <seraphire@gmail.com>
Date
Jan 30, 2020, 14:20 UTC
Message-ID
<1dfe9fba-ec25-cd44-981a-25f7bcba31cc@gmail.com>
In-Reply-To
<xmqqeevhenbh.fsf@gitster-ct.c.googlers.com>
On 1/29/2020 8:37 PM, Junio C Hamano wrote:
Show 6 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Thanks, but it wasn't very helpful to see an Ack (i.e. "an expert
>> says this is good") without seeing any of my "why is this good?"
>> answered by either the original author or the expert X-<.
> More specifically, to summarize the issues I raised:
Thanks for summarizing your questions, below are my thoughts.
Show 5 quoted lines
>
>   * Is the proposed name of the hook a reasonable one?  If so, the
>     log message should explain why it is a reasonable one.  If not,
>     it should be given a more reasonable name and the log message
>     should justify the new name.

Having re-read your original comments, no, I think that I should change the name of the hook from "p4-pre-edit-changelist" to follow the git standard hooks:

* "p4-prepare-changelist" - This will replace the proposed hook but still
   take only the filename. This hook will be called, even if the
   prepare-p4-only option is selected.
* "p4-changelist" - this is a new hook that will be added after the
   user edit of the changelist text, but prior to the actual submission.
   This hook will also take the temporary file as it's only parameter
   and a failed response will fail the submission.
Show 5 quoted lines
>   * Given that "git commit" has a pair of hooks for log message, is
>     adding one new hook a reasonable thing?  If so, the log mesasge
>     should explain why (e.g. perhaps the other one already is there,
>     or perhaps the other one is not applicable in the context of
>     interacting with P4 with such and such reasons).)
I agree with your suggestion.
>   * Is it reasonable not to have a mechanism to disable/skip the
>     hook, like "git commit" does?  If not, the log message should
>     explain why such an escape hatch, which is needed for "git
>     commit", is not needed.

The existing hook, p4-pre-submit, does not have an escape hatch, so I did not add one to this method, but I can certainly add one.

I am amenable to adding an escape hatch, I'll add --no-verify.
>
>   * githooks(5) manual page is supposed to list all hooks, so a patch
>     that adds a new one should add a description for it in there.
I'll add text for these files (githooks and the git-p4 pages).
I'll make a new submission soon.
Show 85 quoted lines
>
> Thanks.
>
>>>> "Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:
>>>>
>>>>> From: Ben Keene <seraphire@gmail.com>
>>>>> Subject: Re: [PATCH] git-p4: Add hook p4-pre-pedit-changelist
>>>> "git shortlog --no-merges" would show that the convention is to
>>>> downcase "Add".
>>>>
>>>> With two consecutive non-words (i.e. 'pre' and "pedit'), it really
>>>> feels an unpronounceable mouthful to a non-perforce person like me.
>>>>
>>>> On the core Git side, "git commit", which is the primary command
>>>> that is used to create a new commit, has two hooks that helps to
>>>> enforce consistency to the commit log messages:
>>>>
>>>>   - The "prepare-commit-msg" hook prepares the message to be further
>>>>     edited by the end-user in the editor
>>>>
>>>>   - The "commit-msg" hook takes what the end-user edited in the
>>>>     editor, and can audit and/or tweaks it.
>>>>
>>>> Having a matching pair of hooks and making sure the new hooks have
>>>> similar names to these existing ones may help experienced Git users
>>>> adopt the new hooks "git p4" learns here.
>>>>
>>>> What makes "p4-pre-pedit-changelist" a good name for this hook?  "In
>>>> pure Perforce without Git, there is 'pre-pedit-changelist' hook that
>>>> Perforce users are already familiar with" would be a good answer but
>>>> not being P4 user myself, I do not know if that is true.
>>>>
>>>> Also, "git commit" has a mechanism (i.e. "--no-verify") to suppress
>>>> the "auditing" hook, and it serves as an escape hatch.  The new hook
>>>> "git p4" learns may want to have a similar mechanism, to keep its
>>>> users productive even when they have broken/stale/bogus hook rejects
>>>> their legitimate log message, by allowing them to bypass the
>>>> offending hook(s).
>>>>
>>>>
>>>>> Add an additional hook to the git-p4 command to allow a hook to modify
>>>>> the text of the changelist prior to displaying the p4editor command.
>>>>>
>>>>> This hook will be called prior to checking for the flag
>>>>> "--prepare-p4-only".
>>>>>
>>>>> The hook is optional, if it does not exist, it will be skipped.
>>>>>
>>>>> The hook takes a single parameter, the filename of the temporary file
>>>>> that contains the P4 submit text.
>>>>>
>>>>> The hook should return a zero exit code on success or a non-zero exit
>>>>> code on failure.  If the hook returns a non-zero exit code, git-p4
>>>>> will revert the P4 edits by calling p4_revert(f) on each file that was
>>>>> flagged as edited and then it will return False so the calling method
>>>>> may continue as it does in existing failure cases.
>>>> The githooks(5) page should talk about some of these, I would think.
>>>>
>>>>>   git-p4.py | 11 +++++++++++
>>>>>   1 file changed, 11 insertions(+)
>>>>>
>>>>> diff --git a/git-p4.py b/git-p4.py
>>>>> index 40d9e7c594..1f8c7383df 100755
>>>>> --- a/git-p4.py
>>>>> +++ b/git-p4.py
>>>>> @@ -2026,6 +2026,17 @@ def applyCommit(self, id):
>>>>>           tmpFile.write(submitTemplate)
>>>>>           tmpFile.close()
>>>>>
>>>>> +        # Run the pre-edit hook to allow programmatic update to the changelist
>>>>> +        hooks_path = gitConfig("core.hooksPath")
>>>>> +        if len(hooks_path) <= 0:
>>>>> +            hooks_path = os.path.join(os.environ.get("GIT_DIR", ".git"), "hooks")
>>>>> +
>>>>> +        hook_file = os.path.join(hooks_path, "p4-pre-edit-changelist")
>>>>> +        if os.path.isfile(hook_file) and os.access(hook_file, os.X_OK) and subprocess.call([hook_file, fileName]) != 0:
>>>>> +            for f in editedFiles:
>>>>> +                p4_revert(f)
>>>>> +            return False
>>>>> +
>>>>>           if self.prepare_p4_only:
>>>>>               #
>>>>>               # Leave the p4 tree prepared, and the submit template around
>>>>>
>>>>> base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 57 in “git-p4: Add hook p4-pre-pedit-changelist”
  1. git-p4: Add hook p4-pre-pedit-changelistBen Keene via GitGitGadget, Jan 20, 2020
  2. Junio C HamanoJan 21, 2020
  3. Luke DiamandJan 29, 2020
  4. Junio C HamanoJan 29, 2020
  5. Luke DiamandJan 29, 2020
  6. Junio C HamanoJan 30, 2020
  7. Ben KeeneJan 30, 2020
  8. Junio C HamanoJan 30, 2020
  9. Bryan TurnerJan 30, 2020
  10. Ben KeeneJan 30, 2020
  11. 0/4 git-p4: add hook p4-pre-edit-changelistBen Keene via GitGitGadget, Jan 31, 2020
  12. 1/4 git-p4: rewrite prompt to be Windows compatibleBen Keene via GitGitGadget, Jan 31, 2020
  13. 3/4 git-p4: add hook p4-pre-edit-changelistBen Keene via GitGitGadget, Jan 31, 2020
  14. 2/4 git-p4: create new method gitRunHookBen Keene via GitGitGadget, Jan 31, 2020
  15. Junio C HamanoFeb 4, 2020
  16. Ben KeeneFeb 5, 2020
  17. Junio C HamanoFeb 5, 2020
  18. Ben KeeneFeb 6, 2020
  19. Junio C HamanoFeb 6, 2020
  20. 4/4 git-p4: add p4 submit hooksBen Keene via GitGitGadget, Jan 31, 2020
  21. Junio C HamanoFeb 4, 2020
  22. 0/5 git-p4: add hook p4-pre-edit-changelistBen Keene via GitGitGadget, Feb 6, 2020
  23. 1/5 git-p4: rewrite prompt to be Windows compatibleBen Keene via GitGitGadget, Feb 6, 2020
  24. Junio C HamanoFeb 6, 2020
  25. Ben KeeneFeb 10, 2020
  26. 2/5 git-p4: create new function run_git_hookBen Keene via GitGitGadget, Feb 6, 2020
  27. Junio C HamanoFeb 6, 2020
  28. Ben KeeneFeb 10, 2020
  29. 3/5 git-p4: add --no-verify optionBen Keene via GitGitGadget, Feb 6, 2020
  30. Junio C HamanoFeb 6, 2020
  31. Ben KeeneFeb 10, 2020
  32. 4/5 git-p4: restructure code in submitBen Keene via GitGitGadget, Feb 6, 2020
  33. 5/5 git-p4: add p4 submit hooksBen Keene via GitGitGadget, Feb 6, 2020
  34. 0/6 git-p4: add hooks for p4-changelistBen Keene via GitGitGadget, Feb 10, 2020
  35. 1/6 git-p4: rewrite prompt to be Windows compatibleBen Keene via GitGitGadget, Feb 10, 2020
  36. 4/6 git-p4: restructure code in submitBen Keene via GitGitGadget, Feb 10, 2020
  37. 6/6 git-4: add RCS keyword status messageBen Keene via GitGitGadget, Feb 10, 2020
  38. 2/6 git-p4: create new function run_git_hookBen Keene via GitGitGadget, Feb 10, 2020
  39. Junio C HamanoFeb 10, 2020
  40. 3/6 git-p4: add --no-verify optionBen Keene via GitGitGadget, Feb 10, 2020
  41. 5/6 git-p4: add p4 submit hooksBen Keene via GitGitGadget, Feb 10, 2020
  42. 0/7 git-p4: add hooks for p4-changelistBen Keene via GitGitGadget, Feb 11, 2020
  43. 1/7 git-p4: rewrite prompt to be Windows compatibleBen Keene via GitGitGadget, Feb 11, 2020
  44. 2/7 git-p4: create new function run_git_hookBen Keene via GitGitGadget, Feb 11, 2020
  45. 5/7 git-p4: restructure code in submitBen Keene via GitGitGadget, Feb 11, 2020
  46. 6/7 git-p4: add p4 submit hooksBen Keene via GitGitGadget, Feb 11, 2020
  47. 3/7 git-p4: add p4-pre-submit exit textBen Keene via GitGitGadget, Feb 11, 2020
  48. 4/7 git-p4: add --no-verify optionBen Keene via GitGitGadget, Feb 11, 2020
  49. 7/7 git-p4: add RCS keyword status messageBen Keene via GitGitGadget, Feb 11, 2020
  50. 0/7 git-p4: add hooks for p4-changelistBen Keene via GitGitGadget, Feb 14, 2020
  51. 1/7 git-p4: rewrite prompt to be Windows compatibleBen Keene via GitGitGadget, Feb 14, 2020
  52. 2/7 git-p4: create new function run_git_hookBen Keene via GitGitGadget, Feb 14, 2020
  53. 3/7 git-p4: add p4-pre-submit exit textBen Keene via GitGitGadget, Feb 14, 2020
  54. 5/7 git-p4: restructure code in submitBen Keene via GitGitGadget, Feb 14, 2020
  55. 4/7 git-p4: add --no-verify optionBen Keene via GitGitGadget, Feb 14, 2020
  56. 6/7 git-p4: add p4 submit hooksBen Keene via GitGitGadget, Feb 14, 2020
  57. 7/7 git-p4: add RCS keyword status messageBen Keene via GitGitGadget, Feb 14, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.