Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2022-11-12 01:42:45 +0300
committerTaylor Blau <me@ttaylorr.com>2022-11-12 01:42:45 +0300
commita33fffa724edce321e63d31c14f938273e561fcd (patch)
tree8ab98209ea35551dafe9c48f4d84b1d69d947ca8
parentc08655a5adb84ef269216cd27001abdd91c2d98a (diff)
parentc0e6faf2c9ef93b89a84ddc544353278183f0d3d (diff)
Merge branch 'sa/cat-file-mailmap--batch-check' into seen
'cat-file' gains mailmap support for its '--batch-check' and '-s' options. * sa/cat-file-mailmap--batch-check: cat-file: add mailmap support to --batch-check option cat-file: add mailmap support to -s option
-rw-r--r--Documentation/git-cat-file.txt6
-rw-r--r--builtin/cat-file.c27
-rwxr-xr-xt/t4203-mailmap.sh59
3 files changed, 91 insertions, 1 deletions
diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt
index ec30b5c5743..a8e7906b3d5 100644
--- a/Documentation/git-cat-file.txt
+++ b/Documentation/git-cat-file.txt
@@ -45,7 +45,9 @@ OPTIONS
-s::
Instead of the content, show the object size identified by
- `<object>`.
+ `<object>`. If used with `--use-mailmap` option, will show the
+ size of updated object after replacing idents using the mailmap
+ mechanism.
-e::
Exit with zero status if `<object>` exists and is a valid
@@ -101,6 +103,8 @@ OPTIONS
`--textconv` or `--filters`, in which case the input lines also
need to specify the path, separated by whitespace. See the
section `BATCH OUTPUT` 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 fa7bd891692..39f2a2483f5 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -132,8 +132,21 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
case 's':
oi.sizep = &size;
+
+ if (use_mailmap) {
+ oi.typep = &type;
+ oi.contentp = (void**)&buf;
+ }
+
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
+
+ if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
+ size_t s = size;
+ buf = replace_idents_using_mailmap(buf, &s);
+ size = cast_size_t_to_ulong(s);
+ }
+
printf("%"PRIuMAX"\n", (uintmax_t)size);
ret = 0;
goto cleanup;
@@ -431,6 +444,9 @@ static void batch_object_write(const char *obj_name,
if (!data->skip_object_info) {
int ret;
+ if (use_mailmap)
+ data->info.typep = &data->type;
+
if (pack)
ret = packed_object_info(the_repository, pack, offset,
&data->info);
@@ -444,6 +460,17 @@ static void batch_object_write(const char *obj_name,
fflush(stdout);
return;
}
+
+ if (use_mailmap && (data->type == OBJ_COMMIT || data->type == OBJ_TAG)) {
+ size_t s = data->size;
+ char *buf = NULL;
+
+ buf = read_object_file(&data->oid, &data->type, &data->size);
+ buf = replace_idents_using_mailmap(buf, &s);
+ data->size = cast_size_t_to_ulong(s);
+
+ free(buf);
+ }
}
strbuf_reset(scratch);
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index cd1cab3e54b..b4355c3e519 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -1022,4 +1022,63 @@ test_expect_success '--mailmap enables mailmap in cat-file for annotated tag obj
test_cmp expect actual
'
+test_expect_success 'git cat-file -s returns correct size with --use-mailmap' '
+ test_when_finished "rm .mailmap" &&
+ cat >.mailmap <<-\EOF &&
+ C O Mitter <committer@example.com> Orig <orig@example.com>
+ EOF
+ cat >expect <<-\EOF &&
+ 209
+ 220
+ EOF
+ git cat-file -s HEAD >actual &&
+ git cat-file --use-mailmap -s HEAD >>actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git cat-file -s returns correct size with --use-mailmap for tag objects' '
+ test_when_finished "rm .mailmap" &&
+ cat >.mailmap <<-\EOF &&
+ Orig <orig@example.com> C O Mitter <committer@example.com>
+ EOF
+ git tag -a -m "annotated tag" v3 &&
+ cat >expect <<-\EOF &&
+ 141
+ 130
+ EOF
+ git cat-file -s v3 >actual &&
+ git cat-file --use-mailmap -s v3 >>actual &&
+ 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@example.com> Orig <orig@example.com>
+ EOF
+ cat >expect <<-\EOF &&
+ 92d99959b011b1cd69fe7be5315d6732fe302575 commit 209
+ 92d99959b011b1cd69fe7be5315d6732fe302575 commit 220
+ EOF
+ echo "HEAD" >in &&
+ git cat-file --batch-check <in >actual &&
+ 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@example.com> Orig <orig@example.com>
+ EOF
+ cat >expect <<-\EOF &&
+ 92d99959b011b1cd69fe7be5315d6732fe302575 commit 209
+ 92d99959b011b1cd69fe7be5315d6732fe302575 commit 220
+ EOF
+ echo "info HEAD" >in &&
+ git cat-file --batch-command <in >actual &&
+ git cat-file --use-mailmap --batch-command <in >>actual &&
+ test_cmp expect actual
+'
+
test_done