From patchwork Thu Sep 15 14:51:02 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: 12977498 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 8317AECAAA1 for ; Thu, 15 Sep 2022 14:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229863AbiIOOvN (ORCPT ); Thu, 15 Sep 2022 10:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiIOOvM (ORCPT ); Thu, 15 Sep 2022 10:51:12 -0400 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AEEE25C74 for ; Thu, 15 Sep 2022 07:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1663253464; bh=THSt71gF9k8GukMeFVIzcIDAd+4/1i183ZnL3obbjUk=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=asL3CudwVRkL40+y4RZ0pYnfsjdHMveKQpalULjlSUuktXT7FLw7MBHckletmkb0w GqAXVo7deVAicbLNxzZwkUy6gtaPDwhpnNAQPk5pb9uSHzU3geBfJGyBy8eoP/9EcC r3+32te/GhQ3wb8Jx/h8IvSsUvrZ4hpprA6cv5y7lc5EKU8YVanVxgUgbyw1rLQRXV /k3m2wAaCK8zOls7N3XpNZtbiLPcGzKuhLa0NlmqFemZjyFt0tSwYeZPxjodWOuoFu sGyuD3qHOsnE3RZ+OqMeoAZN1woxxeFLMQiPTCImGqVwBof8NOCZ5AsrGrt72IWEno LDwdYd/BTnR2g== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.24.217]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MdwJY-1p8jBZ48Qw-00b9uZ; Thu, 15 Sep 2022 16:51:04 +0200 Message-ID: <9baebb3d-8f2a-33eb-3f42-3e1755883d19@web.de> Date: Thu, 15 Sep 2022 16:51:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PATCH 1/6] 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: In-Reply-To: X-Provags-ID: V03:K1:a7uefNiDKs0HnsoIKTIcD32vJwjZ4jtoFdJCrHI9XyiEmXvEAMb BOOS47S75agMKNpcU2T3nBrKibwTqj1lRUdDDeqE2vScY6lyz+gQhs+X2EqRFsxm49Azu3i y7zF1NFulZixMRVglW5k78PZ8HNfLJHg0s2SUp4jb1b7Zxq3WHrUiw1weFuHNAHCwmKCFcI wpDjr/bZb99KJ+XFJ+ABw== X-UI-Out-Filterresults: notjunk:1;V03:K0:1nRgKuiYRlE=:CGLOlF63eCFbMo3pMEztnq W6e820Rmz5vfmeOX/0YRC5cIDoJ0L8ZbopGqkhH5LBQWdDaXI42IYj2vHZpwk8LP1Q/WLs4WB w/LVb1W3bTJ4ZPeCJiyr+wn8gJV+1wCQomwAWcoXsOfeM9yKGIcdC2vv0iYNo2itvCBe31l3H p25CnxQMLOfWxj5fmzt/QpvCOywVqnAx8+wMPdNM3wGYLFMQB0/q+6QJQQMWDkSpQML+5oVOa /FHPYOtstEY6jFNJ8X9acjf0wJ7C+NvTxrHo53KdK2z1jzLCOxZGyFk77lyNpSy4jebaImJ3W lucgdDZhfrzpRNrem4clLObtofel/YKnBoKmqGB+7fWzj7UD/MCNzpXmgrFd65YsQCmPgDXAD kFZIF0ZtJxfWJZaF3F1o8R2HbA0E+01QnglUj2+NGEaIpiVIdu7To3uy/CdwQjxP8PDigslR2 mEP+CfqYvz6HLuM2SSxIFsvGjDxftdvZO0lmpSsARt+QZIGKhDgkm9EsugIb9Mx7+xHSOTwG4 a6wpCRxO3L+oXGJgPlVTaLgJYX87mIo9Zdtiy7rtPOehJq7Z4btWNsA3uMYWBoNh2QOR/+aaE fMjak8GiWKMWl7YrpKORWrlsLhZ+EZGhiWx6U5PZ1yA/q/R5Xau1Z64GgiOk69mUFEfSvAhcx 8Vs1/Y1pxUKZyDn3M7HDzE3XaEFe7x5nQ3D5keM/FFMW5GAdm1JiT9iTL/B/xixJ6zdqPWAgl mIKzOJYi5t2waNMY/PoNaitVrNK4w+bDTrpYcWMHqmBTjJBZC7oUJOBpsKB+Vdbbcwv3I0Bbu BqFtDNutggHZhedDP9iVVzlNiB0/Y51q70/45XHC8VMP+KCVFAZtW5bqBaAU+tM/0fNGVFaba YYbC+x3ZI6v+PwIzNzFnmyg45zwhqoRCKM52L2KaAkzP0BjRQY/XTS3llUkYOTysDTd97+iDm NgX80HImuvenc77q0TOuKfNZf4alOEUuD32MGKg2v2o9S1yOXRO32vPcunRxUr02lVt1JOokA AoWgVlri7zkpZlSZh4IUIXH4cztOUFx3PIH9E+97/ymWnT2E1DGtSx6b5lqymbEGn7TRznjlo vhoA21Qkj/MADbWWZ4ndBHn/G6/WoviS/WflfZ/ouQLxyKymLrvqi5BQsa24US3Cm+8I3ddq/ P90us= 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 d5f4463cb6..0b8d48f94c 100644 --- a/revision.c +++ b/revision.c @@ -2119,9 +2119,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 Thu Sep 15 14:52:04 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: 12977513 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 029D0ECAAA1 for ; Thu, 15 Sep 2022 14:52:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbiIOOwY (ORCPT ); Thu, 15 Sep 2022 10:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbiIOOwV (ORCPT ); Thu, 15 Sep 2022 10:52:21 -0400 Received: from mout.web.de (mout.web.de [217.72.192.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A432B43315 for ; Thu, 15 Sep 2022 07:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1663253525; bh=fuYAzHKGgZWX3jNE/5nRrvdhz0MnDeg/o/aZY3REUvg=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=OgZ0abzAVpZG8/AHQLsgFk/tSPp7ebAV1pjiM2Pr476CjKh6eBqoBNuWNB4DsmuwG rTzhhpod3vPGNSm+nZrS0eXZ3B8u4K5Tkf4DTK6LFb8vGZrgRAOLa8yLDH68OE9Gg5 P+CUt2lD5SBdHHn0W+H1DbNnXQ1738vVzGPCjHdlG8agFIU9ViEFBNPe+k3LUrbZa8 pLwqCOv7Zt8IfB90GBRx4cxYFR14mjcFPABzs5tmP9I3ORSMhFVGChZb+88rPC6cAn 6G2wB+3EFi0hvr91cHHYcnnTyWZ8C1GAhyQPa874H5iEX7wYwgBXuVIh43DhS/bD2D 6lyJxAaS52b8A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.24.217]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N7gXQ-1pKqVb2axe-014ujF; Thu, 15 Sep 2022 16:52:05 +0200 Message-ID: <90bdf408-9bad-6816-06c1-66ac64ea9c3b@web.de> Date: Thu, 15 Sep 2022 16:52:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PATCH 2/6] revision: factor out get_commit() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Tim Jaacks , Chris Torek References: In-Reply-To: X-Provags-ID: V03:K1:KfiZ4C5nhLaXTWPCwAcgQd66k+/dg1+ej8atjg4RpkRuUqQ9Imi VzPbJHgPRDDwRBA27CqJ3CVQ6+2qAya8GT8KeQ5PoPPCEkFIL2gucI1zHIeeQOUccBibr5s rk7v6WEqp67pS4ESNMsN5Xqxvl2DYmkf7iDWn3D7kSWjHoW6d24YLrt16lT30p409wkbYHf jMyaqfKDmgiu+hORerfhQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:nsu1/cBYMFA=:H7PFi3zZdwRzM5vgH2l3jc 8Ke7HwQSEkcBc3qrp0WiYMLDKp4wkcCZoheryUmWDeyrWpzRmJDEKrIs6lhMu7FGExhFGQVAt UaXgXDUGre/n13XrcwXyp5gcoLnQEmnSPzcVUrIRtK+67oH1ArRfMtWOBz+445SmMGWLbQIYt yrdC2FC95x37tv12l+yWGyDpsHuMkOyFOyq93EVdbLMwiqLRDu6vmnNCtXAywhufETOThK0K/ 2iKsinjJfkytqNlRyw/RDvCm4lqCisjZpDVXYzVvAz1Ng7pzpJibyOrcZh3qv9UdOvIlHkSsk phteQdkfG8VvuVpvDpdZM1Bxf58KZtTxsKqMlBDi6h6fyu2PgaT3xdFLlX7/LMC7rP0EbRrjp 3LLsNfT5IAtSK5ecj9UzRcXxRjbRynb+Ms1klsAzeAxhqDhiTJ+W8T28vcyZt6nh86ijyv1tP zacC0sHGX5qd9p0uBNmcrA5GPUMLp9CoGxC7+MTF0lZjrxWQzdxID1jbEPite8RXyz+P/r1EC +tQoQpJVgdyi7G4sBB6OOv/RPgSGcdOVE8atMrozdE/A17DtyMFL7xhnN1VMGKjQfeazig160 PjkyrZVkfckZh04Gj0pAoG9nkQi3zEt2SQTGQ0MkcBAg0K9rATJnmO0gd8h3oLlV9i+K/m2UJ PA+5dRDRXTcJ3xfHBHFxMk3GGTLa7Tbmmjw9MLPt+tRCvOgkB0rcAE4aDMbiQm0XyStxMofRS 4GvZ0XwmTLx3IC5PZ+c5UqiUO6l/EerV8qumI6+/Lfp5+lpeOcnFCL5DFl+Arse6mT3vQgQgj Lq5mH9tATTCm5ZItwAgqhB5ycgu/4/KSCvmVWOhycO815Tbd9fvYhalyoBF4toyXM3QmJ3Q2u 2DrEkBiDXJ/suTzJgLkVFXA+tUxcUkJNsnZedpy/LGCV0l/nZgsI9PENFQld2FAdpCleo1P8Y Z4+AYru0MPao15kFao60Cx0xKOvZDtvd9bzJYPVEgZEqbQQUUE2MNxSqvdtyh5p4Rq26u0mQy Hv86+n9G08tNi4iF/MTBCE2CjughybK7U05wZBO+qqob9cI6PYtVczP1EhonAzTe9fSsRHClW vOyyNmfwDRAVlusTJnGFlXlkwy98NoHaYfAMMkJ6SgRwWcGoqiATYrjsjj0tKUWf5/TaWg99G p5DUY= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split out the first half of add_parents_only() to obtain a function that finds and returns the commit object. It allows checking the validity of the child separately from adding its parents. Signed-off-by: René Scharfe --- revision.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) -- 2.37.3 diff --git a/revision.c b/revision.c index 0b8d48f94c..4f896b4992 100644 --- a/revision.c +++ b/revision.c @@ -1822,35 +1822,46 @@ static void add_alternate_refs_to_pending(struct rev_info *revs, for_each_alternate_ref(add_one_alternate_ref, &data); } -static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, - int exclude_parent) +static struct commit *get_commit(struct rev_info *revs, const char *arg_) { struct object_id oid; struct object *it; - struct commit *commit; - struct commit_list *parents; - int parent_number; const char *arg = arg_; - if (*arg == '^') { - flags ^= UNINTERESTING | BOTTOM; + if (*arg == '^') arg++; - } if (get_oid_committish(arg, &oid)) - return 0; + return NULL; while (1) { it = get_reference(revs, arg, &oid, 0); if (!it && revs->ignore_missing) - return 0; + return NULL; if (it->type != OBJ_TAG) break; if (!((struct tag*)it)->tagged) - return 0; + return NULL; oidcpy(&oid, &((struct tag*)it)->tagged->oid); } if (it->type != OBJ_COMMIT) + return NULL; + return (struct commit *)it; +} + +static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, + int exclude_parent) +{ + struct object *it; + struct commit *commit = get_commit(revs, arg_); + struct commit_list *parents; + int parent_number; + const char *arg = arg_; + + if (*arg == '^') { + flags ^= UNINTERESTING | BOTTOM; + arg++; + } + if (!commit) return 0; - commit = (struct commit *)it; if (exclude_parent && exclude_parent > commit_list_count(commit->parents)) return 0; From patchwork Thu Sep 15 14:52:54 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: 12977514 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 266A7C6FA8A for ; Thu, 15 Sep 2022 14:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbiIOOxI (ORCPT ); Thu, 15 Sep 2022 10:53:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230337AbiIOOxG (ORCPT ); Thu, 15 Sep 2022 10:53:06 -0400 Received: from mout.web.de (mout.web.de [212.227.17.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44D944CA31 for ; Thu, 15 Sep 2022 07:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1663253575; bh=OZ099UUw5TKSjEWZe7//UIiZjqpa10VIZqb7ajfxhuM=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=i3D3XofCSueywkvExtEjK7dNyf1GwUv5TkZRypI+V9xw5cG0Vq/c/7ayhUxEAxdEc Z6VjuTJTefb8iZ94lpL3wf1/ixhmVEJMRWl4PgSXjhNOtLMHbMSJcZ3TOeo7wsCz6f aXSqidEUqJRh3ZdUwSCHJXnDO7KYvxx9R4ylkernNkbXyVQH/noJ4arrWvnFl9lmMH PS+BFxvffp8kixSTPQBlwadTzSI1untrERboeB1RBjrgu1tI+37x7xHhFjLuL2DRzi r3n6xXwBw9UknCRXrVztSWZIdfGkGpfb0Dhj+e5SZbyiR08ds0XbBJHwCEdA7kircf 8s1rQdvFq5qXg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.24.217]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M59nK-1oZwA63nxE-001Nwk; Thu, 15 Sep 2022 16:52:54 +0200 Message-ID: Date: Thu, 15 Sep 2022 16:52:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PATCH 3/6] revision: factor out add_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: In-Reply-To: X-Provags-ID: V03:K1:0gut0sxnMD89imk3UndRzMMikDhN0KJYuO3k8mNgTGyLkiEgkA8 fLJmgFjB94ZQFwWka3UiiOG2U7cNek04d42KN5myUnwbiPxhAqTbrayzV8F1bKgpvvBGa+C 9Pg3OphT1c/6Bur5tMKEBN9s6itKUypAWvpI6+1K4AAZGWKX5hbK8kHrMyWQuhcx8k4L+pu hkn3cXMJRlanFutsNMlFA== X-UI-Out-Filterresults: notjunk:1;V03:K0:T5I6eNA75rY=:K8U/KtvE0YRG8YFxRrNznr o+vnGh0rim/q3/wXXbMzb30+4XWnfTKd2a+9yMGh/vMaN4V5Fqj9X+90S1IOYQPj4iToXNAAC HfFiC48M+Cc1/wuQxIB9CB28hf8J99kVVW6TEnJAtWJ3XZ3yg8xbJrsGkBgZtHfDlk/hhSjJf WFpLziSBHcg3uKtsg2vUV0Vq9j+pYpHWrFw9z2N8ABLGXqRi2QrnoxX2UVZ7Tv3x6ZZ4mO/SK /Bqr6WooTheLpvJoa1ezfJtfcLYsvSkmsEg047NYYWXmWqMw+hbIHOQI4goaF3UM7BM1Clayj DekvTJw4QgPqxdpEdVRMXzLIFFSzrNqeD5b9lmx04o6Iz2EnhbtNiV/lD8p0aK+sPocZdq/N0 tnfgiEX/i/Rm11sU6ygsppjS8RavHl/RsviQIiefG4oK0HfoOwff+AFtPBF+15CeCMIejF6pC orZgUU1CYOj1qQzxD13xArmISNs96kFYI86MSu5SA7ll85zSW8kJMewZI/mTU3tmcTWxzFpbM MoLXrSoc77ZhCeWUbJxW3LJBj46bkxMaUMRzL/zSorSErFZCJgBxBW9605hSEK6WeyFrlHhNT jlj3CrYWIiAppth//ltPoYk9V9hkhM4yx1xY36iWdAk9T0fg8B/XOZXOsKKOBxnnQRbTXA3TV /PJ0e40ZsDXqK4Z3o0u2gnluoEdj/gCqLCYcjZcYZ/I6uvKZWSsfjAhPlZAxJf1l1RiNwo/qN QtgrfJbRHlW45xBKF/8reLbW5NYdzo2+z45g7ij13iWYmGvQEXOl6qgrpIMClZdIZnZ9xuVcZ cDYGCEeWn7ASZpMPhXLD3oPiblNE/g1E5lyIwuWTBskvHGt3gbOexKWlidu/VXseF06Ge2CRb 1KKYrv/dcYXOGKrehPB5dS1EkijIORcy/O4ptT3mguzVDy35n4BsYFr379ZvAUNuZGmAu3edX YY4YNUYvyJBhjWVEkhU3/JMlqDN9BZtUwDlcG31aIzS7jq3J5V892stkk/QbIxiSdR1Okj6zI kWpDJjrkdPYZxmr1d8AV52Zem1XBBew37R8/9BLy/dTFuLIZMPRseEqPToeMTdqwZWFVbzr4f Qv23ZaD82wdyVQpaHyurEd5izR3TIE3IrHRVRIH/ncThJdDlIdzg7KrQaKbvbmG1Nc5nsTse0 gbfF0= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split out the addition of a single parent into a helper. We'll use it in the next commit. Signed-off-by: René Scharfe --- revision.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) -- 2.37.3 diff --git a/revision.c b/revision.c index 4f896b4992..14cb73e508 100644 --- a/revision.c +++ b/revision.c @@ -1847,19 +1847,27 @@ static struct commit *get_commit(struct rev_info *revs, const char *arg_) return (struct commit *)it; } -static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, - int exclude_parent) +static void add_parent(struct rev_info *revs, struct object *parent, + const char *arg_, int flags) { - struct object *it; - struct commit *commit = get_commit(revs, arg_); - struct commit_list *parents; - int parent_number; const char *arg = arg_; if (*arg == '^') { flags ^= UNINTERESTING | BOTTOM; arg++; } + parent->flags |= flags; + add_rev_cmdline(revs, parent, arg_, REV_CMD_PARENTS_ONLY, flags); + add_pending_object(revs, parent, arg); +} + +static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, + int exclude_parent) +{ + struct commit *commit = get_commit(revs, arg_); + struct commit_list *parents; + int parent_number; + if (!commit) return 0; if (exclude_parent && @@ -1871,10 +1879,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, if (exclude_parent && parent_number != exclude_parent) continue; - it = &parents->item->object; - it->flags |= flags; - add_rev_cmdline(revs, it, arg_, REV_CMD_PARENTS_ONLY, flags); - add_pending_object(revs, it, arg); + add_parent(revs, &parents->item->object, arg_, flags); } return 1; } From patchwork Thu Sep 15 14:53:40 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: 12977515 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 B3768C6FA89 for ; Thu, 15 Sep 2022 14:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbiIOOxs (ORCPT ); Thu, 15 Sep 2022 10:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbiIOOxr (ORCPT ); Thu, 15 Sep 2022 10:53:47 -0400 Received: from mout.web.de (mout.web.de [217.72.192.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BAFC6BD64 for ; Thu, 15 Sep 2022 07:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1663253620; bh=QwmtbTbnJdosXXGu42YRMYs4D0jluRtsUq//istLdIc=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=Dxh09unEoDtDrsH5WdV3qtxXEe+Tc8eetmmYf2kc44WRVu4G5TcDvhsiFnZ0nnsjY cEsUpok1K3yJyNyWZjbqh7wAFX7j3N6/El2bqSou2m6/J5d2pqqzYeaUnGtwtlQ7KP 7wApLlvkzhotac7O200qIv1QvQM3joyfyM+XgkzgmJFfRiVSabTXYDTjWAhqzSJkYR lDAW/+tYD2O9LjqEVI0iP3XX4FeRejZwC8v1SmsucqK5uhy2LlQJvurcCLuAjwNmAI HvAMUJ/4AJk5ZyT63i8WcL1Ku/LIicsGrKSFKVOvBdwN931MfUDtmGQd3iMwekJk1Y Ha86tjl0Faxag== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.24.217]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M9ZeA-1oeJt23Cvk-005o80; Thu, 15 Sep 2022 16:53:40 +0200 Message-ID: <23a6914b-47e5-d3a9-ca95-01035b691bca@web.de> Date: Thu, 15 Sep 2022 16:53:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PATCH 4/6] revision: factor out add_parents() Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Tim Jaacks , Chris Torek References: In-Reply-To: X-Provags-ID: V03:K1:wB4hPEkvC1fC3Lk2etN0EbZbTsAX8QAPuV48tcyoOX3keduoHjm kLoxPbSzsusTL2E54oHu/BivJ2l2BXHxV4weypQNGc0XDhh/Nc5XrWYO/XrwgbFFtmRPsPX qvARnTtlVnCb/ba7h4osSLPatNN6nF36Zzz3nUJwkZq87glJRp6cRvZFpe06dluFMtzs+pw OdH95Tob+eNffalDKR/OA== X-UI-Out-Filterresults: notjunk:1;V03:K0:ee4xdjItARU=:w+1gwuJkiilmSG+GWhosaQ BXLggvyp3vYA+SpcQRoDFFQM4pxA5SRnx0Dh0ply5ZflR7d0M1ahSwv4FyIu/p/rIzBuqbHxw X3W1TWhkdi0gJtK3GRuiArQvkfAQpySPGwS2nD6tDyQGDdizHvmNtJYEUlp37Uj16mjdZGeg6 GpjmfqYA1hJvh1UH9QUBi/X6FTgk7vUC1v+/zgZp7sBkESE+ZT5N+LSyaywMUUD2IWPcAO3qf UgmiTZpqE0hZ1at6cG3469Mq5eKHfdDdbwrXbgLzcqA2kb/F5Nr8B7306Tw7B1fQzxEkt5bQI Uk4GUshvQ+YxzP/jZcl2SEZRjw2M4mPChCrS3Fe21OAvlZhsShoVdFcZtdoANXvO+XeMW/+kL NU1iwssA0nRmHtHthSH2qicC2Xok1xlI7A5sErjw1a0Pnpjm54IdLDqCFM0rpABbamJ2X7x/q jGT435XhK31HRvr4jx1XtlVJEnQt4CZ0bftBv6Q+uIBj2GMdjMTBcuV92rbbIVrDSsmPQ+rSK B6zrFbrPDBEG5CV91Jnb0ROMeGXRIg1SFi0au7W0f/IlLTDA9L2fEmcdeWiTp99xehHgC1nOB LxbF3OpQMCXXpVIQne/Te0RCoCJVSvoHVF2Doa7HgLTXCYJ351DpMc/PGQ2rSX7UoaFHiAeDP yezC6EwRIX04n6+pshpRSnEtLnWzSxewWWT/jjTrk6SyxPAHjbFPqZIiBx4BsQ9DOrCzs3JU+ 0LGEY/Qw8itzOpmXfq89CLMtdk86kOU0IE2n1v8buJkLNUTfjycSWpxLkkmOrGSDrvofI/CYf zgOv6mCineK7WPkYA6KroKzkU7ZyCKCH2WlZgK7q/UB+j+4xaSpoy5cO8XDFV749cC7ud1UOP TpAeq8I79p1Te2ny6JibjwI3gpvQCtP0oCXW1gWLrxghazVd5uUJmT6dYRGM0MN7c2howeSMm dxebz86FCizabrECLy70WuKIR7m8XZZWf1S24MKjC+N4xugwojX9+CO5UI0AKvgei/PIIelKq MzfcFRzbwVqM9V0mli+A0aCkUlxWslNtRweQZeoM2owX4wBYHGKQqUQ0AQVr786EvV5OaRyhP b/KWQcB1kW2chpCHuqVvo3UszwEmhkx59mH9/2aiE/oAJyMn33YYIShRWTBSeICzVlwSzu1Tb TWCrQ= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a function that registers all parents. Use it in add_parents_only() to handle the case of exclude_parent being unset early. With that out of the way we can specialize the remaining loop can to register only the specified parent. And since we exit reporting success once we got it we no longer need to check the total number of parents beforehand. Signed-off-by: René Scharfe --- revision.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) -- 2.37.3 diff --git a/revision.c b/revision.c index 14cb73e508..284393a146 100644 --- a/revision.c +++ b/revision.c @@ -1861,6 +1861,13 @@ static void add_parent(struct rev_info *revs, struct object *parent, add_pending_object(revs, parent, arg); } +static void add_parents(struct rev_info *revs, struct commit_list *parents, + const char *arg, int flags) +{ + for (; parents; parents = parents->next) + add_parent(revs, &parents->item->object, arg, flags); +} + static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, int exclude_parent) { @@ -1870,18 +1877,19 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, if (!commit) return 0; - if (exclude_parent && - exclude_parent > commit_list_count(commit->parents)) - return 0; + if (!exclude_parent) { + add_parents(revs, commit->parents, arg_, flags); + return 1; + } for (parents = commit->parents, parent_number = 1; parents; parents = parents->next, parent_number++) { - if (exclude_parent && parent_number != exclude_parent) - continue; - - add_parent(revs, &parents->item->object, arg_, flags); + if (parent_number == exclude_parent) { + add_parent(revs, &parents->item->object, arg_, flags); + return 1; + } } - return 1; + return 0; } void repo_init_revisions(struct repository *r, From patchwork Thu Sep 15 14:54:32 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: 12977516 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 E294AECAAA1 for ; Thu, 15 Sep 2022 14:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbiIOOyn (ORCPT ); Thu, 15 Sep 2022 10:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbiIOOyk (ORCPT ); Thu, 15 Sep 2022 10:54:40 -0400 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3D8623BD4 for ; Thu, 15 Sep 2022 07:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1663253673; bh=0DmODq5CW63AawTZKOweHBZvRZATF7KtSszSW2ChbWM=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=HE63Tn6eBGPOTVIft4aBDJohWY8W5LyGwc26hAxYeOI4Bj9jHZB8t7J4oqHAxgKwY 0aL6EdQdsBfpdQeOsS5Zu2S8KvgAXx3PaN6gnN0Gny380okmidVmQj6tLjWkYJTQOS BnrHEbBvyBv0s4cLc7J/M+RmVuAQp6KI7piHO74WRfNQQUZGi9YltewwjGzVBkmLgg zCfi/sYGgW7Mr50xIAfvJFw6DOkiNBN8GqyZ6BrqECfy4gxJBmymNHFv9USLnpZd50 jGsb0xxuCm7GodF1xv6lUcL0PNEsVkQmIk8Pf94R3Ca6fu04gwr1I1ECxeu4LAV2Py xlIJsiQ7sQwrw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.24.217]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MSqTE-1okPmp27Yc-00Ujmy; Thu, 15 Sep 2022 16:54:33 +0200 Message-ID: <73e1e0e2-d6a4-3d1b-4303-f9e8984eaa79@web.de> Date: Thu, 15 Sep 2022 16:54:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PATCH 5/6] revision: rename add_parents_only() to add_nth_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: In-Reply-To: X-Provags-ID: V03:K1:34dA66nXNF9fyUYBRXSWbkrjNmh0FWwKuUMskIIZ6zI7+Vp/4PR NiiEGhLpsQXqxVSJejT59kEw0jOkAt9+ZR9tUpENKj672iL7/pKGeWgS7C3G3eijN+NjDXB QJNKsKHy4DkyQlOkyIRdb8JmYmxsl2uOvQ1bWZGcoe7NshCpMwcwf29atVHiZNBBE2F4rQT ibYmA4oVzgoK/J7/p7pkQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:Gikb3xIv0hg=:R/itht+HphEI9BrfAA7etI XrppnBxylafYDfkSFhEezk7vXub+DJJo2Vz/eGwN/HOzv5gTvYNvT6+coaFAKrVEB8xqBSe0V 0a+ouU593Ztm44rZbwUISIQCdxosYUfl1cJKoCxqWJCRQBGQXS0l2ZMbB5eyrCpegB6FBSP7F EACOlyzMQ3pt1XTM3kn+PwoSNNCRvUCHuagFJngDiN8PAKbeONpvTzTB+uurS6TMox8zPfwi4 E65Z14nbOT8ENJCCeNLsLhPWGfwBKhJxKh7X9/WM71sR+toxNK7aeKfBtXTp9P5nhXAGBbX6K MZ0+Ou0jKdrYN3lxjPXsaLBuUfNT8uk8MGGhH2FEmNmV1Sax2fgktWNUsHOd5lIL+g2lG1tjp n7Y1JJ1RhCO5WSUoYZBFDPBC3Wy6K8U1fqs23RGK7vS98ZWdK6ab2qYHVAJHDd/6YBS+Yix67 5i/oeq1Phs71w7vIbPJh4E24A5AkQkCsAiiVG+dRzYTrJV7YQcglTjR1oQXo/ktIVZRoyrDL6 mIcOKeZKhTcW0Yk3zlb1WG4LilxG2fedIhcNs0vpExQ1cYJEyep1fQTdCr3PKYwoHFgOi/B0N xA/CBONZsLaREvrvlpPkCBRjPS55/8U6IC8d/zFQV71Ev92ULC/R7iU7zfZXeFDDVx6FCRD/J 2wNeBRMIh+4daRmQIUR0aJS4P+QMEAD3RxSip4B2nAWgv+Oe53eM3YtVsG2OoRX07RZF3zOey rcY6wGh2AoOkDCC9Y7VRxVNJ0j9JlMR4YYsJp9IfMXAS5HTyiIJSW5AbT/SK/HOM25vrddYKf pkiu2/FAVhl4MpOMTZEkgzr6mm352l2VUiT7uGPhrm3PJKCqbRD7ntnYecFLOQ84+tVu2KGhX 65M7A5cwX0TmicUoAa3Z3epsH/SYebUwIDZfVkRRNF7WMtab/XP2RKZYuXkWpLZHv4MQBMlGw DCE4aF7v1p1GGtIBel/JMlGLJnxxlrJSMXvT8HvwEI9PXrqJCvw+L3NfbwrlNVRrxaFnvJJ72 wFmxtKnOnf9voBooXFhHMmQqwZAEXoXF4PolWBdMFPSVQw1oGthyApEl3rkxVxDBP/ryJDo9m L1Pu+rMLmO58M5JsAClChM1GCsbFA1eKiRG8uuqPAmEiF+FpVSQR3zY5KFutuDgF5I+TWAXRi Q9mFQ= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the handling of !exclude_parent to the two callers that pass zero. This allows checking the validity of the child separately from adding its parents, which we'll make use of in the next patch. Rename the function to reflect its changed purpose, now that it requires exclude_parent to be given and only adds at most one parent. Signed-off-by: René Scharfe --- Created with --inter-hunk-context=1 for easier review. revision.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) -- 2.37.3 diff --git a/revision.c b/revision.c index 284393a146..5e756b76aa 100644 --- a/revision.c +++ b/revision.c @@ -1868,19 +1868,15 @@ static void add_parents(struct rev_info *revs, struct commit_list *parents, add_parent(revs, &parents->item->object, arg, flags); } -static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, - int exclude_parent) +static int add_nth_parent(struct rev_info *revs, const char *arg_, int flags, + int exclude_parent) { struct commit *commit = get_commit(revs, arg_); struct commit_list *parents; int parent_number; if (!commit) return 0; - if (!exclude_parent) { - add_parents(revs, commit->parents, arg_, flags); - return 1; - } for (parents = commit->parents, parent_number = 1; parents; parents = parents->next, parent_number++) { @@ -2127,15 +2123,26 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl mark = strstr(arg, "^@"); if (mark && !mark[2]) { + struct commit *commit; + *mark = 0; - if (add_parents_only(revs, arg, flags, 0)) + commit = get_commit(revs, arg); + if (commit) { + add_parents(revs, commit->parents, arg, flags); return 0; + } *mark = '^'; } mark = strstr(arg, "^!"); if (mark && !mark[2]) { + struct commit *commit; + *mark = 0; - if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), 0)) + commit = get_commit(revs, arg); + if (commit) + add_parents(revs, commit->parents, arg, + flags ^ (UNINTERESTING | BOTTOM)); + else *mark = '^'; } mark = strstr(arg, "^-"); @@ -2149,7 +2156,7 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl } *mark = 0; - if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), exclude_parent)) + if (!add_nth_parent(revs, arg, flags ^ (UNINTERESTING | BOTTOM), exclude_parent)) *mark = '^'; } From patchwork Thu Sep 15 14:55:12 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: 12977517 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 19D3EC6FA89 for ; Thu, 15 Sep 2022 14:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230015AbiIOOzZ (ORCPT ); Thu, 15 Sep 2022 10:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbiIOOzX (ORCPT ); Thu, 15 Sep 2022 10:55:23 -0400 Received: from mout.web.de (mout.web.de [212.227.17.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D9275E663 for ; Thu, 15 Sep 2022 07:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1663253713; bh=ZyqRspsBwsVmCO9QoQcKENUeDxFeLE6KEpbrMUz49as=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=KUawnoOligMyNMiJEawEP+XrJ8sXwMlXfcLTVPZ40CwULSFVp+jgf47+p0aNOH4LU uYn6RDLaWle6gcKJFwD/f6PgRh8p7ePyc8L5Yo3YfFgzbBJPgSByrxPqnFPEUXA2hK M9my/3v7HqWwjZWG/N8ZXUc6lVBuRH+gQ/yinjeZ2jZ5s6QXBfK5WT8c6gcpl45xtD hbMKcw1pWirWT6JzoihuqjnTl6EA33mpo+Pi9i5nTal34k/UldD65br4hlS7MoHraK nLBtGHS2jsNWUky30PfIfJ7xq+Lp5iFT1W5vN9ik6av1bmI0Sp2mW3M3bheUSIbdME i3/yKyTAU/dDA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([79.203.24.217]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MuF8x-1pSrCm0f4n-00uIla; Thu, 15 Sep 2022 16:55:13 +0200 Message-ID: <84018532-169f-dc9b-f894-3d19bb7b4245@web.de> Date: Thu, 15 Sep 2022 16:55:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: [PATCH 6/6] revision: add parents after child for ^! Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , Tim Jaacks , Chris Torek References: In-Reply-To: X-Provags-ID: V03:K1:aLKpTaKPUNP/aZ7a3FCuEQAOp4hxdYvzHOcX+itNhOick8BY6cG TYjTCD/FMzHEvX820MIumng8RK0LGsfoFsceB7fl3Li7pRqjYjnqoMGlfBYZ5e+epobDJe8 VZKJQ/ui2TF3uCmoHZa1n0zPmMJ6uvjhBjunx0nzGOSPg3dSF7aIf+8ajRbVtbBQha2aeqq 77EATy2LZX5uMc703h7Lg== X-UI-Out-Filterresults: notjunk:1;V03:K0:pOtFrS55ZpQ=:pf4SuhwpLs0A2U6ptLWHfe 2wgfw+twNkhUItaRC/m6cWYz/ALQT20cA8JAxfhMKO1gXy6s5zdkDy+jgL+6YiN8WiBZP09Yr 3zLkKWNwjb1+WVGJcQBC5lSvTHMXIr/Pn53wXBq4N5ESSJkzcCiT4JUMVVJ8VuJWnw/Eu3r1V jxyjXmBzGc+ZaMZw5wKgKRu+/Ib7gLvpJf58DRsFlyjMr9yezWEoVLNiMOyD8oinmh0UDWq6d 4NAHeJvriaOeW4F0F2LW0Kymrbz3029Qll5Xc27rhai/veJ9P2GJ3RGDcT8qpn06okqjU7Tqr k0jHYaxpg2DhRpsd0QmFqnM/U9eXPS8bpFMSmqshNe/5Gcg85rVgq1rZ2wKjvq/fe4zFd4VFH T5C+t6VyFraevzO344GA9fWjjSa7UZHEOE8TYlynA4uZ/o5YM4mVTy88NvDbK0Geu2mUgFEBC atnn+YmgIWXvf9thkOAbwM1htn4dzqHIJupEPSw+ra7MPXuMaWEcwsCF9zZJwWHDHvrbUom+Q xXiPSAlLn7TmtmjFiOqv7bcmF5B+DUdwsMzox9BB2pPyog3eVjD+i00QbPg20rV0IeX1KWrcP ezx5DtZJ3+5jQGQ36m6medZaAPSQxSmRU60omxixSpBScFoRR3+eQLtKxai5x1aPTiulSwMZO Nhv7gqOBHQs2ZcdnwtBzroMeqyqfL23qm5l7sFg+vRnHWLx3btMEmYOpuKc5REAfXQ2/H+x1+ 9MomlosgJqwIOWmOXJYrzk9r529ProIbP0hYzg9SbE75aR0k+YMBQxS8rGQlO1cKx255bXXsX AenchqJmd1Y3WvYhqXAiHOd0/y/tKYO0oZILV97eMUimL8wZqLSHZuMGmti73ztPFm+BuqBEU Tuu9W7PKiqrjup6A5OEyOebluNTfY2mxwxlDYXyLGmwsL2YUynr+O8+L11alwbNLqLhnWR17F CI/iGZNKpVgeEGjmipZN8IPzVnnNlG7eB4E0N4qi5hmOtzbeqSkUdc6MOzD9NV1keDf2vgm8X 3yGuptXLyItiqjZk/cSrXioDME6/EeRU1dJMoR18iJh08akiVjljUiP4nQ3pT9iXCRP835UU+ GFsz8pY8b/T6As5xbzlJrdKU6jESb7eBJJdFrTjZajbkifzMXZpVb4dfMc+nVZEdggLyo+Y+Y rAw/o= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org gitrevisions(7) says: "A suffix '^' followed by an exclamation mark is the same as giving commit '' and then all its parents prefixed with '^' to exclude them (and their ancestors)." handle_revision_arg_1() however adds the negated parents first. This leads to unexpected results with git diff and merge commits, as that command expects the documented order. Split up the handling of ^! by moving the actual addition of the parents after the addition of the child. Reported-by: Tim Jaacks Signed-off-by: René Scharfe Reported-by: Tim Jaacks Signed-off-by: René Scharfe --- revision.c | 13 ++++++------- t/t4038-diff-combined.sh | 10 ++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) -- 2.37.3 diff --git a/revision.c b/revision.c index 5e756b76aa..8385127f1a 100644 --- a/revision.c +++ b/revision.c @@ -2107,6 +2107,7 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl const char *arg = arg_; int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; unsigned get_sha1_flags = GET_OID_RECORD_PATH; + struct commit *caret_bang_commit = NULL; flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM; @@ -2135,14 +2136,9 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl } mark = strstr(arg, "^!"); if (mark && !mark[2]) { - struct commit *commit; - *mark = 0; - commit = get_commit(revs, arg); - if (commit) - add_parents(revs, commit->parents, arg, - flags ^ (UNINTERESTING | BOTTOM)); - else + caret_bang_commit = get_commit(revs, arg); + if (!caret_bang_commit) *mark = '^'; } mark = strstr(arg, "^-"); @@ -2179,6 +2175,9 @@ static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); add_pending_object_with_path(revs, object, arg, oc.mode, oc.path); free(oc.path); + if (caret_bang_commit) + add_parents(revs, caret_bang_commit->parents, arg, + flags ^ (UNINTERESTING | BOTTOM)); return 0; } 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 &&