From: Siddharth Asthana <siddharthasthana31@gmail.com>
To: git@vger.kernel.org
Cc: phillip.wood123@gmail.com, congdanhqx@gmail.com,
christian.couder@gmail.com, avarab@gmail.com, gitster@pobox.com,
Johannes.Schindelin@gmx.de, johncai86@gmail.com,
Siddharth Asthana <siddharthasthana31@gmail.com>
Subject: [PATCH v6 0/4] Add support for mailmap in cat-file
Date: Tue, 19 Jul 2022 01:20:58 +0530 [thread overview]
Message-ID: <20220718195102.66321-1-siddharthasthana31@gmail.com> (raw)
In-Reply-To: <20220716074055.1786231-1-siddharthasthana31@gmail.com>
Thanks a lot Junio for your suggestion :) I have made the suggested
changes.
= 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 v6:
- The function rewrite_ident_line() returns the difference between the
new and the old length of the ident line. We were not using this
information and instead parsing the buffer again to look for the line
ending. This patch set starts using that information to update the
buf_offset value in commit_rewrite_person().
- This patch set also tweaks the commit_rewrite_person() so that it is
easier to understand and avoids unnecessary parsing of the buffer
wherever possible.
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 | 74 ++++++++++++++++++++++++++++++++++
revision.c | 50 ++---------------------
t/t4203-mailmap.sh | 59 +++++++++++++++++++++++++++
6 files changed, 190 insertions(+), 48 deletions(-)
Range-diff against v5:
1: 8c29ad9351 ! 1: 7c086e4c8a revision: improve commit_rewrite_person()
@@ revision.c: int rewrite_parents(struct rev_info *revs, struct commit *commit,
+/*
+ * Returns the difference between the new and old length of the ident line.
+ */
-+static ssize_t rewrite_ident_line(const char *person, struct strbuf *buf,
-+ struct string_list *mailmap)
++static ssize_t rewrite_ident_line(const char *person, size_t len,
++ struct strbuf *buf,
++ struct string_list *mailmap)
{
- char *person, *endp;
-+ char *endp;
- size_t len, namelen, maillen;
+- size_t len, namelen, maillen;
++ size_t namelen, maillen;
const char *name;
const char *mail;
struct ident_split ident;
@@ revision.c: int rewrite_parents(struct rev_info *revs, struct commit *commit,
- return 0;
-
- person += strlen(what);
- endp = strchr(person, '\n');
- if (!endp)
+- endp = strchr(person, '\n');
+- if (!endp)
+- return 0;
+-
+- len = endp - person;
+-
+ if (split_ident_line(&ident, person, len))
return 0;
+
@@ revision.c: static int commit_rewrite_person(struct strbuf *buf, const char *what, struct st
if (map_user(mailmap, &mail, &maillen, &name, &namelen)) {
@@ revision.c: static int commit_rewrite_person(struct strbuf *buf, const char *wha
strbuf_addf(&namemail, "%.*s <%.*s>",
(int)namelen, name, (int)maillen, mail);
@@ revision.c: static int commit_rewrite_person(struct strbuf *buf, const char *what, struct st
+ strbuf_splice(buf, ident.name_begin - buf->buf,
ident.mail_end - ident.name_begin + 1,
namemail.buf, namemail.len);
-
+ newlen = namemail.len;
-+
+
strbuf_release(&namemail);
- return 1;
-+ return newlen - (ident.mail_end - ident.name_begin + 1);
++ return newlen - (ident.mail_end - ident.name_begin);
}
return 0;
}
+static void commit_rewrite_person(struct strbuf *buf, const char **header,
-+ struct string_list *mailmap)
++ struct string_list *mailmap)
+{
+ size_t buf_offset = 0;
+
@@ revision.c: static int commit_rewrite_person(struct strbuf *buf, const char *wha
+ for (;;) {
+ const char *person, *line;
+ size_t i;
++ int found_header = 0;
+
+ line = buf->buf + buf_offset;
+ if (!*line || *line == '\n')
-+ return; /* End of header */
++ return; /* End of headers */
+
+ for (i = 0; header[i]; i++)
+ if (skip_prefix(line, header[i], &person)) {
-+ rewrite_ident_line(person, buf, mailmap);
++ const char *endp = strchrnul(person, '\n');
++ found_header = 1;
++ buf_offset += endp - line;
++ buf_offset += rewrite_ident_line(person, endp - person, buf, mailmap);
+ break;
+ }
+
-+ buf_offset = strchrnul(buf->buf + buf_offset, '\n') - buf->buf;
-+ if (buf->buf[buf_offset] == '\n')
-+ ++buf_offset;
++ if (!found_header) {
++ buf_offset = strchrnul(line, '\n') - buf->buf;
++ if (buf->buf[buf_offset] == '\n')
++ buf_offset++;
++ }
+ }
+}
+
2: ccb7f72fcb ! 2: 2f8fba7f57 ident: move commit_rewrite_person() to ident.c
@@ ident.c: int split_ident_line(struct ident_split *split, const char *line, int l
+/*
+ * Returns the difference between the new and old length of the ident line.
+ */
-+static ssize_t rewrite_ident_line(const char *person, struct strbuf *buf,
-+ struct string_list *mailmap)
++static ssize_t rewrite_ident_line(const char *person, size_t len,
++ struct strbuf *buf,
++ struct string_list *mailmap)
+{
-+ char *endp;
-+ size_t len, namelen, maillen;
++ size_t namelen, maillen;
+ const char *name;
+ const char *mail;
+ struct ident_split ident;
+
-+ endp = strchr(person, '\n');
-+ if (!endp)
-+ return 0;
-+
-+ len = endp - person;
-+
+ if (split_ident_line(&ident, person, len))
+ return 0;
+
@@ ident.c: int split_ident_line(struct ident_split *split, const char *line, int l
+ strbuf_splice(buf, ident.name_begin - buf->buf,
+ ident.mail_end - ident.name_begin + 1,
+ namemail.buf, namemail.len);
-+
+ newlen = namemail.len;
+
+ strbuf_release(&namemail);
+
-+ return newlen - (ident.mail_end - ident.name_begin + 1);
++ return newlen - (ident.mail_end - ident.name_begin);
+ }
+
+ return 0;
+}
+
+void commit_rewrite_person(struct strbuf *buf, const char **header,
-+ struct string_list *mailmap)
++ struct string_list *mailmap)
+{
+ size_t buf_offset = 0;
+
@@ ident.c: int split_ident_line(struct ident_split *split, const char *line, int l
+ for (;;) {
+ const char *person, *line;
+ size_t i;
++ int found_header = 0;
+
+ line = buf->buf + buf_offset;
+ if (!*line || *line == '\n')
-+ return; /* End of header */
++ return; /* End of headers */
+
+ for (i = 0; header[i]; i++)
+ if (skip_prefix(line, header[i], &person)) {
-+ rewrite_ident_line(person, buf, mailmap);
++ const char *endp = strchrnul(person, '\n');
++ found_header = 1;
++ buf_offset += endp - line;
++ buf_offset += rewrite_ident_line(person, endp - person, buf, mailmap);
+ break;
+ }
+
-+ buf_offset = strchrnul(buf->buf + buf_offset, '\n') - buf->buf;
-+ if (buf->buf[buf_offset] == '\n')
-+ ++buf_offset;
++ if (!found_header) {
++ buf_offset = strchrnul(line, '\n') - buf->buf;
++ if (buf->buf[buf_offset] == '\n')
++ buf_offset++;
++ }
+ }
+}
@@ revision.c: int rewrite_parents(struct rev_info *revs, struct commit *commit,
-/*
- * Returns the difference between the new and old length of the ident line.
- */
--static ssize_t rewrite_ident_line(const char *person, struct strbuf *buf,
-- struct string_list *mailmap)
+-static ssize_t rewrite_ident_line(const char *person, size_t len,
+- struct strbuf *buf,
+- struct string_list *mailmap)
-{
-- char *endp;
-- size_t len, namelen, maillen;
+- size_t namelen, maillen;
- const char *name;
- const char *mail;
- struct ident_split ident;
-
-- endp = strchr(person, '\n');
-- if (!endp)
-- return 0;
--
-- len = endp - person;
--
- if (split_ident_line(&ident, person, len))
- return 0;
-
@@ revision.c: int rewrite_parents(struct rev_info *revs, struct commit *commit,
- strbuf_splice(buf, ident.name_begin - buf->buf,
- ident.mail_end - ident.name_begin + 1,
- namemail.buf, namemail.len);
--
- newlen = namemail.len;
-
- strbuf_release(&namemail);
-
-- return newlen - (ident.mail_end - ident.name_begin + 1);
+- return newlen - (ident.mail_end - ident.name_begin);
- }
-
- return 0;
-}
-
-static void commit_rewrite_person(struct strbuf *buf, const char **header,
-- struct string_list *mailmap)
+- struct string_list *mailmap)
-{
- size_t buf_offset = 0;
-
@@ revision.c: int rewrite_parents(struct rev_info *revs, struct commit *commit,
- for (;;) {
- const char *person, *line;
- size_t i;
+- int found_header = 0;
-
- line = buf->buf + buf_offset;
- if (!*line || *line == '\n')
-- return; /* End of header */
+- return; /* End of headers */
-
- for (i = 0; header[i]; i++)
- if (skip_prefix(line, header[i], &person)) {
-- rewrite_ident_line(person, buf, mailmap);
+- const char *endp = strchrnul(person, '\n');
+- found_header = 1;
+- buf_offset += endp - line;
+- buf_offset += rewrite_ident_line(person, endp - person, buf, mailmap);
- break;
- }
-
-- buf_offset = strchrnul(buf->buf + buf_offset, '\n') - buf->buf;
-- if (buf->buf[buf_offset] == '\n')
-- ++buf_offset;
+- if (!found_header) {
+- buf_offset = strchrnul(line, '\n') - buf->buf;
+- if (buf->buf[buf_offset] == '\n')
+- buf_offset++;
+- }
- }
-}
-
3: 38c18fd10d ! 3: b4f2477b14 ident: rename commit_rewrite_person() to apply_mailmap_to_header()
@@ cache.h: struct ident_split {
* Compare split idents for equality or strict ordering. Note that we
## ident.c ##
-@@ ident.c: static ssize_t rewrite_ident_line(const char *person, struct strbuf *buf,
+@@ ident.c: static ssize_t rewrite_ident_line(const char *person, size_t len,
return 0;
}
-void commit_rewrite_person(struct strbuf *buf, const char **header,
-- struct string_list *mailmap)
+- struct string_list *mailmap)
+void apply_mailmap_to_header(struct strbuf *buf, const char **header,
-+ struct string_list *mailmap)
++ struct string_list *mailmap)
{
size_t buf_offset = 0;
4: 0a459d4c53 = 4: 63d6f8c201 cat-file: add mailmap support
--
2.37.1.120.g63d6f8c201
next prev parent reply other threads:[~2022-07-18 19:51 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-30 14:24 [PATCH 0/3] Add support for mailmap in cat-file Siddharth Asthana
2022-06-30 14:24 ` [PATCH 1/3] ident: move commit_rewrite_person() to ident.c Siddharth Asthana
2022-06-30 16:00 ` Đoàn Trần Công Danh
2022-06-30 23:22 ` Junio C Hamano
2022-06-30 14:24 ` [PATCH 2/3] ident: rename commit_rewrite_person() to rewrite_ident_line() Siddharth Asthana
2022-06-30 15:33 ` Phillip Wood
2022-06-30 16:55 ` Christian Couder
2022-06-30 23:31 ` Junio C Hamano
2022-06-30 14:24 ` [PATCH 3/3] cat-file: add mailmap support Siddharth Asthana
2022-06-30 15:50 ` Phillip Wood
2022-06-30 16:36 ` Phillip Wood
2022-06-30 17:07 ` Christian Couder
2022-06-30 21:33 ` Junio C Hamano
2022-07-07 9:15 ` Christian Couder
2022-06-30 23:36 ` Ævar Arnfjörð Bjarmason
2022-06-30 23:53 ` Junio C Hamano
2022-07-07 9:02 ` Christian Couder
2022-06-30 23:41 ` Junio C Hamano
2022-06-30 21:18 ` [PATCH 0/3] Add support for mailmap in cat-file Junio C Hamano
2022-07-07 16:15 ` [PATCH v2 0/4] " Siddharth Asthana
2022-07-07 16:15 ` [PATCH v2 1/4] revision: improve commit_rewrite_person() Siddharth Asthana
2022-07-07 21:52 ` Junio C Hamano
2022-07-08 14:50 ` Đoàn Trần Công Danh
[not found] ` <CAP8UFD116xMnp27pxW8WNDf6PRJxnnwWtcy2TNHU_KyV2ZVA1g@mail.gmail.com>
2022-07-09 1:02 ` Đoàn Trần Công Danh
2022-07-09 5:04 ` Christian Couder
2022-07-07 16:15 ` [PATCH v2 2/4] ident: move commit_rewrite_person() to ident.c Siddharth Asthana
2022-07-07 16:15 ` [PATCH v2 3/4] ident: rename commit_rewrite_person() to apply_mailmap_to_header() Siddharth Asthana
2022-07-07 16:15 ` [PATCH v2 4/4] cat-file: add mailmap support Siddharth Asthana
2022-07-07 21:55 ` Junio C Hamano
2022-07-08 11:53 ` Johannes Schindelin
2022-07-07 22:06 ` [PATCH v2 0/4] Add support for mailmap in cat-file Junio C Hamano
2022-07-07 22:58 ` Junio C Hamano
2022-07-09 15:41 ` [PATCH v3 " Siddharth Asthana
2022-07-09 15:41 ` [PATCH v3 1/4] revision: improve commit_rewrite_person() Siddharth Asthana
2022-07-12 16:29 ` Johannes Schindelin
2022-07-09 15:41 ` [PATCH v3 2/4] ident: move commit_rewrite_person() to ident.c Siddharth Asthana
2022-07-09 15:41 ` [PATCH v3 3/4] ident: rename commit_rewrite_person() to apply_mailmap_to_header() Siddharth Asthana
2022-07-09 15:41 ` [PATCH v3 4/4] cat-file: add mailmap support Siddharth Asthana
2022-07-10 5:34 ` [PATCH v3 0/4] Add support for mailmap in cat-file Junio C Hamano
2022-07-12 12:34 ` Johannes Schindelin
2022-07-12 14:16 ` Junio C Hamano
2022-07-12 16:01 ` Siddharth Asthana
2022-07-12 16:06 ` Junio C Hamano
2022-07-12 16:06 ` [PATCH v4 " Siddharth Asthana
2022-07-12 16:06 ` [PATCH v4 1/4] revision: improve commit_rewrite_person() Siddharth Asthana
2022-07-13 1:25 ` Ævar Arnfjörð Bjarmason
2022-07-13 12:18 ` Christian Couder
2022-07-14 21:02 ` Junio C Hamano
2022-07-12 16:06 ` [PATCH v4 2/4] ident: move commit_rewrite_person() to ident.c Siddharth Asthana
2022-07-12 16:06 ` [PATCH v4 3/4] ident: rename commit_rewrite_person() to apply_mailmap_to_header() Siddharth Asthana
2022-07-13 1:25 ` Ævar Arnfjörð Bjarmason
2022-07-13 13:29 ` Christian Couder
2022-07-12 16:06 ` [PATCH v4 4/4] cat-file: add mailmap support Siddharth Asthana
2022-07-16 7:40 ` [PATCH v5 0/4] Add support for mailmap in cat-file Siddharth Asthana
2022-07-16 7:40 ` [PATCH v5 1/4] revision: improve commit_rewrite_person() Siddharth Asthana
2022-07-17 22:11 ` Junio C Hamano
2022-07-16 7:40 ` [PATCH v5 2/4] ident: move commit_rewrite_person() to ident.c Siddharth Asthana
2022-07-16 7:40 ` [PATCH v5 3/4] ident: rename commit_rewrite_person() to apply_mailmap_to_header() Siddharth Asthana
2022-07-16 7:40 ` [PATCH v5 4/4] cat-file: add mailmap support Siddharth Asthana
2022-07-18 19:50 ` Siddharth Asthana [this message]
2022-07-18 19:50 ` [PATCH v6 1/4] revision: improve commit_rewrite_person() Siddharth Asthana
2022-07-18 19:51 ` [PATCH v6 2/4] ident: move commit_rewrite_person() to ident.c Siddharth Asthana
2022-07-18 19:51 ` [PATCH v6 3/4] ident: rename commit_rewrite_person() to apply_mailmap_to_header() Siddharth Asthana
2022-07-18 19:51 ` [PATCH v6 4/4] cat-file: add mailmap support Siddharth Asthana
2022-07-25 18:58 ` [PATCH v6 0/4] Add support for mailmap in cat-file Junio C Hamano
2022-07-28 19:07 ` Christian Couder
2022-07-28 19:32 ` Junio C Hamano
2022-07-30 7:50 ` Siddharth Asthana
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=20220718195102.66321-1-siddharthasthana31@gmail.com \
--to=siddharthasthana31@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=christian.couder@gmail.com \
--cc=congdanhqx@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johncai86@gmail.com \
--cc=phillip.wood123@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).