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

Re: [PATCH v2 2/4] git-p4: create new method gitRunHook

From
Ben Keene <seraphire@gmail.com>
Date
Feb 6, 2020, 14:00 UTC
Message-ID
<9cf8790e-6d13-4653-cddc-f5328f22b0df@gmail.com>
In-Reply-To
<xmqq36bohfsi.fsf@gitster-ct.c.googlers.com>
On 2/5/2020 4:42 PM, Junio C Hamano wrote:
Show 27 quoted lines
> Ben Keene <seraphire@gmail.com> writes:
>
>>>> +        hooks_path = os.path.join(os.environ.get("GIT_DIR", ".git"), "hooks")
>>> This assumes that the process when his function is called (by the
>>> way, even though the title of the patch uses the word "method", this
>>> is not a method but a function, no?), it is always at the top level
>>> of the working tree.  Is that a good assumption?  I don't know the
>>> code well, so "yes it is good because a very early thing we do is to
>>> go up to the top" is a good answer.
>> I'm not sure what you mean by top level of the tree unless you mean
>> that it is not part of a class, but a "Free standing" function?
> No.  The discussion about function vs method was over immediately
> after we left the parentheses ;-)
>
> The "top level of the working tree" is the directory where the files
> you see in "git ls-tree $commit^{tree}" would appear in.  In our
> project, that is where the primary Makefile, COPYING, Documentation/,
> etc. hangs from.
>
> The code in your patch (quoted above) says that "When $GIT_DIR is
> not set, '.git/hooks/' is the directory the hooks live in".  That is
> true only when your process is at the top level of the working tree.
> If you chdir'ed to a subdirectory (e.g. Documentation/ in our
> project) and then let the quoted code run, hooks_path is set to
> ".git/hooks/", but from the point of view of the process running
> inside "Documentation/" subdirectory, it should actually be
> "../.git/hooks/", right?

Okay, NOW I get what you meant.  Thank you for the explanation! The hook directory resolution is what was originally found in the git-p4.py script.  I just tried to describe what it is doing because I moved the code around.

As best as I understand the mechanics, and I haven't examined the source code of git, this is just experimental, the GIT_DIR environment value is set (at least in Git for Windows) when the program is executed, so this always has GIT_DIR set, which may be why this wasn't an issue in the past?

Does this prompt the need to search the hierarchy if we don't find the directory?

Show 15 quoted lines
>> And
>> yes, it returns a value so it should be called a function. I'll
>> correct that.
> This is an irrelevant tangent ;-) but yeah, it is a function, as
> opposed to a method, because it is not attached to any class.  I did
> not think Python differentiated functions that return a value and
> ones that do not (e.g. Pascal call the latter "procedure").
>
>> I chose to not put the function within a class so
>> that if other hooks should be added, it would not require a refactoring
>> of the code to use the function in other classes.
> I think that is a sensible design decision to have a free-standing
> function to execute hooks.
>
> Thanks.
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 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.