From patchwork Fri Nov 18 11:18:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048085 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 3216EC433FE for ; Fri, 18 Nov 2022 11:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241442AbiKRLSl (ORCPT ); Fri, 18 Nov 2022 06:18:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235237AbiKRLSi (ORCPT ); Fri, 18 Nov 2022 06:18:38 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B9DE14016 for ; Fri, 18 Nov 2022 03:18:35 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id vv4so2936214ejc.2 for ; Fri, 18 Nov 2022 03:18:35 -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=5j0OtJ/pT2mCNtYINNUolxU5Rc0Pp5AWJsA1AwpOpPg=; b=KaMAFnodHaIoy0++hmVym87ltajhs2KcJstWckx2y3avFZGDJ6T70A31BnZjkE1KBo gZGHI4x/b5OHiHBB3gdz+o/3fz/XXfN9znXExWDsMMdD4brILwKbx17IkUVyOek/DWHa zY67zHbdqCYXZ65jTF/pScgEs7KiCuir1keRpiMBgq98ZkGrDXJ0M7bgWLwgKKKGKOfl jEbAgvlOVgVjQSstKZ8xh52rUOiu9bS+2aER84yGVjpuzw9oecVDQBl/X/UNO2EqCXvC VIiRM1zIPTbxC8d0CqwiiNIGzCFAuIjWt6BDblf2LZ9cvk4KCuvLqN+SbVjiNiXBWwEE CqzA== 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=5j0OtJ/pT2mCNtYINNUolxU5Rc0Pp5AWJsA1AwpOpPg=; b=F9boe5+I/WPnhYuYyx4lD3iEnF3mEerRO0sue3H4D4nqkdHaY3+4yK3/hFDmMcKXe2 WQAYhJnmYIcSmPBabVgDrn4R3yWq8f9/usg6fh5unT9BK1yTpcRIkKSLNlDyKrbshXCV X3EA8Yl7IXUzT0wgSKb9tE8jmEAiPXDp08I+CUbnp864IUA4VyZ3Ri9G2dPYro1o3fkf 33VbXgIXDptAsEUKkeUalkLqbR3j3xLOjcmcuuJL+VYkx1cLZAqg9uoPU5AG3iETDImG yVuIhlFlHalqc+f5TwBZKfkf1QXTrIq0Jv91y57gPtmDlCKv1KMnJGcBSTiYqbnP38rV c31g== X-Gm-Message-State: ANoB5pmHB+g7OX7qKlcQqCO0wCxtai4Lk6MV9bSdxwYIrbLThPWRnD2i spi0xLjg9/SmLzullb5975o87i/h0nM4mg== X-Google-Smtp-Source: AA0mqf7Q/2T/U9VbiC4mKdRSZ4J6PNiifBO/JlfqsEZ0xkIPgWVHJp64bF58iR/d3yL6aTNQW52koA== X-Received: by 2002:a17:906:2650:b0:7b2:c004:55fe with SMTP id i16-20020a170906265000b007b2c00455femr1298063ejc.742.1668770313666; Fri, 18 Nov 2022 03:18:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:33 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 01/12] merge-index doc & -h: fix padding, labels and "()" use Date: Fri, 18 Nov 2022 12:18:18 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make the "merge-index" doc SYNOPSIS and "-h" output consistent with one another, and small issues with it: - Whitespace padding, per e2f4e7e8c0f (doc txt & -h consistency: correct padding around "[]()", 2022-10-13). - Use "" consistently, rather than using "" in the "-h" output, and "" in the SYNOPSIS. - The "-h" version incorrectly claimed that the filename was optional, but it's not. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-merge-index.txt | 2 +- builtin/merge-index.c | 2 +- t/t0450/txt-help-mismatches | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Documentation/git-merge-index.txt b/Documentation/git-merge-index.txt index eea56b3154e..a297105d6d8 100644 --- a/Documentation/git-merge-index.txt +++ b/Documentation/git-merge-index.txt @@ -9,7 +9,7 @@ git-merge-index - Run a merge for files needing merging SYNOPSIS -------- [verse] -'git merge-index' [-o] [-q] (-a | ( [--] ...) ) +'git merge-index' [-o] [-q] (-a | ([--] ...)) DESCRIPTION ----------- diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 012f52bd007..1a5a64afd2a 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -80,7 +80,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) signal(SIGCHLD, SIG_DFL); if (argc < 3) - usage("git merge-index [-o] [-q] (-a | [--] [...])"); + usage("git merge-index [-o] [-q] (-a | ([--] ...))"); read_cache(); diff --git a/t/t0450/txt-help-mismatches b/t/t0450/txt-help-mismatches index a0777acd667..9e73c1892ae 100644 --- a/t/t0450/txt-help-mismatches +++ b/t/t0450/txt-help-mismatches @@ -34,7 +34,6 @@ mailsplit maintenance merge merge-file -merge-index merge-one-file multi-pack-index name-rev From patchwork Fri Nov 18 11:18:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048087 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 C66A3C433FE for ; Fri, 18 Nov 2022 11:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241132AbiKRLSt (ORCPT ); Fri, 18 Nov 2022 06:18:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241271AbiKRLSj (ORCPT ); Fri, 18 Nov 2022 06:18:39 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7ECC1403A for ; Fri, 18 Nov 2022 03:18:36 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id i10so12234669ejg.6 for ; Fri, 18 Nov 2022 03:18:36 -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=oVIATdrav0gFbw12TFNmdDh+HKS2CloRQfdF2atTVsI=; b=mGLl+Xj/sut7xssuWUutYFloard/juAViRD0coUpQY1Ht+fpq2mSK31JQfIFZsuj1x PwyEB4Nxdx/YQMJAcMcMn+0yxVjB2MH88MxuQ8QFJV7D4A1gtEGq3FzxsR5XIsd6EmlR pq9iMCZSLF9sJg6wAlF8qi65LhBt1K/dqnDmTXocqUzmZKW8b5ofYwaqxiYIgaaMyG2h PN1UyPMwOMNjwsVsrP8AmnUFeKlN37XNQ8CE5wi396GNmTx4cFDRR3MAjJUuWQi3o1J+ JwSorQCVDJNEymDqttn46jrqBB9KTMLQg6OY8kHIHUWvr+3dFDjgwNk4SUs6CWuO3b1s 5b3g== 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=oVIATdrav0gFbw12TFNmdDh+HKS2CloRQfdF2atTVsI=; b=A6UXznATwy9sb7v+tc0ECxArSXto+41qSGmxfgkM6r0VzbOzZIlDzJfXTukbrXaq1W KQQph80s+A4xZm6/tvkPkcPytadv6oi8ZBv6ujEXCcmsBC+cE0qF/DabQOt73RXo+Ddi mujY6PtEyyf5HvIt00r9tNFMFfkeC29DndN3c8lTVaaTBCL948eKi6Ms0HKaq1iPJQTw aWmuhYKqpW5Mxp45YSGavXRVBA3i4N6Pcobr6lS74K3t6uXfThVU/wBkbsue4Q7d7qTf hUgIGjzuTeSlDvj7PSLYqCuz7rl/Q/pWIMEtuZZi61rHxAGstVDFIUXO2h/EsHYNKRhl 5v7Q== X-Gm-Message-State: ANoB5pnlkV+XA5IwEzOZHZjRAbIcgv/xdCXEFLlVpRv63Vp8ygSBDu17 qDHPSINBRE5L5BezJita1zLsAAUY/sSvBg== X-Google-Smtp-Source: AA0mqf6HoM2Z/DNsW3IR0yg33Ipid27+K8v/9tE0LTEwVINeKeOO4pja92OmYDPZDnzh3NDQ6rjLWg== X-Received: by 2002:a17:907:2bde:b0:7ae:4a7f:3280 with SMTP id gv30-20020a1709072bde00b007ae4a7f3280mr5687605ejc.265.1668770314769; Fri, 18 Nov 2022 03:18:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:33 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 02/12] t6060: modify multiple files to expose a possible issue with merge-index Date: Fri, 18 Nov 2022 12:18:19 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alban Gruin Currently, merge-index iterates over every index entry, skipping stage0 entries. It will then count how many entries following the current one have the same name, then fork to do the merge. It will then increase the iterator by the number of entries to skip them. This behaviour is correct, as even if the subprocess modifies the index, merge-index does not reload it at all. But when it will be rewritten to use a function, the index it will use will be modified and may shrink when a conflict happens or if a file is removed, so we have to be careful to handle such cases. Here is an example: * Merge branches, file1 and file2 are trivially mergeable. |\ | * Modifies file1 and file2. * | Modifies file1 and file2. |/ * Adds file1 and file2. When the merge happens, the index will look like that: i -> 0. file1 (stage1) 1. file1 (stage2) 2. file1 (stage3) 3. file2 (stage1) 4. file2 (stage2) 5. file2 (stage3) merge-index handles `file1' first. As it appears 3 times after the iterator, it is merged. The index is now stale, `i' is increased by 3, and the index now looks like this: 0. file1 (stage1) 1. file1 (stage2) 2. file1 (stage3) i -> 3. file2 (stage1) 4. file2 (stage2) 5. file2 (stage3) `file2' appears three times too, so it is merged. With a naive rewrite, the index would look like this: 0. file1 (stage0) 1. file2 (stage1) 2. file2 (stage2) i -> 3. file2 (stage3) `file2' appears once at the iterator or after, so it will be added, _not_ merged. Which is wrong. A naive rewrite would lead to unproperly merged files, or even files not handled at all. This changes t6060 to reproduce this case, by creating 2 files instead of 1, to check the correctness of the soon-to-be-rewritten merge-index. The files are identical, which is not really important -- the factors that could trigger this issue are that they should be separated by at most one entry in the index, and that the first one in the index should be trivially mergeable. Signed-off-by: Alban Gruin Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t6060-merge-index.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index 1a8b64cce18..30513351c23 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -7,16 +7,19 @@ TEST_PASSES_SANITIZE_LEAK=true test_expect_success 'setup diverging branches' ' test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && - git add file && + cp file file2 && + git add file file2 && git commit -m base && git tag base && sed s/2/two/ tmp && mv tmp file && + cp file file2 && git commit -a -m two && git tag two && git checkout -b other HEAD^ && sed s/10/ten/ tmp && mv tmp file && + cp file file2 && git commit -a -m ten && git tag ten ' @@ -35,8 +38,11 @@ ten EOF test_expect_success 'read-tree does not resolve content merge' ' + cat >expect <<-\EOF && + file + file2 + EOF git read-tree -i -m base ten two && - echo file >expect && git diff-files --name-only --diff-filter=U >unmerged && test_cmp expect unmerged ' From patchwork Fri Nov 18 11:18:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048086 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 510B8C433FE for ; Fri, 18 Nov 2022 11:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241570AbiKRLSp (ORCPT ); Fri, 18 Nov 2022 06:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241132AbiKRLSi (ORCPT ); Fri, 18 Nov 2022 06:18:38 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A61F5140A6 for ; Fri, 18 Nov 2022 03:18:37 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id m22so12172141eji.10 for ; Fri, 18 Nov 2022 03:18:37 -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=jbaVSWPxS4sAfZaeGc+YHhToAn6m864bioeAoh5xGAM=; b=CKlrwyjeuW24xrC7pxSZE09XHo3GaPYfF+WQpZy4J7HbHnS1VFzb8tLIEWxTe5d4+f 8MNijgiVRGv6fovFBBIAGhfR7GPV/RjPpF1hO7M+VaIbsF88LI0RHrc7U9MWTbl13104 Ru+Wq6fzOo5/jL1ljc4QT1U0UdMpdwUrDeMNyD/YGHGcox70orYCruhoc2gb+bq4TTzd zqyT+uF8Gzq/mAbHY2f3YIY8UHAVV/e0AkqjlvVlC/sm94W24wigAsPLV3N557kMltnz 2hYgr+JtorDcvkfsf+JyUBZFclHuPuEuuEH4IFXwnc7SozmD6Hqc9xLsrcZqvxxkTgx7 TEPg== 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=jbaVSWPxS4sAfZaeGc+YHhToAn6m864bioeAoh5xGAM=; b=oFwJZT5+KZc9bDTOl4w1SrOqg+1GsCam3dEqTQZOFMcd5+pzkD70G0k81QyWGPN6C7 Wi9jb029R/H3EC8VyoDvDGE33sfvGKM8wYhaghS0VAAeqoH1WzhTF07jTE/ln/XCi7TK N3Q7iNgv+54TWnkdaRY5eub7uoFJYqAoX09EsY7CTOXdBsK36E0gspRc32e4YZktSSqF jNJ4IqSUVmcRm3E5DAIrbqUn2DLO9cXq9dXnafPLSqHkbO1S0bol75rpRj7nfhC323so bdsc+DtdHpzMIGRWea4F1HrVSk+lwR4TXH7LdvZKv8073We2HznwKEQvoti3Xy11nL8R VhCw== X-Gm-Message-State: ANoB5pkMkUvuxl4WPwfpj7HRjvXi71d7vn8nZcon6MpvLzLap5/+++vT EpM5NVqHJv8n8VUuB8wY62gqAfWN911/Lg== X-Google-Smtp-Source: AA0mqf55MkJPqYRRhp9Hef3+BFJSTQg3RCW4kqkdJb2QaXQPkdK3xpG8dphKcoo9E6fNMakRP83QBQ== X-Received: by 2002:a17:906:c011:b0:778:f9b6:6fc with SMTP id e17-20020a170906c01100b00778f9b606fcmr5615957ejz.580.1668770315822; Fri, 18 Nov 2022 03:18:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:35 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 03/12] t6060: add tests for removed files Date: Fri, 18 Nov 2022 12:18:20 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alban Gruin Until now, t6060 did not not check git-merge-one-file's behaviour when a file is deleted in a branch. To avoid regressions on this during the conversion from shell to C, this adds a new file, `file3', in the commit tagged as `base', and deletes it in the commit tagged as `two'. Signed-off-by: Alban Gruin Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t6060-merge-index.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index 30513351c23..079151ee06d 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -8,12 +8,14 @@ TEST_PASSES_SANITIZE_LEAK=true test_expect_success 'setup diverging branches' ' test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && cp file file2 && - git add file file2 && + cp file file3 && + git add file file2 file3 && git commit -m base && git tag base && sed s/2/two/ tmp && mv tmp file && cp file file2 && + git rm file3 && git commit -a -m two && git tag two && git checkout -b other HEAD^ && @@ -41,6 +43,7 @@ test_expect_success 'read-tree does not resolve content merge' ' cat >expect <<-\EOF && file file2 + file3 EOF git read-tree -i -m base ten two && git diff-files --name-only --diff-filter=U >unmerged && From patchwork Fri Nov 18 11:18:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048090 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 ABF05C433FE for ; Fri, 18 Nov 2022 11:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241547AbiKRLS7 (ORCPT ); Fri, 18 Nov 2022 06:18:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241463AbiKRLSl (ORCPT ); Fri, 18 Nov 2022 06:18:41 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BE4DDF6A for ; Fri, 18 Nov 2022 03:18:38 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id n20so12402064ejh.0 for ; Fri, 18 Nov 2022 03:18:38 -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=/F97DB+WLmIomP20QV790iAT4lkS7Ulx/aH28hqS23U=; b=hkhOsiuDBZj1wgPPRL5z06EwTTDSIODQqzvEwGqwiFuxK9kxuDnQZJi5XK1PSftQiz V+8Veyqq3iVqCCtCijZs6tZFe/fG9ukKD2EKppSfz5fn13rXBXG0lw9A9OOdb3pj9wy+ OarfWY0fijyQqzcACZO1TYAr6APs4/6jbeoYHZ+b+9ZMUqD4/4/zXjSTFc1f+oH8Saf1 FQeeh8i51BpKRj2igQ9omycMap4UwwKfg22cpV8SbNyiLThqbibG4WB5PkxdAE3FBA7i jk2ORahNj2FsulF1QsRgyOUn5CdDLMsIF02GcsxdggQ95dOIWKdoIML6UYUWlBrus2E2 A8OQ== 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=/F97DB+WLmIomP20QV790iAT4lkS7Ulx/aH28hqS23U=; b=7hrblYK9Tgq1uWvlXzJYA+8Gwui6A17lNZxLl8uXFplZHQ5TZohcaIrS8jd9acVyiD meDtmqktSzR9pecpCsv/ZE25Tty/ddMMPQd7/cEf2PSuKPWmTtzRuaWziIlak2y+YbZK HXGn0rFyTBYLI04aL01EwG8fZUtZKbXETG//pqRKuM/YZJz0Z8xCZr92DHdGajOJmWVd qM94m79BAv7XNEMDYY8ahd8/Rpuzk56jYZpc9cTJmjjpIGOLtqpkGnqDX9L7m31xmriz ieEIWirS5vaHRCiXNM4b0LpQrCipPzEAqTCTw+H+nARfG3zMPMOpwd4h0CE2iSeSv7Gm OQ3g== X-Gm-Message-State: ANoB5pmIfW95tOjNvoHBfnZvosxu01epusIzMp8lOL1pex6pKuYyjy81 G1ErRTyL/haSuxb3d/slktdMte3tCB35qw== X-Google-Smtp-Source: AA0mqf4w0OaT5ck1x2fWOM76VnfMpAIFFzT14058OD3uollH0QXUz3bfmYAiQYjuWPjYqy4z2aD5lA== X-Received: by 2002:a17:906:da0f:b0:7ad:95cf:726e with SMTP id fi15-20020a170906da0f00b007ad95cf726emr5695114ejb.60.1668770316800; Fri, 18 Nov 2022 03:18:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:36 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 04/12] merge-index tests: add usage tests Date: Fri, 18 Nov 2022 12:18:21 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add tests that stress the current behavior of the options parsing in cmd_merge_index(), in preparation for moving it over to parse_options(). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t6060-merge-index.sh | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index 079151ee06d..edc03b41ab9 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -5,6 +5,50 @@ test_description='basic git merge-index / git-merge-one-file tests' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +test_expect_success 'usage: 1 argument' ' + test_expect_code 129 git merge-index a >out 2>err && + test_must_be_empty out && + grep ^usage err +' + +test_expect_success 'usage: 2 arguments' ' + cat >expect <<-\EOF && + fatal: git merge-index: b not in the cache + EOF + test_expect_code 128 git merge-index a b >out 2>actual && + test_must_be_empty out && + test_cmp expect actual +' + +test_expect_success 'usage: -a before ' ' + cat >expect <<-\EOF && + fatal: git merge-index: b not in the cache + EOF + test_expect_code 128 git merge-index -a b program >out 2>actual && + test_must_be_empty out && + test_cmp expect actual +' + +for opt in -q -o +do + test_expect_success "usage: $opt after -a" ' + cat >expect <<-EOF && + fatal: git merge-index: unknown option $opt + EOF + test_expect_code 128 git merge-index -a $opt >out 2>actual && + test_must_be_empty out && + test_cmp expect actual + ' + + test_expect_success "usage: $opt program" ' + test_expect_code 0 git merge-index $opt program + ' +done + +test_expect_success 'usage: program' ' + test_expect_code 129 git merge-index program +' + test_expect_success 'setup diverging branches' ' test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && cp file file2 && From patchwork Fri Nov 18 11:18:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048088 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 6936AC433FE for ; Fri, 18 Nov 2022 11:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241663AbiKRLSz (ORCPT ); Fri, 18 Nov 2022 06:18:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241181AbiKRLSl (ORCPT ); Fri, 18 Nov 2022 06:18:41 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8837F15A38 for ; Fri, 18 Nov 2022 03:18:39 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id m22so12172311eji.10 for ; Fri, 18 Nov 2022 03:18:39 -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=AA6/mZb7+6bN66lK8hMNUdrqBO7YwIM1KUWly6kRs7M=; b=j0/qYKsUrlk6BcZclkTrpaBpGfXS/dZyjFbebc8uQyDMYO+swPnBEa9mpQnglhwQL5 sEaDnot0UFG5kAMeqAT4FUwFT0WzmRIfeLY/SE+YlGzbTuufK8u0VXPG8tKHj38Avohx dor0dtNqKMf2mP99SMhAwazPtdBWEjCyk+W/b3BbaWt8mCM+1y9cR9EwDNMcRa4tag0n HotS7Ag33VaBMCjKogTuPGuU7Ba0GfoeEjb/q/5mgLBzYqZ3SSvP2sGB0obfGEJ6L2Ra N9DdIRNrYGZP4MUFh3wTKMxU8DD0ijw6K3ybvA4rR4DqgBR1Q81M7tNOc4uutIzc8ORM 3D5g== 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=AA6/mZb7+6bN66lK8hMNUdrqBO7YwIM1KUWly6kRs7M=; b=lmPKEC0b6FTg3dKKJPY2FVkiClwKyuHNiEuLTNaAbbCmPJnKuc9949oHUrviRjOhbX 63Ewuh9XO0mwvUychAfa5LM51p3+gAZjWsyTbVvH0qkTAONLsLxl4IQOPA1lvBe33nge Mz++FLzB0dS8MzmLq1EkFV5BAYWwCgUziJGxdQjubn51sDjbMWiNCSSXxT2v9u6UbVHR ZcPuR/kMU4aTGQs7UdUcUfLPJgDAgrWzlSiP7SsiIejtFCMzmFV8zSY5qj3+FOSm660l JPyo+k3nnXa+KEoH2HhVVNsOMjw9bfy/pQ41QuGuXVl9sN6UXbuhBgrTNe8B8erUBa8B lPgg== X-Gm-Message-State: ANoB5pkanZkX1ZT7HUeYxeV7vOJRm0xfTdlvKFUcF4qMZqOa7uskzpjF uoQaDutsOZMKM1NVS7OiCagkgc2ArL1z8w== X-Google-Smtp-Source: AA0mqf5ktEP4m113XidwujbF9aYJlqtdCqQRJnal1gxNZuyfIJinTS5BBZz1S71OBdo1dFbgLPT+4Q== X-Received: by 2002:a17:906:1c52:b0:780:bd74:f960 with SMTP id l18-20020a1709061c5200b00780bd74f960mr5524260ejg.701.1668770317716; Fri, 18 Nov 2022 03:18:37 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:37 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 05/12] merge-index: migrate to parse_options() API Date: Fri, 18 Nov 2022 12:18:22 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Migrate the "merge-index" command to the parse_options() API, a preceding commit added tests for the existing behavior. In a subsequent commit we'll adjust the behavior to be more consistent with how most other commands work, but for now let's take pains to preserve it as-is. We need to e.g. call parse_options() twice now, as the "-a" option is currently only understood after "". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 71 ++++++++++++++++++++++++++---------------- git.c | 2 +- t/t6060-merge-index.sh | 10 +++--- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 1a5a64afd2a..3bd0790465e 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" +#include "parse-options.h" #include "run-command.h" static const char *pgm; @@ -72,7 +73,26 @@ static void merge_all(void) int cmd_merge_index(int argc, const char **argv, const char *prefix) { - int i, force_file = 0; + int all = 0; + const char * const usage[] = { + N_("git merge-index [-o] [-q] (-a | ([--] ...))"), + NULL + }; +#define OPT__MERGE_INDEX_ALL(v) \ + OPT_BOOL('a', NULL, (v), \ + N_("merge all files in the index that need merging")) + struct option options[] = { + OPT_BOOL('o', NULL, &one_shot, + N_("don't stop at the first failed merge")), + OPT__QUIET(&quiet, N_("be quiet")), + OPT__MERGE_INDEX_ALL(&all), /* include "-a" to show it in "-bh" */ + OPT_END(), + }; + struct option options_prog[] = { + OPT__MERGE_INDEX_ALL(&all), + OPT_END(), + }; +#undef OPT__MERGE_INDEX_ALL /* Without this we cannot rely on waitpid() to tell * what happened to our children. @@ -80,38 +100,35 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) signal(SIGCHLD, SIG_DFL); if (argc < 3) - usage("git merge-index [-o] [-q] (-a | ([--] ...))"); + usage_with_options(usage, options); + + /* Option parsing without options */ + argc = parse_options(argc, argv, prefix, options, usage, + PARSE_OPT_STOP_AT_NON_OPTION); + if (all) + usage_msg_optf(_("'%s' option can only be provided after ''"), + usage, options, "-a"); + /* and its options */ + if (!argc) + usage_msg_opt(_("need a argument"), usage, options); + pgm = argv[0]; + argc = parse_options(argc, argv, prefix, options_prog, usage, 0); + if (argc && all) + usage_msg_opt(_("'-a' and '...' are mutually exclusive"), + usage, options); read_cache(); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - i = 1; - if (!strcmp(argv[i], "-o")) { - one_shot = 1; - i++; - } - if (!strcmp(argv[i], "-q")) { - quiet = 1; - i++; - } - pgm = argv[i++]; - for (; i < argc; i++) { - const char *arg = argv[i]; - if (!force_file && *arg == '-') { - if (!strcmp(arg, "--")) { - force_file = 1; - continue; - } - if (!strcmp(arg, "-a")) { - merge_all(); - continue; - } - die("git merge-index: unknown option %s", arg); - } - merge_one_path(arg); - } + + if (all) + merge_all(); + else + for (size_t i = 0; i < argc; i++) + merge_one_path(argv[i]); + if (err && !quiet) die("merge program failed"); return err; diff --git a/git.c b/git.c index 6662548986f..83696fd8b4a 100644 --- a/git.c +++ b/git.c @@ -560,7 +560,7 @@ static struct cmd_struct commands[] = { { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE }, { "merge-base", cmd_merge_base, RUN_SETUP }, { "merge-file", cmd_merge_file, RUN_SETUP_GENTLY }, - { "merge-index", cmd_merge_index, RUN_SETUP | NO_PARSEOPT }, + { "merge-index", cmd_merge_index, RUN_SETUP }, { "merge-ours", cmd_merge_ours, RUN_SETUP | NO_PARSEOPT }, { "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, { "merge-recursive-ours", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index edc03b41ab9..6c59e7bc4e5 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -22,9 +22,10 @@ test_expect_success 'usage: 2 arguments' ' test_expect_success 'usage: -a before ' ' cat >expect <<-\EOF && - fatal: git merge-index: b not in the cache + fatal: '\''-a'\'' option can only be provided after '\'''\'' EOF - test_expect_code 128 git merge-index -a b program >out 2>actual && + test_expect_code 129 git merge-index -a b program >out 2>actual.raw && + grep "^fatal:" actual.raw >actual && test_must_be_empty out && test_cmp expect actual ' @@ -33,9 +34,10 @@ for opt in -q -o do test_expect_success "usage: $opt after -a" ' cat >expect <<-EOF && - fatal: git merge-index: unknown option $opt + fatal: '\''-a'\'' option can only be provided after '\'''\'' EOF - test_expect_code 128 git merge-index -a $opt >out 2>actual && + test_expect_code 129 git merge-index -a $opt >out 2>actual.raw && + grep "^fatal:" actual.raw >actual && test_must_be_empty out && test_cmp expect actual ' From patchwork Fri Nov 18 11:18:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048091 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 749FEC433FE for ; Fri, 18 Nov 2022 11:19:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232404AbiKRLTC (ORCPT ); Fri, 18 Nov 2022 06:19:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241003AbiKRLSm (ORCPT ); Fri, 18 Nov 2022 06:18:42 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5D31403A for ; Fri, 18 Nov 2022 03:18:40 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id f7so6690353edc.6 for ; Fri, 18 Nov 2022 03:18:40 -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=5CPQq9eUBF8v9tQzO4la4Afhse7mPXnrmd/49dOdjjA=; b=m7f2LLRAKn3wooeQwDuW+PlGsWn1k3qAEIXxinBQCksVElWmxd+Of5vjg46ldSoJa0 nSDXC8MTzCBje0f51ySNojNM5svl8swt63Fp76/m9IlBmKgVrX54UjT9V+YnFVdjNrUf ytK0fDG6qNTIMpjAhTce7RPnlAzawuxWUWKgUB254laEG5wKhqgGRBQwziuMY8n38Tpe AQg4Zu9KYcbKz1TPjSP/L9JkEkbiVmoPdMwvc4evVVvEudeRFxI4eEr/BNiTrrVaqLdJ cB3/uGdD/I8iteeWxpduxkGfrU0en0M6xMYLt/wTBCRODWaQSQS6h54NYzNH7vwjWkqR VNxw== 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=5CPQq9eUBF8v9tQzO4la4Afhse7mPXnrmd/49dOdjjA=; b=C9/Mxr3iThWmjqJBzG0FFpoTm34OFCu8PwnxR0hsfA6MmmCNdbNwa3hnR69v5suu76 IBSzhDNATkS2fjHixrSJ1XQ8QyUkhbKKPtLzKt+hhU6+B/Zp42k9fLY9xAbV3cwEY/j2 0+BK3pZCbGxT4tiO22M82+7cF28VaoAwJHRFrakkTFc2Ex50LvQM+hAI4UwMBw8n6s0U gw4gtIw4Fx1lF17CHnpQDHE6yoxCvBULzl+gZXa0Rq/BceSHgSz/PTt0ZLG4ih72gbRp WrykS7dquBHBv1xc8j4XeMPshmdBJ11aeiWRHX4ONu4IHHueeyDhmmAysAeSOd0IBMxp otSg== X-Gm-Message-State: ANoB5pnRVJubP/FuJWuIk7o7uOnemrHjhQw1GuUrUwLa6QDRTQ+6vkwF P94l60qWiwwsNT9zk2CWS6T3EVl9skHhjQ== X-Google-Smtp-Source: AA0mqf5vtiho18KBMtySmDY7Lk5HpHTBnuhLCWcPFMKXEr1/YaLhY2vN6lCpCZC0jNDVq3G3uZ+clw== X-Received: by 2002:a50:ee03:0:b0:467:897d:eb09 with SMTP id g3-20020a50ee03000000b00467897deb09mr5828259eds.60.1668770318640; Fri, 18 Nov 2022 03:18:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:38 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 06/12] merge-index: improve die() error messages Date: Fri, 18 Nov 2022 12:18:23 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alban Gruin Our usual convention is not to repeat the program name back at the user, and to quote path arguments. Let's do that now to reduce the size of the subsequent commit. Signed-off-by: Alban Gruin Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 4 ++-- t/t6060-merge-index.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 3bd0790465e..0b06c69354b 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -16,7 +16,7 @@ static int merge_entry(int pos, const char *path) struct child_process cmd = CHILD_PROCESS_INIT; if (pos >= active_nr) - die("git merge-index: %s not in the cache", path); + die("'%s' is not in the cache", path); found = 0; do { const struct cache_entry *ce = active_cache[pos]; @@ -31,7 +31,7 @@ static int merge_entry(int pos, const char *path) arguments[stage + 4] = ownbuf[stage]; } while (++pos < active_nr); if (!found) - die("git merge-index: %s not in the cache", path); + die("'%s' is not in the cache", path); strvec_pushv(&cmd.args, arguments); if (run_command(&cmd)) { diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index 6c59e7bc4e5..bc201a69552 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -13,7 +13,7 @@ test_expect_success 'usage: 1 argument' ' test_expect_success 'usage: 2 arguments' ' cat >expect <<-\EOF && - fatal: git merge-index: b not in the cache + fatal: '\''b'\'' is not in the cache EOF test_expect_code 128 git merge-index a b >out 2>actual && test_must_be_empty out && From patchwork Fri Nov 18 11:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048089 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 C4693C4332F for ; Fri, 18 Nov 2022 11:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241271AbiKRLS5 (ORCPT ); Fri, 18 Nov 2022 06:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241287AbiKRLSl (ORCPT ); Fri, 18 Nov 2022 06:18:41 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F6717E26 for ; Fri, 18 Nov 2022 03:18:40 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id vv4so2936767ejc.2 for ; Fri, 18 Nov 2022 03:18:40 -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=EAX/X9OmbrYFqBqdE9BX3H7MVNafDIY286wBwcUaP/0=; b=HEewrrrY3n3yjqIQXjwTH7CdTZAm8RDa+Q3tB7kBuR+DNUeS1BYuRUToleAXmxD3PV f1mgMLfqkSoQzB62cVn0eDABF2iOHHU1Mmb3mogfvqgG98/jRPZQIqVSGQ1gueNwdTrg YdJlK2q0Xp7y31HzvvNbgZpkciQHePydaEXhRePgusFdyTU9SfmqkSC1cUex1NsSWcnT l/gqxKp/2RI1CvoSicAklFcb/WoDYZflShHDKvyUjcpaIbMX+fjowO7gyGFxjWBErV6t oqofexmijYV+Gv6QP+ZfxWKPs9nR1RH8rdRTc8+feNbcUUnhomwMIxynLio+gvCABogr bqig== 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=EAX/X9OmbrYFqBqdE9BX3H7MVNafDIY286wBwcUaP/0=; b=l7C7db4Kc9YOIaf/ATlZntDlnKQdiQtgLdgDRQvLwkrvRsB/D2MciXHLwTpKymCqtI EVikIrdOgEQn5h3R0gWpR7axZu7yBmDJfMZaRZBnInouwr98shC89Y0MY7SEbl60Vxa4 866qUqNbVfyplBCJCQ520GAGbr3sQYsoGXgOg3C2zPS4DT3nNKf0iCHScQihddU3zTnC hjIGc4vidKdvU8MgOJLAfe6/pdwQpK6MrM2zIcR6Kc0zZ0UT5y7sJ15LyBRRVgPdalY6 GaA/h0/4Xg2wKRPrhCnDw06QLKdTJ/85HKOp8cdSsTDTkEsY8i0jdxrKoGuh3UcrEKsp w5aQ== X-Gm-Message-State: ANoB5pkOUZf5M0o14H8BqlflIchzoSr+BHN39o0ihDZixrgu7iO6FZor e7tNzMfRe/MtMZPpbWNqTQ6J3lukQLJ/jQ== X-Google-Smtp-Source: AA0mqf6tRdhHnvvJw78vRlRtqE8y1689YNAzpTV8H3B5MZxL9mJOVzeMQCQL7ZxeI+C8Jp7lIhWXKA== X-Received: by 2002:a17:907:204c:b0:7ae:63b8:d688 with SMTP id pg12-20020a170907204c00b007ae63b8d688mr5658387ejb.222.1668770319530; Fri, 18 Nov 2022 03:18:39 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:38 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 07/12] merge-index i18n: mark die() messages for translation Date: Fri, 18 Nov 2022 12:18:24 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Mark the die() messages for translation with _(). We don't rely on the specifics of these messages as plumbing, so they can be safely translated. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 0b06c69354b..ee48587a8fb 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -16,7 +16,7 @@ static int merge_entry(int pos, const char *path) struct child_process cmd = CHILD_PROCESS_INIT; if (pos >= active_nr) - die("'%s' is not in the cache", path); + die(_("'%s' is not in the cache"), path); found = 0; do { const struct cache_entry *ce = active_cache[pos]; @@ -31,7 +31,7 @@ static int merge_entry(int pos, const char *path) arguments[stage + 4] = ownbuf[stage]; } while (++pos < active_nr); if (!found) - die("'%s' is not in the cache", path); + die(_("'%s' is not in the cache"), path); strvec_pushv(&cmd.args, arguments); if (run_command(&cmd)) { @@ -39,7 +39,7 @@ static int merge_entry(int pos, const char *path) err++; else { if (!quiet) - die("merge program failed"); + die(_("merge program failed")); exit(1); } } @@ -130,6 +130,6 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) merge_one_path(argv[i]); if (err && !quiet) - die("merge program failed"); + die(_("merge program failed")); return err; } From patchwork Fri Nov 18 11:18:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048092 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 C39A3C433FE for ; Fri, 18 Nov 2022 11:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241137AbiKRLTE (ORCPT ); Fri, 18 Nov 2022 06:19:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241441AbiKRLSo (ORCPT ); Fri, 18 Nov 2022 06:18:44 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6435C18364 for ; Fri, 18 Nov 2022 03:18:42 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id f27so12310717eje.1 for ; Fri, 18 Nov 2022 03:18:42 -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=q/eu7AgKdaxXH3EksEd0F5/hiQARojqiblAAuKhpprQ=; b=NjDokXiq2CTW85OsWTXTMpegTg5AnZgXhpEFMZpqtCdcw9Qr/1/xHq/uRD+t7lSLDW 3TWuncR/2ttcfMEv4tg8hgS6XU+3SW4JsWp/h9dOfiTZqbFRCD9PBI4KoIWAug4/4HM4 0XtqLjqNKnQMz0A++wUHsyPt8ZvUrSj2cxFPlCnfNyz1CT9y/nIJswxiydIsO0uaovxI pmrPUScVqEcCz9VPTMwAe/wx7fxUpY7yOYzBWoq4l5OzrzBfMWjLaqGajOyBlG0wS+tN 4AgREsTNslGnvVYpjDYc0z8EAFzjgbSp+cPE9Nl0ved6qlmFPn7j3qHuY/NuTWMEP6W2 Tcxg== 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=q/eu7AgKdaxXH3EksEd0F5/hiQARojqiblAAuKhpprQ=; b=W+ACGOoD+Ja/D1jCkeEiaJgECcVY1GWdUP486bJG+nd+VDP/blbq4Xy8gwVAcsoZC8 SDBYUbO1beLaAQACnXaqhcsjiAe4p80ZnXA0oi/su0TdhrM5iO2M8ontqM/7EorjrL2n /v7gKQxZxf0JPuwwFew0o1hsv8oo4fvkXSus7V0BzzdXq+r+Up0NyPAG7AZgxGf6VjUU q1jkIY5zQlNeUNlOo8m7rsh52IA0umMRo8R55ZUkGbKS1jzIu/+TEOg7QPqaSiq3+WeI wO/LZXsgHzkfm4Q8bWkFV7ELqDthaAv2i9bpuRmWEl0s41xMCgiF8hLjjAnQEfbm7h/F 8+nQ== X-Gm-Message-State: ANoB5pll1nzCV9EU6Dt2pM7f9MQVVn1BTHtEA95e7IbZxjR1vemOXbFd WgpkfteCwGhkpyh+oisZyCq+rYrXlkSxuw== X-Google-Smtp-Source: AA0mqf7U/A4697Ad8sxlqBwBiYEwWcqz0qR+8HWdO2/WZX5MJy+dKrWaTnQ+thNrY1Z/v545gTO/Bg== X-Received: by 2002:a17:906:ca18:b0:781:c97c:84d1 with SMTP id jt24-20020a170906ca1800b00781c97c84d1mr5492067ejb.147.1668770320433; Fri, 18 Nov 2022 03:18:40 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:39 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 08/12] merge-index: stop calling ensure_full_index() twice Date: Fri, 18 Nov 2022 12:18:25 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When most of the ensure_full_index() calls were added in 8e97852919f (Merge branch 'ds/sparse-index-protections', 2021-04-30) we could add them at the start of cmd_*() for built-ins, but in some cases we couldn't do that, as we'd only want to initialize the index conditionally on some branches in the code. But this code added in 299e2c4561b (merge-index: ensure full index, 2021-04-01) (part of 8e97852919f) isn't such a case. The merge_all() function is only called by cmd_merge_index(), which before calling it will have called ensure_full_index() unconditionally. We can therefore skip this. While we're at it, and mainly so that we'll see the relevant code in the context, let's fix a minor whitespace issue that the addition of the ensure_full_index() call in 299e2c4561b introduced. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index ee48587a8fb..9bffcc5b0f1 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -61,8 +61,7 @@ static void merge_one_path(const char *path) static void merge_all(void) { int i; - /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); + for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; if (!ce_stage(ce)) @@ -122,7 +121,6 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) /* TODO: audit for interaction with sparse-index. */ ensure_full_index(&the_index); - if (all) merge_all(); else From patchwork Fri Nov 18 11:18:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048094 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 B7293C4332F for ; Fri, 18 Nov 2022 11:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233999AbiKRLTL (ORCPT ); Fri, 18 Nov 2022 06:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241493AbiKRLSo (ORCPT ); Fri, 18 Nov 2022 06:18:44 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467EB20984 for ; Fri, 18 Nov 2022 03:18:43 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id n21so12206628ejb.9 for ; Fri, 18 Nov 2022 03:18:43 -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=axs2AR0zL47+0jCPuLp/bfTP9r7AbJOyo7Gbyrj0kAE=; b=cf/ZDRPu9sxX76qQH3ZbhiCrEdJ6JN5fFbKXaW3GXHgYfaIXBQl/CqXGBQ+L31QBpQ 1u6bSsSQCmrNL+Z96f2qWn69MRtb7VtbgG8mvbEkc5vnwxShEs9+NPm7QxcmZ7Cz3KW4 2LulGN7878xXqK1B4sxDg3MnvLUawLK4mdMgLQIG5ZgzYQvm/z6HJskyITIdyDRvlTZv ikcRmt1q/WvyMwB63gpQOgA8u5TBxeV2sx06J/qvXe64pqo2Dl1XYYfvz8kJR6Wc+koA AQOcfBJCl+eMu9oveqmViqD4XCW0Q6dn2TOEyW2RBxSE2B4J4qHX6mwMZt6+7wR6md5y 7JqQ== 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=axs2AR0zL47+0jCPuLp/bfTP9r7AbJOyo7Gbyrj0kAE=; b=fnUtLcNIyOBjy3PnJph+8mY51MB9ne0QNwtK8OQLR/SakUHyiwmyA7FQC3tM0wvRtl qzdjCsKpFeg+NZOafzwQGC3pvJ04QNR83iUq/KsugtyoT7LlSnKGCVM3l8YJVfRBVNo1 LTuHC7ujweg3DPo7i3rp30NQsN7G7qIq92XbfX23GMOutXLEotDlNEhj7qgaN053ti6E LN45651feXjzZ3fweQoWVeEpcXKuwUJHUt1Rx2cOace+EWn5BTDotPjXSly6W73Gzv3x rw2MDnp0E3T1JzBxS0I8D0umvRD4e0Al41bEdIsFmbN5GVC6HHQdk6ubHG6t3mgaY8KX In8A== X-Gm-Message-State: ANoB5pnSvWzd/uaKansNx3z7a0aRnFTj8zp2IKpI7NAxZxx6eQlGJGjZ ujwOvCJTyUTgofJCIp4QmOoWpFiZYxv0aQ== X-Google-Smtp-Source: AA0mqf4uXeLdoiuQpHYMWjN715kbYbDEdfJ2yTP3eratrquXguNocuLY+0tc9GRtJcHOgJ2I1i/GQw== X-Received: by 2002:a17:906:81cc:b0:7ae:4373:c8aa with SMTP id e12-20020a17090681cc00b007ae4373c8aamr5650702ejx.466.1668770321474; Fri, 18 Nov 2022 03:18:41 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:40 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 09/12] builtin/merge-index.c: don't USE_THE_INDEX_COMPATIBILITY_MACROS Date: Fri, 18 Nov 2022 12:18:26 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove "USE_THE_INDEX_COMPATIBILITY_MACROS" and instead pass "the_index" around between the functions in this file. In a subsequent commit we'll libify this, and don't want to use "USE_THE_INDEX_COMPATIBILITY_MACROS" in any more places in the top-level *.c files. Doing this first makes that diff a lot smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 9bffcc5b0f1..c269d76cc8f 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,4 +1,3 @@ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "parse-options.h" #include "run-command.h" @@ -7,7 +6,7 @@ static const char *pgm; static int one_shot, quiet; static int err; -static int merge_entry(int pos, const char *path) +static int merge_entry(struct index_state *istate, int pos, const char *path) { int found; const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL }; @@ -15,11 +14,11 @@ static int merge_entry(int pos, const char *path) char ownbuf[4][60]; struct child_process cmd = CHILD_PROCESS_INIT; - if (pos >= active_nr) + if (pos >= istate->cache_nr) die(_("'%s' is not in the cache"), path); found = 0; do { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = istate->cache[pos]; int stage = ce_stage(ce); if (strcmp(ce->name, path)) @@ -29,7 +28,7 @@ static int merge_entry(int pos, const char *path) xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode); arguments[stage] = hexbuf[stage]; arguments[stage + 4] = ownbuf[stage]; - } while (++pos < active_nr); + } while (++pos < istate->cache_nr); if (!found) die(_("'%s' is not in the cache"), path); @@ -46,27 +45,27 @@ static int merge_entry(int pos, const char *path) return found; } -static void merge_one_path(const char *path) +static void merge_one_path(struct index_state *istate, const char *path) { - int pos = cache_name_pos(path, strlen(path)); + int pos = index_name_pos(istate, path, strlen(path)); /* * If it already exists in the cache as stage0, it's * already merged and there is nothing to do. */ if (pos < 0) - merge_entry(-pos-1, path); + merge_entry(istate, -pos-1, path); } -static void merge_all(void) +static void merge_all(struct index_state *istate) { int i; - for (i = 0; i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; if (!ce_stage(ce)) continue; - i += merge_entry(i, ce->name)-1; + i += merge_entry(istate, i, ce->name)-1; } } @@ -116,16 +115,16 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) usage_msg_opt(_("'-a' and '...' are mutually exclusive"), usage, options); - read_cache(); + repo_read_index(the_repository); /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); + ensure_full_index(the_repository->index); if (all) - merge_all(); + merge_all(the_repository->index); else for (size_t i = 0; i < argc; i++) - merge_one_path(argv[i]); + merge_one_path(the_repository->index, argv[i]); if (err && !quiet) die(_("merge program failed")); From patchwork Fri Nov 18 11:18:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048093 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 6752CC433FE for ; Fri, 18 Nov 2022 11:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241705AbiKRLTH (ORCPT ); Fri, 18 Nov 2022 06:19:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241540AbiKRLSq (ORCPT ); Fri, 18 Nov 2022 06:18:46 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6274F1A22D for ; Fri, 18 Nov 2022 03:18:44 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id f18so12264579ejz.5 for ; Fri, 18 Nov 2022 03:18:44 -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=j5LQuB7/t+iJlAKGV61jn4A5w203UXDyJDtx8BCO5ug=; b=p8aYPPXUnSk6pyTmmM5k06otcBYnncpm359xaxd+yWPubKGJUKq34VcewKWEXAE8tx aKAI2plDvNrWm1QkMZTw+r5uJjBzxwKNjiorMXNaBTJmTf9SP1WupyuRtXn9lIU9UbHt 38jbUc5dTKZyskKjpynhJmNZurTUcEBRF6a20py0efJnO1vuv3LgPBMWHz8AW5Mit1zq 0ctF1bRAOi40ob+/oypJZZjHU0gERX7+KNcRDchfv7BQxe7tnPTi/I+LaiTjmArnlGrx 21W4qZSrK6Xo/YTSw9VZQFOCJ4jesgu+fFFxTjAPjBMWzGhSRKucPlhWA7IkO2sPEyXz JfuQ== 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=j5LQuB7/t+iJlAKGV61jn4A5w203UXDyJDtx8BCO5ug=; b=Iv/8Tz6c1u5bY1OKmAme5ivsjBPO032WeaJ0boUd3SfpiOdDxJExWGhUgssLf3+L0m JG0Xz7DhfN4DZNrcDPOS52imHeiYVBni0hj76AkQYgS1ucl2ueczFHWcMSiPiPIvXzvM m17x20E8ipn1FmE528HnQa+OcwBvXmVEhVtfJycXAiW16WS7ZCjgKRp4IeHLH/meT4FC isdTf6+/s5YFtzYi32UTVaUXRQ72jTt8X5oSuloJeVAmUhqsGp8LZ97UJFOqcBJUWkO3 cZI5N/poPFpFdr+PXNrvfz4uuijOMMaSJXpENx266ekHMbWCNC8f5MmrWRRuOR0GuHP8 kXjA== X-Gm-Message-State: ANoB5pnoq05ztnMPcFVXaNoB42yPi9TF80hUiBvQxb+fVMneUbR+78H6 hQhAoPlR7D0xszRPBpYrBslFLodKCyMjSQ== X-Google-Smtp-Source: AA0mqf6zVeY5yBUfQF6ncanZA0Eo1EwZRFIrTjWAvIhdFvLJmElCoLoM0tbFXpALMxb2IwwpsqGq0Q== X-Received: by 2002:a17:906:945a:b0:7a8:3597:34a8 with SMTP id z26-20020a170906945a00b007a8359734a8mr5580388ejx.628.1668770322510; Fri, 18 Nov 2022 03:18:42 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:41 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 10/12] merge-index: libify merge_one_path() and merge_all() Date: Fri, 18 Nov 2022 12:18:27 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alban Gruin Move the workhorse functions in "builtin/merge-index.c" into a new "merge-strategies" library, and mostly "libify" the code while doing so. Eventually this will allow us to invoke merge strategies such as "resolve" and "octopus" in-process, once we've followed-up and replaced "git-merge-{resolve,octopus}.sh" etc. But for now let's move this code, while trying to optimize for as much of it as possible being highlighted by the diff rename detection. We still call die() in this library. An earlier version of this[1] converted these to "error()", but the problem with that that we'd then potentially run into the same error N times, e.g. once for every "" we were asked to operate on, instead of dying on the first case. So let's leave those to "die()" for now. 1. https://lore.kernel.org/git/20220809185429.20098-4-alban.gruin@gmail.com/ Signed-off-by: Alban Gruin Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 1 + builtin/merge-index.c | 95 ++++++++++++++++--------------------------- merge-strategies.c | 87 +++++++++++++++++++++++++++++++++++++++ merge-strategies.h | 19 +++++++++ 4 files changed, 142 insertions(+), 60 deletions(-) create mode 100644 merge-strategies.c create mode 100644 merge-strategies.h diff --git a/Makefile b/Makefile index 4927379184c..ccd467cec79 100644 --- a/Makefile +++ b/Makefile @@ -1000,6 +1000,7 @@ LIB_OBJS += merge-blobs.o LIB_OBJS += merge-ort.o LIB_OBJS += merge-ort-wrappers.o LIB_OBJS += merge-recursive.o +LIB_OBJS += merge-strategies.o LIB_OBJS += merge.o LIB_OBJS += midx.o LIB_OBJS += name-hash.o diff --git a/builtin/merge-index.c b/builtin/merge-index.c index c269d76cc8f..21598a52383 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,77 +1,50 @@ #include "builtin.h" #include "parse-options.h" +#include "merge-strategies.h" #include "run-command.h" -static const char *pgm; -static int one_shot, quiet; -static int err; +struct mofs_data { + const char *program; +}; -static int merge_entry(struct index_state *istate, int pos, const char *path) +static int merge_one_file(struct index_state *istate, + const struct object_id *orig_blob, + const struct object_id *our_blob, + const struct object_id *their_blob, const char *path, + unsigned int orig_mode, unsigned int our_mode, + unsigned int their_mode, void *data) { - int found; + struct mofs_data *d = data; + const char *pgm = d->program; const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL }; char hexbuf[4][GIT_MAX_HEXSZ + 1]; char ownbuf[4][60]; + int stage = 0; struct child_process cmd = CHILD_PROCESS_INIT; - if (pos >= istate->cache_nr) - die(_("'%s' is not in the cache"), path); - found = 0; - do { - const struct cache_entry *ce = istate->cache[pos]; - int stage = ce_stage(ce); - - if (strcmp(ce->name, path)) - break; - found++; - oid_to_hex_r(hexbuf[stage], &ce->oid); - xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode); - arguments[stage] = hexbuf[stage]; - arguments[stage + 4] = ownbuf[stage]; - } while (++pos < istate->cache_nr); - if (!found) - die(_("'%s' is not in the cache"), path); - - strvec_pushv(&cmd.args, arguments); - if (run_command(&cmd)) { - if (one_shot) - err++; - else { - if (!quiet) - die(_("merge program failed")); - exit(1); - } +#define ADD_MOF_ARG(oid, mode) \ + if ((oid)) { \ + stage++; \ + oid_to_hex_r(hexbuf[stage], (oid)); \ + xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%06o", (mode)); \ + arguments[stage] = hexbuf[stage]; \ + arguments[stage + 4] = ownbuf[stage]; \ } - return found; -} - -static void merge_one_path(struct index_state *istate, const char *path) -{ - int pos = index_name_pos(istate, path, strlen(path)); - /* - * If it already exists in the cache as stage0, it's - * already merged and there is nothing to do. - */ - if (pos < 0) - merge_entry(istate, -pos-1, path); -} - -static void merge_all(struct index_state *istate) -{ - int i; + ADD_MOF_ARG(orig_blob, orig_mode); + ADD_MOF_ARG(our_blob, our_mode); + ADD_MOF_ARG(their_blob, their_mode); - for (i = 0; i < istate->cache_nr; i++) { - const struct cache_entry *ce = istate->cache[i]; - if (!ce_stage(ce)) - continue; - i += merge_entry(istate, i, ce->name)-1; - } + strvec_pushv(&cmd.args, arguments); + return run_command(&cmd); } int cmd_merge_index(int argc, const char **argv, const char *prefix) { + int err = 0; int all = 0; + int one_shot = 0; + int quiet = 0; const char * const usage[] = { N_("git merge-index [-o] [-q] (-a | ([--] ...))"), NULL @@ -91,6 +64,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) OPT_END(), }; #undef OPT__MERGE_INDEX_ALL + struct mofs_data data = { 0 }; /* Without this we cannot rely on waitpid() to tell * what happened to our children. @@ -109,7 +83,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) /* and its options */ if (!argc) usage_msg_opt(_("need a argument"), usage, options); - pgm = argv[0]; + data.program = argv[0]; argc = parse_options(argc, argv, prefix, options_prog, usage, 0); if (argc && all) usage_msg_opt(_("'-a' and '...' are mutually exclusive"), @@ -121,12 +95,13 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) ensure_full_index(the_repository->index); if (all) - merge_all(the_repository->index); + err |= merge_all_index(the_repository->index, one_shot, quiet, + merge_one_file, &data); else for (size_t i = 0; i < argc; i++) - merge_one_path(the_repository->index, argv[i]); + err |= merge_index_path(the_repository->index, + one_shot, quiet, argv[i], + merge_one_file, &data); - if (err && !quiet) - die(_("merge program failed")); return err; } diff --git a/merge-strategies.c b/merge-strategies.c new file mode 100644 index 00000000000..30691fccd77 --- /dev/null +++ b/merge-strategies.c @@ -0,0 +1,87 @@ +#include "cache.h" +#include "merge-strategies.h" + +static int merge_entry(struct index_state *istate, unsigned int pos, + const char *path, int *err, merge_index_fn fn, + void *data) +{ + int found = 0; + const struct object_id *oids[3] = { 0 }; + unsigned int modes[3] = { 0 }; + + *err = 0; + + if (pos >= istate->cache_nr) + die(_("'%s' is not in the cache"), path); + do { + const struct cache_entry *ce = istate->cache[pos]; + int stage = ce_stage(ce); + + if (strcmp(ce->name, path)) + break; + found++; + oids[stage - 1] = &ce->oid; + modes[stage - 1] = ce->ce_mode; + } while (++pos < istate->cache_nr); + if (!found) + die(_("'%s' is not in the cache"), path); + + if (fn(istate, oids[0], oids[1], oids[2], path, modes[0], modes[1], + modes[2], data)) + (*err)++; + + return found; +} + +int merge_index_path(struct index_state *istate, int oneshot, int quiet, + const char *path, merge_index_fn fn, void *data) +{ + int err, ret; + int pos = index_name_pos(istate, path, strlen(path)); + + /* + * If it already exists in the cache as stage0, it's + * already merged and there is nothing to do. + */ + if (pos >= 0) + return 0; + + ret = merge_entry(istate, -pos - 1, path, &err, fn, data); + if (ret < 0) + return ret; + if (err) { + if (!quiet && !oneshot) + die(_("merge program failed")); + return 1; + } + return 0; +} + +int merge_all_index(struct index_state *istate, int oneshot, int quiet, + merge_index_fn fn, void *data) +{ + int err, ret; + unsigned int i; + + for (i = 0; i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; + if (!ce_stage(ce)) + continue; + + ret = merge_entry(istate, i, ce->name, &err, fn, data); + if (ret < 0) + return ret; + else if (ret > 0) + i += ret - 1; + + if (err && !oneshot) { + if (!quiet) + die(_("merge program failed")); + return 1; + } + } + + if (err && !quiet) + die(_("merge program failed")); + return err; +} diff --git a/merge-strategies.h b/merge-strategies.h new file mode 100644 index 00000000000..cee9168a046 --- /dev/null +++ b/merge-strategies.h @@ -0,0 +1,19 @@ +#ifndef MERGE_STRATEGIES_H +#define MERGE_STRATEGIES_H + +struct object_id; +struct index_state; +typedef int (*merge_index_fn)(struct index_state *istate, + const struct object_id *orig_blob, + const struct object_id *our_blob, + const struct object_id *their_blob, + const char *path, unsigned int orig_mode, + unsigned int our_mode, unsigned int their_mode, + void *data); + +int merge_index_path(struct index_state *istate, int oneshot, int quiet, + const char *path, merge_index_fn fn, void *data); +int merge_all_index(struct index_state *istate, int oneshot, int quiet, + merge_index_fn fn, void *data); + +#endif /* MERGE_STRATEGIES_H */ From patchwork Fri Nov 18 11:18:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048095 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 09994C4332F for ; Fri, 18 Nov 2022 11:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241777AbiKRLTO (ORCPT ); Fri, 18 Nov 2022 06:19:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241651AbiKRLSz (ORCPT ); Fri, 18 Nov 2022 06:18:55 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45D5F1A05F for ; Fri, 18 Nov 2022 03:18:45 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id n21so12206813ejb.9 for ; Fri, 18 Nov 2022 03:18:45 -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=O1jc3g6FVR4JsZ8MKj9R2CKrUWqJw9rMcQoh/2RRAX8=; b=UB8bEGfGJTYqNofOxcKGGvz9bPvlTCk7F1lnM7pdMI6Emd1yuff9MhufYGI7HG0DpT dYd2PSH9Im8utUURPoCf6TZq9ImB/th2Dn7tp4Y/Q479oylxZcH78YanB5wbkPiv0yi6 7h2Beg/wql2ZvYY6iksiJJa/4+542klrHpGMKyKWFPkOa41tcX/qNCV3KHG1XR1ZQTmV i7cpXaDFsex4nnf+WeNNcfUS36KIc2/0UTFTwZdow9RZz9qPJWoyG9UzKLNfnR57vYRJ QZOXLXTAjlmpqU2pLbfq1OVItT93bbl+ZIeQwbv36IhDPAOvpKcah7SCcSKUm6h+2Qv4 EyMQ== 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=O1jc3g6FVR4JsZ8MKj9R2CKrUWqJw9rMcQoh/2RRAX8=; b=dqGP6B+/2kMtkxd/kXL73arpBZnEoFlj1gEZ6ZfltLzi4/Z3g68qrXEovlzfxZxP+I rEobKZ+WFX2pUs6DJ6RZAgjL8nZd7w6RWAetrHzHCFd72C2I1w0l83anLwTCM5uStkL2 dCQuc4ER9ZZJ4YZzEFQ5lhsfC7987HikUHKd3bltbtb4RL3fZm7V/vQ3SPV5pTv/ueGF LhnqA3NaZMD6/V+s6JqkXYsP0s58JiIfANYieMJD7iduoFwly41ACDxWBmE25jcGibkb j8D0OupX+HdVPjq7JlrvIyGsfWKrr56Dv5b5L2yOjCIdhk+Fe8La5SQ4sJRkqwCIIvwJ 27ug== X-Gm-Message-State: ANoB5plASOvgcoPKmfw6B04GMkfH7GlEDEd2thAKi9kxJIQtqBWc+Dfy ygT2gxSaX3vGsPOapHsISqkIVoyWk7a1nw== X-Google-Smtp-Source: AA0mqf4XXDKfPA7DYsu6sC0wc9OC5hCiKIBja1F1Pgcf/zYI6/0PtU7HeGBuqtLLoWfPSNnF+RJJFQ== X-Received: by 2002:a17:907:c787:b0:7ad:8035:ae3d with SMTP id tz7-20020a170907c78700b007ad8035ae3dmr5525585ejc.46.1668770323427; Fri, 18 Nov 2022 03:18:43 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:42 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 11/12] merge-index: use "struct strvec" and helper to prepare args Date: Fri, 18 Nov 2022 12:18:28 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the code that was libified in the preceding commit to use strvec_pushf() with a helper function, instead of in-place xsnprintf() code that we generate with a macro. This is less efficient in term of the number of allocations we do, but it's now much clearer what's going on. The logic is simply that we have an argument list like: Where we always need either an OID/mode pair, or "". Now we'll add both to their own strvec, which we then combine at the end. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 21598a52383..d679272391b 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -7,6 +7,18 @@ struct mofs_data { const char *program; }; +static void push_arg(struct strvec *oids, struct strvec *modes, + const struct object_id *oid, const unsigned int mode) +{ + if (oid) { + strvec_push(oids, oid_to_hex(oid)); + strvec_pushf(modes, "%06o", mode); + } else { + strvec_push(oids, ""); + strvec_push(modes, ""); + } +} + static int merge_one_file(struct index_state *istate, const struct object_id *orig_blob, const struct object_id *our_blob, @@ -15,27 +27,25 @@ static int merge_one_file(struct index_state *istate, unsigned int their_mode, void *data) { struct mofs_data *d = data; - const char *pgm = d->program; - const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL }; - char hexbuf[4][GIT_MAX_HEXSZ + 1]; - char ownbuf[4][60]; - int stage = 0; + const char *program = d->program; + struct strvec oids = STRVEC_INIT; + struct strvec modes = STRVEC_INIT; struct child_process cmd = CHILD_PROCESS_INIT; -#define ADD_MOF_ARG(oid, mode) \ - if ((oid)) { \ - stage++; \ - oid_to_hex_r(hexbuf[stage], (oid)); \ - xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%06o", (mode)); \ - arguments[stage] = hexbuf[stage]; \ - arguments[stage + 4] = ownbuf[stage]; \ - } + strvec_push(&cmd.args, program); + + push_arg(&oids, &modes, orig_blob, orig_mode); + push_arg(&oids, &modes, our_blob, our_mode); + push_arg(&oids, &modes, their_blob, their_mode); + + strvec_pushv(&cmd.args, oids.v); + strvec_clear(&oids); + + strvec_push(&cmd.args, path); - ADD_MOF_ARG(orig_blob, orig_mode); - ADD_MOF_ARG(our_blob, our_mode); - ADD_MOF_ARG(their_blob, their_mode); + strvec_pushv(&cmd.args, modes.v); + strvec_clear(&modes); - strvec_pushv(&cmd.args, arguments); return run_command(&cmd); } From patchwork Fri Nov 18 11:18:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13048096 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 1D5CAC4332F for ; Fri, 18 Nov 2022 11:19:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241612AbiKRLTP (ORCPT ); Fri, 18 Nov 2022 06:19:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241677AbiKRLSz (ORCPT ); Fri, 18 Nov 2022 06:18:55 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 531BA27DDB for ; Fri, 18 Nov 2022 03:18:46 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id t25so12210139ejb.8 for ; Fri, 18 Nov 2022 03:18:46 -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=RyQUUDJzUS7qPfmDjUbm1Ri3+Ge1ynUxLBCOdhQgtxk=; b=j6Qs2+VWBtqRlzYW+3Kj6GDouzEUG72K9OBCSIQBFbZLBO52U0mWmnTjuRwJ9ZS+Qv Qmso704SFNN/hb95VxYodlV777aagbd8HWrSD2mR3zuIgjyo4SpGTZwDqZ6OhLtSnPzk kByC2bQks4jX2bSqftIvPtSFbPGc1PSB+MbNEK/jaTtT2H5VD87+I/rG4NM/nNVSEQIs tKmQP/fDpzBU6rF146/Wl9VbeFWbCR0yf2uWsMzZHG6VhMW8RHxE8MUQ4QEdb1Jb+RSs 1GU5u4kAzdSe+KkmNveBEXtEGuHtj+gGh1q641wXdDfZQxfw6g9BDtikeOK6gXOzTLnf FbCA== 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=RyQUUDJzUS7qPfmDjUbm1Ri3+Ge1ynUxLBCOdhQgtxk=; b=nkxEHbAM9qeDZsb+lsjl659GCwlLO/Nv+AUD416Z4wB49G81ntZFCnapCssGMisH37 SqeAqrE90Z4X7PNIP93E4SFjiA750pqvWIi5IMx6WxYtUxTcII9P3ue6B2lITC7EQ0uH 6A8pMotQeVxceUF7Cak9YlcuQ8JYm4fPSEoBkUx1tn2yDEcAk19yQpiKshfWsOgSrmoO CK/cUofRvY+yJuJBoqY5hJyWNyRtlwNJ6zig1qFIa4+Tbni24rilP2kK7ZPvyvztwSX1 N/8JSFumGXBicdZRMgRz28Po6BfdBDCwdht5LN9PcOeztXOcFinqqYdsxWdRLDxsINMI vxhg== X-Gm-Message-State: ANoB5png7WYD0ahzuAh9sa7EB6s07wvtfDPDhXyJmDUOFDR1E1idqeVW seSr9NT5+LdLcszhVTkmOkT34m+ka2Dz4A== X-Google-Smtp-Source: AA0mqf6AeYKAicIj40Q+NEsmLq5TQH7ARYjnKY1v+wi3diMiwsvyfOyROJbID1ljXomfUzpjbyl8pg== X-Received: by 2002:a17:906:cd10:b0:7ad:c0e7:7a99 with SMTP id oz16-20020a170906cd1000b007adc0e77a99mr5333926ejb.689.1668770324326; Fri, 18 Nov 2022 03:18:44 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id fy20-20020a1709069f1400b00788c622fa2csm1558955ejc.135.2022.11.18.03.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 03:18:43 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Taylor Blau , Junio C Hamano , Alban Gruin , Phillip Wood , Elijah Newren , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v9 12/12] merge-index: make the argument parsing sensible & simpler Date: Fri, 18 Nov 2022 12:18:29 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1511.gcdcff1f1dc2 In-Reply-To: References: <20220809185429.20098-1-alban.gruin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a preceding commit when we migrated to parse_options() we took pains to be bug-for-bug compatible with the existing command-line interface, if possible. I.e. we forbade forms like: git merge-index -a git merge-index -a But allowed: git merge-index -a git merge-index -a As the "-a" argument was considered be provided for the "", but not a part of "". We don't really need this strictness, as we don't have two "-a" options. It's much simpler to implement a schema where the first non-option argument is the , and the rest are the "...". We only allow that rest if the "-a" option isn't supplied. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge-index.c | 28 ++++++++-------------------- t/t6060-merge-index.sh | 12 +++++++++--- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index d679272391b..d8b62e4f663 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -59,21 +59,14 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) N_("git merge-index [-o] [-q] (-a | ([--] ...))"), NULL }; -#define OPT__MERGE_INDEX_ALL(v) \ - OPT_BOOL('a', NULL, (v), \ - N_("merge all files in the index that need merging")) struct option options[] = { OPT_BOOL('o', NULL, &one_shot, N_("don't stop at the first failed merge")), OPT__QUIET(&quiet, N_("be quiet")), - OPT__MERGE_INDEX_ALL(&all), /* include "-a" to show it in "-bh" */ + OPT_BOOL('a', NULL, &all, + N_("merge all files in the index that need merging")), OPT_END(), }; - struct option options_prog[] = { - OPT__MERGE_INDEX_ALL(&all), - OPT_END(), - }; -#undef OPT__MERGE_INDEX_ALL struct mofs_data data = { 0 }; /* Without this we cannot rely on waitpid() to tell @@ -81,20 +74,15 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) */ signal(SIGCHLD, SIG_DFL); - if (argc < 3) - usage_with_options(usage, options); - - /* Option parsing without options */ - argc = parse_options(argc, argv, prefix, options, usage, - PARSE_OPT_STOP_AT_NON_OPTION); - if (all) - usage_msg_optf(_("'%s' option can only be provided after ''"), - usage, options, "-a"); - /* and its options */ + argc = parse_options(argc, argv, prefix, options, usage, 0); if (!argc) usage_msg_opt(_("need a argument"), usage, options); data.program = argv[0]; - argc = parse_options(argc, argv, prefix, options_prog, usage, 0); + argv++; + argc--; + if (!argc && !all) + usage_msg_opt(_("need '-a' or '...'"), + usage, options); if (argc && all) usage_msg_opt(_("'-a' and '...' are mutually exclusive"), usage, options); diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index bc201a69552..4ff9ace7f73 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -22,7 +22,7 @@ test_expect_success 'usage: 2 arguments' ' test_expect_success 'usage: -a before ' ' cat >expect <<-\EOF && - fatal: '\''-a'\'' option can only be provided after '\'''\'' + fatal: '\''-a'\'' and '\''...'\'' are mutually exclusive EOF test_expect_code 129 git merge-index -a b program >out 2>actual.raw && grep "^fatal:" actual.raw >actual && @@ -34,7 +34,7 @@ for opt in -q -o do test_expect_success "usage: $opt after -a" ' cat >expect <<-EOF && - fatal: '\''-a'\'' option can only be provided after '\'''\'' + fatal: need a argument EOF test_expect_code 129 git merge-index -a $opt >out 2>actual.raw && grep "^fatal:" actual.raw >actual && @@ -43,7 +43,13 @@ do ' test_expect_success "usage: $opt program" ' - test_expect_code 0 git merge-index $opt program + cat >expect <<-EOF && + fatal: need '\''-a'\'' or '\''...'\'' + EOF + test_expect_code 129 git merge-index $opt program 2>actual.raw && + grep "^fatal:" actual.raw >actual && + test_must_be_empty out && + test_cmp expect actual ' done