[PATCH 3/3] cat-file: add mailmap support to --batch-check option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Using `git cat-file --use-mailmap` with --batch-check option, like the
following is allowed:

 git cat-file --use-mailmap -batch-check

The current implementation will return the same object size irrespective
of the mailmap option, which is not as useful as it could be. When we
use the mailmap mechanism to replace the idents, the size of the object
can change and --batch-check option would be more useful if it shows the
size of the changed object. This patch implements that.

Mentored-by: Christian Couder's avatarChristian Couder <christian.couder@xxxxxxxxx>
Mentored-by: John Cai's avatarJohn Cai <johncai86@xxxxxxxxx>
Signed-off-by: Siddharth Asthana <siddharthasthana31@xxxxxxxxx>
---
 Documentation/git-cat-file.txt |  2 ++
 builtin/cat-file.c             | 13 +++++++++++++
 t/t4203-mailmap.sh             | 22 ++++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt
index 708d094db4..0d5cc9335f 100644
--- a/Documentation/git-cat-file.txt
+++ b/Documentation/git-cat-file.txt
@@ -101,6 +101,8 @@ OPTIONS
 	with `--use-mailmap`, `--textconv` or `--filters`. In the case of `--textconv` or
 	`--filters` the input lines also need to specify the path, separated by whitespace.
 	See the `BATCH OUTPUT` section below for details.
+	If used with `--use-mailmap` option, will show the size of updated object after
+	replacing idents using the mailmap mechanism.
 
 --batch-command::
 --batch-command=<format>::
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 9942b93867..93d127d687 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -424,6 +424,12 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
 
 static void print_default_format(struct strbuf *scratch, struct expand_data *data)
 {
+	if (use_mailmap && (data->type == OBJ_COMMIT || data->type == OBJ_TAG)) {
+		size_t s = data->size;
+		*data->info.contentp = replace_idents_using_mailmap((char*)*data->info.contentp, &s);
+		data->size = cast_size_t_to_ulong(s);
+	}
+
 	strbuf_addf(scratch, "%s %s %"PRIuMAX"\n", oid_to_hex(&data->oid),
 		    type_name(data->type),
 		    (uintmax_t)data->size);
@@ -441,9 +447,14 @@ static void batch_object_write(const char *obj_name,
 			       struct packed_git *pack,
 			       off_t offset)
 {
+	void *buf = NULL;
+
 	if (!data->skip_object_info) {
 		int ret;
 
+		if (use_mailmap)
+			data->info.contentp = &buf;
+
 		if (pack)
 			ret = packed_object_info(the_repository, pack, offset,
 						 &data->info);
@@ -474,6 +485,8 @@ static void batch_object_write(const char *obj_name,
 		print_object_or_die(opt, data);
 		batch_write(opt, "\n", 1);
 	}
+
+	free(buf);
 }
 
 static void batch_one_object(const char *obj_name,
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 59513e7c57..4b236c68aa 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -1032,4 +1032,26 @@ test_expect_success 'git cat-file -s returns correct size with --use-mailmap' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git cat-file --batch-check returns correct size with --use-mailmap' '
+	test_when_finished "rm .mailmap" &&
+	cat >.mailmap <<-EOF &&
+	C O Mitter <committer@xxxxxxxxxxx> Orig <orig@xxxxxxxxxxx>
+	EOF
+	echo "92d99959b011b1cd69fe7be5315d6732fe302575 commit 220" >expect &&
+	echo "HEAD" >in &&
+	git cat-file --use-mailmap --batch-check <in >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git cat-file --batch-command returns correct size with --use-mailmap' '
+	test_when_finished "rm .mailmap" &&
+	cat >.mailmap <<-EOF &&
+	C O Mitter <committer@xxxxxxxxxxx> Orig <orig@xxxxxxxxxxx>
+	EOF
+	echo "92d99959b011b1cd69fe7be5315d6732fe302575 commit 220" >expect &&
+	echo "info HEAD" >in &&
+	git cat-file --use-mailmap --batch-command <in >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.38.0.rc0.3.g53c2677cac




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux