mbox series

[v4,0/4] Add support for mailmap in cat-file

Message ID 20220712160634.213956-1-siddharthasthana31@gmail.com (mailing list archive)
Headers show
Series Add support for mailmap in cat-file | expand

Message

Siddharth Asthana July 12, 2022, 4:06 p.m. UTC
Thanks a lot for helping me fix the broken test Johannes and Junio! :D

= Description

This patch series adds mailmap support to the git-cat-file command. It
adds the mailmap support only for the commit and tag objects by
replacing the idents for "author", "committer" and "tagger" headers. The
mailmap only takes effect when --[no-]-use-mailmap or --[no-]-mailmap
option is passed to the git cat-file command. The changes will work with
the batch mode as well.

So, if one wants to enable mailmap they can use either of the following
commands:
$ git cat-file --use-mailmap -p <object>
$ git cat-file --use-mailmap <type> <object>

To use it in the batch mode, one can use the following command:
$ git cat-file --use-mailmap --batch

= Patch Organization

- The first patch improves the commit_rewrite_person() by restricting it 
  to traverse only through the header part of the commit object buffer.
  It also adds an argument called headers which the callers can pass. 
  The function will replace idents only on these  passed headers. 
  Thus, the caller won't have to make repeated calls to the function.
- The second patch moves commit_rewrite_person() to ident.c to expose it
  as a public function so that it can be used to replace idents in the
  headers of desired objects.
- The third patch renames commit_rewrite_person() to a name which
  describes its functionality clearly. It is renamed to
  apply_mailmap_to_header().
- The last patch adds mailmap support to the git cat-file command. It
  adds the required documentation and tests as well.

Changes in v4:
- This patch series introduces new test cases for testing the mailmap
  mechanism in git-cat-file command. These tests rely on the side
  effects of the earlier test case `set up symlink tests`. However, that
  test case is guarded behind the `SYMLINKS` prereq, therefore it is not
  run e.g. on Windows. This caused the --use-mailmap tests to fail on 
  Windows. So, that has been fixed by removing the prereq from `set up`
  test case.
- The `set up symlink tests` has also been renamed to `prepare for
  symlink/--use-mailmap tests` to reflect its broadened responsibility.

Siddharth Asthana (4):
  revision: improve commit_rewrite_person()
  ident: move commit_rewrite_person() to ident.c
  ident: rename commit_rewrite_person() to apply_mailmap_to_header()
  cat-file: add mailmap support

 Documentation/git-cat-file.txt |  6 +++
 builtin/cat-file.c             | 43 +++++++++++++++++++-
 cache.h                        |  6 +++
 ident.c                        | 72 ++++++++++++++++++++++++++++++++++
 revision.c                     | 50 ++---------------------
 t/t4203-mailmap.sh             | 56 +++++++++++++++++++++++++-
 6 files changed, 184 insertions(+), 49 deletions(-)

Range-diff against v3:
1:  9e95326c58 = 1:  9e95326c58 revision: improve commit_rewrite_person()
2:  d9395cb8b2 = 2:  d9395cb8b2 ident: move commit_rewrite_person() to ident.c
3:  355bbda25e = 3:  355bbda25e ident: rename commit_rewrite_person() to apply_mailmap_to_header()
4:  69b7ad898b ! 4:  ac532965b4 cat-file: add mailmap support
    @@ Commit message
         cat-file command. It also adds --[no-]mailmap option as an alias to
         --[no-]use-mailmap.
     
    +    This patch also introduces new test cases to test the mailmap mechanism in
    +    git cat-file command.
    +
    +    The tests added in this patch series rely on the side effects of the earlier
    +    test case `set up symlink tests`. However, that test case is guarded behind the
    +    `SYMLINKS` prereq, therefore it is not run e.g. on Windows which can cause the
    +    added tests to fail on Windows. So, fix that by removing the prereq from the
    +    `set up` test case, and adjusting its title to reflect its broadened responsibility.
    +
         Mentored-by: Christian Couder <christian.couder@gmail.com>
         Mentored-by: John Cai <johncai86@gmail.com>
         Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
    @@ builtin/cat-file.c: int cmd_cat_file(int argc, const char **argv, const char *pr
      		batch.all_objects = 1;
     
      ## t/t4203-mailmap.sh ##
    +@@ t/t4203-mailmap.sh: test_expect_success 'find top-level mailmap from subdir' '
    + 	test_cmp expect actual
    + '
    + 
    +-test_expect_success SYMLINKS 'set up symlink tests' '
    ++test_expect_success 'prepare for symlink/--use-mailmap tests' '
    + 	git commit --allow-empty -m foo --author="Orig <orig@example.com>" &&
    + 	echo "New <new@example.com> <orig@example.com>" >map &&
    + 	rm -f .mailmap
     @@ t/t4203-mailmap.sh: test_expect_success SYMLINKS 'symlinks not respected in-tree' '
      	test_cmp expect actual
      '