git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: SURA <surak8806@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: I've noticed the command `git --git-dir=<path> shortlog`
Date: Fri, 5 Feb 2021 11:57:21 -0500	[thread overview]
Message-ID: <YB148VZJqKIPC8P2@coredump.intra.peff.net> (raw)
In-Reply-To: <CAD6AYr-BD08FcbnVfHpOUt7ZwFH0PgoATgyegKnBQ3GOe9isdA@mail.gmail.com>

On Mon, Feb 01, 2021 at 11:05:13AM +0800, SURA wrote:

> $ git clone --bare https://github.com/gitlabhq/gitlabhq.git
> $ git clone https://gitlab.com/gitlab-org/gitaly.git
> 
> $ git --git-dir=./gitlabhq.git shortlog --summary --email --numbered
> --committer HEAD --end-of-options | wc -l
> > 2592
> [...]
> $ cd gitaly
> $ git --git-dir=../gitlabhq.git shortlog --summary --email --numbered
> --committer HEAD --end-of-options | wc -l
> > 2587

I think what's happening is that the second command is using the
.mailmap file found in the working tree of the gitaly repository.

If the first checkout were non-bare, I would say that is the right
behavior (because --git-dir without otherwise specifying the working
tree means that the current directory becomes the working tree, and we
read ".mailmap" out of the top of the working tree). But because it was
cloned with "--bare", it should have the core.bare config set, and will
think there is no working tree at all.

So I do think there is a bug, which is: Git should avoid looking for
".mailmap" in the current directory if we do not have a working tree.
I.e., something like:

diff --git a/mailmap.c b/mailmap.c
index eb77c6e77c..3ea35a2289 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 (!is_bare_repository())
+		err |= read_mailmap_file(map, ".mailmap");
 	if (startup_info->have_repository)
 		err |= read_mailmap_blob(map, git_mailmap_blob);
 	err |= read_mailmap_file(map, git_mailmap_file);

It's possible somebody is relying on this in order to read ".mailmap" in
a bare repository, but it seems rather unlikely. And the documentation
says "If the file .mailmap exists at the toplevel of the repository",
which I think pretty clearly means the top of the working tree.

-Peff

  reply	other threads:[~2021-02-05 17:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01  3:05 I've noticed the command `git --git-dir=<path> shortlog` SURA
2021-02-05 16:57 ` Jeff King [this message]
2021-02-05 20:02   ` Bryan Turner
2021-02-09 17:29     ` [PATCH] mailmap: only look for .mailmap in work tree Jeff King
2021-02-09 19:00       ` Eric Sunshine
2021-02-09 22:16         ` Junio C Hamano
2021-02-10 16:05         ` Jeff King
2021-02-09 21:23       ` Junio C Hamano
2021-02-10 16:15         ` Jeff King
2021-02-10 20:10           ` Junio C Hamano
2021-02-10 20:31             ` Jeff King
2021-02-10 20:34               ` Jeff King

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=YB148VZJqKIPC8P2@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=surak8806@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).