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

Re: `git bundle create -` may not write to `stdout`

From
Jeff King <peff@peff.net>
Date
Mar 4, 2023, 01:43 UTC
Message-ID
<ZAKiV9nAet4wlEEu@coredump.intra.peff.net>
In-Reply-To
<xmqqa60tco76.fsf@gitster.g>
On Fri, Mar 03, 2023 at 05:14:37PM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > (I do still think we don't want to push it down into prefix_filename(),
> > because it gets used for paths and pathspecs given raw on the command
> > line. It does make me wonder if there are places where OPT_FILENAME() is
> > doing the wrong thing).
> 
> To be quite honest, I had the opposite reaction ;-)  At least for
> OPT_FILENAME() thing, I think it is well known that you should work
> around with "git cmd --opt ./-" if you do mean a file whose name
> happens to be a single dash.  Teaching prefix_filename() the same
> trick does not look _too_ bad.

For OPT_FILENAME() I agree you are generally thinking about "-" as special anyway. But if it's the argument to an option, you do not generally need to prefix it.

After a little grepping, here's a real world example where we wouldn't want prefix_filename() to treat "-" specially:

  git archive --add-virtual-file=-:1234abcd

Using "stdin" there doesn't make sense. It's OK because it's not using OPT_FILENAME(), but it is using prefix_filename().

But I'd worry much more about non-option arguments. There you _do_ need to say "./-" if you are intermingled with options. But a "--" separator splits that. So something like:

  git mv -- - to

should move the literal file "-", and it _should_ be prefixed with the subdirectory if there is one. Having it mean stdin makes no sense there, as we are not reading or writing the file, but rather operating on the path.

Now this particular case isn't a problem, because it uses internal_prefix_pathspec(), and not prefix_filename(). And maybe most things are in that boat. Grepping around, most spots I see using prefix_filename() could reasonably handle "-" as stdin/stdout, though there are definitely some outliers. E.g., "git format-patch -o" wants a directory, and "git merge-file" probably doesn't want to handle stdin.

So I think we probably do want to stick with "-" as being not-special by default for prefix_filename(), and individual sites would opt into it.

Show 15 quoted lines
> There is a problem that commands that use prefix_filename() may not
> be prepared to read from the standard input or write to the standard
> output.  For some such callers it may be just the matter of
> replacing an unconditional open() with
> 
> 	-	fd = open(filename, O_RDONLY);
> 	+	if (!strcmp(filename, "-"))
> 	+		fd = 0;
> 	+	else
> 	+		fd = open(filename, O_RDONLY);
> 
> or something, but if some callers have fundamental reasons why they
> do not want to work with the standard input, it may make sense to
> treat "-" as a normal filename, and for them, blindly prefixing the
> leading directory name would be much better than special casing "-".

Right. I think we should stick with the status quo and change over individual callers if people want that effect (but I do not really hear anybody clamoring for it, so it seems very non-urgent).

-Peff
Previous: Junio C HamanoNext: Michael Henry
Message 21 of 24 in “`git bundle create -` may not write to `stdout`”
  1. Michael HenryFeb 25, 2023
  2. Jeff KingFeb 26, 2023
  3. Junio C HamanoMar 3, 2023
  4. Jeff KingMar 3, 2023
  5. Junio C HamanoMar 3, 2023
  6. Jeff KingMar 4, 2023
  7. Jeff KingMar 4, 2023
  8. 0/5 handling "-" as stdin/stdout in git bundleJeff King, Mar 4, 2023
  9. 1/5 bundle: let "-" mean stdin for reading operationsJeff King, Mar 4, 2023
  10. 2/5 bundle: document handling of "-" as stdinJeff King, Mar 4, 2023
  11. 3/5 bundle: don't blindly apply prefix_filename() to "-"Jeff King, Mar 4, 2023
  12. 4/5 parse-options: consistently allocate memory in fix_filename()Jeff King, Mar 4, 2023
  13. 5/5 parse-options: use prefix_filename_except_for_dash() helperJeff King, Mar 4, 2023
  14. bundle: turn on --all-progress-implied by defaultJeff King, Mar 4, 2023
  15. Robin H. JohnsonMar 6, 2023
  16. Jeff KingMar 6, 2023
  17. Jeff KingMar 6, 2023
  18. Junio C HamanoMar 6, 2023
  19. Junio C HamanoMar 6, 2023
  20. Junio C HamanoMar 4, 2023
  21. Jeff KingMar 4, 2023
  22. Michael HenryMar 3, 2023
  23. Jeff KingMar 4, 2023
  24. Michael HenryMar 4, 2023

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.