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=1796249753; b=tUO9bMoIbfTnRUp/DyPiz1ygwu36ZvXe85x8HkGh4ZbByB/dBHq/QSfC8A8H1wyW0mcW wqkw8K5g6OFbI8D5D40kNQVVLdbCvzfGfZ5nuabxWdwL1jhzParSOWdYdWwE2Xq/HADBg 9z46zLglE0G0uTTrfNkFKKC0uZz05Vznyl25bVkMSiTDLj00EgZGtVr0d1dLDCJl8wnKh XutMXw2U87cCCKn3088DTp+Pueko84W/KHKXyyHuJzjZi+fE0C50eF2yAvevq6xHX6pS+ /I31g8LlUutqwIppy8GHTP67SVcYNmNrmisSusg4gfeMaXROV4EgpZVtFIVA8FrdbYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796249753; 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-Type:Content-Transfer-Encoding; bh=9yvor+FNRoEWetgqCjy/CwSSK7DAH7YJyyTFjWVKCq4=; b=OZpnP5NLyblUGZQwGnNWAjj8xSK2/Jzf+CuO6jJcQ+SZ81n/+LU7L+Br1jgVPKkgVkC+ T4S0E8CtqGDO+rpAbgwYNU9s+d7wHzkBqScj37kmn+rkmA7HRi6KrHG9mEipp6uLt/F1S DeS0403v2zepLPSNVixxdeHgbwW1JS9iQ12np/6VPAM1LEgxqAE/FxzvDO2diYBcj69vf O6n/W8JLQ8NM7K8tglrgq+1iFFXSZXpUYvwl/O1986QQMKVXL308qF03HwYWC9LkXg3i/ 2qfvo9Z01PDRJdSDSRcCwmvpwQQ1tTXJl+YYFrKRN2r5qs86VOufTy9Ar7wX1qaCs1A== 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=RoPGqiES; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=PPAEYVrD; 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 E434A606A322 for ; Wed, 2 Dec 2026 22:15:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E434A606A322 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=RoPGqiES; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=PPAEYVrD Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0DD6D140011E for ; Wed, 2 Dec 2026 17:15:52 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Wed, 02 Dec 2026 17:15:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc:cc:content-transfer-encoding:content-type: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=1796249752; x=1796336152; bh=9yvor+FNRoEWetgqCjy/CwSSK7DAH7YJyyTFjWVKCq4=; b= RoPGqiES7r5SwG+gUEnYBAscWydC0wVudHJo2puQEX9OAt7mc8kgI2kZaP7azQjo /b76WPmy5dKpcFQk6lwzvzyxACF44V3DBeYoq4KZZgQbgDW616TyjSGiZcEsKlDT Ae3qFF7nWNVLEWhLHCoN5YzEIKPhnJg8ZD1ic8XtnM2QWPBg4QNn3bgyz0q0LqXS wAcCchaRInbdEpY7ko6jWi9vhusuHns6gnq/3dxOdSzbA/uSSbqN8tmz5df3DmdP 6l8XEbxe+Q6aXD5/W+A2gtoHTgg0PKWY75/7zIRIblGVEq5/1mRz5wzBrWO/sdv1 i+Ml6DfaVaBubEqezcUYLw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=1796249752; x= 1796336152; bh=9yvor+FNRoEWetgqCjy/CwSSK7DAH7YJyyTFjWVKCq4=; b=P PAEYVrDs9IWrPg2YzrTwzzKZjLZJYmq/r3qLCxKhg75ABmyQOHlZVK+jUfTMnTUF GlmqXWEDBx+xW9aepjE2og4+6+OdOckRe4L86YIP+Afzpgs6mzDRD0FlNEJj0YYu 4JeltnZof4e6Gi/3MiDPdxnZzegnBLjqTSsvweIj00Yhza5jJDtkln9KVlTMCK+V 0d8nadhxiYcDs2+PMMan9Cm8h+QG4cd2eEcO/EOUqr0F+C/K+qTuPelcv6oiG2y6 z+MgGED3EbFrssIh+O+j6daM4uTLbFTK21JeGsiYon0oLHYrjpgmfqNI7l4kYxlY GkDqhTiszzIN3GhNZk1pA== 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=1796249752; d=fastmail.com; mf=PGtyaXN0b2ZmZXJoYXVnc2Jha2tAZmFzdG1haWwuY29tPg==; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:Ht8fPnDtFl+IdtZsG01h0EhFF/BTJCJ373c6duq1X6ODPlh yrMySxw/ACcRQhkOOJZoG/bgXeXLv45zz8/5xaKid/AHVqdGIzD+leNbXGR8aCTp KdJNtPFKkTYVIs5rcG/b7Mb8uNvL6hzviblAepjNagjKE912QnNf5ttGM08Mbt0W 9dtEKWOYalATBFzGn1EKmskRH15ybSvhRFCB7hXjwIB26fi0pQuf3auUadJCtC7F 1uSg7cw7f3Hlh+J7IcaFHFzPl5BTHYJIUWc/snc2qO575DObKpgocFPlvXQCstDS tVcuPRWJyTmP/4Bau49c7YrTlYrlQ4PkeW0IjIw==; 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=12; hn=cc,content-transfer-encoding,content-type,date,feedback-id, from,in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:PO/3ZAC7+aalLUykU+OlZuhetDJSu0iS4ht8vQjdLk0=:CE4+Evp4lxe4QaMXyGSuLx9cGxpzIAWOwIVL7P0zVRA=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFXM3T0fZEi0btnMcYRutLPDn5SE7PUWmi3ng7TvIVlpexXbEBVqH6cvGesLHRLYv Htmy2eB3hg5kotiy3t4WCPojDogrTzUH3oi0c+J5wmCL9kSn8WjggA8eL11gJOoSwUYu6S ddYOHHjIbKrIkPmJEZmQCJgwPvmLC7bhheYLq/fB9H+GVTcRz5uqrTjFkJ2fab0VrL0EGH KLSrqTDveKKxNltm6xbcad4f7ZGOfUPAECeA6jIYJMOp9W3Z3cdUQK/fQlkVHr53WC0SyR KYEco6LHPqHiZCBs/FpWWEQ0Ye8iPoR7KpBu5VvW8S31/o6chHZn0ZJ5QeGQIMEXicI0UU Y9gN1JTx6XXa28vLumOlvJrCFpReWmzoqOkR7By7aAB3y81VYNecuKzlUWwX5sxgj9zgMj ipFvSGVIK293KuY5oghfF7QKCqETaNaEY0P+2feBMqdQYLuHBbjvU5yGScflfmg9RRSlmv Y1stYtEsqcB/lZIc3BlvtvTk5+j+kAhJzhRpW9jVpK98l2wRh+jKB1cvk2oxZbWCz3JlV1 wpzw9woss/t/DXUO8/0Zs0I5hjK387EquUq7QXqAyfecuBOPROTv979/Koe0DTN7bxM+/3 UcM81alycMCTfBowFmAeyMxtq1PLRvwKZo5wRfe82NTnKcAHmpleLBPxscdw X-ME-Proxy: Feedback-ID: i8b11424c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Dec 2026 17:15:51 -0500 (EST) From: kristofferhaugsbakk@fastmail.com To: git@vger.kernel.org Cc: Kristoffer Haugsbakk Subject: [PATCH 05/12] log-tree: terminate cmt+diff when -z --patch Date: Wed, 2 Dec 2026 23:14:13 +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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Kristoffer Haugsbakk Terminate the whole log record, i.e. the commit and the diff, with NUL when e.g. 'git log -z --patch' or 'git log -z --stat' is used and records use terminators. This is in line with how these commands work with separators. This fixes test case 'NUL termination with --stat' in t4205. This behavior is useful because a program can read one record at a time by looking for NUL. And, unlike the separator case, it can be read piecemeal; in the separator case, you feed one commit to log-tree.c and get a record without any delimiter. You have to feed the *next* commit to get the delimiter and then the next record. The separator case was fixed in abd4e222 (Fix "git log -z" behaviour, 2007-02-07). It tells us this: For commit messages, we should really put the "line_termination" when we output the character in between different commits, *not* between the commit and the diff. The diff goes hand-in-hand with the commit, it shouldn't be separated from it with the termination character. So this: - uses the termination character for true inter-commit spacing - uses a regular newline between the commit log and the diff [...] This is the problem that the terminator case has right now. The reason is that show_log(...) handles record termination at the end of the function. At that point we have only printed the commit message. Let’s put off the NUL termination case to the end of log_tree_commit. That covers all cases: no diff, regular diff, and diff on merge commits. Now, as to the the commit ID and diff case:[1] git diff-tree -z --patch --stdin It would be nice to uniformly have NUL termination for the whole record by using a newline between the commit ID and the diff. But it might seem that backwards compatibility could be a problem here. Fortunately it isn’t, since there isn’t a way to get both NUL delimiting and record termination; record termination is turned on by using custom pretty formats, and custom pretty formats turn off the plain commit ID display. So we are free to define this behavior. † 1: log-tree.c:767 Signed-off-by: Kristoffer Haugsbakk --- builtin/diff-tree.c | 1 + log-tree.c | 28 ++++++++++++++++++++++++++-- log-tree.h | 5 +++++ t/t4205-log-pretty-formats.sh | 10 +++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 8b8f8b54e40..c7734f7be63 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -59,6 +59,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p) diff_tree_oid(&tree1->object.oid, &tree2->object.oid, "", &log_tree_opt.diffopt); log_tree_diff_flush(&log_tree_opt); + log_tree_nul_terminate(&log_tree_opt); return 0; } diff --git a/log-tree.c b/log-tree.c index 361dfadbb36..5dcee870be0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -764,7 +764,18 @@ void show_log(struct rev_info *opt) putc('\n', opt->diffopt.file); graph_show_remainder(opt->graph); } - putc(opt->diffopt.line_termination, opt->diffopt.file); + if (opt->use_terminator && + opt->diffopt.line_termination == '\0') { + /* + * NUL termination means that we postpone the terminator. + * But we do want a newline between the commit ID and + * the diff. + */ + if (opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) + putc('\n', opt->diffopt.file); + } else { + putc(opt->diffopt.line_termination, opt->diffopt.file); + } return; } @@ -916,7 +927,12 @@ void show_log(struct rev_info *opt) if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) { if (!opt->missing_newline) graph_show_padding(opt->graph); - putc(opt->diffopt.line_termination, opt->diffopt.file); + /* + * Termination is postponed for NUL in case there is + * diff output after the log message. + */ + if (opt->diffopt.line_termination != '\0') + putc(opt->diffopt.line_termination, opt->diffopt.file); } strbuf_release(&msgbuf); @@ -973,6 +989,12 @@ int log_tree_diff_flush(struct rev_info *opt) return 1; } +void log_tree_nul_terminate(struct rev_info *opt) { + if (opt->use_terminator && + opt->diffopt.line_termination == '\0') + putc(opt->diffopt.line_termination, opt->diffopt.file); +} + static int do_diff_combined(struct rev_info *opt, struct commit *commit) { diff_tree_combined_merge(commit, opt); @@ -1312,6 +1334,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) } } + log_tree_nul_terminate(opt); + opt->loginfo = NULL; maybe_flush_or_die(opt->diffopt.file, "stdout"); opt->diffopt.no_free = no_free; diff --git a/log-tree.h b/log-tree.h index e8679b6c4aa..c5eec0459d8 100644 --- a/log-tree.h +++ b/log-tree.h @@ -26,6 +26,11 @@ struct decoration_options { int parse_decorate_color_config(const char *var, const char *slot_name, const char *value); int log_tree_diff_flush(struct rev_info *); int log_tree_commit(struct rev_info *, struct commit *); +/* + * Terminates the record if 'opt->use_terminator' and if + * 'opt->line_termination' is NUL. + */ +void log_tree_nul_terminate(struct rev_info *opt); void release_follow_pathspec_slab(struct rev_info *); void show_log(struct rev_info *opt); void format_decorations(struct strbuf *sb, const struct commit *commit, diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index b03dd647ee4..a9a470606cf 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -169,7 +169,7 @@ test_expect_success 'NUL separation with --format=medium --patch' ' test_cmp_bin expected actual ' -test_expect_failure 'NUL termination with --stat' ' +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^) && printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n\0" >expected && @@ -177,6 +177,14 @@ test_expect_failure 'NUL termination with --stat' ' test_cmp expected actual ' +test_expect_success 'NUL termination with --patch' ' + diff0_part=$(git diff HEAD^ HEAD) && + diff1_part=$(git diff-tree --no-commit-id --patch --root HEAD^) && + printf "add bar\n${diff0_part}\n\0$(commit_msg)\n${diff1_part}\n\0" >expected && + git log -z --patch --pretty="tformat:%s" >actual && + test_cmp_bin expected actual +' + for p in short medium full fuller email raw do test_expect_success "NUL termination with --reflog --pretty=$p" ' -- 2.56.1.5.g155936fbb2a