From: Bence Ferdinandy <bence@ferdinandy.com>
To: git@vger.kernel.org
Cc: "Kristoffer Haugsbakk" <code@khaugsbakk.name>,
"Bence Ferdinandy" <bence@ferdinandy.com>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Junio C Hamano" <gitster@pobox.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>,
"Teng Long" <dyroneteng@gmail.com>
Subject: [RFC PATCH] notes: add prepend command
Date: Wed, 23 Oct 2024 22:14:24 +0200 [thread overview]
Message-ID: <20241023201430.986389-1-bence@ferdinandy.com> (raw)
When a note is detailing commit history, it makes sense to keep the
latest change on top, but unlike adding things at the bottom with
"git notes append" this can only be done manually. Add a
git notes prepend
command, which works exactly like the append command, except that it
inserts the text before the current contents of the note instead of
after.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
---
Notes:
RFC v1: Cf.
https://lore.kernel.org/git/20241023153736.257733-1-bence@ferdinandy.com/T/#m5b6644827590c2518089ab84f936a970c4e9be0f
For that particular series I've used
git rev-list HEAD~8..HEAD | xargs -i git notes append {} -m "v12: no change"
for a quick-start on updating notes, when only 1 note needed to be
really edited with meaningful content, and for some of the patches
you now need to scroll a bit to actually find that "no change" text,
instead of seeing it right at the top.
builtin/notes.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 8c26e45526..cf158cab1c 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -35,6 +35,7 @@ static const char * const git_notes_usage[] = {
N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
N_("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>"),
N_("git notes [--ref <notes-ref>] append [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
+ N_("git notes [--ref <notes-ref>] prepend [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
N_("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]"),
N_("git notes [--ref <notes-ref>] show [<object>]"),
N_("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>"),
@@ -644,7 +645,8 @@ static int copy(int argc, const char **argv, const char *prefix)
return retval;
}
-static int append_edit(int argc, const char **argv, const char *prefix)
+
+static int append_prepend_edit(int argc, const char **argv, const char *prefix, int prepend)
{
int allow_empty = 0;
const char *object_ref;
@@ -716,11 +718,18 @@ 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);
- if (d.buf.len && size)
- append_separator(&buf);
- strbuf_insert(&d.buf, 0, buf.buf, buf.len);
+ if (prepend) {
+ if (d.buf.len && size)
+ append_separator(&buf);
+ if (size)
+ strbuf_add(&buf, prev_buf, size);
+ } else {
+ if (size)
+ strbuf_add(&buf, prev_buf, size);
+ if (d.buf.len && size)
+ append_separator(&buf);
+ }
+ strbuf_insert(&d.buf, prepend ? d.buf.len : 0, buf.buf, buf.len);
free(prev_buf);
strbuf_release(&buf);
@@ -745,6 +754,16 @@ static int append_edit(int argc, const char **argv, const char *prefix)
return 0;
}
+static int prepend_edit(int argc, const char **argv, const char *prefix)
+{
+ return append_prepend_edit(argc, argv, prefix, 1);
+}
+
+static int append_edit(int argc, const char **argv, const char *prefix)
+{
+ return append_prepend_edit(argc, argv, prefix, 0);
+}
+
static int show(int argc, const char **argv, const char *prefix)
{
const char *object_ref;
@@ -1116,6 +1135,7 @@ int cmd_notes(int argc,
OPT_SUBCOMMAND("add", &fn, add),
OPT_SUBCOMMAND("copy", &fn, copy),
OPT_SUBCOMMAND("append", &fn, append_edit),
+ OPT_SUBCOMMAND("prepend", &fn, prepend_edit),
OPT_SUBCOMMAND("edit", &fn, append_edit),
OPT_SUBCOMMAND("show", &fn, show),
OPT_SUBCOMMAND("merge", &fn, merge),
--
2.47.0.119.g5b706304f7.dirty
next reply other threads:[~2024-10-23 20:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 20:14 Bence Ferdinandy [this message]
2024-10-23 20:20 ` [RFC PATCH] notes: add prepend command Taylor Blau
2024-10-23 20:32 ` Bence Ferdinandy
2024-10-24 11:19 ` Đoàn Trần Công Danh
2024-10-26 22:34 ` Bence Ferdinandy
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=20241023201430.986389-1-bence@ferdinandy.com \
--to=bence@ferdinandy.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=code@khaugsbakk.name \
--cc=congdanhqx@gmail.com \
--cc=dyroneteng@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=szeder.dev@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 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.