public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Tian Yuchen <a3205153416@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, phillip.wood@dunelm.org.uk
Subject: [PATCH v3 2/3] pretty: plumb 'struct repository' into pretty-print APIs
Date: Mon,  2 Mar 2026 04:35:38 +0800	[thread overview]
Message-ID: <20260301203539.1421152-3-a3205153416@gmail.com> (raw)
In-Reply-To: <20260301203539.1421152-1-a3205153416@gmail.com>

To prepare for the elimination of the global state associated with
'log_output_encoding', functions responsible for formatting commit
messages, such as 'pretty_print_commit()' and 'pp_commit_easy()',
must be able to access a repository instance.

Plumb the 'struct repository' pointer down the call chain for these
APIs. Where no such context is readily available in built-ins or
high-level functions, fallback to 'the_repository'.

Signed-off-by: Tian Yuchen <a3205153416@gmail.com>
---
 builtin/checkout.c    | 4 ++--
 builtin/log.c         | 2 +-
 builtin/merge.c       | 2 +-
 builtin/reset.c       | 2 +-
 builtin/rev-list.c    | 2 +-
 builtin/shortlog.c    | 2 +-
 builtin/show-branch.c | 2 +-
 builtin/stash.c       | 2 +-
 bundle.c              | 2 +-
 log-tree.c            | 2 +-
 pretty.c              | 6 +++---
 pretty.h              | 4 ++--
 range-diff.c          | 2 +-
 sequencer.c           | 6 +++---
 14 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index f7b313816e..64c5c9ed1a 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -689,7 +689,7 @@ static void describe_detached_head(const char *msg, struct commit *commit)
 	struct strbuf sb = STRBUF_INIT;
 
 	if (!repo_parse_commit(the_repository, commit))
-		pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
+		pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &sb);
 	if (print_sha1_ellipsis()) {
 		fprintf(stderr, "%s %s... %s\n", msg,
 			repo_find_unique_abbrev(the_repository, &commit->object.oid, DEFAULT_ABBREV),
@@ -1077,7 +1077,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
 	strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV);
 	strbuf_addch(sb, ' ');
 	if (!repo_parse_commit(the_repository, commit))
-		pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
+		pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, sb);
 	strbuf_addch(sb, '\n');
 }
 
diff --git a/builtin/log.c b/builtin/log.c
index 8ab6d3a943..0758aed580 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -2521,7 +2521,7 @@ static void print_commit(char sign, struct commit *commit, int verbose,
 		       repo_find_unique_abbrev(the_repository, &commit->object.oid, abbrev));
 	} else {
 		struct strbuf buf = STRBUF_INIT;
-		pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
+		pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &buf);
 		fprintf(file, "%c %s %s\n", sign,
 		       repo_find_unique_abbrev(the_repository, &commit->object.oid, abbrev),
 		       buf.buf);
diff --git a/builtin/merge.c b/builtin/merge.c
index 7c944fe179..dff8185776 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -470,7 +470,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
 		strbuf_addch(&out, '\n');
 		strbuf_addf(&out, "commit %s\n",
 			oid_to_hex(&commit->object.oid));
-		pretty_print_commit(&ctx, commit, &out);
+		pretty_print_commit(the_repository, &ctx, commit, &out);
 	}
 	write_file_buf(git_path_squash_msg(the_repository), out.buf, out.len);
 	strbuf_release(&out);
diff --git a/builtin/reset.c b/builtin/reset.c
index c48d9845f8..733f3fa905 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -141,7 +141,7 @@ static void print_new_head_line(struct commit *commit)
 	printf(_("HEAD is now at %s"),
 		repo_find_unique_abbrev(the_repository, &commit->object.oid, DEFAULT_ABBREV));
 
-	pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
+	pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &buf);
 	if (buf.len > 0)
 		printf(" %s", buf.buf);
 	putchar('\n');
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ddea8aa251..57c7b8d3ff 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -307,7 +307,7 @@ static void show_commit(struct commit *commit, void *data)
 		ctx.output_encoding = get_log_output_encoding();
 		ctx.color = revs->diffopt.use_color;
 		ctx.rev = revs;
-		pretty_print_commit(&ctx, commit, &buf);
+		pretty_print_commit(the_repository, &ctx, commit, &buf);
 		if (buf.len) {
 			if (revs->commit_format != CMIT_FMT_ONELINE)
 				graph_show_oneline(revs->graph);
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index d80bf1a7d0..109785fd00 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -252,7 +252,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 
 	if (!log->summary) {
 		if (log->user_format)
-			pretty_print_commit(&ctx, commit, &oneline);
+			pretty_print_commit(the_repository, &ctx, commit, &oneline);
 		else
 			repo_format_commit_message(the_repository, commit,
 						   "%s", &oneline, &ctx);
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index f02831b085..6bfe9e2e96 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -310,7 +310,7 @@ static void show_one_commit(struct commit *commit, int no_name)
 	struct commit_name *name = commit_to_name(commit);
 
 	if (commit->object.parsed) {
-		pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
+		pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &pretty);
 		pretty_str = pretty.buf;
 	}
 	skip_prefix(pretty_str, "[PATCH] ", &pretty_str);
diff --git a/builtin/stash.c b/builtin/stash.c
index 785c1f9e5d..a522bb6de5 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1480,7 +1480,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
 						  &head_commit->object.oid,
 						  DEFAULT_ABBREV);
 	strbuf_addf(&msg, "%s: %s ", branch_name, head_short_sha1);
-	pp_commit_easy(CMIT_FMT_ONELINE, head_commit, &msg);
+	pp_commit_easy(the_repository, CMIT_FMT_ONELINE, head_commit, &msg);
 
 	strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf);
 	commit_list_insert(head_commit, &parents);
diff --git a/bundle.c b/bundle.c
index 42327f9739..3bc2ed9ee9 100644
--- a/bundle.c
+++ b/bundle.c
@@ -463,7 +463,7 @@ static void write_bundle_prerequisites(struct commit *commit, void *data)
 	ctx.fmt = CMIT_FMT_ONELINE;
 	ctx.output_encoding = get_log_output_encoding();
 	strbuf_reset(&buf);
-	pretty_print_commit(&ctx, commit, &buf);
+	pretty_print_commit(the_repository, &ctx, commit, &buf);
 	strbuf_trim(&buf);
 
 	object = (struct object *)commit;
diff --git a/log-tree.c b/log-tree.c
index 7e048701d0..fd2fb0bed6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -885,7 +885,7 @@ void show_log(struct rev_info *opt)
 		ctx.from_ident = &opt->from_ident;
 	if (opt->graph)
 		ctx.graph_width = graph_width(opt->graph);
-	pretty_print_commit(&ctx, commit, &msgbuf);
+	pretty_print_commit(opt->repo, &ctx, commit, &msgbuf);
 
 	if (opt->add_signoff)
 		append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);
diff --git a/pretty.c b/pretty.c
index e0646bbc5d..51e3480431 100644
--- a/pretty.c
+++ b/pretty.c
@@ -2281,7 +2281,7 @@ void pp_remainder(struct pretty_print_context *pp,
 	}
 }
 
-void pretty_print_commit(struct pretty_print_context *pp,
+void pretty_print_commit(struct repository *r, struct pretty_print_context *pp,
 			 const struct commit *commit,
 			 struct strbuf *sb)
 {
@@ -2363,10 +2363,10 @@ void pretty_print_commit(struct pretty_print_context *pp,
 	repo_unuse_commit_buffer(the_repository, commit, reencoded);
 }
 
-void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
+void pp_commit_easy(struct repository *r, enum cmit_fmt fmt, const struct commit *commit,
 		    struct strbuf *sb)
 {
 	struct pretty_print_context pp = {0};
 	pp.fmt = fmt;
-	pretty_print_commit(&pp, commit, sb);
+	pretty_print_commit(r, &pp, commit, sb);
 }
diff --git a/pretty.h b/pretty.h
index fac699033e..13eb0189bd 100644
--- a/pretty.h
+++ b/pretty.h
@@ -82,7 +82,7 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w);
  * Shortcut for invoking pretty_print_commit if we do not have any context.
  * Context would be set empty except "fmt".
  */
-void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
+void pp_commit_easy(struct repository *r, enum cmit_fmt fmt, const struct commit *commit,
 			struct strbuf *sb);
 
 /*
@@ -132,7 +132,7 @@ void get_commit_format(const char *arg, struct rev_info *);
  * and put it into "sb".
  * Please use this function if you have a context (candidate for "pp").
  */
-void pretty_print_commit(struct pretty_print_context *pp,
+void pretty_print_commit(struct repository *r, struct pretty_print_context *pp,
 			const struct commit *commit,
 			struct strbuf *sb);
 
diff --git a/range-diff.c b/range-diff.c
index 57edff40a8..31d38c2318 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -460,7 +460,7 @@ static void output_pair_header(struct diff_options *diffopt,
 			strbuf_addf(buf, "%s%s", color_reset, color);
 
 		strbuf_addch(buf, ' ');
-		pp_commit_easy(CMIT_FMT_ONELINE, commit, buf);
+		pp_commit_easy(diffopt->repo, CMIT_FMT_ONELINE, commit, buf);
 	}
 	strbuf_addf(buf, "%s\n", color_reset);
 
diff --git a/sequencer.c b/sequencer.c
index 627020d65b..e6b3e05fce 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5870,7 +5870,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
 			continue;
 
 		strbuf_reset(&oneline);
-		pretty_print_commit(pp, commit, &oneline);
+		pretty_print_commit(revs->repo, pp, commit, &oneline);
 
 		to_merge = commit->parents ? commit->parents->next : NULL;
 		if (!to_merge) {
@@ -6012,7 +6012,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
 				strbuf_addf(out, "%s onto\n", cmd_reset);
 			else {
 				strbuf_reset(&oneline);
-				pretty_print_commit(pp, commit, &oneline);
+				pretty_print_commit(revs->repo, pp, commit, &oneline);
 				strbuf_addf(out, "%s %s %s\n",
 					    cmd_reset, to, oneline.buf);
 			}
@@ -6124,7 +6124,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out,
 			continue;
 		strbuf_addf(out, "%s %s ", insn,
 			    oid_to_hex(&commit->object.oid));
-		pretty_print_commit(&pp, commit, out);
+		pretty_print_commit(r, &pp, commit, out);
 		if (is_empty)
 			strbuf_addf(out, " %s empty", comment_line_str);
 		strbuf_addch(out, '\n');
-- 
2.43.0


  parent reply	other threads:[~2026-03-01 20:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28  4:07 [PATCH v1] environment: migrate encoding settings to repo-settings Tian Yuchen
2026-02-28 19:01 ` [PATCH v2 0/3] migrate encoding settings and bubble up repository Tian Yuchen
2026-02-28 19:01   ` [PATCH v2 1/3] environment: migrate encoding settings to repo-settings Tian Yuchen
2026-02-28 19:02   ` [PATCH v2 2/3] commit: pass 'struct repository' to commit creation APIs Tian Yuchen
2026-02-28 19:02   ` [PATCH v2 3/3] pretty: pass 'struct repository' to pretty_print_commit() Tian Yuchen
2026-03-01 20:35 ` [PATCH v3 0/3] environment: move encoding configs to struct repository Tian Yuchen
2026-03-01 20:35   ` [PATCH v3 1/3] commit: plumb 'struct repository' into commit creation APIs Tian Yuchen
2026-03-01 20:35   ` Tian Yuchen [this message]
2026-03-01 20:35   ` [PATCH v3 3/3] environment: migrate encoding configs to struct repository Tian Yuchen
2026-03-02  8:57 ` [PATCH v4 0/3] move encoding configs to repo_config_values() Tian Yuchen
2026-03-02  8:57   ` [PATCH v4 1/3] commit: plumb 'struct repository' into commit creation APIs Tian Yuchen
2026-03-02  8:57   ` [PATCH v4 2/3] pretty: plumb 'struct repository' into pretty-print APIs Tian Yuchen
2026-03-02  8:57   ` [PATCH v4 3/3] environment: migrate encoding configs to repo_config_values() Tian Yuchen

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=20260301203539.1421152-3-a3205153416@gmail.com \
    --to=a3205153416@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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