All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Bosmans <mkbosmans@gmail.com>
To: git@vger.kernel.org
Cc: Maarten Bosmans <maarten.bosmans@vortech.nl>
Subject: [PATCH v2 2/5] notes: avoid launching a child process to show a note blob
Date: Sun, 18 Feb 2024 20:59:35 +0100	[thread overview]
Message-ID: <20240218195938.6253-3-maarten.bosmans@vortech.nl> (raw)
In-Reply-To: <20240218195938.6253-1-maarten.bosmans@vortech.nl>

From: Maarten Bosmans <mkbosmans@gmail.com>

From: Maarten Bosmans <maarten.bosmans@vortech.nl>

Avoid the need to launch a subprocess by calling stream_blob_to_fd
directly.  This does not only get rid of the overhead of a separate
child process, but also avoids the initalization of the whole log
machinery that `git show` does.  That is needed for example to show
decorated commits and applying the mailmap.  For simply displaying
a blob however, the only useful thing show does is enabling the pager.

This locks in the expectation that a note oid refers to a blob, and
not a tree or something else.  To still keep the option open that the
blob might not be a text blob and in the future we might handle such
notes differently, the show_blob_object() function is called in order
to have the same behaviour as though `git show <note-oid>` was called.

Signed-off-by: Maarten Bosmans <maarten.bosmans@vortech.nl>
---
 builtin/notes.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index caf20fd5bd..2a31da6c97 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -20,7 +20,8 @@
 #include "repository.h"
 #include "pretty.h"
 #include "refs.h"
-#include "exec-cmd.h"
+#include "pager.h"
+#include "log.h"
 #include "run-command.h"
 #include "parse-options.h"
 #include "string-list.h"
@@ -753,7 +754,7 @@ static int show(int argc, const char **argv, const char *prefix)
 	struct notes_tree *t;
 	struct object_id object;
 	const struct object_id *note;
-	int retval;
+	int retval = 0;
 	struct option options[] = {
 		OPT_END()
 	};
@@ -778,8 +779,9 @@ static int show(int argc, const char **argv, const char *prefix)
 		retval = error(_("no note found for object %s."),
 			       oid_to_hex(&object));
 	else {
-		const char *show_args[3] = {"show", oid_to_hex(note), NULL};
-		retval = execv_git_cmd(show_args);
+		setup_pager();
+		if (show_blob_object(note, NULL, false))
+			die(_("object %s is not a blob"), oid_to_hex(note));
 	}
 	free_notes(t);
 	return retval;
-- 
2.35.3


  parent reply	other threads:[~2024-02-18 19:59 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 20:49 [PATCH 0/4] Speed up git-notes show Maarten Bosmans
2024-02-05 20:49 ` [PATCH 1/4] notes: print note blob to stdout directly Maarten Bosmans
2024-02-06  3:44   ` Junio C Hamano
2024-02-06  9:55     ` Maarten Bosmans
2024-02-06 17:52       ` Junio C Hamano
2024-02-13  8:00         ` Jeff King
2024-02-13 17:35           ` Junio C Hamano
2024-02-15  5:26             ` Jeff King
2024-02-16  6:25               ` Junio C Hamano
2024-02-17  5:16                 ` Jeff King
2024-02-17  5:56                   ` Junio C Hamano
2024-02-17  6:09                     ` Jeff King
2024-02-15  7:46           ` Maarten Bosmans
2024-02-15 15:04             ` Jeff King
2024-02-17 12:45               ` Maarten Bosmans
2024-02-20  1:51                 ` Jeff King
2024-02-15  7:41         ` Maarten Bosmans
2024-02-06 13:55     ` Kristoffer Haugsbakk
2024-02-05 20:49 ` [PATCH 2/4] notes: use exisisting function stream_blob_to_fd Maarten Bosmans
2024-02-05 22:00   ` Eric Sunshine
2024-02-05 20:49 ` [PATCH 3/4] notes: do not clean up right before calling die() Maarten Bosmans
2024-02-05 20:49 ` [PATCH 4/4] notes: use strbuf_attach to take ownership of the object contents Maarten Bosmans
2024-02-06  7:08 ` [PATCH 0/4] Speed up git-notes show Kristoffer Haugsbakk
2024-02-06  8:51   ` Maarten Bosmans
2024-02-18 19:59 ` [PATCH v2 0/5] " Maarten Bosmans
2024-02-18 19:59   ` [PATCH v2 1/5] log: Move show_blob_object() to log.c Maarten Bosmans
2024-02-20  1:22     ` Junio C Hamano
2024-02-20  1:59       ` Jeff King
2024-02-20  3:03         ` Junio C Hamano
2024-02-20 11:40         ` Maarten Bosmans
2024-02-18 19:59   ` Maarten Bosmans [this message]
2024-02-18 19:59   ` [PATCH v2 3/5] notes: use existing function stream_blob_to_fd Maarten Bosmans
2024-02-18 19:59   ` [PATCH v2 4/5] notes: do not clean up right before calling die() Maarten Bosmans
2024-02-18 19:59   ` [PATCH v2 5/5] notes: use strbuf_attach to take ownership of the object contents Maarten Bosmans
2024-02-20  2:12     ` Jeff King
2024-02-20  7:42       ` Maarten Bosmans

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=20240218195938.6253-3-maarten.bosmans@vortech.nl \
    --to=mkbosmans@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=maarten.bosmans@vortech.nl \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.