git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* `git bundle create -` may not write to `stdout`
@ 2023-02-25 12:58 Michael Henry
  2023-02-26 23:16 ` Jeff King
  0 siblings, 1 reply; 24+ messages in thread
From: Michael Henry @ 2023-02-25 12:58 UTC (permalink / raw)
  To: git

All,

I've encountered some unexpected behavior with `git bundle create -`.

Summary
=======

Using `-` to create a bundle file on `stdout` works only when the current
working directory is at the root of the repository; when in a
subdirectory, `-`
is treated as the name of a file instead.

What did you do before the bug happened? (Steps to reproduce your issue)
========================================================================

The below steps are using Git's `next` branch (cloned today) to demonstrate.

- Bundle creation to `stdout` works in the repository root:

      $ ./git bundle create -q - HEAD ^HEAD~ > head.bundle
      $ ./git bundle list-heads head.bundle
      a93b1961839a603a8ac2df08fd80c48bd140fe02 HEAD

- From the `Documentation` directory, `-` is treated like a filename:

      $ cd Documentation/
      $ ../git bundle create -q - HEAD ^HEAD~ > head.bundle
      $ ../git bundle list-heads head.bundle
      error: 'Documentation/head.bundle' does not look like a v2 or v3
bundle file
      $ ../git bundle list-heads ./-
      a93b1961839a603a8ac2df08fd80c48bd140fe02 HEAD

- Consider this patch to display the bundle file path:

      diff --git a/bundle.c b/bundle.c
      index 6ab6cd7378..05be3ed520 100644
      --- a/bundle.c
      +++ b/bundle.c
      @@ -524,6 +524,7 @@ int create_bundle(struct repository *r, const
char *path,
                      goto err;
              }
       
      +    fprintf(stderr, "create_bundle(): path=\"%s\"\n", path);
              bundle_to_stdout = !strcmp(path, "-");
              if (bundle_to_stdout)
                      bundle_fd = 1;

  When in a subdirectory, it seems that the current working directory is
being
  changed to the root, and the bundle file's path is being adjusted
accordingly:

      $ ../git bundle create -q - HEAD ^HEAD~ > head.bundle
      create_bundle(): path="Documentation/-"

What did you expect to happen? (Expected behavior)
==================================================

I expected `-` to be treated as `stdout` in subdirectories as well as in the
repository root directory.

What happened instead? (Actual behavior)
========================================

When in a subdirectory `some/subdir`, `-` is converted to
`some/subdir/-` and
treated like a regular file instead of `stdout`.

What's different between what you expected and what actually happened?
======================================================================

I expected the bundle file to appear on `stdout`; instead, it was
written to a
file named `-` in the current directory.

Anything else you want to add:
==============================

It's unclear to me whether creating a bundle file to `stdout` is documented
behavior.  I can't find direct mention of it in
`Documentation/git-bundle.txt`,
though that document does have this text:

    --all-progress::
            When --stdout is specified then progress report is
            displayed during the object count and compression phases
            but inhibited during the write-out phase. The reason is
            that in some cases the output stream is directly linked
            to another command which may wish to display progress
            status of its own as it processes incoming pack data.
            This flag is like --progress except that it forces progress
            report for the write-out phase as well even if --stdout is
            used.

The switch `--stdout` doesn't seem to exist, though; perhaps it was a past
feature that got removed but the documentation hung around?

I find the ability to create a bundle to `stdout` a useful feature, though a
niche use case: I'm post-processing the bundle file's contents before
writing to
a file, and bundling to `stdout` saves the creation of a potentially large
temporary file.  I'm currently using the temporary file approach, however,
because I'm not sure that bundling to `stdout` is intended as a supported
feature; I'll leave that for you to determine.

Thanks,
Michael Henry

==============================================================================

[System Info]
git version:
git version 2.40.0.rc0.245.ga93b196183
cpu: x86_64
built from commit: a93b1961839a603a8ac2df08fd80c48bd140fe02
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC
2022 x86_64
compiler info: gnuc: 11.3
libc info: glibc: 2.35
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-03-06 17:43 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-25 12:58 `git bundle create -` may not write to `stdout` Michael Henry
2023-02-26 23:16 ` Jeff King
2023-03-03 22:31   ` Junio C Hamano
2023-03-03 22:54     ` Jeff King
2023-03-03 23:05       ` Junio C Hamano
2023-03-04  1:28         ` Jeff King
2023-03-04  1:46           ` Jeff King
2023-03-04 10:22             ` [PATCH 0/5] handling "-" as stdin/stdout in git bundle Jeff King
2023-03-04 10:26               ` [PATCH 1/5] bundle: let "-" mean stdin for reading operations Jeff King
2023-03-04 10:26               ` [PATCH 2/5] bundle: document handling of "-" as stdin Jeff King
2023-03-04 10:27               ` [PATCH 3/5] bundle: don't blindly apply prefix_filename() to "-" Jeff King
2023-03-04 10:31               ` [PATCH 4/5] parse-options: consistently allocate memory in fix_filename() Jeff King
2023-03-04 10:31               ` [PATCH 5/5] parse-options: use prefix_filename_except_for_dash() helper Jeff King
2023-03-04 10:55               ` [RFC/PATCH] bundle: turn on --all-progress-implied by default Jeff King
2023-03-06  3:44                 ` Robin H. Johnson
2023-03-06  5:38                   ` Jeff King
2023-03-06  9:25                     ` Jeff King
2023-03-06 17:41                 ` Junio C Hamano
2023-03-06 17:34             ` `git bundle create -` may not write to `stdout` Junio C Hamano
2023-03-04  1:14       ` Junio C Hamano
2023-03-04  1:43         ` Jeff King
2023-03-03 23:59     ` Michael Henry
2023-03-04  2:22       ` Jeff King
2023-03-04 10:08         ` Michael Henry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).