sequencer: use repository parameter in short_commit_name()

Instead of just using the_repository, we can take a repository parameter from the caller. Most of them already have one, and doing so clears up a few -Wunused-parameter warnings. There are still a few callers which use the_repository, but this pushes us one small step forward to eventually getting rid of those. Note that a few of these functions have a "rev_info" whose "repo" parameter could probably be used instead of the_repository. I'm leaving that for further cleanups, as it's not immediately obvious that revs->repo is always valid, and there's quite a bit of other possible refactoring here (even getting rid of some "struct repository" arguments in favor of revs->repo). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 29, 2023 at 19:43 UTC cb646ffb0aff30cec6cd47d43df8ba33c320afd9
1 file changed +13 -12
sequencer.c
+13 -12
@@ -433,10 +433,9 @@ struct commit_message {
433 const char *message;
434 };
435
436 -static const char *short_commit_name(struct commit *commit)
436 +static const char *short_commit_name(struct repository *r, struct commit *commit)
437 {
438 - return repo_find_unique_abbrev(the_repository, &commit->object.oid,
439 - DEFAULT_ABBREV);
438 + return repo_find_unique_abbrev(r, &commit->object.oid, DEFAULT_ABBREV);
439 }
440
441 static int get_message(struct commit *commit, struct commit_message *out)
@@ -446,7 +445,7 @@ static int get_message(struct commit *commit, struct commit_message *out)
445
446 out->message = repo_logmsg_reencode(the_repository, commit, NULL,
447 get_commit_output_encoding());
449 - abbrev = short_commit_name(commit);
448 + abbrev = short_commit_name(the_repository, commit);
449
450 subject_len = find_commit_subject(out->message, &subject);
451
@@ -2383,7 +2382,7 @@ static int do_pick_commit(struct repository *r,
2382 error(command == TODO_REVERT
2383 ? _("could not revert %s... %s")
2384 : _("could not apply %s... %s"),
2386 - short_commit_name(commit), msg.subject);
2385 + short_commit_name(r, commit), msg.subject);
2386 print_advice(r, res == 1, opts);
2387 repo_rerere(r, opts->allow_rerere_auto);
2388 goto leave;
@@ -3172,7 +3171,8 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
3171 item->offset_in_buf = todo_list->buf.len;
3172 subject_len = find_commit_subject(commit_buffer, &subject);
3173 strbuf_addf(&todo_list->buf, "%s %s %.*s\n", command_string,
3175 - short_commit_name(commit), subject_len, subject);
3174 + short_commit_name(the_repository, commit),
3175 + subject_len, subject);
3176 repo_unuse_commit_buffer(the_repository, commit,
3177 commit_buffer);
3178 }
@@ -3593,7 +3593,7 @@ static int error_with_patch(struct repository *r,
3593 } else if (exit_code) {
3594 if (commit)
3595 fprintf_ln(stderr, _("Could not apply %s... %.*s"),
3596 - short_commit_name(commit), subject_len, subject);
3596 + short_commit_name(r, commit), subject_len, subject);
3597 else
3598 /*
3599 * We don't have the hash of the parent so
@@ -4728,7 +4728,7 @@ static int pick_commits(struct repository *r,
4728 term_clear_line();
4729 fprintf(stderr,
4730 _("Stopped at %s... %.*s\n"),
4731 - short_commit_name(commit),
4731 + short_commit_name(r, commit),
4732 item->arg_len, arg);
4733 }
4734 return error_with_patch(r, commit,
@@ -5564,7 +5564,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
5564 if (!is_empty && (commit->object.flags & PATCHSAME)) {
5565 if (flags & TODO_LIST_WARN_SKIPPED_CHERRY_PICKS)
5566 warning(_("skipped previously applied commit %s"),
5567 - short_commit_name(commit));
5567 + short_commit_name(the_repository, commit));
5568 skipped_commit = 1;
5569 continue;
5570 }
@@ -5800,7 +5800,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
5800 if (!is_empty && (commit->object.flags & PATCHSAME)) {
5801 if (flags & TODO_LIST_WARN_SKIPPED_CHERRY_PICKS)
5802 warning(_("skipped previously applied commit %s"),
5803 - short_commit_name(commit));
5803 + short_commit_name(r, commit));
5804 skipped_commit = 1;
5805 continue;
5806 }
@@ -5892,7 +5892,8 @@ static void todo_list_add_exec_commands(struct todo_list *todo_list,
5892 todo_list->alloc = alloc;
5893 }
5894
5895 -static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list,
5895 +static void todo_list_to_strbuf(struct repository *r,
5896 + struct todo_list *todo_list,
5897 struct strbuf *buf, int num, unsigned flags)
5898 {
5899 struct todo_item *item;
@@ -5921,7 +5922,7 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
5922 /* add commit id */
5923 if (item->commit) {
5924 const char *oid = flags & TODO_LIST_SHORTEN_IDS ?
5924 - short_commit_name(item->commit) :
5925 + short_commit_name(r, item->commit) :
5926 oid_to_hex(&item->commit->object.oid);
5927
5928 if (item->command == TODO_FIXUP) {