All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 01/22] sequencer: use repository parameter in short_commit_name()
Date: Mon, 28 Aug 2023 15:21:11 -0700	[thread overview]
Message-ID: <xmqqsf82g65k.fsf@gitster.g> (raw)
In-Reply-To: <20230828214629.GA3831137@coredump.intra.peff.net> (Jeff King's message of "Mon, 28 Aug 2023 17:46:29 -0400")

Jeff King <peff@peff.net> writes:

> -static const char *short_commit_name(struct commit *commit)
> +static const char *short_commit_name(struct repository *r, struct commit *commit)
>  {
> -	return repo_find_unique_abbrev(the_repository, &commit->object.oid,
> -				       DEFAULT_ABBREV);
> +	return repo_find_unique_abbrev(r, &commit->object.oid, DEFAULT_ABBREV);
>  }

Theoretically this is the right thing to do, and ...

>  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)
>  
>  	out->message = repo_logmsg_reencode(the_repository, commit, NULL,
>  					    get_commit_output_encoding());
> -	abbrev = short_commit_name(commit);
> +	abbrev = short_commit_name(the_repository, commit);

... this is a no-op.

> @@ -2383,7 +2382,7 @@ static int do_pick_commit(struct repository *r,
>  		error(command == TODO_REVERT
>  		      ? _("could not revert %s... %s")
>  		      : _("could not apply %s... %s"),
> -		      short_commit_name(commit), msg.subject);
> +		      short_commit_name(r, commit), msg.subject);

And this is a logical consequence for a function that is told by the
caller in which repository to work in via its parameter.

> @@ -3172,7 +3171,8 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
>  		item->offset_in_buf = todo_list->buf.len;
>  		subject_len = find_commit_subject(commit_buffer, &subject);
>  		strbuf_addf(&todo_list->buf, "%s %s %.*s\n", command_string,
> -			short_commit_name(commit), subject_len, subject);
> +			short_commit_name(opts->revs->repo, commit),
> +			subject_len, subject);
>  		repo_unuse_commit_buffer(the_repository, commit,
>  					 commit_buffer);

But how do we ascertain that opts->revs->repo is always safe to use
(iow initialized to a sensible value)?  repo_init_revisions() takes
a repository as its parameter and the first thing it does is to set
it to the revs->repo, so it is safe for any "struct rev_info" that
came from there, but REV_INFO_INIT omits initializer for the .repo
member.

The other two calls in this loop refer to the_repository so the
current code would be safe even if opts->revs->repo is set or NULL,
but that will no longer be true with the updated code.  I'd feel
safer if at the beginning of the function we create a local variable
"struct rev_info *repo" that is initialized to opts->revs->repo and
use it throughout the function instead of the_repository.


> @@ -5564,7 +5564,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
>  		if (!is_empty && (commit->object.flags & PATCHSAME)) {
>  			if (flags & TODO_LIST_WARN_SKIPPED_CHERRY_PICKS)
>  				warning(_("skipped previously applied commit %s"),
> -					short_commit_name(commit));
> +					short_commit_name(revs->repo, commit));
>  			skipped_commit = 1;
>  			continue;
>  		}

This one I am fairly certain is a safe and correct conversion; the
function would be segfaulting in its call to get_revision() if
revs->repo were set to a bogus value.

Thanks.

  reply	other threads:[~2023-08-28 22:21 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-28 21:46 [PATCH 0/22] YAUPS: Yet Another Unused Parameter Series Jeff King
2023-08-28 21:46 ` [PATCH 01/22] sequencer: use repository parameter in short_commit_name() Jeff King
2023-08-28 22:21   ` Junio C Hamano [this message]
2023-08-28 23:06     ` Taylor Blau
2023-08-29  0:48     ` Jeff King
2023-08-29  1:16       ` Junio C Hamano
2023-08-28 21:47 ` [PATCH 02/22] sequencer: mark repository argument as unused Jeff King
2023-08-28 23:24   ` Taylor Blau
2023-08-29 15:55   ` Phillip Wood
2023-08-29 23:32     ` Jeff King
2023-08-30 13:35       ` Phillip Wood
2023-08-28 21:47 ` [PATCH 03/22] ref-filter: mark unused parameters in parser callbacks Jeff King
2023-08-28 21:47 ` [PATCH 04/22] pack-bitmap: mark unused parameters in show_object callback Jeff King
2023-08-28 21:47 ` [PATCH 05/22] worktree: mark unused parameters in each_ref_fn callback Jeff King
2023-08-28 21:47 ` [PATCH 06/22] commit-graph: mark unused data parameters in generation callbacks Jeff King
2023-08-28 23:32   ` Taylor Blau
2023-08-29  0:52     ` Jeff King
2023-08-28 21:47 ` [PATCH 07/22] ls-tree: mark unused parameter in callback Jeff King
2023-08-28 21:47 ` [PATCH 08/22] stash: mark unused parameter in diff callback Jeff King
2023-08-28 21:47 ` [PATCH 09/22] trace2: mark unused us_elapsed_absolute parameters Jeff King
2023-08-28 21:47 ` [PATCH 10/22] trace2: mark unused config callback parameter Jeff King
2023-08-28 21:47 ` [PATCH 11/22] test-trace2: mark unused argv/argc parameters Jeff King
2023-08-28 21:47 ` [PATCH 12/22] grep: mark unused parameter in output function Jeff King
2023-08-28 21:48 ` [PATCH 13/22] add-interactive: mark unused callback parameters Jeff King
2023-08-28 21:48 ` [PATCH 14/22] negotiator/noop: " Jeff King
2023-08-28 21:48 ` [PATCH 15/22] worktree: mark unused parameters in noop repair callback Jeff King
2023-08-28 21:48 ` [PATCH 16/22] imap-send: mark unused parameters with NO_OPENSSL Jeff King
2023-08-28 21:48 ` [PATCH 17/22] grep: mark unused parmaeters in pcre fallbacks Jeff King
2023-08-28 21:48 ` [PATCH 18/22] credential: mark unused parameter in urlmatch callback Jeff King
2023-08-28 21:48 ` [PATCH 19/22] fetch: mark unused parameter in ref_transaction callback Jeff King
2023-08-28 21:48 ` [PATCH 20/22] bundle-uri: mark unused parameters in callbacks Jeff King
2023-08-28 21:48 ` [PATCH 21/22] gc: mark unused descriptors in scheduler callbacks Jeff King
2023-08-28 21:48 ` [PATCH 22/22] update-ref: mark unused parameter in parser callbacks Jeff King
2023-08-28 23:35 ` [PATCH 0/22] YAUPS: Yet Another Unused Parameter Series Taylor Blau
2023-08-29 23:43 ` [PATCH v2 0/22] " Jeff King
2023-08-29 23:43   ` [PATCH v2 01/22] sequencer: use repository parameter in short_commit_name() Jeff King
2023-08-30 13:24     ` Phillip Wood
2023-08-29 23:44   ` [PATCH v2 02/22] sequencer: mark repository argument as unused Jeff King
2023-08-29 23:45   ` [PATCH v2 03/22] ref-filter: mark unused parameters in parser callbacks Jeff King
2023-08-29 23:45   ` [PATCH v2 04/22] pack-bitmap: mark unused parameters in show_object callback Jeff King
2023-08-29 23:45   ` [PATCH v2 05/22] worktree: mark unused parameters in each_ref_fn callback Jeff King
2023-08-29 23:45   ` [PATCH v2 06/22] commit-graph: mark unused data parameters in generation callbacks Jeff King
2023-08-29 23:45   ` [PATCH v2 07/22] ls-tree: mark unused parameter in callback Jeff King
2023-08-29 23:45   ` [PATCH v2 08/22] stash: mark unused parameter in diff callback Jeff King
2023-08-29 23:45   ` [PATCH v2 09/22] trace2: mark unused us_elapsed_absolute parameters Jeff King
2023-08-29 23:45   ` [PATCH v2 10/22] trace2: mark unused config callback parameter Jeff King
2023-08-29 23:45   ` [PATCH v2 11/22] test-trace2: mark unused argv/argc parameters Jeff King
2023-08-29 23:45   ` [PATCH v2 12/22] grep: mark unused parameter in output function Jeff King
2023-08-29 23:45   ` [PATCH v2 13/22] add-interactive: mark unused callback parameters Jeff King
2023-08-29 23:45   ` [PATCH v2 14/22] negotiator/noop: " Jeff King
2023-08-29 23:45   ` [PATCH v2 15/22] worktree: mark unused parameters in noop repair callback Jeff King
2023-08-29 23:45   ` [PATCH v2 16/22] imap-send: mark unused parameters with NO_OPENSSL Jeff King
2023-08-29 23:45   ` [PATCH v2 17/22] grep: mark unused parmaeters in pcre fallbacks Jeff King
2023-08-29 23:45   ` [PATCH v2 18/22] credential: mark unused parameter in urlmatch callback Jeff King
2023-08-29 23:45   ` [PATCH v2 19/22] fetch: mark unused parameter in ref_transaction callback Jeff King
2023-08-29 23:45   ` [PATCH v2 20/22] bundle-uri: mark unused parameters in callbacks Jeff King
2023-08-29 23:45   ` [PATCH v2 21/22] gc: mark unused descriptors in scheduler callbacks Jeff King
2023-08-29 23:45   ` [PATCH v2 22/22] update-ref: mark unused parameter in parser callbacks Jeff King
2023-08-30  1:00   ` [PATCH v2 0/22] Yet Another Unused Parameter Series Junio C Hamano

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=xmqqsf82g65k.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.