Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid
- From
Chris Torek <chris.torek@gmail.com>
- Date
- Sep 20, 2020, 04:25 UTC
- Message-ID
- <CAPx1Gvd6vcvM410wZUZygr4-2Ob6gaScF3DnBtWWsT95XDmKSQ@mail.gmail.com>
- In-Reply-To
- <20200918212609.GC67496@camp.crustytoothpaste.net>
On Fri, Sep 18, 2020 at 2:34 PM brian m. carlson <sandals@crustytoothpaste.net> 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)
Show 11 quoted lines
> 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).
Show 7 quoted lines
> 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