From patchwork Sat Oct 1 10:25:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12996485 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 790B1C433FE for ; Sat, 1 Oct 2022 10:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbiJAKZu (ORCPT ); Sat, 1 Oct 2022 06:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbiJAKZs (ORCPT ); Sat, 1 Oct 2022 06:25:48 -0400 Received: from mout.web.de (mout.web.de [217.72.192.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D27DEF47A1 for ; Sat, 1 Oct 2022 03:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1664619937; bh=tb2RAZHi73azrjn4IqOy4ypgWKvjh4SJ/cS9zczqrAg=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=qlfu41u6V+qIXy4G0j51/VaXvr9k5yz91ZhPTMgNX0XKXe4XXg7APlXJ//EMvScMN F2LgZCOmg0kbcT8aSr+tLuh+Fikv1drTVV8ZhpuD7vdnbsf7arnyQsIU4U2TJ4xaqC D9sZseQcSuD1ckoFyshug017GKU1aD8WEZOPwQQsKid06TLKcSjuw8SzFEQfL45ld4 S0VDE23CsAh7WEXqZT4B6lDJgashDfYL8um0xsb3CLqRB1xob8/nfK6fTSzcWhBi4o +U0GqDp9kfsmw47F+T+V5NvpzuYyLYIiqPTuQFzj08y3d4mwbRYsy1ACx4XHoasvGd GHKSZJFOR48gg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.26.45]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M604f-1oYnCU1sU7-007AgY; Sat, 01 Oct 2022 12:25:37 +0200 Message-ID: <4fc4cf3b-a658-3959-4541-b889534fbbb0@web.de> Date: Sat, 1 Oct 2022 12:25:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: [PATCH v3 1/3] revision: use strtol_i() for exclude_parent Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Tim Jaacks , Chris Torek References: <16c49d20-cafc-4b48-3c6b-e11c74c29abb@web.de> In-Reply-To: <16c49d20-cafc-4b48-3c6b-e11c74c29abb@web.de> X-Provags-ID: V03:K1:ywPq80ZeYmw8EHjqyAcAvJTuhuX74xVKttHf3pd8C5wHN0MYrw1 Jo80QkxMbZXXxVrYnha88sOA54AtfVf+EG0m+AsfmvGLRMFNjE1/p3e/jXoBOF+0fq4Mr03 Z9LXyq/S3IaZbIyqE2E/qw2NHhhgPDhPaYy8WlV5HMgFam6Ek/TTObex+YQ1HuPI0I27Yt1 YSwKFzeVXtd2DCz4AoRcA== X-UI-Out-Filterresults: notjunk:1;V03:K0:5pXxHnq9gRo=:KG4MeQobq31n05qjPggS2q 7tRYBbCUqsGh+d/N6qAoibKtwq/g0u9ngDlf4bh7Ll8PE2y1cBjTnGt8OjxprSKqfWARBKHtq m1WyLtrF6BebTzLbV1RT9OXa4OOCN0tjc+mMNUcuoBo4DKrJtei7sOSJz4d516Q4J2LfOTfas JMvXa9EqQDnm2pjWi5rcVv4XgQampBk2dAy4tbbeaMB89Q2mIAz3ob/Sc2JqcyL7rdjQM/88U lVy+ex7wehe3P2CQZzWjQETLguKYn053s/vbca9R45ORecu2IovJSoMc4fmJc24SOPejR1sQN lR+vPbGZoySfmp03XaHM/NWcMFwXKbF5oR2ifcGsBThcFxLS4jjaODlXRxgOYb8CT08UlIWkn W5KEEzBoj43si64f23retBwQ66xgXEF8gDk6Epyc/mP+ChBccGOhsBIiZNqhvi4O5gWnK1oaM YRCUmvUmc8iK12SwbUZw9gBkRfEC5+oEhhkZ7wKiO38KuIuRbcIsiiffV6K+xJrcWqHKwNkIw lpKgIkqH9Bsu7GeSRAQiHd6Bv7nJzk3l9AbecLerbFJn7E9HPW536/AFbgAnYhwpa/Lq7F96x GMOkW95faA7MScehTGfHKifDsFIotrMbChcEmifk5/PJQ1UOChaoW9wDCiZk7O/5GIB2HFVsW +CcsBUOXg7CmqOjji0KCKTl9164+O/N5zCv/SDiKgj4sZonkuxzd6LFsOyJg0QWxNAoOsJqIP eKcI5qE7tOAZsibX6jlzRcmFiKFHWTCg5E5sPd0jRipCzDJMLxg/IBI7I8/KMYLk5d9PowdI8 Ssb/9+q/A491uj60g8qvwtD6u4JxPMgGobGefmxlmgJge0zGBUiCYq/Dse61NiC6FLDP1+mi/ +QSr3U5cQNW/Ta/MxARhKcUE25QqEFl0dA9kFKcLKZf5PygteBgFBGl6dw8pvEtYYJK+qYArP V+9w6ghS+LKx1uzc1TbxmHT7WlHohla7vLqpaHh+FXS429IHGB1zSFgwNBYc11MuuVlkxljtc EUHIojoQ2nK56pi8FskSypuVML0+HO/cehyjJPUNF8exWgpjYufl8UDr7S8V0Gojb5CfN9n2g F7tgKzOW36z/X0w7CI/ztm4M7eZhgAZg0yDgcyrrD9ocUTLOTWawGeuKs5pKGDuzQxEeH5XW2 se/TU= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Avoid silent overflow of the int exclude_parent by using the appropriate function, strtol_i(), to parse its value. Signed-off-by: René Scharfe --- revision.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.37.3 diff --git a/revision.c b/revision.c index 36e31942ce..79b88604c7 100644 --- a/revision.c +++ b/revision.c @@ -2120,9 +2120,8 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl int exclude_parent = 1; if (mark[2]) { - char *end; - exclude_parent = strtoul(mark + 2, &end, 10); - if (*end != '\0' || !exclude_parent) + if (strtol_i(mark + 2, 10, &exclude_parent) || + exclude_parent < 1) return -1; } From patchwork Sat Oct 1 10:26:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12996486 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 21921C433F5 for ; Sat, 1 Oct 2022 10:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbiJAK0o (ORCPT ); Sat, 1 Oct 2022 06:26:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiJAK0m (ORCPT ); Sat, 1 Oct 2022 06:26:42 -0400 Received: from mout.web.de (mout.web.de [217.72.192.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E4C746D97 for ; Sat, 1 Oct 2022 03:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1664619995; bh=0UeMPlsRMgZXFHKg8fiRoMQIxyEZy8T0IwsqKK7oS8E=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=Jx4QNDdTwbnWnQnVm+/t2RGnvR/GlrghZNPVHowVX/cKx6nK10mMOmQbhE7W3bIpX lkfu25hx6Yn7UZSj+zpoHvM5kDgtgWbkzyFAPf/UMAmikjsNA7D3dyi8ZvGUiETquY x8Fd6SvQSEes4Ph7eVrN4y6S8PLKPhg3UGBzYMj2xCR8tbLXuq3Gv9K0k4/odbU2il Ol6I1dfz5cIsdaqEjJhun3IqgJC5q7Xw0aPVmkotGve9lujmZe4IDW0nteP8LbvSaG dBJwaZs4h7nLHP+Wr0Imloq9QE3ZWPRn8lylgW0TU0AejS3PdZeY/g8Ww9m0vPDYUY ugkRt/A6gE6RA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.26.45]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Melax-1pFHMl4BpV-00aRYa; Sat, 01 Oct 2022 12:26:35 +0200 Message-ID: <970fd3b1-8792-cc59-c3ee-00656a0615d0@web.de> Date: Sat, 1 Oct 2022 12:26:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: [PATCH v3 2/3] revisions.txt: unspecify order of resolved parts of ^! Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Tim Jaacks , Chris Torek References: <16c49d20-cafc-4b48-3c6b-e11c74c29abb@web.de> In-Reply-To: <16c49d20-cafc-4b48-3c6b-e11c74c29abb@web.de> X-Provags-ID: V03:K1:bE7e+9Uonk2IEyJLJeQKMOI+PElpIE7gYPYKgIiXuUGGRCtZhIK Qu5LiOvK2SplWpUBNd/w+5KhkVnCbb6Gu9PWoCHHc/nFLpiVeZtJrRDyUE8as7lJJiUblGc i64al/hHfpDYYSZOuf0EGLkyXhHO64tVcA6zuXiHxJZqVpJmkGGN+MfUSDT8n9IUE49itQV B78x9XFasbAbyabbGBLFw== X-UI-Out-Filterresults: notjunk:1;V03:K0:ReolqDOKvcw=:meTP8UqfFAMdWAsnhl9YiV 49kiQv5z8eQMhOu37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VUTKEJoK/XysFInrAF6/kuA/uTt5fqxr40n/jnin4WHvPK3/SBe/8pCmEwhs0227E9Tjo p776c= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org gitrevisions(7) says that ^! resolves to and then all the parents of . revision.c::handle_revision_arg_1() actually adds all parents first, then . Change the documentation to leave the order unspecified, to avoid misleading readers. Signed-off-by: René Scharfe --- Documentation/revisions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.37.3 diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index e3e350126d..0d2e55d781 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -363,7 +363,7 @@ Revision Range Summary '{caret}!', e.g. 'HEAD{caret}!':: A suffix '{caret}' followed by an exclamation mark is the same - as giving commit '' and then all its parents prefixed with + as giving commit '' and all its parents prefixed with '{caret}' to exclude them (and their ancestors). '{caret}-', e.g. 'HEAD{caret}-, HEAD{caret}-2':: From patchwork Sat Oct 1 10:28:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12996487 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 585DEC433F5 for ; Sat, 1 Oct 2022 10:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbiJAK2T (ORCPT ); Sat, 1 Oct 2022 06:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiJAK2R (ORCPT ); Sat, 1 Oct 2022 06:28:17 -0400 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BAC910053 for ; Sat, 1 Oct 2022 03:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1664620088; bh=PU8jp4oq4J41oqJopvFVNO/wN0Ol66QaGM5gaLHkggs=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=fMAVu1dbEhEyXrvToWMocW2HxxE1cqvYI8prS7FmC59ko22jK/mAjSPQOqoxRu+yC QWkPMQEYrwgsK5juJXubCycdjZ9eAJfoX2MD2LwsbDD8M4e+QKx2BioRPv4jvs4QMQ vQg1VitA/B6OpJ/bE8srbuLKU947OC6w2Mca0KSBmLqY3VNGRaRxiEcM60CwpuwBtv gS6iKBeiBIcxRj300DfefXeu4g6ikEY92oBa7mTUshflsR0KLefdoofQ3BWmAIKNop SgwyGoJDGQ1e9lvTnos/1hioREndIM1qKFdr97HfIxW24LKeEeSdwAhvTPaSU7ToEL SA1TbiLz4fdXg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.26.45]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MHmm4-1oT2KM1SFi-00FHWn; Sat, 01 Oct 2022 12:28:08 +0200 Message-ID: <0cf042fa-aa6f-4e3e-5982-3354c1cab677@web.de> Date: Sat, 1 Oct 2022 12:28:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: [PATCH v3 3/3] diff: support ^! for merges Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Tim Jaacks , Chris Torek References: <16c49d20-cafc-4b48-3c6b-e11c74c29abb@web.de> In-Reply-To: <16c49d20-cafc-4b48-3c6b-e11c74c29abb@web.de> X-Provags-ID: V03:K1:fJ5CKMSen/1bgrD/A74q/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CrImpMWmo9CzOdJfk3wq5Cfy5O+ZX7MRx5Ar88FYYrMMVkFPYpzpVr/epuzi4cONyHlM1Px lFLNEEZ09pEUPCpVyzjsKguu1NvFWgVWtG0EmBXEOnyynCffsyI9OqxXWRS5H7YhDaO0tqSaX YZNBwYJU0/zcYe21K4KvF1NvzANMuCgB4vU9apVntU+gPXjaViqET44+U3cOmez2/ZbXSsRrG teTceVTFCjCfxEytHw0moWYS8DMEEijQAXik4KKBMx4CLw1ofTTeovqADJTyEwupQy6QQD9O0 hkqigmKKc/cLRrccxwwirmTZlGRuC6rZmn9JvdpJwc7osP+FWw1L8yY0XtVA8FSda5lnd52Ep /WnRE= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org revision.c::handle_revision_arg_1() resolves ^! by first adding the negated parents and then itself. builtin_diff_combined() expects the first tree to be the merge and the remaining ones to be the parents, though. This mismatch results in bogus diff output. Remember the first tree that doesn't belong to a parent and use it instead of blindly picking the first one. This makes "git diff ^!" consistent with "git show ^!". Reported-by: Tim Jaacks Suggested-by: Junio C Hamano Signed-off-by: René Scharfe --- Documentation/git-diff.txt | 8 ++++---- builtin/diff.c | 23 ++++++++++++++++++----- t/t4038-diff-combined.sh | 10 ++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) -- 2.37.3 diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 85ae6d6d08..52b679256c 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -79,10 +79,10 @@ If --merge-base is given, use the merge base of the two commits for the This form is to view the results of a merge commit. The first listed must be the merge itself; the remaining two or - more commits should be its parents. A convenient way to produce - the desired set of revisions is to use the `^@` suffix. - For instance, if `master` names a merge commit, `git diff master - master^@` gives the same combined diff as `git show master`. + more commits should be its parents. Convenient ways to produce + the desired set of revisions are to use the suffixes `^@` and + `^!`. If A is a merge commit, then `git diff A A^@`, + `git diff A^!` and `git show A` all give the same combined diff. 'git diff' [] .. [--] [...]:: diff --git a/builtin/diff.c b/builtin/diff.c index 54bb3de964..0e49919735 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -209,7 +209,7 @@ static int builtin_diff_tree(struct rev_info *revs, static int builtin_diff_combined(struct rev_info *revs, int argc, const char **argv, struct object_array_entry *ent, - int ents) + int ents, int first_non_parent) { struct oid_array parents = OID_ARRAY_INIT; int i; @@ -217,11 +217,18 @@ static int builtin_diff_combined(struct rev_info *revs, if (argc > 1) usage(builtin_diff_usage); + if (first_non_parent < 0) + die(_("no merge given, only parents.")); + if (first_non_parent >= ents) + BUG("first_non_parent out of range: %d", first_non_parent); + diff_merges_set_dense_combined_if_unset(revs); - for (i = 1; i < ents; i++) - oid_array_append(&parents, &ent[i].item->oid); - diff_tree_combined(&ent[0].item->oid, &parents, revs); + for (i = 0; i < ents; i++) { + if (i != first_non_parent) + oid_array_append(&parents, &ent[i].item->oid); + } + diff_tree_combined(&ent[first_non_parent].item->oid, &parents, revs); oid_array_clear(&parents); return 0; } @@ -385,6 +392,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) int i; struct rev_info rev; struct object_array ent = OBJECT_ARRAY_INIT; + int first_non_parent = -1; int blobs = 0, paths = 0; struct object_array_entry *blob[2]; int nongit = 0, no_index = 0; @@ -543,6 +551,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix) continue; obj->flags |= flags; add_object_array(obj, name, &ent); + if (first_non_parent < 0 && + (i >= rev.cmdline.nr || /* HEAD by hand. */ + rev.cmdline.rev[i].whence != REV_CMD_PARENTS_ONLY)) + first_non_parent = ent.nr - 1; } else if (obj->type == OBJ_BLOB) { if (2 <= blobs) die(_("more than two blobs given: '%s'"), name); @@ -590,7 +602,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) &ent.objects[0], &ent.objects[1]); } else result = builtin_diff_combined(&rev, argc, argv, - ent.objects, ent.nr); + ent.objects, ent.nr, + first_non_parent); result = diff_result_code(&rev.diffopt, result); if (1 < rev.diffopt.skip_stat_unmatch) refresh_index_quietly(); diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index 9a292bac70..2ce26e585c 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -80,11 +80,21 @@ test_expect_success 'check combined output (1)' ' verify_helper sidewithone ' +test_expect_success 'check combined output (1) with git diff ^!' ' + git diff sidewithone^! -- >sidewithone && + verify_helper sidewithone +' + test_expect_success 'check combined output (2)' ' git show sidesansone -- >sidesansone && verify_helper sidesansone ' +test_expect_success 'check combined output (2) with git diff ^!' ' + git diff sidesansone^! -- >sidesansone && + verify_helper sidesansone +' + test_expect_success 'diagnose truncated file' ' >file && git add file &&