From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, christian.couder@gmail.com,
Justin Tobler <jltobler@gmail.com>
Subject: [PATCH 4/4] rev-list: support NUL-delimited --missing option
Date: Mon, 10 Mar 2025 14:28:29 -0500 [thread overview]
Message-ID: <20250310192829.661692-5-jltobler@gmail.com> (raw)
In-Reply-To: <20250310192829.661692-1-jltobler@gmail.com>
The `--missing={print,print-info}` option for git-rev-list(1) prints
missing objects found while performing the revision walk. Add support
for printing missing objects in a NUL-delimited format when the `-z`
option is enabled.
$ git rev-list -z --missing=print-info <rev>
<oid> NUL NUL
?<oid> [NUL <token>=<value>]... NUL NUL
In this mode, values containing special characters or spaces are printed
as-is without being escaped or quoted.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
Documentation/rev-list-options.adoc | 10 +++++++++-
builtin/rev-list.c | 27 +++++++++++++++++++-------
t/t6022-rev-list-missing.sh | 30 +++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 8 deletions(-)
diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc
index d21016d657..48648b7507 100644
--- a/Documentation/rev-list-options.adoc
+++ b/Documentation/rev-list-options.adoc
@@ -378,7 +378,15 @@ containing newline characters:
<OID> [NUL <object-name>] NUL NUL
-----------------------------------------------------------------------
+
-This option is only compatible with `--objects`.
+When the `--missing` option is provided, missing objects are printed in the
+following form where value is printed as-is without any token specific
+encoding:
++
+-----------------------------------------------------------------------
+?<OID> [NUL <token>=<value>]... NUL NUL
+-----------------------------------------------------------------------
++
+This option is only compatible with `--objects` and `--missing`.
endif::git-rev-list[]
History Simplification
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 86b3ce5806..5bbc4a787e 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -145,25 +145,38 @@ static void print_missing_object(struct missing_objects_map_entry *entry,
int print_missing_info)
{
struct strbuf sb = STRBUF_INIT;
+ char info_sep = ' ';
+
+ if (nul_delim)
+ info_sep = '\0';
+
+ printf("?%s", oid_to_hex(&entry->entry.oid));
if (!print_missing_info) {
- printf("?%s\n", oid_to_hex(&entry->entry.oid));
+ print_object_term(nul_delim);
return;
}
if (entry->path && *entry->path) {
struct strbuf path = STRBUF_INIT;
- strbuf_addstr(&sb, " path=");
- quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP);
- strbuf_addbuf(&sb, &path);
+ strbuf_addf(&sb, "%cpath=", info_sep);
+
+ if (nul_delim) {
+ strbuf_addstr(&sb, entry->path);
+ } else {
+ quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP);
+ strbuf_addbuf(&sb, &path);
+ }
strbuf_release(&path);
}
if (entry->type)
- strbuf_addf(&sb, " type=%s", type_name(entry->type));
+ strbuf_addf(&sb, "%ctype=%s", info_sep, type_name(entry->type));
+
+ fwrite(sb.buf, sizeof(char), sb.len, stdout);
+ print_object_term(nul_delim);
- printf("?%s%s\n", oid_to_hex(&entry->entry.oid), sb.buf);
strbuf_release(&sb);
}
@@ -782,7 +795,7 @@ int cmd_rev_list(int argc,
if (nul_delim) {
if (revs.graph || revs.verbose_header || show_disk_usage ||
info.show_timestamp || info.header_prefix || bisect_list ||
- use_bitmap_index || revs.edge_hint || arg_missing_action)
+ use_bitmap_index || revs.edge_hint)
die(_("-z option used with unsupported option"));
}
diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh
index 3e2790d4c8..3ae25e4cfb 100755
--- a/t/t6022-rev-list-missing.sh
+++ b/t/t6022-rev-list-missing.sh
@@ -198,4 +198,34 @@ do
'
done
+test_expect_success "-z nul-delimited --missing" '
+ test_when_finished rm -rf repo &&
+
+ git init repo &&
+ (
+ cd repo &&
+ git commit --allow-empty -m first &&
+
+ path="foo bar" &&
+ echo foobar >"$path" &&
+ git add -A &&
+ git commit -m second &&
+
+ oid=$(git rev-parse "HEAD:$path") &&
+ type="$(git cat-file -t $oid)" &&
+
+ obj_path=".git/objects/$(test_oid_to_path $oid)" &&
+
+ git rev-list -z --objects --no-object-names \
+ HEAD ^"$oid" >expect &&
+ printf "?%s\0path=%s\0type=%s\0\0" "$oid" "$path" "$type" >>expect &&
+
+ mv "$obj_path" "$obj_path.hidden" &&
+ git rev-list -z --objects --no-object-names \
+ --missing=print-info HEAD >actual &&
+
+ test_cmp expect actual
+ )
+'
+
test_done
--
2.49.0.rc2
next prev parent reply other threads:[~2025-03-10 19:32 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 19:28 [PATCH 0/4] rev-list: introduce NUL-delimited output mode Justin Tobler
2025-03-10 19:28 ` [PATCH 1/4] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-10 20:51 ` Junio C Hamano
2025-03-10 19:28 ` [PATCH 2/4] rev-list: refactor early option parsing Justin Tobler
2025-03-10 20:54 ` Junio C Hamano
2025-03-12 21:39 ` Justin Tobler
2025-03-10 19:28 ` [PATCH 3/4] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-10 20:59 ` Junio C Hamano
2025-03-12 21:39 ` Justin Tobler
2025-03-12 7:50 ` Patrick Steinhardt
2025-03-12 21:41 ` Justin Tobler
2025-03-10 19:28 ` Justin Tobler [this message]
2025-03-10 20:37 ` [PATCH 0/4] rev-list: introduce NUL-delimited output mode Junio C Hamano
2025-03-10 21:08 ` Junio C Hamano
2025-03-11 23:24 ` Justin Tobler
2025-03-11 23:19 ` Justin Tobler
2025-03-11 23:44 ` Junio C Hamano
2025-03-12 7:37 ` Patrick Steinhardt
2025-03-12 21:45 ` Justin Tobler
2025-03-10 22:38 ` D. Ben Knoble
2025-03-11 22:59 ` Justin Tobler
2025-03-11 23:57 ` Jeff King
2025-03-12 7:42 ` Patrick Steinhardt
2025-03-12 15:56 ` Junio C Hamano
2025-03-13 7:46 ` Patrick Steinhardt
2025-03-12 22:09 ` Justin Tobler
2025-03-13 5:33 ` Jeff King
2025-03-13 16:41 ` Justin Tobler
2025-03-14 2:49 ` Jeff King
2025-03-14 17:02 ` Junio C Hamano
2025-03-14 18:59 ` Jeff King
2025-03-14 19:53 ` Justin Tobler
2025-03-14 21:16 ` Junio C Hamano
2025-03-19 15:58 ` Justin Tobler
2025-03-13 0:17 ` [PATCH v2 0/6] " Justin Tobler
2025-03-13 0:17 ` [PATCH v2 1/6] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-13 0:17 ` [PATCH v2 2/6] rev-list: refactor early option parsing Justin Tobler
2025-03-13 0:17 ` [PATCH v2 3/6] revision: support NUL-delimited --stdin mode Justin Tobler
2025-03-13 0:17 ` [PATCH v2 4/6] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-13 12:55 ` Patrick Steinhardt
2025-03-13 14:44 ` Justin Tobler
2025-03-13 0:17 ` [PATCH v2 5/6] rev-list: support NUL-delimited --boundary option Justin Tobler
2025-03-13 0:17 ` [PATCH v2 6/6] rev-list: support NUL-delimited --missing option Justin Tobler
2025-03-13 12:55 ` Patrick Steinhardt
2025-03-13 14:51 ` Justin Tobler
2025-03-13 23:57 ` [PATCH v3 0/6] rev-list: introduce NUL-delimited output mode Justin Tobler
2025-03-13 23:57 ` [PATCH v3 1/6] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-13 23:57 ` [PATCH v3 2/6] rev-list: refactor early option parsing Justin Tobler
2025-03-13 23:57 ` [PATCH v3 3/6] revision: support NUL-delimited --stdin mode Justin Tobler
2025-03-13 23:57 ` [PATCH v3 4/6] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-19 12:35 ` Christian Couder
2025-03-19 16:02 ` Justin Tobler
2025-03-13 23:57 ` [PATCH v3 5/6] rev-list: support NUL-delimited --boundary option Justin Tobler
2025-03-13 23:57 ` [PATCH v3 6/6] rev-list: support NUL-delimited --missing option Justin Tobler
2025-03-19 18:34 ` [PATCH v4 0/5] rev-list: introduce NUL-delimited output mode Justin Tobler
2025-03-19 18:34 ` [PATCH v4 1/5] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-19 18:34 ` [PATCH v4 2/5] rev-list: refactor early option parsing Justin Tobler
2025-03-19 18:34 ` [PATCH v4 3/5] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-19 18:34 ` [PATCH v4 4/5] rev-list: support NUL-delimited --boundary option Justin Tobler
2025-03-19 18:34 ` [PATCH v4 5/5] rev-list: support NUL-delimited --missing option Justin Tobler
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=20250310192829.661692-5-jltobler@gmail.com \
--to=jltobler@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/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).