git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 20, 2020, 18:58 UTC
Message-ID
<20200920185817.GJ67496@camp.crustytoothpaste.net>
In-Reply-To
<CAPx1Gvd6vcvM410wZUZygr4-2Ob6gaScF3DnBtWWsT95XDmKSQ@mail.gmail.com>
On 2020-09-20 at 04:25:33, Chris Torek wrote:
Show 18 quoted lines
> On Fri, Sep 18, 2020 at 2:34 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > 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).

If we're looking for best compatibility here, then using egrep and /dev/null is best, I agree. I personally use the POSIX version because it's been that way since at least 2001 and I don't have a problem with requiring compliance with a 19-year-old standard. But for Git, we should definitely do whatever we do in the testsuite if we use this approach, since presumably that works everywhere.

As Andreas pointed out, there are ways to avoid the external process that we could stuff in a shell function. I'm not picky.

Show 11 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...?

I believe all modern versions of Git for Windows provide /dev/null via the shell, since it's required for a lot of things to work, so I'm not worried about this case. It is definitely good to think about Windows, though.

-- 
brian m. carlson: Houston, Texas, US
Previous: Chris TorekNext: Taylor Blau
Message 9 of 23 in “sample hooks: become hash agnostic”
  1. 0/4 sample hooks: become hash agnosticDenton Liu, Sep 18, 2020
  2. 2/4 builtin/rev-parse: learn --null-oidDenton Liu, Sep 18, 2020
  3. Taylor BlauSep 18, 2020
  4. Taylor BlauSep 18, 2020
  5. Junio C HamanoSep 18, 2020
  6. Taylor BlauSep 18, 2020
  7. brian m. carlsonSep 18, 2020
  8. Chris TorekSep 20, 2020
  9. brian m. carlsonSep 20, 2020
  10. Taylor BlauSep 20, 2020
  11. Andreas SchwabSep 20, 2020
  12. 1/4 hooks--pre-push.sample: prefer $() for command substitutionDenton Liu, Sep 18, 2020
  13. Eric SunshineSep 18, 2020
  14. 3/4 hooks--pre-push.sample: use hash-agnostic null OIDDenton Liu, Sep 18, 2020
  15. Eric SunshineSep 18, 2020
  16. 4/4 hooks--update.sample: use hash-agnostic null OIDDenton Liu, Sep 18, 2020
  17. Eric SunshineSep 18, 2020
  18. brian m. carlsonSep 18, 2020
  19. 0/3 sample hooks: become hash agnosticDenton Liu, Sep 23, 2020
  20. 1/3 hooks--pre-push.sample: modernize scriptDenton Liu, Sep 23, 2020
  21. 3/3 hooks--update.sample: use hash-agnostic zero OIDDenton Liu, Sep 23, 2020
  22. 2/3 hooks--pre-push.sample: use hash-agnostic zero OIDDenton Liu, Sep 23, 2020
  23. Junio C HamanoSep 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.