From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.154 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796249788; b=122pRwtF0glCm+T8f9OdXhHynv0C0kJCIyL+Yh3wbJ2eTN2qmukyyzRbkTodlF9Cd6eI hb2jXAwlg7RaRGynVAWAn/fxf4vUa1tcBPogTkG6Yqyu4m6lnkmc2ViA5cePw0+/IgnAX MvAplp/LjANz4+X1H7CEjLWMj95ISqKDhE4t+kE1bZl3SuoiBX8uEsWlELbb4QLPyLxjv iGTL15Q3rTuNGDny6ESZwsljlHmrzUqQtw7zdwTvD45+Nzk0g+gCFTtCbNeuJ0B0buzdp 4FAktZyaZb2Nucgm6miMPOR58R2of2usGQfaE5mBUOBkxK+l/hv73fXIxwsPizp+qiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796249788; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=TOVEfP+uEcz2ef942Wspkt2gFJm5zWf3OhWZEGfm/JE=; b=EOPen34PhS6QWT1bOeDmwsyyCUaBR8DXTfZWA3ttc1A+B2oFOEb3LiCT88uM8xoYW9yd mA0c7wVbgfhqwwotHJ11Ekd38LiPSUzqfedCm4uhYNVrrjZIUDyZobPzn/HsXswcPhsLW 5CHdzBjIjW7fcmEvhiNeypH04q7Vq/TxvvhDI59YOHjofBGlU8nJ5n1WtUBf/adwbbmBk Dq5UeLwZuXX9FtWgF2OmdyqbHU/syUhnM/Z0Ixwl7Gy74TTSXwayYpTCml20BGdBQl11W F/LAapylct038qyrn3s7OETYB4oojb1yIejRuSitJRuPC8MsVJpMGQdMwkS8ij/AS4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fastmail.com; spf=pass smtp.mailfrom=fastmail.com; dkim=pass header.d=fastmail.com header.i=@fastmail.com header.a=rsa-sha256 header.s=fm3 header.b=aGwLF9Su; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b="TaJp8/uW"; arc=none smtp.remote-ip=103.168.172.154 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43691606A322 for ; Wed, 2 Dec 2026 22:16:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 43691606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fastmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fastmail.com header.i=@fastmail.com header.a=rsa-sha256 header.s=fm3 header.b=aGwLF9Su; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=TaJp8/uW Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 2DAD61400046 for ; Wed, 2 Dec 2026 17:16:27 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Wed, 02 Dec 2026 17:16:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1796249787; x= 1796336187; bh=TOVEfP+uEcz2ef942Wspkt2gFJm5zWf3OhWZEGfm/JE=; b=a GwLF9Sugx4Mc0WvLU9qidjexSyEdNEg91uovFboUiZsYRHTxkFMI0rX7plXFq7Gp 4nbabaG02S+qruFAaIQv9f7woYVTuZXytEMxvDlCyRtyihqdJ84sAwtiz4E6L6ch rzY8AgbRyXrJlDG/ss0wzI5oaUzvoAoQAN8YR12uplJpjzwMw288kIg+Exr5oSk9 Ws0fKs8r/VwkblSg+FbdYQ8K6P1K/aUUrI0gBmOCqOHWbB8rWF0NaZZWSJ1P4lU8 KQ7XsuuPxExUFAdZFNQte3aqPvKTwyUY6QRr7u00FsJ+WggtMkIryE9gzFHF8Mvi 1EfD3EsZps1iFLmy5pdSw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796249787; x=1796336187; bh=T OVEfP+uEcz2ef942Wspkt2gFJm5zWf3OhWZEGfm/JE=; b=TaJp8/uWfpBEnriG/ 8smIJxk1oVxwuQBdPSRQhxPXlvODl9jDQMfP+R3oN4dpncHbg/mta0wA/NTqtGnJ UwUM4HFEG/MUqXwfyZaXdidCQQF54+HSrULGUcsEmVyX8EDQzP81hkNJHmElgyfl +IKQQsoNM7iGZkrX/Wi1y00FP30ePvtnW/JSxBGnlrU/qc/iGoZisuid7KT+M3wi cHAYBAYez9WCV+VQQyHgpC2SvBfw5Mx3jdqVuUomsvuZYDmyk1zvN5yFg9bZhmsl khsTeUpV4EVA78TDHbWMF/NbB5kRUZfOBhxl9N0wk5aHUIjrP74jR4sa6fPjs/oE KJ3Bw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=fastmail.com a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796249787; d=fastmail.com; mf=PGtyaXN0b2ZmZXJoYXVnc2Jha2tAZmFzdG1haWwuY29tPg==; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:i40Cha28ie5d+AWIuDMGREGKkK1smgSpsk1sORAkLW3ioGi yZG6MBQ349pkk0saGkMV0sojHvWteB02Q6srzCry8+w/xU9CYlmdhX0v+wLHxa/f GA4Tj8W2Ktgc4pcmCPxylq1/WD7wBAktqXSft/E5VgQwP34IgMSMZFR9LEfdaXYi W+YDk9N8pvJ9MYDYlzdWIXfhxVt2qwUoni6BAUgzxFzkrtON310wNlcWrb4i/x1V zUjjE35uw/SD14LygxCq8gRSc1uzUI+GctaBS8pCniUueI0UGZRx7JLoe4qBKGK3 iUArhB0RW3JMtDU6nzdPvnbnOMM2huwC2mjqs8w==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:58GLh9/6Fwma4h7N5U9eUvOOwz+TD8jk5hKbfatkP8U=:nEPhN35srBmAUr7dAU0zh4d58I5cVjS+/DvV4UwHiDU=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTF+ZmuMvprRmYyIU5xGBWC58jPA2aDPQIEXEOcukTXklgR1gvHGEKJ3PexvjU0FNO HMooiWhLLJ69hURBbNuqHiBM9onwLMmzA5WoJdMs+LwVBxkRU4k+oXSC77RlM2ZDitKlbn qrS6Y9vXRc4BvKlrd08QZXdbq8J2Rt+mPNVyjdnsLkgvKN2KWy5IzVo+M+YMacTi8LRpna azqk30KPASpsKE9BmB8owQTmeYuY5upvBHmb3IMGRfG2iJi7+NQ4xIx5BiQFE1XBbKK+Be ToOYZXic8ulnwl/rrwUgCor7NhFdFPfvtBH1FkeVBR40UWvPmqqUZi4c/+rZdA3Cu9A7QO E7wYhGqeelxP6cfCcM+7swzlfFQkT/krEGE4FtGHASx7HflRnCw/fVnMus64BwkbvRZP+U OYEgtiyUsF5/J6Td902slZ+0V2cbKbkTZ38q8Sv+RLZzgFNJSI+1zqK5lIkoO0wdxtqxP6 KVhUEgaf456KjfrI2ClwsdhRFUvUvoNQOo7LncDaBvYQ9ziqvAKfj/TNshETGss9Ti5ZuF R0Ci3dbtT+n49GrQsglas9dcAkRb9osECpDwk9K490whBOnZn+tf6kFdOdml2IsfW4Q3hl 4WFDx23MKwJhwa7T5dpYaGnGaaHtlTxu8BiWQ/XwdKqSZfACIkX6BdE2Lxvg X-ME-Proxy: Feedback-ID: i8b11424c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Dec 2026 17:16:26 -0500 (EST) From: kristofferhaugsbakk@fastmail.com To: git@vger.kernel.org Cc: Kristoffer Haugsbakk Subject: [PATCH 07/12] revision: learn -Z for NUL termination Date: Wed, 2 Dec 2026 23:14:15 +0100 Message-ID: X-Mailer: git-send-email 2.56.1.5.g155936fbb2a In-Reply-To: References: X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kristoffer Haugsbakk Add a new option -Z which turns on NUL terminators for commit records. Separator delimiting is the default, while terminators are turned on for user-defined pretty formats. But that means that you cannot get terminator behavior for built-in pretty formats. This options fills in that gap. Combining NUL delimiting with termination behavior means that the user can read and act on each record immediately without risking deadlocks. However, the picture is not as simple as just splitting on NUL. The terminator/delimiter character is taken from struct diff_options, so you have to take the diff behavior with the git-log(1) behavior. But we will split these up in the next comit so that you use -Z without getting NUL in any diff format. Signed-off-by: Kristoffer Haugsbakk --- Documentation/rev-list-options.adoc | 12 ++++++++++++ pretty.c | 8 +++++--- revision.c | 4 ++++ revision.h | 5 +++++ t/t4013-diff-various.sh | 23 +++++++++++++++++++++++ t/t4205-log-pretty-formats.sh | 27 +++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 3 deletions(-) diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc index c234e865cb1..a4bf96e7d0a 100644 --- a/Documentation/rev-list-options.adoc +++ b/Documentation/rev-list-options.adoc @@ -396,6 +396,18 @@ This mode is only compatible with the `--objects`, `--boundary`, and `--missing` output options. endif::git-rev-list[] +`-Z`:: + Use NUL terminator to delimit records. The _record_ is the + commit and whatever extra information about it, like for example + `--patch` or `--stat`. ++ +Note that separator/terminator behavior is usually set when using +`--pretty` or `--format`. These have no effect when this option is +given. ++ +This implies `-z`, so diff output formats like `--raw` and `--numstat` +will also contain _NUL_ internally. + History Simplification ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pretty.c b/pretty.c index d8a9f370f6c..019e1f88511 100644 --- a/pretty.c +++ b/pretty.c @@ -54,7 +54,7 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma { free(user_format); user_format = xstrdup(cp); - if (is_tformat) + if (!rev->want_terminator && is_tformat) rev->use_terminator = 1; rev->commit_format = CMIT_FMT_USERFORMAT; } @@ -191,7 +191,8 @@ void get_commit_format(const char *arg, struct rev_info *rev) { struct cmt_fmt_map *commit_format; - rev->use_terminator = 0; + if (!rev->want_terminator) + rev->use_terminator = 0; if (!arg) { rev->commit_format = CMIT_FMT_DEFAULT; return; @@ -211,7 +212,8 @@ void get_commit_format(const char *arg, struct rev_info *rev) die("invalid --pretty format: %s", arg); rev->commit_format = commit_format->format; - rev->use_terminator = commit_format->is_tformat; + if (!rev->want_terminator) + rev->use_terminator = commit_format->is_tformat; rev->expand_tabs_in_log_default = commit_format->expand_tabs_in_log; if (!rev->date_mode_explicit && commit_format->default_date_mode_type) rev->date_mode.type = commit_format->default_date_mode_type; diff --git a/revision.c b/revision.c index a83e499047b..1d2a10267ca 100644 --- a/revision.c +++ b/revision.c @@ -2755,6 +2755,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg if (revs->repo->fetch_if_missing) BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0"); revs->exclude_promisor_objects = 1; + } else if (!strcmp(arg, "-Z")) { + revs->want_terminator = 1; + revs->use_terminator = 1; + revs->diffopt.line_termination = '\0'; } else { int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix); if (!opts) diff --git a/revision.h b/revision.h index e5dabd18ce1..c6598ba6f22 100644 --- a/revision.h +++ b/revision.h @@ -272,6 +272,11 @@ struct rev_info { abbrev_commit:1, abbrev_commit_given:1, zero_commit:1, + /* + * pretty.c should not set 'use_terminator' if + * this is true. + */ + want_terminator:1, use_terminator:1, missing_newline:1, date_mode_explicit:1, diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 928a07a91bd..207bd2df423 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -626,6 +626,29 @@ test_expect_success 'diff-tree --stdin --patch -z --always with one empty diff' test_cmp_bin expect actual ' +test_expect_success 'diff-tree --stdin --patch -Z' ' + cat oid1 >expect && + echo >>expect && + cat diff1 >>expect && + printf "\0" >>expect && + cat oid2 >>expect && + echo >>expect && + cat diff2 >>expect && + printf "\0" >>expect && + git diff-tree --stdin --patch -Z actual && + test_cmp_bin expect actual +' + +test_expect_success 'diff-tree --stdin --patch -Z --always with one empty diff' ' + git rev-parse main >expect && + printf "\0" >>expect && + git rev-parse main~1 >>expect && + cat diff1 >>expect && + printf "\0" >>expect && + git diff-tree --stdin --patch -Z --always actual && + test_cmp_bin expect actual +' + test_expect_success 'show A B ... -- ' ' # side touches dir/sub, file0, and file3 # main^ touches dir/sub, and file1 diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index ece4def4cfd..2d6cca46fff 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -169,6 +169,33 @@ test_expect_success 'NUL separation with --format=medium --patch' ' test_cmp_bin expected actual ' +test_expect_success 'NUL with -Z and --format=medium --patch' ' + git show HEAD >expected && + printf "\0" >>expected && + git show HEAD^ >>expected && + printf "\0" >>expected && + git log -Z --patch >actual && + test_cmp_bin expected actual +' + +test_expect_success 'NUL and terminator behavior with -Z' ' + git show HEAD >expected && + printf "\0" >>expected && + git show HEAD^ >>expected && + printf "\0" >>expected && + git log -Z --patch >actual && + test_cmp_bin expected actual +' + +test_expect_success '-Z --format=medium still uses terminator' ' + git show HEAD >expected && + printf "\0" >>expected && + git show HEAD^ >>expected && + printf "\0" >>expected && + git log -Z --format=medium --patch >actual && + test_cmp_bin expected actual +' + test_expect_success 'NUL termination with --stat' ' stat0_part=$(git diff --stat HEAD^ HEAD) && stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && -- 2.56.1.5.g155936fbb2a