git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: "brian m . carlson" <sandals@crustytoothpaste.net>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Taylor Blau <me@ttaylorr.com>, Junio C Hamano <gitster@pobox.com>,
	Chris Torek <chris.torek@gmail.com>,
	Andreas Schwab <schwab@linux-m68k.org>
Subject: [PATCH v2 0/3] sample hooks: become hash agnostic
Date: Wed, 23 Sep 2020 02:38:42 -0700	[thread overview]
Message-ID: <cover.1600853895.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1600427894.git.liu.denton@gmail.com>

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 <liu.denton@gmail.com>
     
      ## 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
-- 
2.28.0.760.g8d73e04208


  parent reply	other threads:[~2020-09-23  9:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-18 11:19 [PATCH 0/4] sample hooks: become hash agnostic Denton Liu
2020-09-18 11:19 ` [PATCH 1/4] hooks--pre-push.sample: prefer $() for command substitution Denton Liu
2020-09-18 16:57   ` Eric Sunshine
2020-09-18 11:19 ` [PATCH 2/4] builtin/rev-parse: learn --null-oid Denton Liu
2020-09-18 14:11   ` Taylor Blau
2020-09-18 14:16     ` Taylor Blau
2020-09-18 18:16       ` Junio C Hamano
2020-09-18 18:21         ` Taylor Blau
2020-09-18 21:26     ` brian m. carlson
2020-09-20  4:25       ` Chris Torek
2020-09-20 18:58         ` brian m. carlson
2020-09-20 15:35       ` Taylor Blau
2020-09-20 16:03       ` Andreas Schwab
2020-09-18 11:19 ` [PATCH 3/4] hooks--pre-push.sample: use hash-agnostic null OID Denton Liu
2020-09-18 17:06   ` Eric Sunshine
2020-09-18 11:19 ` [PATCH 4/4] hooks--update.sample: " Denton Liu
2020-09-18 17:08   ` Eric Sunshine
2020-09-18 21:35 ` [PATCH 0/4] sample hooks: become hash agnostic brian m. carlson
2020-09-23  9:38 ` Denton Liu [this message]
2020-09-23  9:38   ` [PATCH v2 1/3] hooks--pre-push.sample: modernize script Denton Liu
2020-09-23  9:38   ` [PATCH v2 2/3] hooks--pre-push.sample: use hash-agnostic zero OID Denton Liu
2020-09-23  9:38   ` [PATCH v2 3/3] hooks--update.sample: " Denton Liu
2020-09-23 16:34   ` [PATCH v2 0/3] sample hooks: become hash agnostic Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1600853895.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=schwab@linux-m68k.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).