From: Taylor Blau <me@ttaylorr.com>
To: John Cai <johncai86@gmail.com>
Cc: "Taylor Blau" <me@ttaylorr.com>,
"Christian Couder" <christian.couder@gmail.com>,
git <git@vger.kernel.org>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Phillip Wood" <phillip.wood123@gmail.com>,
"Eric Wong" <e@80x24.org>
Subject: Re: [RFC v3] cat-file: add a --stdin-cmd mode
Date: Tue, 1 Feb 2022 15:14:01 -0500 [thread overview]
Message-ID: <YfmUiXJ//ZC5NZU+@nand.local> (raw)
In-Reply-To: <674CD40F-7060-4892-97CD-1940AEF7C3D7@gmail.com>
On Tue, Feb 01, 2022 at 02:27:54PM -0500, John Cai wrote:
> On 1 Feb 2022, at 12:52, Taylor Blau wrote:
> > I'm not sure that I've seen a response along the lines of "we need to
> > control when the output stream is flushed in order to do ..." yet, but I
> > would be interested to see one before moving too much further ahead of
> > where we already are.
>
> This would be useful when there is another process A interacting with
> a long running git cat-file process B that is retrieving object
> information from the odb interactively but also wants to use --buffer
> mode.
Let me try and repeat my understanding of what you said to make sure
that I fully grok the use-case you have in mind.
You have a repository and want to have a long-running `git cat-file`
process that can serve multiple requests. Because the processes which
interact with your long-running `cat-file` may ask for many objects, you
don't want to flush the output buffer after each object, and so would
ideally like to use `--buffer`.
But that doesn't quite work, since the `cat-file` process may not have
decided to flush its output buffer even when process A is about to go
away.
I wonder about the viability of accomplishing this via a signal handler,
i.e., that `cat-file` would call fflush(2) whenever it receives e.g.,
SIGUSR1. A couple of possible downsides:
- SIGUSR1 doesn't exist on Windows AFAIK.
- There are definitely going to be synchrony issues to contend with.
What happens if we receive our signal while writing to the output
stream? I think you would just need to mark a variable that
indicates we should flush after finishing serving the current
request, but I haven't thought too hard about it.
So maybe a signal isn't the way to go. But I don't think `--stdin-cmd`
is the simplest approach either. At the very least, I don't totally
understand your plan after implementing a flush command. You mention
that it would be nice to implement other commands, but I'm not totally
convinced by your examples[1].
I wonder if we could strike a middle ground, which might look like `git
cat-file --batch --buffer`, and just feeding it something which we know
for certain isn't an object identifier. In other words, what if we
did something as simple as:
--- >8 ---
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index d94050e6c1..bae162fc18 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -595,6 +595,11 @@ static int batch_objects(struct batch_options *opt)
warn_on_object_refname_ambiguity = 0;
while (strbuf_getline(&input, stdin) != EOF) {
+ if (!strcmp("<flush>", input.buf)) {
+ fflush(stdout);
+ continue;
+ }
+
if (data.split_on_whitespace) {
/*
* Split at first whitespace, tying off the beginning
--- 8< ---
On the other hand, something even hackier than the above is that we
flush stdout whenever we get a request to print an object which could
not be found. So if you feed a single "\n" to your `cat-file` process,
you'll get " missing" on its output, and the buffer will immediately be
flushed.
I'm not sure that I'd recommend relying on that behavior exactly, but if
you're looking for a short-term solution, it might work ;).
Thanks,
Taylor
[1]: One that comes to mind is changing the output format mid-stream.
But how often does it really make sense to change the output
format? I can understand wanting to flush at the end asking
cat-file for a bunch of objects, but I don't see how you would want
to change the output format often enough that shaving off Git's
negligible startup cost is worthwhile (or couldn't be accomplished
by just spawning another cat-file process and using that).
next prev parent reply other threads:[~2022-02-01 20:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 18:33 [RFC v3] cat-file: add a --stdin-cmd mode John Cai
2022-01-31 11:44 ` Bagas Sanjaya
2022-01-31 18:24 ` Junio C Hamano
2022-02-01 9:48 ` Ævar Arnfjörð Bjarmason
2022-02-01 9:39 ` Christian Couder
2022-02-01 17:52 ` Taylor Blau
2022-02-01 19:27 ` John Cai
2022-02-01 20:14 ` Taylor Blau [this message]
[not found] ` <3FE1D509-8AD0-4F0E-9298-DFD3552A98EF@gmail.com>
2022-02-02 1:45 ` Taylor Blau
2022-02-02 13:11 ` John Cai
2022-02-01 10:43 ` Phillip Wood
2022-02-02 15:05 ` John Cai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YfmUiXJ//ZC5NZU+@nand.local \
--to=me@ttaylorr.com \
--cc=avarab@gmail.com \
--cc=christian.couder@gmail.com \
--cc=e@80x24.org \
--cc=git@vger.kernel.org \
--cc=johncai86@gmail.com \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).