mirror of
https://github.com/git/git.git
synced 2024-10-28 12:59:41 +01:00
Merge branch 'sa/cat-file-mailmap--batch-check'
'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
This commit is contained in:
commit
319c3abadb
3 changed files with 132 additions and 14 deletions
|
@ -45,7 +45,9 @@ OPTIONS
|
||||||
|
|
||||||
-s::
|
-s::
|
||||||
Instead of the content, show the object size identified by
|
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::
|
-e::
|
||||||
Exit with zero status if `<object>` exists and is a valid
|
Exit with zero status if `<object>` exists and is a valid
|
||||||
|
@ -89,26 +91,49 @@ OPTIONS
|
||||||
--batch::
|
--batch::
|
||||||
--batch=<format>::
|
--batch=<format>::
|
||||||
Print object information and contents for each object provided
|
Print object information and contents for each object provided
|
||||||
on stdin. May not be combined with any other options or arguments
|
on stdin. May not be combined with any other options or arguments
|
||||||
except `--textconv` or `--filters`, in which case the input lines
|
except `--textconv`, `--filters`, or `--use-mailmap`.
|
||||||
also need to specify the path, separated by whitespace. See the
|
+
|
||||||
section `BATCH OUTPUT` below for details.
|
* When used with `--textconv` or `--filters`, the input lines
|
||||||
|
must specify the path, separated by whitespace. See the section
|
||||||
|
`BATCH OUTPUT` below for details.
|
||||||
|
+
|
||||||
|
* When used with `--use-mailmap`, for commit and tag objects, the
|
||||||
|
contents part of the output shows the identities replaced using the
|
||||||
|
mailmap mechanism, while the information part of the output shows
|
||||||
|
the size of the object as if it actually recorded the replacement
|
||||||
|
identities.
|
||||||
|
|
||||||
--batch-check::
|
--batch-check::
|
||||||
--batch-check=<format>::
|
--batch-check=<format>::
|
||||||
Print object information for each object provided on stdin. May
|
Print object information for each object provided on stdin. May not be
|
||||||
not be combined with any other options or arguments except
|
combined with any other options or arguments except `--textconv`, `--filters`
|
||||||
`--textconv` or `--filters`, in which case the input lines also
|
or `--use-mailmap`.
|
||||||
need to specify the path, separated by whitespace. See the
|
+
|
||||||
section `BATCH OUTPUT` below for details.
|
* When used with `--textconv` or `--filters`, the input lines must
|
||||||
|
specify the path, separated by whitespace. See the section
|
||||||
|
`BATCH OUTPUT` below for details.
|
||||||
|
+
|
||||||
|
* When used with `--use-mailmap`, for commit and tag objects, the
|
||||||
|
printed object information shows the size of the object as if the
|
||||||
|
identities recorded in it were replaced by the mailmap mechanism.
|
||||||
|
|
||||||
--batch-command::
|
--batch-command::
|
||||||
--batch-command=<format>::
|
--batch-command=<format>::
|
||||||
Enter a command mode that reads commands and arguments from stdin. May
|
Enter a command mode that reads commands and arguments from stdin. May
|
||||||
only be combined with `--buffer`, `--textconv` or `--filters`. In the
|
only be combined with `--buffer`, `--textconv`, `--use-mailmap` or
|
||||||
case of `--textconv` or `--filters`, the input lines also need to specify
|
`--filters`.
|
||||||
the path, separated by whitespace. See the section `BATCH OUTPUT` below
|
+
|
||||||
for details.
|
* When used with `--textconv` or `--filters`, the input lines must
|
||||||
|
specify the path, separated by whitespace. See the section
|
||||||
|
`BATCH OUTPUT` below for details.
|
||||||
|
+
|
||||||
|
* When used with `--use-mailmap`, for commit and tag objects, the
|
||||||
|
`contents` command shows the identities replaced using the
|
||||||
|
mailmap mechanism, while the `info` command shows the size
|
||||||
|
of the object as if it actually recorded the replacement
|
||||||
|
identities.
|
||||||
|
|
||||||
+
|
+
|
||||||
`--batch-command` recognizes the following commands:
|
`--batch-command` recognizes the following commands:
|
||||||
+
|
+
|
||||||
|
|
|
@ -132,8 +132,21 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
oi.sizep = &size;
|
oi.sizep = &size;
|
||||||
|
|
||||||
|
if (use_mailmap) {
|
||||||
|
oi.typep = &type;
|
||||||
|
oi.contentp = (void**)&buf;
|
||||||
|
}
|
||||||
|
|
||||||
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
|
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
|
||||||
die("git cat-file: could not get object info");
|
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);
|
printf("%"PRIuMAX"\n", (uintmax_t)size);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -431,6 +444,9 @@ static void batch_object_write(const char *obj_name,
|
||||||
if (!data->skip_object_info) {
|
if (!data->skip_object_info) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (use_mailmap)
|
||||||
|
data->info.typep = &data->type;
|
||||||
|
|
||||||
if (pack)
|
if (pack)
|
||||||
ret = packed_object_info(the_repository, pack, offset,
|
ret = packed_object_info(the_repository, pack, offset,
|
||||||
&data->info);
|
&data->info);
|
||||||
|
@ -444,6 +460,18 @@ static void batch_object_write(const char *obj_name,
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (use_mailmap && (data->type == OBJ_COMMIT || data->type == OBJ_TAG)) {
|
||||||
|
size_t s = data->size;
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
|
buf = repo_read_object_file(the_repository, &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);
|
strbuf_reset(scratch);
|
||||||
|
|
|
@ -1022,4 +1022,69 @@ test_expect_success '--mailmap enables mailmap in cat-file for annotated tag obj
|
||||||
test_cmp expect actual
|
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
|
||||||
|
git cat-file commit HEAD >commit.out &&
|
||||||
|
echo $(wc -c <commit.out) >expect &&
|
||||||
|
git cat-file --use-mailmap commit HEAD >commit.out &&
|
||||||
|
echo $(wc -c <commit.out) >>expect &&
|
||||||
|
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 &&
|
||||||
|
git cat-file tag v3 >tag.out &&
|
||||||
|
echo $(wc -c <tag.out) >expect &&
|
||||||
|
git cat-file --use-mailmap tag v3 >tag.out &&
|
||||||
|
echo $(wc -c <tag.out) >>expect &&
|
||||||
|
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
|
||||||
|
git cat-file commit HEAD >commit.out &&
|
||||||
|
commit_size=$(wc -c <commit.out) &&
|
||||||
|
commit_sha=$(git rev-parse HEAD) &&
|
||||||
|
echo $commit_sha commit $commit_size >expect &&
|
||||||
|
git cat-file --use-mailmap commit HEAD >commit.out &&
|
||||||
|
commit_size=$(wc -c <commit.out) &&
|
||||||
|
echo $commit_sha commit $commit_size >>expect &&
|
||||||
|
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
|
||||||
|
git cat-file commit HEAD >commit.out &&
|
||||||
|
commit_size=$(wc -c <commit.out) &&
|
||||||
|
commit_sha=$(git rev-parse HEAD) &&
|
||||||
|
echo $commit_sha commit $commit_size >expect &&
|
||||||
|
git cat-file --use-mailmap commit HEAD >commit.out &&
|
||||||
|
commit_size=$(wc -c <commit.out) &&
|
||||||
|
echo $commit_sha commit $commit_size >>expect &&
|
||||||
|
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
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue