From patchwork Thu Dec 1 15:55:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Siddharth Asthana X-Patchwork-Id: 13061506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B2D3C4321E for ; Thu, 1 Dec 2022 15:55:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232106AbiLAPzb (ORCPT ); Thu, 1 Dec 2022 10:55:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232084AbiLAPzY (ORCPT ); Thu, 1 Dec 2022 10:55:24 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9D57B0DF8 for ; Thu, 1 Dec 2022 07:55:22 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id v3-20020a17090ac90300b00218441ac0f6so4457629pjt.0 for ; Thu, 01 Dec 2022 07:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=udXHvFkyQ0YXY8dmM/NJJn93DFgDlnFXD8i0ORTr6LY=; b=n73PA/68HyOV1yzXin0R91XMQvqGSex6oKtFL8YfI6XARF2lcjx2m0M5nEFmJLJA2R +owjCrnRcOKXfmdSwIkYbQ3xMBwUdm9Tl3xcJ08L21GC9kZDSLZhwjYf5WZKwRjszXAM 0sii907ysapzGnaTDZ4LSLH+FZmfCV+8a9UOLAbi1Exw5YNxcx6qFKY+tUU4a9PNu7Nd sLNkfV223+xjb1qAFa7whUd3Kwdhm5c96jybfCFbw/E31dwTsuUvYxxSlUS8jxCfszW9 qAazlUUi4wptiB7aK7YiRnWkoFaCWkhTib66FgoPCuxRdXESxEqd6pkuOPiOJkCEjTpH OpLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=udXHvFkyQ0YXY8dmM/NJJn93DFgDlnFXD8i0ORTr6LY=; b=STyDcdrEFmvyPyRXZQgvm3EaKAD+oq8p7TSENc19tQ3QZqTumAlNj0JxEIqoixcdCS utl/yU6mea7h7P3D00vtWoTxs1/fZ/2RNeZhbgDI3n0hZEAETzE8WNFPq2ms9SvnQB8G SW1mjugvmLzBMByDzYbZTsBzIOH/aVbFG6+dBEWvKUlCd+bWQG86kltuahFVcpCYY966 buMJxJ4m3JWccZHre5Q8fGsASJHrfv1KEhGlPmxoAjSyZACPbMfYt4m22hHae6wCNIMH /lJXE5xEXkU3xCxaHLYlMZU7YzYOM2eK/x35ZcT/I26BIv1cen0adplculW60mBot9aA OMrg== X-Gm-Message-State: ANoB5pn4zz/J+50LNL65mBwq67Rl5oGJFuiiD84lsvWd+MNjHt+lKxfs ToJBeR/wzSx1g+s/lv93PeYPdCSt4PQvKQ== X-Google-Smtp-Source: AA0mqf6ArpyWYrcIX1B4X0vVUF3gN9BVLjpbIXIKmYu6OSe4zU5eVKzNeQqLQbon/aC3LmU/XoSMnQ== X-Received: by 2002:a17:90a:588b:b0:219:c40:e5f with SMTP id j11-20020a17090a588b00b002190c400e5fmr34204922pji.49.1669910121851; Thu, 01 Dec 2022 07:55:21 -0800 (PST) Received: from HB2.. ([2401:4900:36ac:5594:1695:30e6:556:ccb7]) by smtp.gmail.com with ESMTPSA id x28-20020aa78f1c000000b0056c349f5c70sm3405290pfr.79.2022.12.01.07.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 07:55:21 -0800 (PST) From: Siddharth Asthana To: git@vger.kernel.org Cc: christian.couder@gmail.com, gitster@pobox.com, johncai86@gmail.com, Johannes.Schindelin@gmx.de, avarab@gmail.com, me@ttaylorr.com, Siddharth Asthana Subject: [PATCH v6 1/2] cat-file: add mailmap support to -s option Date: Thu, 1 Dec 2022 21:25:03 +0530 Message-Id: <20221201155504.320461-2-siddharthasthana31@gmail.com> X-Mailer: git-send-email 2.39.0.rc1.6.g86692db720 In-Reply-To: <20221201155504.320461-1-siddharthasthana31@gmail.com> References: <20220916205946.178925-1-siddharthasthana31@gmail.com> <20221201155504.320461-1-siddharthasthana31@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Even though the cat-file command with `-s` option does not complain when `--use-mailmap` option is given, the latter option is ignored. Compute the size of the object after replacing the idents and report it instead. In order to make `-s` option honour the mailmap mechanism we have to read the contents of the commit/tag object. Make use of the call to `oid_object_info_extended()` to get the contents of the object and store in `buf`. `buf` is later freed in the function. Mentored-by: Christian Couder Mentored-by: John Cai Helped-by: Taylor Blau Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: Siddharth Asthana --- Documentation/git-cat-file.txt | 4 +++- builtin/cat-file.c | 13 +++++++++++++ t/t4203-mailmap.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index ec30b5c574..f82d702d6b 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 - ``. + ``. 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 `` exists and is a valid diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b3be58b1fb..dde8dbeacd 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; diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index cd1cab3e54..b8ec5e0959 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -1022,4 +1022,33 @@ 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 Orig + EOF + git cat-file commit HEAD >commit.out && + echo $(wc -c expect && + git cat-file --use-mailmap commit HEAD >commit.out && + echo $(wc -c >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 C O Mitter + EOF + git tag -a -m "annotated tag" v3 && + git cat-file tag v3 >tag.out && + echo $(wc -c expect && + git cat-file --use-mailmap tag v3 >tag.out && + echo $(wc -c >expect && + git cat-file -s v3 >actual && + git cat-file --use-mailmap -s v3 >>actual && + test_cmp expect actual +' + test_done From patchwork Thu Dec 1 15:55:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Siddharth Asthana X-Patchwork-Id: 13061507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2069DC43217 for ; Thu, 1 Dec 2022 15:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232084AbiLAPzh (ORCPT ); Thu, 1 Dec 2022 10:55:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232100AbiLAPza (ORCPT ); Thu, 1 Dec 2022 10:55:30 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2E33B0DF3 for ; Thu, 1 Dec 2022 07:55:29 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id q15so1200853pja.0 for ; Thu, 01 Dec 2022 07:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i9qfpmm1y1m1ufCC0Zf8ZOsk6O1YTRee3MkyeynW2rs=; b=VUVSqDi6l2XmXt8EW4HohxAs2VYZOep8E7Pcg479KTkQEDvjOWJMOvqcb5clKiyo1P UPOkRFmebAgRNFvYhC/zm6CR5wNJ76u5L7vLjjvVO5KW/5G3nOVeJB1jbCbJIZlb6nJT blV72AsoOnz/uY/0jFjFRw2u1G/DS2Zxc4Ysco08XpgNhe23jAqbW8/ymJql6W2IvcnX AEAKDPF4bg2AJZlBSGTvoxrp5pDiQWFecYLdxWSLzlAaNr61XaDqujqQ/DUnfGyiOEqk uTVOY3ECy00vuaDDeN6wkPlaHwd7xuAbhRCV8dvGaFk27EulrZjjQZ5jKk3Q47kVXZ2u PFvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i9qfpmm1y1m1ufCC0Zf8ZOsk6O1YTRee3MkyeynW2rs=; b=nbi3Ei477XiYRFNTcu6elNLFT6HATMkWJbPuMe/iSWPMTtvPmD7rkVTbZAzDQpFfoO sLhOwKUtLabW/N9ozMKIEr0ZC4BVgmLMmpqVhPcJSoMiwYLrbTrhzSiIFuPA6pcO0kh2 hyt3r7sHDRvoGKUAdv600oaj1RndkycXYP4EWw76yJFj/BpxgvN9t2bvihY+Gqh28s2b qDEslQh4pieSBPvRts4GcEwKBoihthYmLntoWxAjlR5lDuP5rf51ViexogGnG73rzj5H yWYgp9U2ZEVP15qBvsNxDIy8Oj26F2WLjMJUBT2p32E2ou9OgaEC1j1LR0IwYLCKPKoc 9kUA== X-Gm-Message-State: ANoB5pnPldMEaicJZx3fxiqsU7FbrjEGmxP4OhMm7b5Kn9Nzx8hFuvM8 eMIG4zTaajGMs2V4QBfEI8DuFZGBnH5cQQ== X-Google-Smtp-Source: AA0mqf7nutv/Bfb6b6mjXpcQKAvPf+Nn6Mpmo765x3s0zMbVN+Nk/YcaZFjcnJ12btA+x4Pe+vD7cQ== X-Received: by 2002:a17:90a:a08:b0:219:7ec6:8f4a with SMTP id o8-20020a17090a0a0800b002197ec68f4amr2342263pjo.184.1669910128673; Thu, 01 Dec 2022 07:55:28 -0800 (PST) Received: from HB2.. ([2401:4900:36ac:5594:1695:30e6:556:ccb7]) by smtp.gmail.com with ESMTPSA id x28-20020aa78f1c000000b0056c349f5c70sm3405290pfr.79.2022.12.01.07.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 07:55:28 -0800 (PST) From: Siddharth Asthana To: git@vger.kernel.org Cc: christian.couder@gmail.com, gitster@pobox.com, johncai86@gmail.com, Johannes.Schindelin@gmx.de, avarab@gmail.com, me@ttaylorr.com, Siddharth Asthana Subject: [PATCH v6 2/2] cat-file: add mailmap support to --batch-check option Date: Thu, 1 Dec 2022 21:25:04 +0530 Message-Id: <20221201155504.320461-3-siddharthasthana31@gmail.com> X-Mailer: git-send-email 2.39.0.rc1.6.g86692db720 In-Reply-To: <20221201155504.320461-1-siddharthasthana31@gmail.com> References: <20220916205946.178925-1-siddharthasthana31@gmail.com> <20221201155504.320461-1-siddharthasthana31@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Even though the cat-file command with `--batch-check` option does not complain when `--use-mailmap` option is given, the latter option is ignored. Compute the size of the object after replacing the idents and report it instead. In order to make `--batch-check` option honour the mailmap mechanism we have to read the contents of the commit/tag object. There were two ways to do it: 1. Make two calls to `oid_object_info_extended()`. If `--use-mailmap` option is given, the first call will get us the type of the object and second call will only be made if the object type is either a commit or tag to get the contents of the object. 2. Make one call to `oid_object_info_extended()` to get the type of the object. Then, if the object type is either of commit or tag, make a call to `read_object_file()` to read the contents of the object. I benchmarked the following command with both the above approaches and compared against the current implementation where `--use-mailmap` option is ignored: `git cat-file --use-mailmap --batch-all-objects --batch-check --buffer --unordered` The results can be summarized as follows: Time (mean ± σ) default 827.7 ms ± 104.8 ms first approach 6.197 s ± 0.093 s second approach 1.975 s ± 0.217 s Since, the second approach is faster than the first one, I implemented it in this patch. The command git cat-file can now use the mailmap mechanism to replace idents with canonical versions for commit and tag objects. There are several options like `--batch`, `--batch-check` and `--batch-command` that can be combined with `--use-mailmap`. But the documentation for `--batch`, `--batch-check` and `--batch-command` doesn't say so. This patch fixes that documentation. Mentored-by: Christian Couder Mentored-by: John Cai Helped-by: Taylor Blau Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: Siddharth Asthana --- Documentation/git-cat-file.txt | 49 +++++++++++++++++++++++++--------- builtin/cat-file.c | 14 ++++++++++ t/t4203-mailmap.sh | 36 +++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index f82d702d6b..81235c60a3 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -91,26 +91,49 @@ OPTIONS --batch:: --batch=:: Print object information and contents for each object provided - on stdin. May not be combined with any other options or arguments - except `--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. + on stdin. May not be combined with any other options or arguments + except --textconv, --filters, or --use-mailmap. + + + * 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=:: - Print object information for each object provided on stdin. May - not be combined with any other options or arguments except - `--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. + Print object information for each object provided on stdin. May not be + combined with any other options or arguments except --textconv, --filters + or --use-mailmap. + + + * 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=:: Enter a command mode that reads commands and arguments from stdin. May - only be combined with `--buffer`, `--textconv` or `--filters`. In the - case of `--textconv` or `--filters`, the input lines also need to specify - the path, separated by whitespace. See the section `BATCH OUTPUT` below - for details. + only be combined with `--buffer`, `--textconv`, `--use-mailmap` or + `--filters`. + + + * 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: + diff --git a/builtin/cat-file.c b/builtin/cat-file.c index dde8dbeacd..7811016ae8 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -444,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); @@ -457,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 b8ec5e0959..fa7f987284 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -1051,4 +1051,40 @@ test_expect_success 'git cat-file -s returns correct size with --use-mailmap for 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 Orig + EOF + git cat-file commit HEAD >commit.out && + commit_size=$(wc -c expect && + git cat-file --use-mailmap commit HEAD >commit.out && + commit_size=$(wc -c >expect && + echo "HEAD" >in && + git cat-file --batch-check actual && + git cat-file --use-mailmap --batch-check >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 Orig + EOF + git cat-file commit HEAD >commit.out && + commit_size=$(wc -c expect && + git cat-file --use-mailmap commit HEAD >commit.out && + commit_size=$(wc -c >expect && + echo "info HEAD" >in && + git cat-file --batch-command actual && + git cat-file --use-mailmap --batch-command >actual && + test_cmp expect actual +' + test_done