git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] mailmap: only look for .mailmap in work tree

From
Jeff King <peff@peff.net>
Date
Feb 10, 2021, 16:15 UTC
Message-ID
<YCQGqeHB4rXi6dG0@coredump.intra.peff.net>
In-Reply-To
<xmqqv9b1ylyj.fsf@gitster.c.googlers.com>
On Tue, Feb 09, 2021 at 01:23:32PM -0800, Junio C Hamano wrote:
Show 21 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> >   If the file `.mailmap` exists at the toplevel of the repository[...]
> >
> > which likewise reinforces the notion that we are looking in the working
> > tree.
> 
> > diff --git a/mailmap.c b/mailmap.c
> > index eb77c6e77c..9bb9cf8b30 100644
> > --- a/mailmap.c
> > +++ b/mailmap.c
> > @@ -225,7 +225,8 @@ int read_mailmap(struct string_list *map)
> >  	if (!git_mailmap_blob && is_bare_repository())
> >  		git_mailmap_blob = "HEAD:.mailmap";
> >  
> > -	err |= read_mailmap_file(map, ".mailmap");
> > +	if (!startup_info->have_repository || !is_bare_repository())
> > +		err |= read_mailmap_file(map, ".mailmap");
> 
> OK.  Do we know at this point that cwd is always/already at the root
> level of the working tree?

I think so. If we're in a non-bare repository, we'd have chdir'd during the setup/discovery steps. At any rate, this patch could not possibly be making such a situation _worse_, as we were previously reading it unconditionally.

If you are proposing that this become:
  if (!startup_info->have_repository) {
	/* no repository (e.g., shortlog reading stdin); use map in cwd */
	err |= read_mailmap_file(map, ".mailmap");
  } else if (get_git_work_tree()) {
        /* we have a work tree; read from the top-level */
	char *map_file = xstrfmt("%s/.mailmap", get_git_work_tree());
	err |= read_mailmap_file(map, map_file);
	free(map_file);
  } else {
        /* bare; do not read filesystem .mailmap */
  }

I could buy that. I suspect it may even be necessary to use a mailmap in an in-process submodule repository (in which case we should be taking a "struct repository" argument and checking it in the first two branches of the conditional). But this is orthogonal to what my patch is doing, I think. And I'd rather punt on it until there is a known upside (probably as part of a larger effort to allow mailmaps outside of the_repository).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 12 in “I've noticed the command `git --git-dir=<path> shortlog`”
  1. SURAFeb 1, 2021
  2. Jeff KingFeb 5, 2021
  3. Bryan TurnerFeb 5, 2021
  4. mailmap: only look for .mailmap in work treeJeff King, Feb 9, 2021
  5. Eric SunshineFeb 9, 2021
  6. Junio C HamanoFeb 9, 2021
  7. Jeff KingFeb 10, 2021
  8. Junio C HamanoFeb 9, 2021
  9. Jeff KingFeb 10, 2021
  10. Junio C HamanoFeb 10, 2021
  11. Jeff KingFeb 10, 2021
  12. Jeff KingFeb 10, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.