From patchwork Sun Feb 18 19:59:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Bosmans X-Patchwork-Id: 13562013 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A420771B3B for ; Sun, 18 Feb 2024 19:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286383; cv=none; b=josIYf9y8Deuzo2elUVBXa5bfBjBy/kX98gMj4UUlbpYN7bZ63xP7UIXDtxWa6CzZDAU7As7QxdsVJG69Bf9xCOOvGiDkz7xFw1nJm+F9DGwnNDBRbbFpp59XzRkyuTlseWlF9j66tnrxIBZecE376Zs5abq8O1+EQHOcwO3P7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286383; c=relaxed/simple; bh=31eouZfqOINtJL4W0zdUaBYkP11FA0yNXh4TpRHK/oY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eGbR5nYza+fxMxSLvvHrAP18EOZywApzWbYGpXDPOI08EuHvYxGZaUBB3CeNJb3uTm6b2SaIyDb9d4JppgVQwlzSFept5MY9mmKnjE7jYaXO9YiAVe/sU2lTiFYuZwX6ZxGr4UdSRhNl5SkawtvTPnV1wxTuFL+dmlfdIjJeQBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lfYd2Wbx; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lfYd2Wbx" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-563c2b2bddbso4589228a12.1 for ; Sun, 18 Feb 2024 11:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708286380; x=1708891180; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rI/HPdGTW0agng8WQoR+PVh9x7Bb6vN39q4/Ah2hrFs=; b=lfYd2WbxKkVTNhz7Uk2GYTscxKFzdzpfk+yE9yI+03vZiEM9wRc37/tCCVel+T3LiY ly4ZKrDJUvfXSc5oQVB1grbVnzIF0N24c/2Mwyb49YdLhHQ3Laj0aUDzefEhCcEyjwtn OlaUcd4XgXiLBKqEiKgzTFiWsd/doTJwqPs4xUYeCIm+DmOKgaQSic4DAFJuYCXmtI0/ nKTWxhaKjLuR6Od45CxD526PD9+wnE4xWmyOiyttbS7RshSQJ5+DGkpmFa1RhV7D5urI HMqFROOevE2U9R3D7vId996ADdm8t0NLrLpGmTsrZr3S5rKVUYRmwTr8lkdHz3+F2PLR NTzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708286380; x=1708891180; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rI/HPdGTW0agng8WQoR+PVh9x7Bb6vN39q4/Ah2hrFs=; b=HTm4Ji0zw4h9NgAvB6gOXnzdNV962ubnsTt3yv9U0OjMrq4Srlrvp6YyXA+JUYJv6j mbOx9AgZ/4LTvjU4kQKuFD1aEABbSGOVD/WFUb7me92AYgC+QBH+0FpYDav8O454Cjl2 i0T0mq5bcyV04AKqUJvGk9iDS2kITZIkzDLtt6p0aScfZ/z6dnWZfi6k4FR2+K0BIDwQ ZW4BeYMdE4HX6iGFGkKYNk6D/qHgjt9JxQ1rur+hXbdc1jzmMkgbGb/kcAeu3sh9Pg/f iH0g4zmc34gurR6GrCQpWRLQxmi3L+oh/uU3pe+9qg121EAnco7s0ukUzHHEhnI2YpLo rdwQ== X-Gm-Message-State: AOJu0YwXe0eczMXWlY9DaG2ykmWkG8XZchTjCqRAflBlavW6goISHEQT yHkY9g2FYbgsYQ+PgQyV0Af/6ITvxLfk4EB0xZ5DXiqTv5LcDcAmUUIW5RxB X-Google-Smtp-Source: AGHT+IGmplhMORVPBnx/7DtWmKL+q7ZTc3bG10pj0NiYIRSNPOLf8HJz/aqG9vAtVGHjmV3FMWOa7w== X-Received: by 2002:a17:906:d86:b0:a3d:7559:6ed1 with SMTP id m6-20020a1709060d8600b00a3d75596ed1mr7133954eji.4.1708286379688; Sun, 18 Feb 2024 11:59:39 -0800 (PST) Received: from mkb-desktop.bosmans (89-224-201-31.ftth.glasoperator.nl. [31.201.224.89]) by smtp.gmail.com with ESMTPSA id dt14-20020a170907728e00b00a3cbbaf5981sm2206999ejc.51.2024.02.18.11.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:59:39 -0800 (PST) From: Maarten Bosmans X-Google-Original-From: Maarten Bosmans To: git@vger.kernel.org Cc: Maarten Bosmans Subject: [PATCH v2 1/5] log: Move show_blob_object() to log.c Date: Sun, 18 Feb 2024 20:59:34 +0100 Message-Id: <20240218195938.6253-2-maarten.bosmans@vortech.nl> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240218195938.6253-1-maarten.bosmans@vortech.nl> References: <20240205204932.16653-1-maarten.bosmans@vortech.nl> <20240218195938.6253-1-maarten.bosmans@vortech.nl> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Maarten Bosmans From: Maarten Bosmans This way it can be used outside of builtin/log.c. The next commit will make builtin/notes.c use it. Signed-off-by: Maarten Bosmans --- Makefile | 1 + builtin/log.c | 39 +++++---------------------------------- log.c | 41 +++++++++++++++++++++++++++++++++++++++++ log.h | 11 +++++++++++ 4 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 log.c create mode 100644 log.h diff --git a/Makefile b/Makefile index 78e874099d..1c19d5c0f3 100644 --- a/Makefile +++ b/Makefile @@ -1059,6 +1059,7 @@ LIB_OBJS += list-objects-filter-options.o LIB_OBJS += list-objects-filter.o LIB_OBJS += list-objects.o LIB_OBJS += lockfile.o +LIB_OBJS += log.o LIB_OBJS += log-tree.o LIB_OBJS += ls-refs.o LIB_OBJS += mailinfo.o diff --git a/builtin/log.c b/builtin/log.c index db1808d7c1..587a4c374d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -32,7 +32,6 @@ #include "parse-options.h" #include "line-log.h" #include "branch.h" -#include "streaming.h" #include "version.h" #include "mailmap.h" #include "progress.h" @@ -42,7 +41,7 @@ #include "range-diff.h" #include "tmp-objdir.h" #include "tree.h" -#include "write-or-die.h" +#include "log.h" #define MAIL_DEFAULT_WRAP 72 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100 @@ -653,37 +652,6 @@ static void show_tagger(const char *buf, struct rev_info *rev) strbuf_release(&out); } -static int show_blob_object(const struct object_id *oid, struct rev_info *rev, const char *obj_name) -{ - struct object_id oidc; - struct object_context obj_context; - char *buf; - unsigned long size; - - fflush(rev->diffopt.file); - if (!rev->diffopt.flags.textconv_set_via_cmdline || - !rev->diffopt.flags.allow_textconv) - return stream_blob_to_fd(1, oid, NULL, 0); - - if (get_oid_with_context(the_repository, obj_name, - GET_OID_RECORD_PATH, - &oidc, &obj_context)) - die(_("not a valid object name %s"), obj_name); - if (!obj_context.path || - !textconv_object(the_repository, obj_context.path, - obj_context.mode, &oidc, 1, &buf, &size)) { - free(obj_context.path); - return stream_blob_to_fd(1, oid, NULL, 0); - } - - if (!buf) - die(_("git show %s: bad file"), obj_name); - - write_or_die(1, buf, size); - free(obj_context.path); - return 0; -} - static int show_tag_object(const struct object_id *oid, struct rev_info *rev) { unsigned long size; @@ -770,7 +738,10 @@ int cmd_show(int argc, const char **argv, const char *prefix) const char *name = rev.pending.objects[i].name; switch (o->type) { case OBJ_BLOB: - ret = show_blob_object(&o->oid, &rev, name); + fflush(rev.diffopt.file); + bool do_textconv = rev.diffopt.flags.textconv_set_via_cmdline && + rev.diffopt.flags.allow_textconv; + ret = show_blob_object(&o->oid, name, do_textconv); break; case OBJ_TAG: { struct tag *t = (struct tag *)o; diff --git a/log.c b/log.c new file mode 100644 index 0000000000..5c77707385 --- /dev/null +++ b/log.c @@ -0,0 +1,41 @@ +#include "git-compat-util.h" +#include "gettext.h" +#include "diff.h" +#include "log.h" +#include "notes.h" +#include "object-name.h" +#include "repository.h" +#include "streaming.h" +#include "write-or-die.h" + +/* + * Print blob contents to stdout. + */ +int show_blob_object(const struct object_id *oid, const char *obj_name, bool do_textconv) +{ + struct object_id oidc; + struct object_context obj_context; + char *buf; + unsigned long size; + + if (!do_textconv) + return stream_blob_to_fd(1, oid, NULL, 0); + + if (get_oid_with_context(the_repository, obj_name, + GET_OID_RECORD_PATH, + &oidc, &obj_context)) + die(_("not a valid object name %s"), obj_name); + if (!obj_context.path || + !textconv_object(the_repository, obj_context.path, + obj_context.mode, &oidc, 1, &buf, &size)) { + free(obj_context.path); + return stream_blob_to_fd(1, oid, NULL, 0); + } + + if (!buf) + die(_("git show %s: bad file"), obj_name); + + write_or_die(1, buf, size); + free(obj_context.path); + return 0; +} diff --git a/log.h b/log.h new file mode 100644 index 0000000000..464cca52ff --- /dev/null +++ b/log.h @@ -0,0 +1,11 @@ +#ifndef LOG_H +#define LOG_H + +struct object_id; + +/* + * Print blob contents to stdout. + */ +int show_blob_object(const struct object_id *oid, const char *obj_name, bool do_textconv); + +#endif From patchwork Sun Feb 18 19:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Bosmans X-Patchwork-Id: 13562015 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27B0571B43 for ; Sun, 18 Feb 2024 19:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286384; cv=none; b=QuxJJPmxru1jmxefTwt3X8n7aBZwFsq3R9t5hHSVKyBHS3fz6R8eMc5GDC7fuptVDTC56ptFHxuPsOsCwsTCc6yUOEW5Fvj5PJB4twdW3tRBqRl9ZTwC6YUTdvvWQ7sgF8IWBm2iHXcWjbDKecr932lRc8DFcuw9Z+bFJi1Kl4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286384; c=relaxed/simple; bh=xelLq95xRldvKB5NCG/ZoCY1dgNlzxuOB8zrNJmpKcY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cf8zuRj2jzrqrU2i3WS+Ju3y8VA8WLaHfnebM+8Ev+otIOI4HcSloxIzPH+Tx3hg2SRixYBAiSfpct6rOe9ibiM3TNapJyiSV2w5Il+6bJV6jd44CL9ITyq1vQM+cozr2SlcHUuW1rebaOk4kRDBU7cHjEiA0pPjoJHf+wGMo74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pzre+wti; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pzre+wti" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-512b29f82d1so487481e87.1 for ; Sun, 18 Feb 2024 11:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708286380; x=1708891180; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0peiUkHc5fI+1Eh9ijkXYBrEd4b4BTC4Rzf8i/gOFRk=; b=Pzre+wtiGrwgxyPgfSlCzD7KUGi9YcM3DlIaCraJOiIF5NKlqPXvPydmXaFYTOr5HH ZcnRt3QkN8qftzwsMNV0ARuuEeCIg/3uh3boo3h9HEgPJ5kMFI1UCM6xFC5uUgpQ+tnz HQ28nQ3RiYCaHg+7Fk+nfKHbT2gILvPS7LRW3x2FR72z5gOkXjvJk2InBGihK+pJRSG6 P0lESEADc1F7ztrozeKw95z3ysyrraZC1xS7jBIYcAjwzbaXs7T8goriQ23rvEX/lzh6 ZwDH8Mq4GTR8gxZ+26RPTlvbej7itJeOzrLkjd/hF8ZCNbu4vojgobImITkWDrmSU8qa fD4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708286380; x=1708891180; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0peiUkHc5fI+1Eh9ijkXYBrEd4b4BTC4Rzf8i/gOFRk=; b=gS14U90+S5nosY9i3hpH6gHZ+pGjmqMgcrEXm9FuYDOBNLi1dJdi7z0Pt0s9l1yXEg XuGipJaUtH9qEho6rRxpav4dnL1B8LXV3YpaKMu5oj1hGK/CDv6QnVAjD0a4t3+14d+W Uzaud0AlPXlzSoDF7aOQzVwnSsnrnBjPz3TdveMptLL20UP5c1biM6dsRr8fx+5vk+4B NR31uYpqv7PODQTSEzcuomF4bAMfq2sGFG/Q7jcCCTFjdmrp9kF1xaXQOOFmOZCRIwGK aakjli2xvX3nRJaz+OG86MRn+R5kb3qXDIER3nvfjvuH6dT7/qgxb8FpN4yANWunmiK3 v3JA== X-Gm-Message-State: AOJu0YwScIkrPzKN7ZrsGoZ9DaFplZn8UUPMs7USwXTB8Q0wSBpyzoA3 kvPkPbx29KET4R/I8DB549Oww9vCBG+90cOfjSqrwNpO617LrkdtHtXILua8 X-Google-Smtp-Source: AGHT+IEWRLaoE0qIv2FisSImPlZgy4GGk7htf5F4UtJfS6MH2nbECyB8m1165IDxPmkSpTRF00yXsQ== X-Received: by 2002:a05:6512:2f3:b0:512:b1c0:55f4 with SMTP id m19-20020a05651202f300b00512b1c055f4mr815830lfq.60.1708286380029; Sun, 18 Feb 2024 11:59:40 -0800 (PST) Received: from mkb-desktop.bosmans (89-224-201-31.ftth.glasoperator.nl. [31.201.224.89]) by smtp.gmail.com with ESMTPSA id dt14-20020a170907728e00b00a3cbbaf5981sm2206999ejc.51.2024.02.18.11.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:59:39 -0800 (PST) From: Maarten Bosmans X-Google-Original-From: Maarten Bosmans To: git@vger.kernel.org Cc: Maarten Bosmans 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 Message-Id: <20240218195938.6253-3-maarten.bosmans@vortech.nl> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240218195938.6253-1-maarten.bosmans@vortech.nl> References: <20240205204932.16653-1-maarten.bosmans@vortech.nl> <20240218195938.6253-1-maarten.bosmans@vortech.nl> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Maarten Bosmans From: Maarten Bosmans 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 ` was called. Signed-off-by: Maarten Bosmans --- 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; From patchwork Sun Feb 18 19:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Bosmans X-Patchwork-Id: 13562014 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16CC36F060 for ; Sun, 18 Feb 2024 19:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286383; cv=none; b=uTh/4MH65uOm28vplINRy8QAXjk4PGaXQ3dUVRszQwsdQ+586tWqi/OKF9bGiePi/LSzRrymEG/GCd4H94GP7XJtyids6JB2yNHCKVWlvp2goD81iCEPb7luUUmRg4j0nMRcUzjgx8ACmsD3PSEiGrodjXnivIldyI3SsiyUHYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286383; c=relaxed/simple; bh=q4HNwjHQbuFVx7YiOirFuLKlK6Gfrn8yRqp7V3DdQmQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G4zgPZBlmuCtnl7AvhfoFjIbL116oXeo5RYGpXEeZbDciTIg++Plj5lMgn7HdF1HjfIVWPWcZvEZgM8ONygqsxoMV6chEVdfJzuBmz+QBRQ3WDlRoiFsEGsUWyyesZFusKGDa3O8dTEw4l62B3KjLCZ75ZNSmawnmSFVtidC+C4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Uaun69lK; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uaun69lK" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a3e6f79e83dso62412866b.2 for ; Sun, 18 Feb 2024 11:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708286380; x=1708891180; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0WMkDZAUmARPHaKnkyRvSfhcVpNQuiWa75v8pxHdkxU=; b=Uaun69lKl9a133MWk0+Fss+E2DZC69I5lOCWfPltW5ntdXL6au0DUsSdvz1629xFPB fWxDdghKp+RC88DpFfyrE7yT4UDCpW3aY4ZReegBU5PNj0jgQN1JGmjlG6M0DOJ1YxPT W32pWYKBChO0SgZh8iJs/piJtFqLUQg6K2oDED2zGutLhjcFNAoCmF1RPH/Rb9UIYbhO 2zAvria6cRs+tmYS5fBjiRydmZWXCln5fYclbU18dT3RgPDS4o1R8Vx3Fwx1hQIRdowD X/z3cdpPqk23FdGlq9WIljrEoni83Vt1lUTittfzQk/cjefrb7SgFc9h+Dmi6QLT6ngC PfzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708286380; x=1708891180; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0WMkDZAUmARPHaKnkyRvSfhcVpNQuiWa75v8pxHdkxU=; b=W3pIa2I0xv4Z3Pn7RSBeIBWvs3kvuHKDuu4zA0YW+b3ehCe1JbKvsI9B94VXJJJAgt 2uxanFk6sH7030L0vAqAsL/1H406dZm+vtqGPRRyleICGX9K/7+2Waoj8QzMo9QV5Lmo VuMD0rGtF6gzr98kOfgVmNe5iPAdk63WKKcTM5riPC70qoQ50D9WFIjj5VM4gWnn4gs2 LhW5+SHIpkKf4QpMINFw6cAiRzIH1P93fF/JR2oqv0VmXnlHDLIx98eWTGCuO6ORN3qA XtYCsBvJX10URBDSP3GWyOj7ST/euAfja4QIRTO5q2bJyIeObQXYz1oFIOVyXrrLZRlZ kd8A== X-Gm-Message-State: AOJu0Yyv0IRmGCjGRb0wDyHfzQ9I5M5DbUS0bAl0Y+w5r0PD4hQ3MF+z nO3/b7TCw1AF16lvGmV7rdL7JzaWIV1M2YuRnVpMlud7jz3J+qDI8JI2AIrj X-Google-Smtp-Source: AGHT+IHycKNZ225WhWd2kD0W+dVrhO81xSYTMX8T0QXUG4zWVZ3hPV5gRWZlwj5UTaYSQ4Ww6xdj9w== X-Received: by 2002:a17:906:af09:b0:a3d:3aef:2311 with SMTP id lx9-20020a170906af0900b00a3d3aef2311mr7856927ejb.35.1708286380357; Sun, 18 Feb 2024 11:59:40 -0800 (PST) Received: from mkb-desktop.bosmans (89-224-201-31.ftth.glasoperator.nl. [31.201.224.89]) by smtp.gmail.com with ESMTPSA id dt14-20020a170907728e00b00a3cbbaf5981sm2206999ejc.51.2024.02.18.11.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:59:40 -0800 (PST) From: Maarten Bosmans X-Google-Original-From: Maarten Bosmans To: git@vger.kernel.org Cc: Maarten Bosmans Subject: [PATCH v2 3/5] notes: use existing function stream_blob_to_fd Date: Sun, 18 Feb 2024 20:59:36 +0100 Message-Id: <20240218195938.6253-4-maarten.bosmans@vortech.nl> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240218195938.6253-1-maarten.bosmans@vortech.nl> References: <20240205204932.16653-1-maarten.bosmans@vortech.nl> <20240218195938.6253-1-maarten.bosmans@vortech.nl> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Maarten Bosmans From: Maarten Bosmans Use functionality from streaming.c and remove the copy_obj_to_fd() function local to notes.c. Streaming the blob to stdout instead of copying through an intermediate buffer might also be more efficient, but at the size a typical note is, this is unlikely to matter a lot. Signed-off-by: Maarten Bosmans --- builtin/notes.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 2a31da6c97..184a92d0c1 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -22,6 +22,7 @@ #include "refs.h" #include "pager.h" #include "log.h" +#include "streaming.h" #include "run-command.h" #include "parse-options.h" #include "string-list.h" @@ -149,18 +150,6 @@ static int list_each_note(const struct object_id *object_oid, return 0; } -static void copy_obj_to_fd(int fd, const struct object_id *oid) -{ - unsigned long size; - enum object_type type; - char *buf = repo_read_object_file(the_repository, oid, &type, &size); - if (buf) { - if (size) - write_or_die(fd, buf, size); - free(buf); - } -} - static void write_commented_object(int fd, const struct object_id *object) { struct child_process show = CHILD_PROCESS_INIT; @@ -205,7 +194,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data * if (d->given) write_or_die(fd, d->buf.buf, d->buf.len); else if (old_note) - copy_obj_to_fd(fd, old_note); + stream_blob_to_fd(fd, old_note, NULL, 0); strbuf_addch(&buf, '\n'); strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char); From patchwork Sun Feb 18 19:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Bosmans X-Patchwork-Id: 13562017 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADFD271B48 for ; Sun, 18 Feb 2024 19:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286384; cv=none; b=cuZ3TTAYJhd3mcmyo5ELiB8mpRcHqXGbu8vtOhrRjo9U2blRLKKvuLXGlEhkefNxz5MqulxdFwX0+uPlcVEJCSxfH50blmsfjdgEF9qsiRotPxDZBc96MRk7geQLtYfx4lizfglPJ/zekblupUlAP2kGLiJQnfpuTVC1Wy4nGnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286384; c=relaxed/simple; bh=Hhr7H8Bd48wQ6dQCXW4zPuaI3vLBzF52Nu9/OLVRej4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b1yXhTjLjkn8ajiP1m2TLOse5201drm2G87rwF+TP+gqoZZrAgxAcJFOvZuzzfaGzJmyKoTh2Xcx91PvgEt/cfVf7CJ7Y5DucHXAfwCafPcttSldoK8SHH9p/YalM/PLa5B74rxej4L9z4ZSUkbXgm+4f8sJbNNLfKZ2oatIQmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UfC1mMWJ; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UfC1mMWJ" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a26ed1e05c7so498253866b.2 for ; Sun, 18 Feb 2024 11:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708286381; x=1708891181; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qaU3EAwEomF6Aj6BbZNDZDsZcoaXMFfYG6mbHdqh29M=; b=UfC1mMWJ5EVhm/+JfD+Fha5cWOhjLuchhfVbgzIb42U2CioJ+xXVVWPJptxRXmFiZo d3+J/HCtV6fEz9nEJatv9jWLT07Fp4M/2fnO5O4WBbzXQZEvmyHEYh5YLZv+iB0uH3BE LNKPn5xzKc2A8JY2y9eiTUIqJDSYSHeO1Wi0B762EpFJfK+NajJVvYYU1Qcd1ZVfGYZ3 Hf68bujrJlH5iZsD+pive3TnPCqpWWWXdQyA5jN44oOeEFnU+VhLymm741sdz1gqOdU3 XhgP4KRtmiDNAWB26H6o/CCAXTe+eR5sebiyaH/pDfeyLfNFzPsrGgklVZOtmMTpjMe5 jZaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708286381; x=1708891181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qaU3EAwEomF6Aj6BbZNDZDsZcoaXMFfYG6mbHdqh29M=; b=E3sUcy8/wKspJuTFzkMUyqL2Z8gSeEi+3VCaVyEk831e/doBiax3AQXSK9nAaDdVfu jCRF2F2hFfYwIfizkj9EBOdyjEs5Bj5kBn9iG/389h2gk+P2DKbnmdjUw8+BOnUB0+xg E4razJ9lZxHVToPEARJrbSp27PZv/2VzEiTKgfjjrDEnQWRvFgoqcOFG0gSjDp3UbWyA IpyHbzMugh23PZ5JburXmZr5jhoBucIz7wHhW8vg7cQ2M2FsXj4jddGP8OPlLYPJlgSz yfmlGunbEnEwPKb7Ulm2IIMCB8ZsOpISQrCjeNVGBgYXUQ/T1spX/FGOD0GzmQES6o+/ zDeA== X-Gm-Message-State: AOJu0YyRzQfjVueYzyaJPkk/UQZxpmIcxb7zNwt8b/0yHgJokf0mg6Dl 7+gm+upSyK2kk4Flis4bDdoGc+HTS2ocNVj75OD9VBaltkQqYm0B53Hw9siU X-Google-Smtp-Source: AGHT+IE7UImvPB3MkwumY99bE0BNnxp9JGjbF2cMno0Sjr93IsezfEF3BrauTgXLXrvob9/w6f+V7Q== X-Received: by 2002:a17:906:780f:b0:a3d:cf66:51ff with SMTP id u15-20020a170906780f00b00a3dcf6651ffmr4735063ejm.13.1708286380652; Sun, 18 Feb 2024 11:59:40 -0800 (PST) Received: from mkb-desktop.bosmans (89-224-201-31.ftth.glasoperator.nl. [31.201.224.89]) by smtp.gmail.com with ESMTPSA id dt14-20020a170907728e00b00a3cbbaf5981sm2206999ejc.51.2024.02.18.11.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:59:40 -0800 (PST) From: Maarten Bosmans X-Google-Original-From: Maarten Bosmans To: git@vger.kernel.org Cc: Maarten Bosmans Subject: [PATCH v2 4/5] notes: do not clean up right before calling die() Date: Sun, 18 Feb 2024 20:59:37 +0100 Message-Id: <20240218195938.6253-5-maarten.bosmans@vortech.nl> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240218195938.6253-1-maarten.bosmans@vortech.nl> References: <20240205204932.16653-1-maarten.bosmans@vortech.nl> <20240218195938.6253-1-maarten.bosmans@vortech.nl> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Maarten Bosmans From: Maarten Bosmans For consistency with the other uses of die() in the same function. Signed-off-by: Maarten Bosmans --- builtin/notes.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 184a92d0c1..6863935d03 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -311,12 +311,8 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset) die(_("failed to resolve '%s' as a valid ref."), arg); if (!(value = repo_read_object_file(the_repository, &object, &type, &len))) die(_("failed to read object '%s'."), arg); - if (type != OBJ_BLOB) { - strbuf_release(&msg->buf); - free(value); - free(msg); + if (type != OBJ_BLOB) die(_("cannot read note data from non-blob object '%s'."), arg); - } strbuf_add(&msg->buf, value, len); free(value); From patchwork Sun Feb 18 19:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Bosmans X-Patchwork-Id: 13562016 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C890C71B4A for ; Sun, 18 Feb 2024 19:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286384; cv=none; b=l2b8I+xxTVrzQ7hPILTn6+QBrepZ2xx5s/WxZsy+73UgRvzjzvPlmnJxy8CJbrgCpEyqMdrQODHHok6un2UemC7sqBu9W5exkBeZjU/G+MEkPuG2yK5EbIDjlfMhM06i8OtDU54F8PMhu3pKj0WdTLk/ke3JgKOUXHoeHEdi+pw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708286384; c=relaxed/simple; bh=FmPAJoncZifGIK+ki6+imjE16pCm3iqm1RJxRBQaHZ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m7S7txe5CtRu2uPF2aMKoF9R5f5ewynaQdGI2uzg75kqcXgVO/fnnrwH5SvOFkh8bdvp+nAWihiOWloUQS5Jymzpg9yAURUMCkJ6xLYFSBWPsqWqTcdpKCliDilNTVKFJkwLwI1WoVimRNfp7H+DDp+IUS64u7Go5nO7V4VwXb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h3CgzqUb; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h3CgzqUb" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a3e82664d53so44413766b.3 for ; Sun, 18 Feb 2024 11:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708286381; x=1708891181; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kp2n/AxMm4iMLySdN2e8I0yh8tEWJx3SZZyloE9mgi0=; b=h3CgzqUbfRkBKWAMSGU551P3BPS5LsGdV5GwhqZCJ2yOJYkPc4Zwrfm3QKQRsffJPU 5EA0dL3RX9dPZC+TWdPPW1pN7DA03zEreyWUr+PJw0eJXBExmGwDc55X5YyNHuTVy8x3 4PlBy8WI9mzmnBNyPKr29Cam7yoJXK3/fIH0jH2/rUNfHyJcmBgzU6n6DafablUmchex 7/PzYmEd8BbxMYQvuZw665CNZ6gism6BnBZpyH2BKwtXGLqt2OikUgjpok8hEFmYfgBJ wjMBu6inZf3daX15KlZhtEhc6T15iqdulIRs3GZ8HUTEEKc0t89ek5U2KB7HStBqweBb breQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708286381; x=1708891181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kp2n/AxMm4iMLySdN2e8I0yh8tEWJx3SZZyloE9mgi0=; b=G76WUVQpPpNM/iBohKX13IzKEHt/RrspmQ8ZnaePuIz26c0UQfpbzLclDvJZ6epmQA lA9juHQdCt/F1tt8h/2K3J+JpkeHei1ajMoKfAicldOa+VxyRgTPquY95gfXngThq3kx h2eHQFR4EopqpGY8UYgAUCqoyHwZ2Wf9DCiK0S8yk6yr4hzuDZBQo+fLYIN4CA4013uE 85l8mSuWg2N0adrEZeU0AmqlJav/OxFG9dLA0UEoYJi1i+jTELSD4rJeKf5ie6fDdRJo 2/lVHiyVJ8sM2KijAnIq7Pveb41v81SAvV0SzG6LGE93EP9sM4qw0863jcDOB4slRM76 WLLg== X-Gm-Message-State: AOJu0YzvP8HXELbAk7Ue8AsTAAtcrEBn+gbW7/OUj3lluIJGm5IZhk4O z0nCTmJWfLSkFR5T+4DP74gPh71H4QvVjWVCxeNpWPiwhfAB6bHUBk8g8QJE X-Google-Smtp-Source: AGHT+IEpyaGSUdSqZd7DUxOB3nzj0+TjM9OzSYxI49m8IUXHRzx0+7MMWmAbMqJ6R7+fGsb0nYB8nw== X-Received: by 2002:a17:906:3b94:b0:a3d:26b2:94f4 with SMTP id u20-20020a1709063b9400b00a3d26b294f4mr7445516ejf.73.1708286381089; Sun, 18 Feb 2024 11:59:41 -0800 (PST) Received: from mkb-desktop.bosmans (89-224-201-31.ftth.glasoperator.nl. [31.201.224.89]) by smtp.gmail.com with ESMTPSA id dt14-20020a170907728e00b00a3cbbaf5981sm2206999ejc.51.2024.02.18.11.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:59:40 -0800 (PST) From: Maarten Bosmans X-Google-Original-From: Maarten Bosmans To: git@vger.kernel.org Cc: Maarten Bosmans Subject: [PATCH v2 5/5] notes: use strbuf_attach to take ownership of the object contents Date: Sun, 18 Feb 2024 20:59:38 +0100 Message-Id: <20240218195938.6253-6-maarten.bosmans@vortech.nl> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240218195938.6253-1-maarten.bosmans@vortech.nl> References: <20240205204932.16653-1-maarten.bosmans@vortech.nl> <20240218195938.6253-1-maarten.bosmans@vortech.nl> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Maarten Bosmans From: Maarten Bosmans Avoid an extra allocation in the strbuf when pushing the string into it. Signed-off-by: Maarten Bosmans --- builtin/notes.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 6863935d03..5be24a9c58 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -314,10 +314,8 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset) if (type != OBJ_BLOB) die(_("cannot read note data from non-blob object '%s'."), arg); - strbuf_add(&msg->buf, value, len); - free(value); + strbuf_attach(&msg->buf, value, len, len + 1); - msg->buf.len = len; ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc); d->messages[d->msg_nr - 1] = msg; msg->stripspace = NO_STRIPSPACE; @@ -705,12 +703,11 @@ static int append_edit(int argc, const char **argv, const char *prefix) if (!prev_buf) die(_("unable to read %s"), oid_to_hex(note)); if (size) - strbuf_add(&buf, prev_buf, size); + strbuf_attach(&buf, prev_buf, size, size + 1); if (d.buf.len && size) append_separator(&buf); strbuf_insert(&d.buf, 0, buf.buf, buf.len); - free(prev_buf); strbuf_release(&buf); }