From patchwork Thu Dec 15 08:52:05 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: 13073975 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 1D52EC4332F for ; Thu, 15 Dec 2022 08:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbiLOIwb (ORCPT ); Thu, 15 Dec 2022 03:52:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiLOIw1 (ORCPT ); Thu, 15 Dec 2022 03:52:27 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC6852613A for ; Thu, 15 Dec 2022 00:52:26 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id f18so2302857wrj.5 for ; Thu, 15 Dec 2022 00:52:26 -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=WQpi3xrjH1eqxG8/vVQD3NOYgQMR8M+Fr0WoDY+57kg=; b=XoLqgsFROR+xvxRMs3AeCVL603So3hTvNgXDosAObvRULjx0jETPIsQYJC2KnlWWkD 3CUHD6J4rbD30y6rRRrvphBsJ1jMJGLVASEF6jdrDP+m5sy2N3ODXkVJ9rwkZLj3Tfod SuTWZ+GRvgSYIcwbY/7rCFTVwgHapcwhpMHEIyCoHet2m6Q6QbsjEiP8lDnmLfdXE0Y/ D8VxPIybp+RvxrV7pyFcKi92DXzlOqOv3r7kLLeo0ohk1cE4QTlQyDFcrhyyRbe4L7lB LRJJ+rIFxYp4QutHMvsfiNVZ9KAxW/JzvCsN7E90NPCxKA7lqC3/dsdFLhRYw9XaGR4/ 1iXA== 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=WQpi3xrjH1eqxG8/vVQD3NOYgQMR8M+Fr0WoDY+57kg=; b=bRze4HMFW076sYgFJB8ZKLU0uBMjoELN67G+mna0VY/bvIjgcX7tafbk+fQj3ihss+ NrcFEM24E+vOC+usD/K7g09PNa1Z9tZeNf3ubtHZuuim5B1JnLGpFOpN09KJWAPib1wl H51THydvcfpegoNDzYlEb/38xPNB6mnxfe04zWIlBoG4w/JLv1zSLJ9F3e5k7JLx6DaB 6abcaJDreVNmnJJ/JzcjMShKgBBYlikQ993qC8G+N/Zd1nyPxl4ZOHTy1nqJPbi9kr1r eqWKZ+QaBgDnCGPiAhbk9stODZJycHkrK+ssaT9efwM7DTUA2gu/acwApgoeYoe++69h K2Ag== X-Gm-Message-State: ANoB5pmR9TgWy+jFF8n75P0QjZyJtDh4K0+otRMnHOHA3Sy4q9FtR4Kb V3FoBthBSlvG3vVMmCw4Sb3d2HVRTW+Y1w== X-Google-Smtp-Source: AA0mqf7z2Kf64OZHe0KcKiUGN+I3g2tc0dITVtl3O0Ai7uVTP29G6/Q0yRUPCE4c5gmdriwxJosztQ== X-Received: by 2002:adf:f802:0:b0:24b:b74d:8011 with SMTP id s2-20020adff802000000b0024bb74d8011mr17537905wrp.6.1671094344897; Thu, 15 Dec 2022 00:52:24 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:24 -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 v10 01/12] merge-index doc & -h: fix padding, labels and "()" use Date: Thu, 15 Dec 2022 09:52:05 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 452f833ac46..69b18ed82ac 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 | ([--] ...))"); repo_read_index(the_repository); 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 Thu Dec 15 08:52:06 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: 13073976 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 D105FC4332F for ; Thu, 15 Dec 2022 08:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbiLOIwe (ORCPT ); Thu, 15 Dec 2022 03:52:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbiLOIw3 (ORCPT ); Thu, 15 Dec 2022 03:52:29 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EF352656B for ; Thu, 15 Dec 2022 00:52:28 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id f18so2302922wrj.5 for ; Thu, 15 Dec 2022 00:52:28 -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=Vu6ClcJcCzmOu/KeLiipByWWC3wZc8dcCKrdQDY3Y74=; b=qnZFi+Vc7dbLMLmktZnl5KVIfSkRM/1HZlsnd2PxXRJyLGSNWuzgN2JYqmjgCY4TrG /kDuzNUSfR6wXEQN0NSHqvsw1GIzEHMohXd4Smlv/jRSUNvqv25lNYbYG2ChOj9/ZDzY EeQTn8iJAp+YTvT4vISK7dO7rzRhBu+kBCtmPRwCxAqLg+R/2kAK8z1MaHCwPePHobf9 Ny+GixXajqioENMn3HSBaKCGSFEfv1T6CORqLfZZf3QuaZwk84HB6gQ5V8+AGbHwEiFf eVKQ12Zmo7k/vZwCQ43yPN2bRYQG4zU2VAS0o+RkGNGMVTJd690woWHmLZPFSBQDTZFJ WgYw== 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=Vu6ClcJcCzmOu/KeLiipByWWC3wZc8dcCKrdQDY3Y74=; b=d63MuZt6qarovKnjDTqhhllIlec9nRABAotlh+Qg0pDgovByStCjhlLtIjf+i/UEiL TCr5XkLBFp+TXD3ua13EH3L3nojv5Qgj7Uhw/gePucYIrWeFIKmPzUahpIqH7V/ds2Of doPDhT1dGq0oOaH0oeppaFexWC+0VRZRfHg7nV8v2AjAJGsoChVEPhtca4fhA2Xm6Giu VPzDUvskR0/rxR/a7xwwhzJ+LKYyvHFQ2yci9rtPstD+J4DmoobQsDbOuAWs2Ya0LtbX YLtHOv9xCmX5oV9VDQ0BSBRTpUJs1+13UdwQL0hEvlb7Lxd/kZXKx5G2elb6Dns4R14t qtGg== X-Gm-Message-State: ANoB5pkNxLm7WmDQu2PRPmlKabk4Igw2pguiRCGE2/FW1E74mS/c3i9B WbmHP4js1fIjIJAL/0QMytdNOqWlTQkcwA== X-Google-Smtp-Source: AA0mqf5Js8MEVJeMyUecn6RBxOs4IZyMumQfLotvQgJ5lvYAKQNkyiEHDBwN9Z3b4vqEaY9NyNqMjg== X-Received: by 2002:adf:e5d1:0:b0:242:849:745 with SMTP id a17-20020adfe5d1000000b0024208490745mr19227398wrn.25.1671094346313; Thu, 15 Dec 2022 00:52:26 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:25 -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 v10 02/12] t6060: modify multiple files to expose a possible issue with merge-index Date: Thu, 15 Dec 2022 09:52:06 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 Thu Dec 15 08:52:07 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: 13073977 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 2B317C4332F for ; Thu, 15 Dec 2022 08:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbiLOIwo (ORCPT ); Thu, 15 Dec 2022 03:52:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiLOIwb (ORCPT ); Thu, 15 Dec 2022 03:52:31 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EEBD1D64D for ; Thu, 15 Dec 2022 00:52:29 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id h10so2307911wrx.3 for ; Thu, 15 Dec 2022 00:52: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=kjKghlCm2715h/Z/Ni1lV80lLwuQoZsFvimgdqNo1TE=; b=JsBB6bRcnimXT+yayZA4pHOEj3y6B32ec68DHWa9sEsQJvnYV6Esr6VETfWYGlUc4Z ZcWY5TSQd5U0cBFTk/K/7UMWmvfBLm0pH9I07iAVUalk2ThxO82IG8nPgR8EFi49SBIN cI++saxqbED1oW+8N2goedO/L8OZDld/LPXM6oJlfW/VPdUyuR6TP83A5HMdHZEk7u5b WlLcXHH42ofR3UOqPVrM5WCBZSQ4aPHYvgM9yy5zQlg30iKrIK1p4H1ZVLHR3XhyIsEW iiENaahyuw+nxEoW4ycC3stvqqtRNegG24eOM8JKnjxZZPyQxUt+6/qNLKw70td9auoS kS1Q== 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=kjKghlCm2715h/Z/Ni1lV80lLwuQoZsFvimgdqNo1TE=; b=R+TW5KUqybhJZPzw/f2xsNuyNydajPkg+QhD6VZO/jjG4ZpAYDymdzx1l/7ggZVdVn j72CPlyFrSsL18cicbAYQvBT1GJqusApjoaB/8XZwCGWghn3FAUwVLumQ14DpBAA+uAB L+kmwo2dRsQ/zlRC6Qz4PAECe0FFBJQkxC+HWEC/iM/VNJcbs+1Z3ICX2aXYcLIK/ZI+ v8Sldio8Xl0xTg2cYSTXpxcFFBJiJfBiMXpSWSCCkVoT4HWGabLF+zgUQruP2+2oPeQV ZRzWNiU9nzDq64iIzoAW0xEKwDjSUbalGPDESAaR/35tAzVu7FdN0OhUUwf3vcHdg23M bOpg== X-Gm-Message-State: ANoB5pnHcw8M2fyXwij5g0gXEwJGCdPDS8cTnYEmGnoEWHmaPdW0YrwD rO94cQdmeNWk33kKw+81A2vwgtju2KC/ZQ== X-Google-Smtp-Source: AA0mqf6ZDF61aH1SrQOYNHBKCkhK2BhVTlXoSl7xs+taT/oVTvLROWHaL8EaDqGccp4ioe/Y/pQCTA== X-Received: by 2002:a5d:4e06:0:b0:242:4f56:6b4b with SMTP id p6-20020a5d4e06000000b002424f566b4bmr16727316wrt.38.1671094347404; Thu, 15 Dec 2022 00:52:27 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:26 -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 v10 03/12] t6060: add tests for removed files Date: Thu, 15 Dec 2022 09:52:07 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 Thu Dec 15 08:52:08 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: 13073978 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 2C7C4C00145 for ; Thu, 15 Dec 2022 08:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbiLOIwq (ORCPT ); Thu, 15 Dec 2022 03:52:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiLOIwb (ORCPT ); Thu, 15 Dec 2022 03:52:31 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3937526ACB for ; Thu, 15 Dec 2022 00:52:30 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id u12so2270362wrr.11 for ; Thu, 15 Dec 2022 00:52:30 -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=Ei6U/nntlUWEF+yRrzSWowNU3EfvHZJODJuqQdNbi9U=; b=eOE4lhIyeDeeLAJvLhEA27Q2Z3q3mhikql2LFk/xtsy+Rv05hWcFsf8VaOczD/DpWF xPhO27Gl9uL4K+JG39GviVA6oja+bzsJjZSqqCg2Cn8RlOASxh3FBKXMIFKRqyz6UT3S jwKh3pK8cR3rMi6VMLeWZvpeF9Cp6VWYwuLTN+yj4JMOQf9NavD19EF7PMsj2Hmtkmn/ lHhAYIhYIRc6KvZHjNZN4vaRjtTK+E5+tPni/8AI61ucBiWUcS0kAaxEHudJH324aRSF y83NouXNZ/HcPTai0VTNojFwrHzP7VBfmSGotnUIRrWToRy6Hguy+L+McxgeKGcPaae0 8iOw== 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=Ei6U/nntlUWEF+yRrzSWowNU3EfvHZJODJuqQdNbi9U=; b=jVYE2ojnV312HYKmE2sYjk2fREk9AXSZFW5RGefEeeYT+30UuBvWzuGdXnSepk0FKn Q2sSMDdoKpxYHivuX6S+5ITsc/lzWLCPe+1G3bmFhS23uR5hA3o9PpaQkSYEFS437cwF wboxz7JSh21imlxbURWryTxlMO0obkcR4gtAbYsnG72q99Y5p4FfK7e3L/M7gfbjZEDO Kf6Q13c/EJic6/BoayUzrvpSzGj193m5AU58c8FHPoyohr3OGpBxFdI2ImqjtZ/abK+Z IuZDke7wsTZdhlaNBnSsLl8G80QfvRTKzZdLMw8PlqGd6jOKYw1lU4Nx1Qu2ZdZRhBrO 7hsw== X-Gm-Message-State: ANoB5pl0+C2YXodYQDoEujDWDEC5g/Bvn6DuE7VOX1pMvC0G9WHfflI1 svJVFAv0Joa6Xim/2jDN+/RVWyfdBapAuA== X-Google-Smtp-Source: AA0mqf5RUMcJKbjlczJvQbs9LUIP+B6xPd24iKxxI28gQNclbfB5FqLuYseJ97/AT44v5B40padiLQ== X-Received: by 2002:a05:6000:15cb:b0:242:fa3:3825 with SMTP id y11-20020a05600015cb00b002420fa33825mr21240925wry.37.1671094348396; Thu, 15 Dec 2022 00:52:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:27 -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 v10 04/12] merge-index tests: add usage tests Date: Thu, 15 Dec 2022 09:52:08 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 Thu Dec 15 08:52:09 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: 13073979 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 40A6CC4332F for ; Thu, 15 Dec 2022 08:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229757AbiLOIws (ORCPT ); Thu, 15 Dec 2022 03:52:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbiLOIwc (ORCPT ); Thu, 15 Dec 2022 03:52:32 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4729F286FC for ; Thu, 15 Dec 2022 00:52:31 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id w15so2281847wrl.9 for ; Thu, 15 Dec 2022 00:52:31 -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=CUVG1T3e5KOzbjNytgckKwmcnBoi3CdYMk+VaOSV6ng=; b=BF/NBMrRUizaeIot7Fmvz+RCondDnSCvlRmVLErAGIBuYrnNcmTVa4Nq50U6ocHfZV aAOF1bwkokufH/T12rv41FTtnRz5zlKdxabVyVlczO+yol6QaSUJbsPXZzXWjQShED59 eLj9GOcaqKSh+hSMCIB3V13OD3L1DUUeo45QxVeGH81e0JIaxruK4nf0pc0u4SHPqtz5 S2FblUy6ZuFrGexSNqC3VV16Tjtd8Y0t9QmGKq+7/Jm0PW7LcdeRuiXSuWW8fd/Wr7LN 8V8/xhiMoL5CbYo/OMAm7WxtokUIbRTrtdI4OJGOCgNL4I3/sOIsJ+FfxEtHo1ysxjEo bvbQ== 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=CUVG1T3e5KOzbjNytgckKwmcnBoi3CdYMk+VaOSV6ng=; b=7jRyxSjlG8+8roPw5GStZ2yQ2R3R61MlO6HrVfI/+j1OEU6traInxjIkwPsXm/8+1E n1ezSyH+MK4+cOVPYAUcGdPeCyeYnJ0i9FSBGEKanT9x+eiXg/n7OkHjHOeQPsK+Ifer z+gsDi9lNdvbkovf5XJdYY7nwMfZCUt2C3VYxpLAQ5aGAiDy0yfeG1/EHC1H6bu2Tl9k tgRRTCM2tT+05CkJwyX2awqyJAyeWFsgQGUyqJzw129rKCCgjlE6NPTdLsyIYg+uNC+v othFXH+mdZtLbN/+4sJWvbBfku1LDXlAypsk0Paneph7zUekiFW+/djY7jweQRS0Qdbd weNQ== X-Gm-Message-State: AFqh2krgptlVnQS6muFEuI6PmaqWn1ftsfIpK6Ytmyax8hRN7YQCb0mZ bHeCcvHCL9knQVNxI++GDBacsKtfgimRkQ== X-Google-Smtp-Source: AMrXdXtWrjEStIVDENhZysrKvbKHHa5+Xx4guCfGvLoxuxmeGuM2RLqRoRMtv5q5iqbKXPDI5mBd7g== X-Received: by 2002:a5d:58f8:0:b0:256:1d9b:bd4b with SMTP id f24-20020a5d58f8000000b002561d9bbd4bmr3889277wrd.55.1671094349438; Thu, 15 Dec 2022 00:52:29 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:28 -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 v10 05/12] merge-index: migrate to parse_options() API Date: Thu, 15 Dec 2022 09:52:09 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 69b18ed82ac..3855531c579 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_VARIABLE #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); repo_read_index(the_repository); /* 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 277a8cce840..557a33925e3 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 Thu Dec 15 08:52:10 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: 13073980 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 31EC6C4332F for ; Thu, 15 Dec 2022 08:52:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbiLOIwv (ORCPT ); Thu, 15 Dec 2022 03:52:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbiLOIwd (ORCPT ); Thu, 15 Dec 2022 03:52:33 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B592A41A for ; Thu, 15 Dec 2022 00:52:32 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id i7so2286969wrv.8 for ; Thu, 15 Dec 2022 00:52:32 -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=5hvpBFodT/68WXPxrXfvR7JdsuqQLUhNsBL8k0RXue0=; b=bdRkK2tkfUnNr6oo5NGX/oIwG4zTD+9v4hkkB3wxAvkJRgVHg7+6DJPwvz1+fzDand EuvaO+r/3ebIfQbQpgzUtuMKABOLpCf1nRXG3QrN8IchnbF6NJb73N6GE/gVvL00J4sW mjARjccKLR0WCdArfphNUArol9eS7be8lCRO+j290L5Li3u/a3+vMwzFDmYILEfYPxnj +03SWVnL+Pqw+OMkdv79Z1rhWtr/0C5HcCRtmdSY4UkLymv8OkRO+1TplAKBboQOooQU k82r5QCJdqHsg3Z47FLmQ/J14iR6Xy0RZPsm63ToASDllTPBmFtUzoX3zpbl10h/MMrn Qp1g== 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=5hvpBFodT/68WXPxrXfvR7JdsuqQLUhNsBL8k0RXue0=; b=75tLebD7KqRDaNM2m92G9WJwanMl/4b9WKa//MxG2kuQjnSFTmfGDUcPto/Ug+Sbt+ ERyQ9FKn/rY+MO/DB4MpuwQnI01eKtEvzUJkR+ZIZ7WS0gFa9KL/FCQq6Hrwsm7J+QLH TisuNeu2lG4oXtkbFdjqfGxJoTnbWRoxb9ZJsKOGXsR5QxcDUFUaVLvLx4ti+SMnolcj 1AITUlLUk6XUyAqnJP9Q0mfqVgvS581Otf9Elj2aMII2ElV9f/I13wKbaw3so5AaW85+ 5x5D9x/8BPPyJpRtYnJY08OVBjYzQ7ayZP0vZcDfhsii5LQBz5Yt590M0f6g3YPmmDtD 5YHQ== X-Gm-Message-State: ANoB5pnMfRW8HD/caNh48Vlj+/ck478fUf0aBQVIAGYoB4SFhoQFyGbX LuHf+dAAyMAFm+8KyHUVjPGTfl1W8We7xg== X-Google-Smtp-Source: AA0mqf5hsTB9lZHLmhUg1j7v42PNYfNVqEs64/+Jhk510zhRXXdr5i/ppZCHb1qckTtTw+TaARGkcQ== X-Received: by 2002:adf:e98f:0:b0:242:7f7f:da09 with SMTP id h15-20020adfe98f000000b002427f7fda09mr17215219wrm.34.1671094350540; Thu, 15 Dec 2022 00:52:30 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:29 -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 v10 06/12] merge-index: improve die() error messages Date: Thu, 15 Dec 2022 09:52:10 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 3855531c579..2dc789fb787 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 >= the_index.cache_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 = the_index.cache[pos]; @@ -31,7 +31,7 @@ static int merge_entry(int pos, const char *path) arguments[stage + 4] = ownbuf[stage]; } while (++pos < the_index.cache_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 Thu Dec 15 08:52:11 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: 13073981 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 CFB93C00145 for ; Thu, 15 Dec 2022 08:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbiLOIww (ORCPT ); Thu, 15 Dec 2022 03:52:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbiLOIwn (ORCPT ); Thu, 15 Dec 2022 03:52:43 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 727D628702 for ; Thu, 15 Dec 2022 00:52:33 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id w15so2281922wrl.9 for ; Thu, 15 Dec 2022 00:52:33 -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=ZdKcGYb1p/lHbC49gl1ooptz03QHJzw2wNvRj4cQdRo=; b=gfm7sHIh6LdVVddRySgFQn3x/oJInPrASp4JkniiiSD2Yt2cL7Io71H/mKulVw4elj vjJ++sCzaclEktfGa1j1N9XfC1l2gO/DLB2uiUpnuzMQDHAwhIVjXlJzVdZqihZzQcAZ y/VUGxNkBZELtvY6BVP6vLFwG1b/i5fuzGC82Y61lcBKDNTpU0pLGHlKwc4zUBjVR3DK f832Pjk5ynLyfZrPjdXFpH2eb8lUbjk47NU8QFoi7Qq1mFloPpMbcsFZ77FRLMp6BcLN NGxPD2L/XzLNfG249d3rAiYetpFlSsWHD2N0/XexPe0UVKABm3MwsPbwOeOyW9/v5z4z YMAg== 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=ZdKcGYb1p/lHbC49gl1ooptz03QHJzw2wNvRj4cQdRo=; b=IOVk4bi4lKpedVszXMTnOPqoKd3HF+Khh3YzKHp/JiStWamlaPmRETWHLYYLYHo6JZ aS+QjlYndYPN52c8kCrSf+0Sex4QE5AuvAiHJ1Y7xnu/qeqttClNIhZdDkDYWVQHxHKz YqD7DtzpZvM/2z3tKMiecKdGL0pL6oTAUJvL2/Mci+y/uTDx8Cms2A1xkHAANfX2mW0u dKEN6zhj2UkcVoii6f3Gr9gs1m9vKSRL5kY/6x+FOsmxcDsUXW3TVNzKWtr8wLjfy58/ elIRMLzHfJ6uE6GYCafB7EfGgP2dpH1siUw7kbGzd4YsvbHf/NdoXB8K3kDCekmxuuEa Nirw== X-Gm-Message-State: ANoB5pkbhxjKX+WNPSgxNpduYtR8iz47YUUuos6eU2nofzrT3lJOkn4M xhIt18RIlepWHVicIYWCE6uoSL60OxDOyw== X-Google-Smtp-Source: AA0mqf7a3OMbVyOnbw/dyxfmsuYctDM6xNW1BoHgUP3atC1NsqDIjjnhl6Ns5p7oisSuoAFlQp616w== X-Received: by 2002:adf:ebce:0:b0:234:f41a:b50b with SMTP id v14-20020adfebce000000b00234f41ab50bmr20030922wrn.38.1671094351554; Thu, 15 Dec 2022 00:52:31 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:30 -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 v10 07/12] merge-index i18n: mark die() messages for translation Date: Thu, 15 Dec 2022 09:52:11 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 2dc789fb787..4d91e7ea122 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 >= the_index.cache_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 = the_index.cache[pos]; @@ -31,7 +31,7 @@ static int merge_entry(int pos, const char *path) arguments[stage + 4] = ownbuf[stage]; } while (++pos < the_index.cache_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 Thu Dec 15 08:52:12 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: 13073982 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 A7927C4332F for ; Thu, 15 Dec 2022 08:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbiLOIwz (ORCPT ); Thu, 15 Dec 2022 03:52:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbiLOIwn (ORCPT ); Thu, 15 Dec 2022 03:52:43 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7288E2A718 for ; Thu, 15 Dec 2022 00:52:33 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id h10so2308109wrx.3 for ; Thu, 15 Dec 2022 00:52:33 -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=OMvwUWQBATO7msOgHm0f1TyK1B/ykbmbofYnwu30sA8=; b=TlYFyN3eXoBKhGSw+RGHr96EunqwTVWuli9lBBhMSitddpK96JgyT1KsO3wfF0u1Lk MkHwWl0jv6j1DrSyjUOQ7qQTnLvcRaQkTXuuqGhRe/wC2lOa6DK5uGyxhmvOmfuCIJyQ pJBhMv+fkoiPhpq6vHIBSS7JhbVzoHF7RWYcEfq1MtYGbB5m9K+ZCjZwWwv+WuSO9XhY Qar2dH9P3QCIJ0qn6QLXE4oQYazM99rA/DopbHkrCgdugw2l2jSYTf+IhKukzHYoWhE1 0yToZ3Y2Ta/7wbZBtbKxJYD1GQCNxtA0ZiquxM3AkDSASOTtSR4lHiqpFpLy+4iV38Gx nysQ== 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=OMvwUWQBATO7msOgHm0f1TyK1B/ykbmbofYnwu30sA8=; b=O2SP6sbnxAQtIBcFgex4Th7CsQPQeCLwnlebw6gr4FRaCVUgSlShyLLHEufFI7OsbC GzD6CwZS/8d4psdxioQYiok5pzohEty6ggvDn1r3WQFu7j828Fd3XupFbMbZ4xEDDOku tBrAh4xchxGZ2eZgMbhFVXLjbAint6dFKUKED93x6z1sbelT/mLNqK6h/IEkxFx11S/s bj619dTodAMoY6nXaTFj42PfmTzrEd5oqrFgprwL7LI4McDPQ8hOc67O4jcekh5wDrP4 wm1vAnguv9hPVaFlblBmJ8cdFa68b0EDfmmrrPHMR9fFW2fMCEjX6V668REOEymi8DTr vvGA== X-Gm-Message-State: ANoB5pnEqiJ7+lzqJaugQKXaqudWKPQOII+sPjq6/rwCjInHTXqAHESs Jx0k6Zgs3uGZo+Sf8zJO00BHkvFHU+xxtQ== X-Google-Smtp-Source: AA0mqf7UpveEJ+WSuy4purRTv4r3edDR+5C6p4qy1ayk4IaqG3FL5JnRkMuWLw9eO0L989hT3l99CA== X-Received: by 2002:adf:db81:0:b0:236:695b:82d4 with SMTP id u1-20020adfdb81000000b00236695b82d4mr17180825wri.30.1671094352509; Thu, 15 Dec 2022 00:52:32 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:31 -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 v10 08/12] merge-index: stop calling ensure_full_index() twice Date: Thu, 15 Dec 2022 09:52:12 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 4d91e7ea122..cd160779cbf 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 < the_index.cache_nr; i++) { const struct cache_entry *ce = the_index.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 Thu Dec 15 08:52:13 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: 13073983 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 7C0BCC4332F for ; Thu, 15 Dec 2022 08:53:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiLOIw7 (ORCPT ); Thu, 15 Dec 2022 03:52:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbiLOIwo (ORCPT ); Thu, 15 Dec 2022 03:52:44 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C5128714 for ; Thu, 15 Dec 2022 00:52:35 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id h10so2308143wrx.3 for ; Thu, 15 Dec 2022 00:52: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=REhBwwEAcN2xjU5gGrSvsaNfDkxGIV2peZZlOOg9rkE=; b=oriB7m+EjA3JOMQDv+QEr3jfDxdReNzphqdcDpeYxiSmC3vlyxaT7mlHcK/4HXWSKt ylWPGEZtTveSqkcmitnfIsChe4t4eG6Xa2Ts7Eybcg0xcF5pE8XiulZUKA6MEORYkPRS 3UZ+5FhcD/2sxVe2NlxUJhCLX9Egt11CvQEh0Be3Db4XWun8eLiCOub1dFHA+asdLSgq WpGVszxxuhvdoREmemVWB/KgEfqcYG2hlEhcdCIrBa81gfjO2roGZW5vVAkPxe2c9auH CjlGrgYUoyYxsgEHQeOXui3XnRS2Vi1P+ZHCalNWFxeXEj3BRheVSfMTU9fUfqfXJbS6 xb+w== 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=REhBwwEAcN2xjU5gGrSvsaNfDkxGIV2peZZlOOg9rkE=; b=H5szGIETZ0AQnlZDn3RZ3OoiC3E9ewnUWyJmtxiJz15G+mzzuoqGW66DclOkzDqSqg PPEmfCLwUEBjBWl99iOW6kpk65+5WHDFXYrClJn765JMB9VIcV1rwV6KDetBEUnRfedB y/X0Pc6NRQ+oXouCZGY/1V/yRuOuSJ6bXjBJxnx9IOgHaadG0r8kvRvFGRoAxA9i5zyZ GUv8Ns89lE8eWi0blWLa4uiyWhrJNxPud46sOIqqDfPPZNXmISn/NrYum2add1O7aTXf I8mjFiBMcTocoY7qH6AmJHbmJjploxlsKKURQumRWxm1DSgduPZFNX/ClirbehSNR0Ur OJeA== X-Gm-Message-State: ANoB5pkLu2RZ2mI7pJ/1MjXlrthOfOmkZ7+jtoMK9nDqo/szstUNUWCc j2Zp31cE+Lwninp1E56jDt3gQfmn8dcK0Q== X-Google-Smtp-Source: AA0mqf5dypXE8p2nHh+SSUqn283RTr487aDLZxV8rslc2hYAyN/Btdqm9sTbbEmvHybcUSUg7Ct6fg== X-Received: by 2002:adf:dbc4:0:b0:242:bef:80a7 with SMTP id e4-20020adfdbc4000000b002420bef80a7mr18754142wrj.49.1671094353481; Thu, 15 Dec 2022 00:52:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:32 -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 v10 09/12] builtin/merge-index.c: don't USE_THE_INDEX_VARIABLE Date: Thu, 15 Dec 2022 09:52:13 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove "USE_THE_INDEX_VARIABLE" 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_VARIABLE" 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 | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/builtin/merge-index.c b/builtin/merge-index.c index cd160779cbf..c269d76cc8f 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,4 +1,3 @@ -#define USE_THE_INDEX_VARIABLE #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 >= the_index.cache_nr) + if (pos >= istate->cache_nr) die(_("'%s' is not in the cache"), path); found = 0; do { - const struct cache_entry *ce = the_index.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 < the_index.cache_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 = index_name_pos(&the_index, 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 < the_index.cache_nr; i++) { - const struct cache_entry *ce = the_index.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; } } @@ -119,13 +118,13 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix) 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 Thu Dec 15 08:52:14 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: 13073984 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 13806C4332F for ; Thu, 15 Dec 2022 08:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbiLOIxQ (ORCPT ); Thu, 15 Dec 2022 03:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229752AbiLOIwq (ORCPT ); Thu, 15 Dec 2022 03:52:46 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59E33E090 for ; Thu, 15 Dec 2022 00:52:36 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id h11so2257434wrw.13 for ; Thu, 15 Dec 2022 00:52: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=57JBlm0NImiEIoiDlgTbf26rGwUtOwPbjIvjNODgzkU=; b=Qvbvmvr7Doz5Mt3tGOxF7VWBFDcLuRwy6BeYsNZXB8SziFbYSwGxFXTetKd58mzqGv TIQPQ+6Ffyhw08NxrRSXbqUZpPGQrY9Xd4JHc/fLjJT+6Col2CLWuLL3+XhG2Zhbvb6Z M4724V9qGkByv6IGkyJFuaB0YzPJRMoJqbPVw2ogp1dtuDlwXqJZTn0u2ppQVB0kuCz+ uP7yqP4jq5f4EaBUlZYqIFO4Fj85Wuh+lXTRRlPekLnpBFtk0uFLm2Tr5jikaUboLXnQ Z0TwtbSqsKZdP68+FJ/jIVpzkTDr4pm+y04huKdNMemGQwDWoqQdyUi55w63qVzdpeMr GY0w== 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=57JBlm0NImiEIoiDlgTbf26rGwUtOwPbjIvjNODgzkU=; b=vfMSV0UScjad957EIyzEazKAz41j4Rn34a72ZEVv57XTaLEpFn79+XTcAaAF55IT3O nRgvkQILMkQkZfdzV304F8JU094t9uq2N48913f9lPTDF5MHkxKVKms15jWvYdfNybTo Kmkafiojod/YVQ/CLcz1l8npC1dowDMzuSGn9JYoRL9io2mZ4IOZDhWvFxD1C3dlswCK QA388FS525KTeGNcTHRWnJkNr/ETh5iTpxMWlEso10/pyZaEmehS1LHrZuUvCosOq80P QQmYPtOBDgS+NzbDh9JN+89DO445JpQCv4rVEO5+YqhvMdhlsOF26zvSp138Jn815Q0e nTZg== X-Gm-Message-State: ANoB5pm16aaOCqx/tLSoCwjkDerppu8agUVgJPX/N/Nxkx1cW2aC4u1e 4K2+dLr7yZBM1nZ0TOKHzwk7Mjn8VCLotA== X-Google-Smtp-Source: AA0mqf4DwVC5KqgCAS0WPtwz0H/iOM20kW5yEpGlDvnOCZJ78ZESogr24zRNguJAU9GNjkVmFxgITQ== X-Received: by 2002:adf:fa09:0:b0:242:4f41:4dae with SMTP id m9-20020adffa09000000b002424f414daemr20205212wrr.71.1671094354481; Thu, 15 Dec 2022 00:52:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52: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 v10 10/12] merge-index: libify merge_one_path() and merge_all() Date: Thu, 15 Dec 2022 09:52:14 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 0f7d7ab1fd2..6f4ac2e541d 100644 --- a/Makefile +++ b/Makefile @@ -1064,6 +1064,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 Thu Dec 15 08:52:15 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: 13073985 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 DF713C00145 for ; Thu, 15 Dec 2022 08:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbiLOIxV (ORCPT ); Thu, 15 Dec 2022 03:53:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiLOIwq (ORCPT ); Thu, 15 Dec 2022 03:52:46 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48ADC3F05F for ; Thu, 15 Dec 2022 00:52:37 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id h7so2301420wrs.6 for ; Thu, 15 Dec 2022 00:52: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=uP/fYLlkODnxDWK0FpA3HsO0Jp43PxNCSvueyf+3ybQ=; b=plpp0FrVTRJ2lmEk9vNTu6uHRoYQdkeHTQ6UfW/o3KWyB/73kiHSQAIIrEPY7vzq4r AjNmJ8eI1RFodaJItWq8U422RsqEFF+YJgnYVLAAWzTQNMGeNNJMoEW+t0cxjLy2r6zY dEIj3lz4JAxUe+/F4usUNzzRG6q9YKA2aWxS5DTNdMAy85uJLo78Do04O+Qoemrx5/9C wyJSPJTwZiyeydDIH07G9KktgzRUoYHBQ9C4I3s4qimXWoY6CZ7nKwTS2uJF5oTvq7LV 3d+GxYfdWqN6qz7U/f52nrPc8yVNzMb8IpB8vBE+WhavAKw6WYk/Hj6Bp6flPvUooJwB 8HpQ== 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=uP/fYLlkODnxDWK0FpA3HsO0Jp43PxNCSvueyf+3ybQ=; b=MAQdgBAFEfS8D4KfU2mQO89Eleavpo8UKDIEKkYE2j9HzKDcZLLkHt31TNioiJzu9s uqxy945QbJFeoblporRvScwyquo/RmBvXCUHzwRbV19D8InFpg701ONIPyKJA+k7iBU8 ymOvnA9RdeFqyQoR/+YjaNQZ+hA5VzWfCiuuLS+R9xRIiVOGEkZeGvyMv+5m/gsEyITB eKNefMXELvxesruKjQ/CSZDGivb7UOGqM53/WFrEcyla6rR8S77qJY8G6GLU3wz7WGDb 6HxwsywBRI4+sJfYBjULONHwd68PrpvfsQlL3lniey87SiIJfezYiBe2MCoJZZiQ6Ilu RnJA== X-Gm-Message-State: ANoB5pl9H19/66FYxj2X7NYjJCWyPLpc+rb8BVz8to75whuN9Y3mpeBR 27ODp/l55wHq2q06lygF/V7vlO7cHl6LhQ== X-Google-Smtp-Source: AA0mqf4y9nEXF5DaHdnGmojTM8S+0T53yhiPzG7aOuQvbgzxZBYcCdtHRY2Aaihoti2Td8gQZRqn4g== X-Received: by 2002:a5d:50c4:0:b0:242:1dce:3fd7 with SMTP id f4-20020a5d50c4000000b002421dce3fd7mr21414107wrt.34.1671094355451; Thu, 15 Dec 2022 00:52:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52:34 -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 v10 11/12] merge-index: use "struct strvec" and helper to prepare args Date: Thu, 15 Dec 2022 09:52:15 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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 Thu Dec 15 08:52:16 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: 13073986 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 A31DBC4167B for ; Thu, 15 Dec 2022 08:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbiLOIxX (ORCPT ); Thu, 15 Dec 2022 03:53:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbiLOIw5 (ORCPT ); Thu, 15 Dec 2022 03:52:57 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A458A40448 for ; Thu, 15 Dec 2022 00:52:38 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id m14so2286930wrh.7 for ; Thu, 15 Dec 2022 00:52: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=bsH0VOQ3xWDuA3bBjbiD1H28OOmyN+4twPZjDwMPgKE=; b=do7RQQqoVjib7z1JuCgyqWKzPvNAeBVBPnptT+diNMGFXAqH7SqaenL71PAhKgRxHZ Sq5iYwLLpq3pNwfGxUgHzs2AUzMuUOA+JxmgLdyZxv7fiHLMRXji1jTiA5wglaijQuza EPgXAeopl6otDC32YlcmBZD79CIyMKMr5EFH2ydUgB1O9cMLStaJXiRoNoQuxy+sR0UR psKUITDMFfHn68ZVZt4xUPrpaa90TuHFAf0Lm3rDXc77KQx8uB9sHLKBQYyPoJO4r4XD TQzbYyrGjYxkKD3tPIuPpMHCKG8hmJucemLDNiwPbeD+/e3SMFXXQpUed2bTv35ebevE SdGA== 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=bsH0VOQ3xWDuA3bBjbiD1H28OOmyN+4twPZjDwMPgKE=; b=CtxJJIyhVaDKjztnxw9Zp0avRkEtSXH+iGCcAd0rHdS2Iundl/PW0efE20zAgzLKPM FudQ1dw35U5MmK2B4+sm4FTK/8SBJce0Gf+j+R4vNBwnmEvFmgj4cQzzogfGNp0qInVM JppnwiN9ireWPS9nmxcrn37X7pBj+2c+o9z3Ad7cqjbD1PiyWUB9UaF+HdueQJ5PKVAZ MBEv7/GQXriZX7Dm2SIsJ9mhTgjMC9BNNJUuo/p1BS5svIclUXDU+X8X0VezQ2VDtEIs mgtL5LHS5yDG2GQjZFCWCKYJec52vvu19rrF4EOxRgtPl8UbRfVSckMkpGovMFrnUuZE 5g/g== X-Gm-Message-State: ANoB5pkvpKShlFB/WrFB+2EzrCqQjPfk4c9jWjTM7MzP0yIv/geAUB7w xYgqZe+H8IWsTbRRhmWhOrJ0bnZR/jZZtg== X-Google-Smtp-Source: AA0mqf6EL0asOxSdqPbkoAA3SjCsldeB8Cyi0OGEe9oHrEwyW3k/QeBUH7qlEXYdUrR9hTSQOQNcSw== X-Received: by 2002:adf:f0c3:0:b0:242:12cd:d73b with SMTP id x3-20020adff0c3000000b0024212cdd73bmr17557402wro.33.1671094356404; Thu, 15 Dec 2022 00:52:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id r10-20020a0560001b8a00b0024274a5db0asm5464905wru.2.2022.12.15.00.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 00:52: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 v10 12/12] merge-index: make the argument parsing sensible & simpler Date: Thu, 15 Dec 2022 09:52:16 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: 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