From patchwork Thu Dec 3 15:59:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C929EC4361B for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DC4F207A5 for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731138AbgLCQAu (ORCPT ); Thu, 3 Dec 2020 11:00:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731069AbgLCQAt (ORCPT ); Thu, 3 Dec 2020 11:00:49 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC913C061A55 for ; Thu, 3 Dec 2020 07:59:57 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id a3so4397215wmb.5 for ; Thu, 03 Dec 2020 07:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pWC3snMc2nAfv9p5VhZzmW6O2DlfW8pA+/Acchs/81U=; b=o2bnVWfbWBvIpXextcMnisq/ZKPbYxAewAUcfkRiMQKWU98dQWb16JRyE+Ma4sJX5k SVu4qbLbC089nWNNnYrT8WMHJq1W1ltkKnOPgs6x9LxAG6D+6QM7wrwwwTxAdZ0MqOry 0SV7xjXo+benSgq359P5F2LSQXrJ+XzZZMW4QyQiiYVpMhbnXEjQ/XsXKaB2EU7Tg7G/ MnlK+loPGwwaehxNH9TM9VcF052kqnG51H+U8zQu1YL2cvINxEviTPWhYjY/dygUxm+q weazXWc1rrAH1BEk67YIEJPeTaTfMoWNLTwlfgrNyxLJjAAVPGv22qRKmd9gWQpiUSSD u+Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pWC3snMc2nAfv9p5VhZzmW6O2DlfW8pA+/Acchs/81U=; b=JQiUTlXN+MFuPgElsv5Bi7VSxHhjAakLe05u1z/I3L9OlgqaIWbrisghBzkM0U4web 1EOtYy7rrKJO33y/MEp5rrdCBXS2Pb38L2mcv5JN7MVCyRDDxFxgw5wFEOSZWcWg7pZR gFLV8+iXWHQ9kg5k+EhPanooZNqDw6o20azDI2bGzrUnURImmrWdKRSWoeDw2ywAdQaN gl+nvUv3BGNyiXDcoOl0QypgPDKhENTL2x6cIBO2gI+l2KTH27Bafdv0RB7cvR90mgUg 2K0JS9Jo+YKP8Nkgzh0HLP3+dqEdsbQQWoe5cY9Wu05TDN78WVOVMrsUTrslM2ywk/oT NpAw== X-Gm-Message-State: AOAM5327LduWV9lhGWBxTddgQ+VHBu6NUMA2pCnCxFwUhac1q/1FDw7h ahPQT3Yw6vnGv4oJFp9oOge5HJkt0rY= X-Google-Smtp-Source: ABdhPJxxjJskmURQHJOWJ2WDl8fhWHPBF4LTl99E4m9CQa/F94kXz+tcc3nFPfP0KmJLe58J34d2lQ== X-Received: by 2002:a1c:3d86:: with SMTP id k128mr4008538wma.66.1607011189495; Thu, 03 Dec 2020 07:59:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e1sm2716362wra.22.2020.12.03.07.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:49 -0800 (PST) Message-Id: <6cd8ee01c7107f54bdba177f27089321df047eac.1607011187.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:40 +0000 Subject: [PATCH 1/7] merge-ort: add a few includes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Include blob.h for definition of blob_type, and commit-reach.h for declarations of get_merge_bases() and in_merge_bases(). While none of these are used yet, we want to avoid cross-dependencies in the next three series of patches for merge-ort and merge them at the end; adding these "#include"s now avoids textual conflicts. Signed-off-by: Elijah Newren --- merge-ort.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index ea6a9d7348..b556897bc0 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -17,7 +17,9 @@ #include "cache.h" #include "merge-ort.h" +#include "blob.h" #include "cache-tree.h" +#include "commit-reach.h" #include "diff.h" #include "diffcore.h" #include "dir.h" From patchwork Thu Dec 3 15:59:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44410C433FE for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E222E207A5 for ; Thu, 3 Dec 2020 16:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731130AbgLCQAg (ORCPT ); Thu, 3 Dec 2020 11:00:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgLCQAf (ORCPT ); Thu, 3 Dec 2020 11:00:35 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 488B6C061A52 for ; Thu, 3 Dec 2020 07:59:55 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id x22so3170484wmc.5 for ; Thu, 03 Dec 2020 07:59:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=A64k+DC/Jzh2ojutC880/vsJ0UtdYQgydsE3M1hvMT4=; b=DxclLTQM/eG+7h1oMoeaHMhy9vCObtE/Z24sDuYPqt5kqtGrKnfDa84vXzVpAZDWPj d54g5kgm5uV3rR8YpwUt7iUXKo93rkfnZqBJdX2enSxSwHFcF2uqdokwtHVqQKNtmY/1 OxHjuB8++S61fCZxx33e6Vlk2c4XzpDezS7T9Zt6SiJvUkTNm42eMKCtpZfXG7ugXvgu Btn0TTJICxd2cxh05qXXeTa7MQLuX/OGschbzwYfr/RzyZys/PmL8QGdsBDTWAmXoD5K QQLDBiJQ26RE1iy3SQ8I/1Guaf1M2snIzaERAilgV0rpWAl88cdv3tui9Dkoz2BJ3gfc DyHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=A64k+DC/Jzh2ojutC880/vsJ0UtdYQgydsE3M1hvMT4=; b=h0EpBZ7DgakH5bcF1uFbIZC8higp0a78yPNBkU7eWu7egE0v8zJTXoreLYP3F0zfZd 1Xvp0Qbu0BOYKi3GqJ9LwdT9EF1SX0/PQPkbX2zfqOcg8whrJ8o8UJIXW8imd/xPOXum rSidA/H8CVDcw+J53ZWMAaSAZ+VIxXXeRjju3moU5Q5EOOki3hR/YZYOLwLs0W0Mtqzp Kvp4QcgF72JroDWQq1lMLX+44I7e3SU31EwkrSCbNtO4X+wiQ7Hm+/7pp6RmAe2QPFq+ h7XXFHMIigVeNLm56cfIsUd4X33RCOZLFK+rUxoEEXSoJRb3rrWAQul6+H49RzVdNgNJ h+iQ== X-Gm-Message-State: AOAM532jzOjbJpcGHEKhbJNlEEXCwe2q3QCirzfFjLha/q5AblPT9px4 k1O+KZ2+iWfWOzgwQPSFGI8StyhDY4s= X-Google-Smtp-Source: ABdhPJzxTIaWW3RswzcN0gVph5ATqNgKstyTXZC/5fw8nw30B/gm1x6+OzDNNjA4+M91XAmn2OSzEA== X-Received: by 2002:a1c:4904:: with SMTP id w4mr4057290wma.140.1607011193779; Thu, 03 Dec 2020 07:59:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h2sm2293549wrv.76.2020.12.03.07.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:53 -0800 (PST) Message-Id: <5d73827b8d6c254f5bc4a99afa421ae34f07182e.1607011187.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:41 +0000 Subject: [PATCH 2/7] merge-ort: add a clear_internal_opts helper Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Move most of merge_finalize() into a new helper function, clear_internal_opts(). This is a step to facilitate recursive merges, as well as some future optimizations. Signed-off-by: Elijah Newren --- merge-ort.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index b556897bc0..0654c76c8c 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -194,6 +194,29 @@ static void free_strmap_strings(struct strmap *map) } } +static void clear_internal_opts(struct merge_options_internal *opti, + int reinitialize) +{ + assert(!reinitialize); + + /* + * We marked opti->paths with strdup_strings = 0, so that we + * wouldn't have to make another copy of the fullpath created by + * make_traverse_path from setup_path_info(). But, now that we've + * used it and have no other references to these strings, it is time + * to deallocate them. + */ + free_strmap_strings(&opti->paths); + strmap_clear(&opti->paths, 1); + + /* + * All keys and values in opti->conflicted are a subset of those in + * opti->paths. We don't want to deallocate anything twice, so we + * don't free the keys and we pass 0 for free_values. + */ + strmap_clear(&opti->conflicted, 0); +} + static int err(struct merge_options *opt, const char *err, ...) { va_list params; @@ -1132,22 +1155,7 @@ void merge_finalize(struct merge_options *opt, assert(opt->priv == NULL); - /* - * We marked opti->paths with strdup_strings = 0, so that we - * wouldn't have to make another copy of the fullpath created by - * make_traverse_path from setup_path_info(). But, now that we've - * used it and have no other references to these strings, it is time - * to deallocate them. - */ - free_strmap_strings(&opti->paths); - strmap_clear(&opti->paths, 1); - - /* - * All keys and values in opti->conflicted are a subset of those in - * opti->paths. We don't want to deallocate anything twice, so we - * don't free the keys and we pass 0 for free_values. - */ - strmap_clear(&opti->conflicted, 0); + clear_internal_opts(opti, 0); FREE_AND_NULL(opti); } From patchwork Thu Dec 3 15:59:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A0E9C4361A for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B218207A9 for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731135AbgLCQAh (ORCPT ); Thu, 3 Dec 2020 11:00:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgLCQAg (ORCPT ); Thu, 3 Dec 2020 11:00:36 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35054C061A53 for ; Thu, 3 Dec 2020 07:59:56 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id e7so2380026wrv.6 for ; Thu, 03 Dec 2020 07:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=yesJq5wnA0hx591JRBvr15RHg4DTg5H+wnz64O+LGNU=; b=iSAYHRbMT9uDMfC2MfIiNOTE8wxbvnrWuuZ96TdqSg7FfvVy58AthSz4wyJ8WvbQXm CqmrpBmnhdNymgOISsJgP9hfNEMBBUFgH425ld248nbUJZci3gECI3FwKAU7DZK/zc/t yzR62khTqnFX/hcsoqdMy4VMTW5rm7+bMpK3FGZ2MV/eKIlZk7TcbE4eKDVIwkBVKgss uAHgTNFBx5RRHELwbJEE3z7ZYgi9ZLMvsFD1Et8k8m3DPgfkJmrqxD6/MBMDin7vRZ2Z WzBcMhrV55E0G8dpNKKln/V1JYID1eqVORgcLl4rmeHwklOHrm7IipcytmqCWneHQbIZ RVUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=yesJq5wnA0hx591JRBvr15RHg4DTg5H+wnz64O+LGNU=; b=H4Q88aGprOmk5wKF6E+5I01Q29SEQGuRrGIGxZFbwcXX4azFdZ/NQ4+nCYMqGzmgZX CDq8rEQiF5kV5COEHMt9OSvnmoKU4ZJ1B2G9DCKXGac8SdIcElQsrY7w9QL6jTqzu5iC 49dMRNb4cqwBqStDAbIC/apnTHdwlT5WeCVdZiufp95svBZ4gyinE3uwXMTA+0oIYMPh xRgfKnpj+g5i2btRm4dLchSdVNRMtDiJWsEv6mgqaBIMSoYgOp7WH9O0D8aLl3gIGRIU c64NsqdF/RKaT9t1DHBg+7RDdt99+7eo0Xftdm4z1MwSxJiCmrxQj5rIzseoCOhJboI0 alsw== X-Gm-Message-State: AOAM533Em4+cr89dE7VHDSC9xwi7a5eC6ud/KkoFISYKCVkFqNowsqr2 ekNAwgkTv4a1qEjG2oVqcV4e7k9CwjU= X-Google-Smtp-Source: ABdhPJxwGQ3GoBxq6d4QAel3dc5EMs/9W8wNhCjFmY9Db5LZJ5Ncst0tOwULWOxEmJt4fJm2TBc+YQ== X-Received: by 2002:adf:e58b:: with SMTP id l11mr4443109wrm.278.1607011194721; Thu, 03 Dec 2020 07:59:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y130sm2219190wmc.22.2020.12.03.07.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:54 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:42 +0000 Subject: [PATCH 3/7] merge-ort: add a path_conflict field to merge_options_internal Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren This field is not yet used, but will be used by both the rename handling code, and the conflict type handling code in process_entry(). Signed-off-by: Elijah Newren --- merge-ort.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index 0654c76c8c..bcd53d3799 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -148,6 +148,13 @@ struct conflict_info { /* Whether this path is/was involved in a directory/file conflict */ unsigned df_conflict:1; + /* + * Whether this path is/was involved in a non-content conflict other + * than a directory/file conflict (e.g. rename/rename, rename/delete, + * file location based on possible directory rename). + */ + unsigned path_conflict:1; + /* * For filemask and dirmask, see tree-walk.h's struct traverse_info, * particularly the documentation above the "fn" member. Note that From patchwork Thu Dec 3 15:59:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CFB0C4167B for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B6CD207AA for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731141AbgLCQAu (ORCPT ); Thu, 3 Dec 2020 11:00:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgLCQAt (ORCPT ); Thu, 3 Dec 2020 11:00:49 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25326C061A54 for ; Thu, 3 Dec 2020 07:59:57 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id e7so2380112wrv.6 for ; Thu, 03 Dec 2020 07:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=VNxxLgrPuJxEVC6iKX9rAAyfurlQPJJGP/oQrjVCsek=; b=dxBQhFC6VBdAi+VrH9/CgDZqw9vbD0squCEQJUairMwjt1nck37//5JtEsU20aY87u G6sYBu5+aPfJML30dP+3ni/KAbL0ZYfwno/YiIAPiOPUqjjbu3k5GNsVC56Nduui8D8H 2/286DSQ/gStYwF4QtjIOx5yGmnBsncZwoVik6D8yN9CpFPkXAlavq0haAX2jFB6uDSP pha7rliG5QUk4pMUBwFdZI9U16deKrJBm/m5YGjM2Qi+fBC01tJCHQXEz+0J8z3oz2dl XFAamZ8xs2yW8PVVXe/E7YK/XqexpKfgc+nUgx5h3yHx3jjd73iIDb3JSpc3sakseeZ5 PAJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=VNxxLgrPuJxEVC6iKX9rAAyfurlQPJJGP/oQrjVCsek=; b=arcxojlsTs1A10/xaPCugGSqYSvGkHZIE63YVc0P4xlTi4Kvub510N8LN62GToPl5A snh6kd0cakJxCi2EhSulwfu3j6I2jbIk+n/7RUm1AT1tn05+D6KTwMWVfGTfXiXXCJHt Fygkcw/sZGQ33IK2w6DpjZQmpxT+y+bbCVeDYlkg5GnWOrdm+UMs3vUKZo4z8/3Lq0Gl yN+wfcoDpMTYQBdWFlIWsgrYD7y4wmSsSFOFpCJ7oYo0lGn3/uutJt/Eq9svGrfqzFSC uAsgjs0VH6FHEPF5J/+Tpjr/Qefdfh97GZ6Qfv+9B5F3oWkatQlMyFTZNfUC+VEptcFV DXew== X-Gm-Message-State: AOAM533VGGaDCHynIkjYcfxgnePBIgzsUOHKGGJO55I8UcJM7Ju+NsL0 K3YDL889QK2aepdFxFJVQTGKkfge70c= X-Google-Smtp-Source: ABdhPJxLoPmkYTNRG3rKBT+eum9OUlO6CeZq3mXk5wvOKNHK/hImazYGbTCfMeRblZ5dEsDYqY53Gw== X-Received: by 2002:a5d:4448:: with SMTP id x8mr4520447wrr.364.1607011195698; Thu, 03 Dec 2020 07:59:55 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q17sm2290710wrr.53.2020.12.03.07.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:55 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:43 +0000 Subject: [PATCH 4/7] merge-ort: add a paths_to_free field to merge_options_internal Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren This field will be used in future patches to allow removal of paths from opt->priv->paths. Signed-off-by: Elijah Newren --- merge-ort.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index bcd53d3799..89b9fdb04a 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -41,6 +41,8 @@ struct merge_options_internal { * * these keys serve to intern all the path strings, which allows * us to do pointer comparison on directory names instead of * strcmp; we just have to be careful to use the interned strings. + * (Technically paths_to_free may track some strings that were + * removed from froms paths.) * * The values of paths: * * either a pointer to a merged_info, or a conflict_info struct @@ -75,6 +77,16 @@ struct merge_options_internal { */ struct strmap conflicted; + /* + * paths_to_free: additional list of strings to free + * + * If keys are removed from "paths", they are added to paths_to_free + * to ensure they are later freed. We avoid free'ing immediately since + * other places (e.g. conflict_info.pathnames[]) may still be + * referencing these paths. + */ + struct string_list paths_to_free; + /* * current_dir_name: temporary var used in collect_merge_info_callback() * @@ -222,6 +234,17 @@ static void clear_internal_opts(struct merge_options_internal *opti, * don't free the keys and we pass 0 for free_values. */ strmap_clear(&opti->conflicted, 0); + + /* + * opti->paths_to_free is similar to opti->paths; we created it with + * strdup_strings = 0 to avoid making _another_ copy of the fullpath + * but now that we've used it and have no other references to these + * strings, it is time to deallocate them. We do so by temporarily + * setting strdup_strings to 1. + */ + opti->paths_to_free.strdup_strings = 1; + string_list_clear(&opti->paths_to_free, 0); + opti->paths_to_free.strdup_strings = 0; } static int err(struct merge_options *opt, const char *err, ...) @@ -1206,13 +1229,14 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) * Although we initialize opt->priv->paths with strdup_strings=0, * that's just to avoid making yet another copy of an allocated * string. Putting the entry into paths means we are taking - * ownership, so we will later free it. + * ownership, so we will later free it. paths_to_free is similar. * * In contrast, conflicted just has a subset of keys from paths, so * we don't want to free those (it'd be a duplicate free). */ strmap_init_with_options(&opt->priv->paths, NULL, 0); strmap_init_with_options(&opt->priv->conflicted, NULL, 0); + string_list_init(&opt->priv->paths_to_free, 0); } /* From patchwork Thu Dec 3 15:59:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E94FAC0018C for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A90BC207A9 for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731143AbgLCQAv (ORCPT ); Thu, 3 Dec 2020 11:00:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731069AbgLCQAu (ORCPT ); Thu, 3 Dec 2020 11:00:50 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F6DBC061A56 for ; Thu, 3 Dec 2020 07:59:58 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id v14so3220664wml.1 for ; Thu, 03 Dec 2020 07:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=yPu6RUJO5LaNqx6tk96dR9KSLH8x+DNpjquDN/HBBhM=; b=U87Sn9doLqe9C+NzUkuhhfbVclSXw62xvhdHppC4C8Xp60lvvhExNM80j3nP5G91A6 tdfbPdUdbdQUDkpS2xqgR03TbSCkdUof7lN4CTnDpPCmNbbHgFSovbKzkaXuS1Wk2Xvd pnzHur+Mm0Fr7vEHWSvpg/ZiW0p2DQH7ZTXqg2ysPZRNjnhHuOjsOF8HvvcI6QRLxeBv NC5TiTHiwRk4xMXNQWDo/owInpLyN7Vn+I7ifROgUwsEOhmsAL1NtZ7E7U6vZWzS0MNB ui/7DK4R72EfissS3XTA3oLpK3xmUI6dtX0iTAbVuWeFFM2ExEa3Yj6G92bTMP9be8+q 6WVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=yPu6RUJO5LaNqx6tk96dR9KSLH8x+DNpjquDN/HBBhM=; b=pOovI7mKVsN8TZgHszLpUcZSQ6CTnCXzHw3wXmhKr910d33Qj8NWICTx78xG+ZibyX 7xMc9pfpC+Z7o00rmS/N6eESMzE/su5QSjausvaQKSasGS8vsV3R7rfnm4QfSeOoTWm0 eqWtkj8YnOLezXBI7s2Vr7apMDEegTRbrO81PwBhVJGZzTLLbLWw8STZZGWkH8dMAyHs evk+CYxGpzBrJDQGiYm/vqHBw/LPP3EQnR4ZuMHdzcvi2kci5VuvZmVb+OdciRU1r1ef ywC8r1fAFhugl2YJwKPjcdXQRy04vxsHygYZyRzNvD/Y8PrcyjeBWrXwoaVNWVo0VRSD YbAg== X-Gm-Message-State: AOAM531wZ5mk0x/T+coENDCVbZnj0rZnbMfKnlR+gPSbaA8Xn0zAm0r0 JA0Nyk2gBwpgkMVpq8Q0E97SRl6z4dQ= X-Google-Smtp-Source: ABdhPJz7XkojKeRV4js+9YUOYRBhCK2W/PtPaH9uJi7u9ratmXpNIkKQ8W2Q1gKGskNEtCcG52MvKQ== X-Received: by 2002:a1c:a583:: with SMTP id o125mr4023088wme.91.1607011196581; Thu, 03 Dec 2020 07:59:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b74sm2204344wme.27.2020.12.03.07.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:56 -0800 (PST) Message-Id: <181627c30cc1995b66eb5659e54737d05964f8a1.1607011187.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:44 +0000 Subject: [PATCH 5/7] merge-ort: add function grouping comments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Commit b658536f59 ("merge-ort: add some high-level algorithm structure", 2020-10-27) added high-level structure of the ort merge algorithm. As we have added more and more functions, that high-level structure has been slightly obscured. Since functions are still grouped according to this high-level structure, add comments denoting sections where all the functions are specifically tied to a piece of the high-level structure. This function groupings include a few sub-divisions of the original high-level structure, including some sub-divisions that are yet to be submitted. Each has (or will have) several functions all serving as helpers to one or two main functions for each section. As an added bonus, the comments will serve to provide a small textual separation between nearby sections and allow the next three patch series to be submitted independently and merge cleanly. Signed-off-by: Elijah Newren --- merge-ort.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index 89b9fdb04a..e653ba35ea 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -183,6 +183,8 @@ struct conflict_info { unsigned match_mask:3; }; +/*** Function Grouping: various utility functions ***/ + /* * For the next three macros, see warning for conflict_info.merged. * @@ -263,6 +265,8 @@ static int err(struct merge_options *opt, const char *err, ...) return -1; } +/*** Function Grouping: functions related to collect_merge_info() ***/ + static void setup_path_info(struct merge_options *opt, struct string_list_item *result, const char *current_dir_name, @@ -517,6 +521,15 @@ static int collect_merge_info(struct merge_options *opt, return ret; } +/*** Function Grouping: functions related to threeway content merges ***/ + +/*** Function Grouping: functions related to detect_and_process_renames(), *** + *** which are split into directory and regular rename detection sections. ***/ + +/*** Function Grouping: functions related to directory rename detection ***/ + +/*** Function Grouping: functions related to regular rename detection ***/ + static int detect_and_process_renames(struct merge_options *opt, struct tree *merge_base, struct tree *side1, @@ -534,6 +547,8 @@ static int detect_and_process_renames(struct merge_options *opt, return clean; } +/*** Function Grouping: functions related to process_entries() ***/ + static int string_list_df_name_compare(const char *one, const char *two) { int onelen = strlen(one); @@ -1001,6 +1016,8 @@ static void process_entries(struct merge_options *opt, string_list_clear(&dir_metadata.offsets, 0); } +/*** Function Grouping: functions related to merge_switch_to_result() ***/ + static int checkout(struct merge_options *opt, struct tree *prev, struct tree *next) @@ -1189,6 +1206,8 @@ void merge_finalize(struct merge_options *opt, FREE_AND_NULL(opti); } +/*** Function Grouping: helper functions for merge_incore_*() ***/ + static void merge_start(struct merge_options *opt, struct merge_result *result) { /* Sanity checks on opt */ @@ -1239,6 +1258,8 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) string_list_init(&opt->priv->paths_to_free, 0); } +/*** Function Grouping: merge_incore_*() and their internal variants ***/ + /* * Originally from merge_trees_internal(); heavily adapted, though. */ From patchwork Thu Dec 3 15:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 266A5C0007A for ; Thu, 3 Dec 2020 16:01:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D721C207AA for ; Thu, 3 Dec 2020 16:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731148AbgLCQA4 (ORCPT ); Thu, 3 Dec 2020 11:00:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731144AbgLCQA4 (ORCPT ); Thu, 3 Dec 2020 11:00:56 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2363C08C5F2 for ; Thu, 3 Dec 2020 07:59:58 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id k14so2402188wrn.1 for ; Thu, 03 Dec 2020 07:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ak+BRQLBQOT/BOTqNcUsFX79zLWvFGBTJU8wm3Epus0=; b=Y0qkcXRZoVq0nrOdiYq5ZvCl2wmL4+9LiNNRPi4zW7GFpM8eMKgboynp2ZNPeXR9Vl K866fTIRts1AWTCpi0dlX8Gyz3nbhPSIKnFfORCeAlUdRXFB3MdlDJ0DynPSIJ4IfRz5 FKj/d2Kl2DIIAYLXLsb5OPYw5m0AKAFMsMkdZmhpNvbh5c8vzgTv+JM0UezawW1DnDVI a6rJQJlvktRVLrEfQNRsbTRAAvIRZgykvGKXUDJUzWYV9k9ehMN4tp6GruIUF4OgCNWG D8HPWrFIDx1iUBrzr4x+LA0uN1smhFsPpQRpmgPS3PA/Bt80HbGvqn2loJRKQMBv6Rql oIbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ak+BRQLBQOT/BOTqNcUsFX79zLWvFGBTJU8wm3Epus0=; b=O9KGZN4jWyBl498br0qZsE3OTImJ8d44e2gE/oTrjs+fVu4kR2qJsL2bB/yTm7xEjD d7qHPpB3+BYIQqy1grxe5XZXzo+7+hC/Je/jwaMYhbgurqqa0XOrLQCjyQm+X9WQgkp+ qz5XJ6Nsqezx5RXiqQm3DraYWf+ZHaS/C2fUMqy7nE3rYNT9lvxCLmW+DlYbFbzJ1T+S LuQoqEpHjtrT/t3qcRe6dFjHwPzTxpAMY3jg4yVEWZ1W3fjM2xjvs6v6hDhpgWnaHuBA 55BJgYzTztNjUurOzFwH/13VniEI7fhTF8y3U1KkotqB/C3GUNS7OLEm9uuvKHkIKO94 AMPg== X-Gm-Message-State: AOAM532l7TWlkxuHMbQ4T4s1jQXnPUbMayIpCc66YGHfuipHinP2marA IcmOSy82kmlap72Njc9YfbcxT7LfscE= X-Google-Smtp-Source: ABdhPJwwKlTU13TPO89GEeDhdYmZGLcTWD0faq00qK2XuIHDqv1vEpeMh9k8ZWTYEgw+VQNlEhKtqA== X-Received: by 2002:a5d:44cf:: with SMTP id z15mr4453988wrr.205.1607011197456; Thu, 03 Dec 2020 07:59:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d13sm2704611wrb.39.2020.12.03.07.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:57 -0800 (PST) Message-Id: <9f1ac20e31886ad7cd56ff582c58cce4ee743fa1.1607011187.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:45 +0000 Subject: [PATCH 6/7] merge-ort: add die-not-implemented stub handle_content_merge() function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren This simplistic and weird-looking patch is here to facilitate future patch submissions. Adding this stub allows rename detection code to reference it in one patch series, while a separate patch series can define the implementation, and then both series can merge cleanly and work nicely together at that point. Signed-off-by: Elijah Newren --- merge-ort.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index e653ba35ea..e7220cbbb4 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -523,6 +523,18 @@ static int collect_merge_info(struct merge_options *opt, /*** Function Grouping: functions related to threeway content merges ***/ +static int handle_content_merge(struct merge_options *opt, + const char *path, + const struct version_info *o, + const struct version_info *a, + const struct version_info *b, + const char *pathnames[3], + const int extra_marker_size, + struct version_info *result) +{ + die("Not yet implemented"); +} + /*** Function Grouping: functions related to detect_and_process_renames(), *** *** which are split into directory and regular rename detection sections. ***/ @@ -919,6 +931,8 @@ static void process_entry(struct merge_options *opt, ci->merged.clean = 0; ci->merged.result.mode = ci->stages[1].mode; oidcpy(&ci->merged.result.oid, &ci->stages[1].oid); + /* When we fix above, we'll call handle_content_merge() */ + (void)handle_content_merge; } else if (ci->filemask == 3 || ci->filemask == 5) { /* Modify/delete */ die("Not yet implemented."); From patchwork Thu Dec 3 15:59:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11949045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D2DBC433FE for ; Thu, 3 Dec 2020 16:01:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45199207A9 for ; Thu, 3 Dec 2020 16:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731153AbgLCQBL (ORCPT ); Thu, 3 Dec 2020 11:01:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731150AbgLCQBL (ORCPT ); Thu, 3 Dec 2020 11:01:11 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB3BC08E85E for ; Thu, 3 Dec 2020 08:00:00 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id v14so3220769wml.1 for ; Thu, 03 Dec 2020 08:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=twWa+J1WG9e02gxYA2qg9SNA45rlybzJ7QhS9MSllrk=; b=anfjaFyc8P19erogV2iLhkSrYUSfkJZZyklwFnsi9tFJG8Kj/mT6OpzIDNQZebQVPU enroijYL3pzsHgjW5U4OgoOw+Ko1CPN4MLrYsYfllVzjanW+8id4JLUOM+PI2+f3Dz5R eXuO+1FzK2WMYsoW47Ges4hM5DwgQk3mZiXwSnc7/U6MXWZdQQ/A8y363+rr8P7RI5At 3tbzY5q0UglAD9gaBEpMrckRB2mVOrfWEFvIKaC9yanLDL7nQtC7G238X4CHpJw/0Gd6 /QIMtAxy7GmXnJxPSlo3G2EVgzuNIkDz3OcXvHkQulkQx7qnn9O0bp2iFPF0uIrujs4M j7Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=twWa+J1WG9e02gxYA2qg9SNA45rlybzJ7QhS9MSllrk=; b=hILDcTsAR5rHiUSzDA7z787f5lNDQHadZbQh+2mNgBMgYMzOYBlVBsleJJYPkNAqpx 4XD9eG+jtpvL9RX8KVI9ENWE4zlS5hCpkP81wcysn1XuIoiLxD0RQmO78qasrZre3bbE t4db+Kr8LbeG+ciyOpelTEDa9gwrVjGEqd4DOg5SSfM0E4FBMXarYEFQA857CM77vZFS xKCzE6T7jaRCP+OCqFN9mXpYAuQFGyxpy6Bgk10Ug9iAqMs7hqT79fYAazwkc00ydKUb kubaPU7bIkOotoCzBzvpXVIBUXzNxO+sYfi0zbwQxeIhYI2UV88aHTL0FRTUZ046/MIt +wzQ== X-Gm-Message-State: AOAM531/Naly7uHkT+PP5NgmWfClOEtZjZV+n40pg7asz43jMhkiyNlb VvSAwI/W6fa5ZipJGzT8yYtkdavnJbc= X-Google-Smtp-Source: ABdhPJxJlTgdgBDZW6kBRNQk5Tr+WnOZrNU+Mp0LmCrpGk0IV+7SfTOLirNd2FPFMJQJ8T18DgM2oA== X-Received: by 2002:a05:600c:220b:: with SMTP id z11mr4153219wml.64.1607011198486; Thu, 03 Dec 2020 07:59:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n10sm2322495wrv.77.2020.12.03.07.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 07:59:57 -0800 (PST) Message-Id: <8ab55a6ecb0b3c7139520d09d752420d7e90f6c2.1607011187.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 03 Dec 2020 15:59:46 +0000 Subject: [PATCH 7/7] merge-ort: add modify/delete handling and delayed output processing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren The focus here is on adding a path_msg() which will queue up warning/conflict/notice messages about the merge for later processing, storing these in a pathname -> strbuf map. It might seem like a big change, but it really just is: * declaration of necessary map with some comments * initialization and recording of data * a bunch of code to iterate over the map at print/free time * at least one caller in order to avoid an error about having an unused function (which we provide in the form of implementing modify/delete conflict handling). At this stage, it is probably not clear why I am opting for delayed output processing. There are multiple reasons: 1. Merges are supposed to abort if they would overwrite dirty changes in the working tree. We cannot correctly determine whether changes would be overwritten until both rename detection has occurred and full processing of entries with the renames has finalized. Warning/conflict/notice messages come up at intermediate codepaths along the way, so unless we want spurious conflict/warning messages being printed when the merge will be aborted anyway, we need to save these messages and only print them when relevant. 2. There can be multiple messages for a single path, and we want all messages for a give path to appear together instead of having them grouped by conflict/warning type. This was a problem already with merge-recursive.c but became even more important due to the splitting apart of conflict types as discussed in the commit message for 1f3c9ba707 ("t6425: be more flexible with rename/delete conflict messages", 2020-08-10) 3. Some callers might want to avoid showing the output in certain cases, such as if the end result is a clean merge. Rebases have typically done this. 4. Some callers might not want the output to go to stdout or even stderr, but might want to do something else with it entirely. For example, a --remerge-diff option to `git show` or `git log -p` that remerges on the fly and diffs merge commits against the remerged version would benefit from stdout/stderr not being written to in the standard form. Signed-off-by: Elijah Newren --- merge-ort.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index e7220cbbb4..64468f0706 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -87,6 +87,15 @@ struct merge_options_internal { */ struct string_list paths_to_free; + /* + * output: special messages and conflict notices for various paths + * + * This is a map of pathnames (a subset of the keys in "paths" above) + * to strbufs. It gathers various warning/conflict/notice messages + * for later processing. + */ + struct strmap output; + /* * current_dir_name: temporary var used in collect_merge_info_callback() * @@ -247,6 +256,27 @@ static void clear_internal_opts(struct merge_options_internal *opti, opti->paths_to_free.strdup_strings = 1; string_list_clear(&opti->paths_to_free, 0); opti->paths_to_free.strdup_strings = 0; + + if (!reinitialize) { + struct hashmap_iter iter; + struct strmap_entry *e; + + /* Release and free each strbuf found in output */ + strmap_for_each_entry(&opti->output, &iter, e) { + struct strbuf *sb = e->value; + strbuf_release(sb); + /* + * While strictly speaking we don't need to free(sb) + * here because we could pass free_values=1 when + * calling strmap_clear() on opti->output, that would + * require strmap_clear to do another + * strmap_for_each_entry() loop, so we just free it + * while we're iterating anyway. + */ + free(sb); + } + strmap_clear(&opti->output, 0); + } } static int err(struct merge_options *opt, const char *err, ...) @@ -265,6 +295,27 @@ static int err(struct merge_options *opt, const char *err, ...) return -1; } +__attribute__((format (printf, 4, 5))) +static void path_msg(struct merge_options *opt, + const char *path, + int omittable_hint, /* skippable under --remerge-diff */ + const char *fmt, ...) +{ + va_list ap; + struct strbuf *sb = strmap_get(&opt->priv->output, path); + if (!sb) { + sb = xmalloc(sizeof(*sb)); + strbuf_init(sb, 0); + strmap_put(&opt->priv->output, path, sb); + } + + va_start(ap, fmt); + strbuf_vaddf(sb, fmt, ap); + va_end(ap); + + strbuf_addch(sb, '\n'); +} + /*** Function Grouping: functions related to collect_merge_info() ***/ static void setup_path_info(struct merge_options *opt, @@ -935,7 +986,23 @@ static void process_entry(struct merge_options *opt, (void)handle_content_merge; } else if (ci->filemask == 3 || ci->filemask == 5) { /* Modify/delete */ - die("Not yet implemented."); + const char *modify_branch, *delete_branch; + int side = (ci->filemask == 5) ? 2 : 1; + int index = opt->priv->call_depth ? 0 : side; + + ci->merged.result.mode = ci->stages[index].mode; + oidcpy(&ci->merged.result.oid, &ci->stages[index].oid); + ci->merged.clean = 0; + + modify_branch = (side == 1) ? opt->branch1 : opt->branch2; + delete_branch = (side == 1) ? opt->branch2 : opt->branch1; + + path_msg(opt, path, 0, + _("CONFLICT (modify/delete): %s deleted in %s " + "and modified in %s. Version %s of %s left " + "in tree."), + path, delete_branch, modify_branch, + modify_branch, path); } else if (ci->filemask == 2 || ci->filemask == 4) { /* Added on one side */ int side = (ci->filemask == 4) ? 2 : 1; @@ -1203,7 +1270,29 @@ void merge_switch_to_result(struct merge_options *opt, } if (display_update_msgs) { - /* TODO: print out CONFLICT and other informational messages. */ + struct merge_options_internal *opti = result->priv; + struct hashmap_iter iter; + struct strmap_entry *e; + struct string_list olist = STRING_LIST_INIT_NODUP; + int i; + + /* Hack to pre-allocate olist to the desired size */ + ALLOC_GROW(olist.items, strmap_get_size(&opti->output), + olist.alloc); + + /* Put every entry from output into olist, then sort */ + strmap_for_each_entry(&opti->output, &iter, e) { + string_list_append(&olist, e->key)->util = e->value; + } + string_list_sort(&olist); + + /* Iterate over the items, printing them */ + for (i = 0; i < olist.nr; ++i) { + struct strbuf *sb = olist.items[i].util; + + printf("%s", sb->buf); + } + string_list_clear(&olist, 0); } merge_finalize(opt, result); @@ -1270,6 +1359,13 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) strmap_init_with_options(&opt->priv->paths, NULL, 0); strmap_init_with_options(&opt->priv->conflicted, NULL, 0); string_list_init(&opt->priv->paths_to_free, 0); + + /* + * keys & strbufs in output will sometimes need to outlive "paths", + * so it will have a copy of relevant keys. It's probably a small + * subset of the overall paths that have special output. + */ + strmap_init(&opt->priv->output); } /*** Function Grouping: merge_incore_*() and their internal variants ***/