git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] githooks.txt: Clarify documentation on reference-transaction hook
@ 2021-02-25  5:50 Patrick Steinhardt
  2021-02-26  6:03 ` Jeff King
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Patrick Steinhardt @ 2021-02-25  5:50 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Yaron Wittenstein, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 2067 bytes --]

The reference-transaction hook doesn't clearly document its scope and
what values it receives as input. Document it to make it less surprising
and clearly delimit its (current) scope.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---

I've been postponing doing this simple doc update for far too long, but
here it finally is. It simply clarifies its current workings and
limitations without changing anything. This is not supposed to be a "We
don't want it to ever cover symrefs", but rather to avoid confusion.

Patrick

 Documentation/githooks.txt | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 1f3b57d04d..b01de04702 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -473,7 +473,8 @@ reference-transaction
 
 This hook is invoked by any Git command that performs reference
 updates. It executes whenever a reference transaction is prepared,
-committed or aborted and may thus get called multiple times.
+committed or aborted and may thus get called multiple times. The hook
+does not cover symbolic references.
 
 The hook takes exactly one argument, which is the current state the
 given reference transaction is in:
@@ -492,6 +493,13 @@ receives on standard input a line of the format:
 
   <old-value> SP <new-value> SP <ref-name> LF
 
+where `<old-value>` is the old object name passed into the reference
+transaction, `<new-value>` is the new object name to be stored in the
+ref and `<ref-name>` is the full name of the ref. When force updating
+the reference regardless of its current value or when the reference is
+to be created anew, `<old-value>` is 40 `0`. To distinguish these cases,
+you can inspect the current value of `<ref-name>` via `git rev-parse`.
+
 The exit status of the hook is ignored for any state except for the
 "prepared" state. In the "prepared" state, a non-zero exit status will
 cause the transaction to be aborted. The hook will not be called with
-- 
2.30.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] githooks.txt: Clarify documentation on reference-transaction hook
  2021-02-25  5:50 [PATCH] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
@ 2021-02-26  6:03 ` Jeff King
  2021-03-01  9:33   ` Patrick Steinhardt
  2021-03-01  9:43 ` [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties Patrick Steinhardt
  2021-03-01  9:43 ` [PATCH v2 2/2] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
  2 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2021-02-26  6:03 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git, Yaron Wittenstein, Junio C Hamano

On Thu, Feb 25, 2021 at 06:50:12AM +0100, Patrick Steinhardt wrote:

> The reference-transaction hook doesn't clearly document its scope and
> what values it receives as input. Document it to make it less surprising
> and clearly delimit its (current) scope.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> 
> I've been postponing doing this simple doc update for far too long, but
> here it finally is. It simply clarifies its current workings and
> limitations without changing anything. This is not supposed to be a "We
> don't want it to ever cover symrefs", but rather to avoid confusion.

I think that's a good step forward. We might want to say "does not cover
symbolic references (but that may change in the future)" to make it
clear that nothing is definite.

OTOH, I suspect adding them would require a change to the hook's stdin
format, so it is not like a hook could be written in a way to magically
handle them if things change in the future.

> @@ -492,6 +493,13 @@ receives on standard input a line of the format:
>  
>    <old-value> SP <new-value> SP <ref-name> LF
>  
> +where `<old-value>` is the old object name passed into the reference
> +transaction, `<new-value>` is the new object name to be stored in the
> +ref and `<ref-name>` is the full name of the ref. When force updating
> +the reference regardless of its current value or when the reference is
> +to be created anew, `<old-value>` is 40 `0`. To distinguish these cases,
> +you can inspect the current value of `<ref-name>` via `git rev-parse`.

We should probably avoid saying "40" here. Maybe "all zeroes" or
something.

-Peff

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] githooks.txt: Clarify documentation on reference-transaction hook
  2021-02-26  6:03 ` Jeff King
@ 2021-03-01  9:33   ` Patrick Steinhardt
  0 siblings, 0 replies; 7+ messages in thread
From: Patrick Steinhardt @ 2021-03-01  9:33 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Yaron Wittenstein, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 2407 bytes --]

On Fri, Feb 26, 2021 at 01:03:43AM -0500, Jeff King wrote:
> On Thu, Feb 25, 2021 at 06:50:12AM +0100, Patrick Steinhardt wrote:
> 
> > The reference-transaction hook doesn't clearly document its scope and
> > what values it receives as input. Document it to make it less surprising
> > and clearly delimit its (current) scope.
> > 
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> > 
> > I've been postponing doing this simple doc update for far too long, but
> > here it finally is. It simply clarifies its current workings and
> > limitations without changing anything. This is not supposed to be a "We
> > don't want it to ever cover symrefs", but rather to avoid confusion.
> 
> I think that's a good step forward. We might want to say "does not cover
> symbolic references (but that may change in the future)" to make it
> clear that nothing is definite.

Fair, I'll add that.

> OTOH, I suspect adding them would require a change to the hook's stdin
> format, so it is not like a hook could be written in a way to magically
> handle them if things change in the future.

Yeah. Hindsight is 20/20, but this should've used some kind of prefix
with the explicitly stated hint that additional prefixed can be added in
the future. I've got myself to blame for that, I should've known better
to make this more readily extensible.

> > @@ -492,6 +493,13 @@ receives on standard input a line of the format:
> >  
> >    <old-value> SP <new-value> SP <ref-name> LF
> >  
> > +where `<old-value>` is the old object name passed into the reference
> > +transaction, `<new-value>` is the new object name to be stored in the
> > +ref and `<ref-name>` is the full name of the ref. When force updating
> > +the reference regardless of its current value or when the reference is
> > +to be created anew, `<old-value>` is 40 `0`. To distinguish these cases,
> > +you can inspect the current value of `<ref-name>` via `git rev-parse`.
> 
> We should probably avoid saying "40" here. Maybe "all zeroes" or
> something.
> 
> -Peff

I wasn't completely sure how to word this and thus opted to do the same
as the other hooks. Most notably, both pre-push and pre-receive hook
explicitly call out SHA-1 and the 40-character thingy.

Maybe I'll just add a patch on top to also change those to instead say
"the all-zero object ID" or something similar.

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties
  2021-02-25  5:50 [PATCH] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
  2021-02-26  6:03 ` Jeff King
@ 2021-03-01  9:43 ` Patrick Steinhardt
  2021-03-01 16:48   ` Junio C Hamano
  2021-03-01  9:43 ` [PATCH v2 2/2] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
  2 siblings, 1 reply; 7+ messages in thread
From: Patrick Steinhardt @ 2021-03-01  9:43 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Yaron Wittenstein, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 4037 bytes --]

The githooks(5) documentation states in several places that the hook
will receive a SHA-1 or hashes of 40 characters length. Given that we're
transitioning to a world where both SHA-1 and SHA-256 are supported,
this is inaccurate.

Fix the issue by replacing mentions of SHA-1 with "object name" and not
explicitly mentioning the hash size.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/githooks.txt | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 1f3b57d04d..4dad80052e 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -138,7 +138,7 @@ given); `template` (if a `-t` option was given or the
 configuration option `commit.template` is set); `merge` (if the
 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
-a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given).
+a commit object name (if a `-c`, `-C` or `--amend` option was given).
 
 If the exit status is non-zero, `git commit` will abort.
 
@@ -231,19 +231,19 @@ named remote is not being used both values will be the same.
 Information about what is to be pushed is provided on the hook's standard
 input with lines of the form:
 
-  <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
+  <local ref> SP <local object name> SP <remote ref> SP <remote object name> LF
 
 For instance, if the command +git push origin master:foreign+ were run the
 hook would receive a line like the following:
 
   refs/heads/master 67890 refs/heads/foreign 12345
 
-although the full, 40-character SHA-1s would be supplied.  If the foreign ref
-does not yet exist the `<remote SHA-1>` will be 40 `0`.  If a ref is to be
-deleted, the `<local ref>` will be supplied as `(delete)` and the `<local
-SHA-1>` will be 40 `0`.  If the local commit was specified by something other
-than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be
-supplied as it was originally given.
+although the full object name would be supplied.  If the foreign ref does not
+yet exist the `<remote object name>` will be the all-zeroes object name.  If a
+ref is to be deleted, the `<local ref>` will be supplied as `(delete)` and the
+`<local object name>` will be the all-zeroes object name.  If the local commit
+was specified by something other than a name which could be expanded (such as
+`HEAD~`, or an object name) it will be supplied as it was originally given.
 
 If this hook exits with a non-zero status, `git push` will abort without
 pushing anything.  Information about why the push is rejected may be sent
@@ -268,7 +268,7 @@ input a line of the format:
 where `<old-value>` is the old object name stored in the ref,
 `<new-value>` is the new object name to be stored in the ref and
 `<ref-name>` is the full name of the ref.
-When creating a new ref, `<old-value>` is 40 `0`.
+When creating a new ref, `<old-value>` is the all-zeroes object name.
 
 If the hook exits with non-zero status, none of the refs will be
 updated. If the hook exits with zero, updating of individual refs can
@@ -550,7 +550,7 @@ command-dependent arguments may be passed in the future.
 The hook receives a list of the rewritten commits on stdin, in the
 format
 
-  <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
+  <old-object-name> SP <new-object-name> [ SP <extra-info> ] LF
 
 The 'extra-info' is again command-dependent.  If it is empty, the
 preceding SP is also omitted.  Currently, no commands pass any
@@ -566,7 +566,7 @@ rebase::
 	For the 'squash' and 'fixup' operation, all commits that were
 	squashed are listed as being rewritten to the squashed commit.
 	This means that there will be several lines sharing the same
-	'new-sha1'.
+	'new-object-name'.
 +
 The commits are guaranteed to be listed in the order that they were
 processed by rebase.
-- 
2.30.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] githooks.txt: Clarify documentation on reference-transaction hook
  2021-02-25  5:50 [PATCH] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
  2021-02-26  6:03 ` Jeff King
  2021-03-01  9:43 ` [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties Patrick Steinhardt
@ 2021-03-01  9:43 ` Patrick Steinhardt
  2021-03-01 16:54   ` Junio C Hamano
  2 siblings, 1 reply; 7+ messages in thread
From: Patrick Steinhardt @ 2021-03-01  9:43 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Yaron Wittenstein, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 1830 bytes --]

The reference-transaction hook doesn't clearly document its scope and
what values it receives as input. Document it to make it less surprising
and clearly delimit its (current) scope.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/githooks.txt | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 4dad80052e..b51959ff94 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -473,7 +473,8 @@ reference-transaction
 
 This hook is invoked by any Git command that performs reference
 updates. It executes whenever a reference transaction is prepared,
-committed or aborted and may thus get called multiple times.
+committed or aborted and may thus get called multiple times. The hook
+does not cover symbolic references (but that may change in the future).
 
 The hook takes exactly one argument, which is the current state the
 given reference transaction is in:
@@ -492,6 +493,14 @@ receives on standard input a line of the format:
 
   <old-value> SP <new-value> SP <ref-name> LF
 
+where `<old-value>` is the old object name passed into the reference
+transaction, `<new-value>` is the new object name to be stored in the
+ref and `<ref-name>` is the full name of the ref. When force updating
+the reference regardless of its current value or when the reference is
+to be created anew, `<old-value>` is the all-zeroes object name. To
+distinguish these cases, you can inspect the current value of
+`<ref-name>` via `git rev-parse`.
+
 The exit status of the hook is ignored for any state except for the
 "prepared" state. In the "prepared" state, a non-zero exit status will
 cause the transaction to be aborted. The hook will not be called with
-- 
2.30.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties
  2021-03-01  9:43 ` [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties Patrick Steinhardt
@ 2021-03-01 16:48   ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2021-03-01 16:48 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git, Jeff King, Yaron Wittenstein

Patrick Steinhardt <ps@pks.im> writes:

> Subject: Re: [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties

Looking at "git shortlog --no-merges -200 master" output, I'd
suggest to please downcase "Replace" to match.

> The githooks(5) documentation states in several places that the hook
> will receive a SHA-1 or hashes of 40 characters length. Given that we're
> transitioning to a world where both SHA-1 and SHA-256 are supported,
> this is inaccurate.
>
> Fix the issue by replacing mentions of SHA-1 with "object name" and not
> explicitly mentioning the hash size.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  Documentation/githooks.txt | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
> index 1f3b57d04d..4dad80052e 100644
> --- a/Documentation/githooks.txt
> +++ b/Documentation/githooks.txt
> @@ -138,7 +138,7 @@ given); `template` (if a `-t` option was given or the
>  configuration option `commit.template` is set); `merge` (if the
>  commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
>  (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
> -a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given).
> +a commit object name (if a `-c`, `-C` or `--amend` option was given).
>  
>  If the exit status is non-zero, `git commit` will abort.
>  
> @@ -231,19 +231,19 @@ named remote is not being used both values will be the same.
>  Information about what is to be pushed is provided on the hook's standard
>  input with lines of the form:
>  
> -  <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
> +  <local ref> SP <local object name> SP <remote ref> SP <remote object name> LF
>  
>  For instance, if the command +git push origin master:foreign+ were run the
>  hook would receive a line like the following:
>  
>    refs/heads/master 67890 refs/heads/foreign 12345
>  
> -although the full, 40-character SHA-1s would be supplied.  If the foreign ref
> -does not yet exist the `<remote SHA-1>` will be 40 `0`.  If a ref is to be
> -deleted, the `<local ref>` will be supplied as `(delete)` and the `<local
> -SHA-1>` will be 40 `0`.  If the local commit was specified by something other
> -than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be
> -supplied as it was originally given.
> +although the full object name would be supplied.  If the foreign ref does not
> +yet exist the `<remote object name>` will be the all-zeroes object name.  If a
> +ref is to be deleted, the `<local ref>` will be supplied as `(delete)` and the
> +`<local object name>` will be the all-zeroes object name.  If the local commit
> +was specified by something other than a name which could be expanded (such as
> +`HEAD~`, or an object name) it will be supplied as it was originally given.
>  
>  If this hook exits with a non-zero status, `git push` will abort without
>  pushing anything.  Information about why the push is rejected may be sent
> @@ -268,7 +268,7 @@ input a line of the format:
>  where `<old-value>` is the old object name stored in the ref,
>  `<new-value>` is the new object name to be stored in the ref and
>  `<ref-name>` is the full name of the ref.
> -When creating a new ref, `<old-value>` is 40 `0`.
> +When creating a new ref, `<old-value>` is the all-zeroes object name.
>  
>  If the hook exits with non-zero status, none of the refs will be
>  updated. If the hook exits with zero, updating of individual refs can
> @@ -550,7 +550,7 @@ command-dependent arguments may be passed in the future.
>  The hook receives a list of the rewritten commits on stdin, in the
>  format
>  
> -  <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
> +  <old-object-name> SP <new-object-name> [ SP <extra-info> ] LF

<???-object-name> is a tad longer than the original as a
placeholder, but this line does not look so bad.

Thanks.

>  The 'extra-info' is again command-dependent.  If it is empty, the
>  preceding SP is also omitted.  Currently, no commands pass any
> @@ -566,7 +566,7 @@ rebase::
>  	For the 'squash' and 'fixup' operation, all commits that were
>  	squashed are listed as being rewritten to the squashed commit.
>  	This means that there will be several lines sharing the same
> -	'new-sha1'.
> +	'new-object-name'.
>  +
>  The commits are guaranteed to be listed in the order that they were
>  processed by rebase.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] githooks.txt: Clarify documentation on reference-transaction hook
  2021-03-01  9:43 ` [PATCH v2 2/2] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
@ 2021-03-01 16:54   ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2021-03-01 16:54 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git, Jeff King, Yaron Wittenstein

Patrick Steinhardt <ps@pks.im> writes:

> The reference-transaction hook doesn't clearly document its scope and
> what values it receives as input. Document it to make it less surprising
> and clearly delimit its (current) scope.

Sounds good (especially "that may change in the future" part is a
nice touch).

Thanks.

> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  Documentation/githooks.txt | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
> index 4dad80052e..b51959ff94 100644
> --- a/Documentation/githooks.txt
> +++ b/Documentation/githooks.txt
> @@ -473,7 +473,8 @@ reference-transaction
>  
>  This hook is invoked by any Git command that performs reference
>  updates. It executes whenever a reference transaction is prepared,
> -committed or aborted and may thus get called multiple times.
> +committed or aborted and may thus get called multiple times. The hook
> +does not cover symbolic references (but that may change in the future).
>  
>  The hook takes exactly one argument, which is the current state the
>  given reference transaction is in:
> @@ -492,6 +493,14 @@ receives on standard input a line of the format:
>  
>    <old-value> SP <new-value> SP <ref-name> LF
>  
> +where `<old-value>` is the old object name passed into the reference
> +transaction, `<new-value>` is the new object name to be stored in the
> +ref and `<ref-name>` is the full name of the ref. When force updating
> +the reference regardless of its current value or when the reference is
> +to be created anew, `<old-value>` is the all-zeroes object name. To
> +distinguish these cases, you can inspect the current value of
> +`<ref-name>` via `git rev-parse`.
> +
>  The exit status of the hook is ignored for any state except for the
>  "prepared" state. In the "prepared" state, a non-zero exit status will
>  cause the transaction to be aborted. The hook will not be called with

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-01 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-25  5:50 [PATCH] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
2021-02-26  6:03 ` Jeff King
2021-03-01  9:33   ` Patrick Steinhardt
2021-03-01  9:43 ` [PATCH v2 1/2] githooks.txt: Replace mentions of SHA-1 specific properties Patrick Steinhardt
2021-03-01 16:48   ` Junio C Hamano
2021-03-01  9:43 ` [PATCH v2 2/2] githooks.txt: Clarify documentation on reference-transaction hook Patrick Steinhardt
2021-03-01 16:54   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).