Skip to content

sample hooks: become hash agnostic

Denton Liu git 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 1 replyIn review
  2. v14 patches 13 repliesSuperseded

Changes in v2 from the cover letter

* Don't implement git rev-parse --null-oid

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3hooks--pre-push.sample: modernize scripttemplates/hooks--pre-push.sample+8 -80 replies
2/3hooks--pre-push.sample: use hash-agnostic zero OIDtemplates/hooks--pre-push.sample+3 -30 replies
3/3hooks--update.sample: use hash-agnostic zero OIDtemplates/hooks--update.sample+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] sample hooks: become hash agnostic

There are currently two hooks that have hardcoded 40 zeros as the null OID and, thus, are not hash-agnostic. Rewrite these to get the zero OID using

	git hash-object --stdin </dev/null | tr '[0-9a-f]' '0'

so that the zero OID is hash-agnostic.

This was initially done by introducing git rev-parse --null-oid to get the zero OID but that seems like overkill. From a cursory search of Github, the only instances of the zero OID being used come from clones of the git.git repository (tests and sample hooks). Since we don't want to introduce an option that no one will use, don't go this route and just do the easiest thing.

If in the future, someone decides that git rev-parse --zero-oid is useful, they can also adjust these hooks accordingly.

Changes since v1:

* Don't implement git rev-parse --null-oid

Denton Liu (3):
hooks--pre-push.sample: modernize script hooks--pre-push.sample: use hash-agnostic zero OID hooks--update.sample: use hash-agnostic zero OID

 templates/hooks--pre-push.sample | 18 +++++++++---------
 templates/hooks--update.sample   |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

Range-diff against v1:

1:  ed1ade7328 < -:  ---------- hooks--pre-push.sample: prefer $() for command substitution
2:  004f2e4c92 < -:  ---------- builtin/rev-parse: learn --null-oid
3:  9d6c2951ab < -:  ---------- hooks--pre-push.sample: use hash-agnostic null OID
-:  ---------- > 1:  95dd0b19ba hooks--pre-push.sample: modernize script
-:  ---------- > 2:  afb460d9fd hooks--pre-push.sample: use hash-agnostic zero OID
4:  42d2829889 ! 3:  784135549f hooks--update.sample: use hash-agnostic null OID

@@ Metadata
Author: Denton Liu <[email protected]>

## Commit message ##
- hooks--update.sample: use hash-agnostic null OID
+ hooks--update.sample: use hash-agnostic zero OID

- The update sample hook has the null OID hardcoded as 40 zeros. However,
+ The update sample hook has the zero OID hardcoded as 40 zeros. However,
with the introduction of SHA-256 support, this assumption no longer holds true. Replace the hardcoded $z40 with a call to
- git rev-parse --null-oid so the sample hook becomes hash-agnostic.
+
+ git hash-object --stdin </dev/null | tr '[0-9a-f]' '0'
+
+ so the sample hook becomes hash-agnostic.

## templates/hooks--update.sample ##
@@ templates/hooks--update.sample: esac
@@ templates/hooks--update.sample: esac
# --- Check types
# if $newrev is 0000...0000, it's a commit to delete a ref.
-zero="0000000000000000000000000000000000000000"
-+zero="$(git rev-list --null-oid)"
++zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
if [ "$newrev" = "$zero" ]; then
newrev_type=delete
else

Signature · 1 line
2.28.0.760.g8d73e04208