Thread (19 messages) 19 messages, 5 authors, 2020-09-23

Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid

From: Chris Torek <hidden>
Date: 2020-09-20 04:25:47

On Fri, Sep 18, 2020 at 2:34 PM brian m. carlson
[off-list ref] wrote:
So I definitely want to distinguish between the null (all-zeros) OID and
the OID of an empty object, and I think using "null" and "empty" are
fine.
(I like this myself)
What I typically do when I write shell scripts, and which may obviate
the need for this patch is turn this:

  [ "$oid" = 0000000000000000000000000000000000000000 ]

into this:

  echo "$oid" | grep -qsE '^0+$'

This is slightly less efficient, but it's also backwards compatible
with older Git version assuming you have a POSIX grep.
Note that a lot of `grep`s do not have `-q` and/or `-s` so the
portable variant of this is `grep '^0+$' >/dev/null` (you only need
the `2>&1` part if you're concerned about bad input files or
an error on a pipe or something).
I'm not sure we need an empty tree and empty blob object, because it's
pretty easy to write these:

  git hash-object -t tree /dev/null
  git hash-object -t blob /dev/null

That's what I've done in some of the transition code at least.
That's what's recommended in my 2012 stackoverflow Q&A, too.
The use of `/dev/null` directly here is perhaps unsatisfactory on
old Windows systems, though...?

Chris
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help