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

Re: [PATCH] doc-diff: don't `cd_to_toplevel` before calling `usage`

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Feb 3, 2019, 10:35 UTC
Message-ID
<CAN0heSohuL=TBOLR+Q9=zrGhZrrjSgfvA=VeT-aA0gr57onAsg@mail.gmail.com>
In-Reply-To
<CAPig+cQYuwMmyw8_p863BeSU5RP-xdB=HFMa7EM4G3YALQj3_g@mail.gmail.com>
On Sun, 3 Feb 2019 at 10:12, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 12 quoted lines
>
> On Sun, Feb 3, 2019 at 4:08 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > I wonder if a more fruitful, longer-term fix which would save us from
> > having to worry about this in the future, would be to make
> > git-sh-setup.sh remember the original $0 before cd_to_toplevel() and
> > then employ the original value when usage() re-execs with the -h
> > option. That would also avoid the slightly ugly repeated
> > cd_to_top_level() and 'tmp' assignment in this patch.
>
> By "original $0", I meant a path which would be suitable for
> re-exec'ing (which wouldn't be the literal original $0). Sorry for the
> confusion.

I thought about this, and I probably should have said something about it in the commit message. My uneducated guess was that "all" other users are in $PATH and aren't being called like `./foobar`, but just `foobar`. Or, they're internal helpers where the caller has already done the grunt setup work, so their cd-ing is a no-op. I could be very wrong.

To be honest, I wasn't very tempted to risk breaking git-sh-setup only(?) to help a development helper script like this. But let's see if I can spend some more time on this...

The only way I'd know how to do something like this would be with readlink or realpath. Judging by d2addc3b96 ("t7800: readlink may not be available", 2016-05-31), we can't count on readlink. And I'd expect that commit to have switched to realpath if THAT were available everywhere. That commit instead goes for "ls | sed" and notes that "[t]his is no universal readlink replacement but works in the controlled test environment well enough."

Ok, so I am not too eager to try and tackle this with fallback strategies and what-not. What would you say if I punted on this? I could add something like this to the commit message:

  A more general fix would be to teach git-sh-setup to save away the
  absolute path for $0 and then use that, instead. I'm not aware of any
  portable way of doing that, see, e.g., d2addc3b96 ("t7800: readlink
  may not be available", 2016-05-31), so let's just fix this user
  instead.
What do you think? Thanks for your comments.
Martin
Previous: Eric SunshineNext: Eric Sunshine
Message 4 of 27 in “doc-diff: don't `cd_to_toplevel` before calling `usage`”
  1. doc-diff: don't `cd_to_toplevel` before calling `usage`Martin Ågren, Feb 3, 2019
  2. Eric SunshineFeb 3, 2019
  3. Eric SunshineFeb 3, 2019
  4. Martin ÅgrenFeb 3, 2019
  5. Eric SunshineFeb 3, 2019
  6. doc-diff: don't `cd_to_toplevel` before calling `usage`Martin Ågren, Feb 3, 2019
  7. Jeff KingFeb 3, 2019
  8. doc-diff: don't `cd_to_toplevel`Martin Ågren, Feb 4, 2019
  9. Jeff KingFeb 4, 2019
  10. Johannes SchindelinFeb 5, 2019
  11. Junio C HamanoFeb 5, 2019
  12. Johannes SchindelinFeb 6, 2019
  13. Junio C HamanoFeb 6, 2019
  14. Jeff KingFeb 6, 2019
  15. Johannes SchindelinFeb 7, 2019
  16. Junio C HamanoFeb 7, 2019
  17. Johannes SchindelinFeb 7, 2019
  18. Jeff KingFeb 7, 2019
  19. Johannes SchindelinFeb 7, 2019
  20. Jeff KingFeb 6, 2019
  21. Johannes SchindelinFeb 7, 2019
  22. Jeff KingFeb 7, 2019
  23. Johannes SchindelinFeb 7, 2019
  24. Jeff KingFeb 8, 2019
  25. Jeff KingFeb 8, 2019
  26. SZEDER GáborFeb 8, 2019
  27. Jeff KingFeb 8, 2019

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.