rev-list: support NUL-delimited --boundary option

The `--boundary` option for git-rev-list(1) prints boundary objects found while performing the object walk in the form: $ git rev-list --boundary <rev> -<oid> LF Add support for printing boundary objects in a NUL-delimited format when the `-z` option is enabled. $ git rev-list -z --boundary <rev> <oid> NUL boundary=yes NUL In this mode, instead of prefixing the boundary OID with '-', a separate `boundary=yes` token/value pair is appended. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Mar 19, 2025 at 13:34 UTC 1c3c1ab3d2a9558050ef6beee0a416700f6b953f
3 files changed +30 -7
Documentation/rev-list-options.adoc
+7 -5
@@ -371,17 +371,19 @@ ifdef::git-rev-list[]
371 <OID> NUL [<token>=<value> NUL]...
372 -----------------------------------------------------------------------
373 +
374 -Additional object metadata, such as object paths, is printed using the
375 -`<token>=<value>` form. Token values are printed as-is without any
376 -encoding/truncation. An OID entry never contains a '=' character and thus
377 -is used to signal the start of a new object record. Examples:
374 +Additional object metadata, such as object paths or boundary objects, is
375 +printed using the `<token>=<value>` form. Token values are printed as-is
376 +without any encoding/truncation. An OID entry never contains a '=' character
377 +and thus is used to signal the start of a new object record. Examples:
378 +
379 -----------------------------------------------------------------------
380 <OID> NUL
381 <OID> NUL path=<path> NUL
382 +<OID> NUL boundary=yes NUL
383 -----------------------------------------------------------------------
384 +
384 -This mode is only compatible with the `--objects` output option.
385 +This mode is only compatible with the `--objects` and `--boundary` output
386 +options.
387 endif::git-rev-list[]
388
389 History Simplification
builtin/rev-list.c
+7 -2
@@ -240,13 +240,18 @@ static void show_commit(struct commit *commit, void *data)
240 fputs(info->header_prefix, stdout);
241
242 if (revs->include_header) {
243 - if (!revs->graph)
243 + if (!revs->graph && line_term)
244 fputs(get_revision_mark(revs, commit), stdout);
245 if (revs->abbrev_commit && revs->abbrev)
246 fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid, revs->abbrev),
247 stdout);
248 else
249 fputs(oid_to_hex(&commit->object.oid), stdout);
250 +
251 + if (!line_term) {
252 + if (commit->object.flags & BOUNDARY)
253 + printf("%cboundary=yes", info_term);
254 + }
255 }
256 if (revs->print_parents) {
257 struct commit_list *parents = commit->parents;
@@ -778,7 +783,7 @@ int cmd_rev_list(int argc,
783 if (revs.graph || revs.verbose_header || show_disk_usage ||
784 info.show_timestamp || info.header_prefix || bisect_list ||
785 use_bitmap_index || revs.edge_hint || revs.left_right ||
781 - revs.cherry_mark || arg_missing_action || revs.boundary)
786 + revs.cherry_mark || arg_missing_action)
787 die(_("-z option used with unsupported option"));
788 }
789
t/t6000-rev-list-misc.sh
+16
@@ -217,4 +217,20 @@ test_expect_success 'rev-list -z --objects' '
217 test_cmp expect actual
218 '
219
220 +test_expect_success 'rev-list -z --boundary' '
221 + test_when_finished rm -rf repo &&
222 +
223 + git init repo &&
224 + test_commit -C repo 1 &&
225 + test_commit -C repo 2 &&
226 +
227 + oid1=$(git -C repo rev-parse HEAD~) &&
228 + oid2=$(git -C repo rev-parse HEAD) &&
229 +
230 + printf "%s\0%s\0boundary=yes\0" "$oid2" "$oid1" >expect &&
231 + git -C repo rev-list -z --boundary HEAD~.. >actual &&
232 +
233 + test_cmp expect actual
234 +'
235 +
236 test_done