From patchwork Wed Dec 9 19:41:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962351 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 00B5BC433FE for ; Wed, 9 Dec 2020 19:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C323F2332A for ; Wed, 9 Dec 2020 19:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387867AbgLITm6 (ORCPT ); Wed, 9 Dec 2020 14:42:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729345AbgLITmL (ORCPT ); Wed, 9 Dec 2020 14:42:11 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D7A7C0613D6 for ; Wed, 9 Dec 2020 11:41:31 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id y23so2950550wmi.1 for ; Wed, 09 Dec 2020 11:41:31 -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=vc70ZGK6wBOuRDSpqyRxlNy56TEQli53YQsso/1Hg1A=; b=V+bPd2CWstMzfKR7mw57emxpmswUG5l30PEka5AKOoJCmNs4NaLOEyVHtj9yVQZ2Hc tCQtG4IJs0WCf+2HUnN0UaRQfcsHvuZyCLq9zmb9BjRcknVdKAAvbzErjtfBeyjo8kCy vb4H0BZxcgcPwopBMf2uWJy6E5zhaDuc9dCz4vtNOok0IfUpSEe9Lzl/+A8oCBwcdQeB Sz00s0Qp5nRIENKLfnLG+jh7ba6cuAF+48HmRGM4Wp0zm041WnEeLI2oigwO5N3j8hdF vu+9ZupyfoTF2QZyCQaNaspMfWPMTQvaAzsZYPA5RllDxOS+Nylg/5AN9FIYOYczyS69 va6A== 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=vc70ZGK6wBOuRDSpqyRxlNy56TEQli53YQsso/1Hg1A=; b=XOq/BFjX2FBI3cs1hpnWwkNuG+QKklFk12uZZG19O3QPlOelQ0Zq93owWd+XOwsjRS frmiWqjvKkAJP7v6v/UeOqHTHVSV2mhVj9+oRQMkhpc/p0EeAn/jmn6JgJu2LHXWAj8x VG/josWd/e3O3QNW+BTRIu5zGrdhbEyzTWw2iinrc26W6uDDrbISowli+nFVBdqC6DEP Oy+GUO/tntjF0wGvcdk2eHi2tP4lz83WwN8Gs7LMvEd/+ItU5Pzt91hbl516tKXFPzfY 2lTrCBUvmAFiOqTouCYijETjWil4IzhnTa1hpCbi2j4zDFDFdqep7eDf/VreM93W3aiP 6EUQ== X-Gm-Message-State: AOAM532Hn8lVnAvq7MJCHkqevrMf9pPBRV0VAHNuxfxPUUrEFOzCnTzP sQ9jwlO3Uob/M6rwGa9t8PtDrUsJTBE= X-Google-Smtp-Source: ABdhPJyaaNtpHi5LWyuHTPYlyh0jFBv7bWXcHAByB2VYN7tW9y0qGdfuTagN72bip1jfaCsIQphWIw== X-Received: by 2002:a1c:1c1:: with SMTP id 184mr4390333wmb.112.1607542889877; Wed, 09 Dec 2020 11:41:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w3sm5115874wma.3.2020.12.09.11.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:29 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:17 +0000 Subject: [PATCH 01/11] merge-ort: add basic data structures for handling renames 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 will grow later, but we only need a few fields for basic rename handling. Signed-off-by: Elijah Newren --- merge-ort.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index ef143348592..90baedac407 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -29,6 +29,25 @@ #include "unpack-trees.h" #include "xdiff-interface.h" +struct rename_info { + /* + * pairs: pairing of filenames from diffcore_rename() + * + * Index 1 and 2 correspond to sides 1 & 2 as used in + * conflict_info.stages. Index 0 unused. + */ + struct diff_queue_struct pairs[3]; + + /* + * needed_limit: value needed for inexact rename detection to run + * + * If the current rename limit wasn't high enough for inexact + * rename detection to run, this records the limit needed. Otherwise, + * this value remains 0. + */ + int needed_limit; +}; + struct merge_options_internal { /* * paths: primary data structure in all of merge ort. @@ -96,6 +115,11 @@ struct merge_options_internal { */ struct strmap output; + /* + * renames: various data relating to rename detection + */ + struct rename_info *renames; + /* * current_dir_name: temporary var used in collect_merge_info_callback() * @@ -1356,6 +1380,7 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) /* Initialization of opt->priv, our internal merge data */ opt->priv = xcalloc(1, sizeof(*opt->priv)); + opt->priv->renames = xcalloc(1, sizeof(*opt->priv->renames)); /* * Although we initialize opt->priv->paths with strdup_strings=0, From patchwork Wed Dec 9 19:41:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962319 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 69822C4361B for ; Wed, 9 Dec 2020 19:42:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 224DD23C92 for ; Wed, 9 Dec 2020 19:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387855AbgLITmm (ORCPT ); Wed, 9 Dec 2020 14:42:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732198AbgLITmM (ORCPT ); Wed, 9 Dec 2020 14:42:12 -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 51261C061793 for ; Wed, 9 Dec 2020 11:41:32 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id k14so3053992wrn.1 for ; Wed, 09 Dec 2020 11:41:32 -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=v5ff/3V5zCDHnxLgjmtWFllBH95eypHAvqX8wSVf7ns=; b=gitU+ftiZgElpm3v/eXm1v2gnAxDnUcoUIDn9Z9rxeQdT/LDp9+HlOA/9cdlYE53CQ yBXGhZAUoPovw4FEFDtJ7jw4VbHNp2sZf8oAGSc7WeFtpM+fp/Ys8/AIX0dXjQttvJX1 D//u0EOKyzeM3PqKwnkML22PyqcATEqz3pBVD+BvS+uGyf622+vFdmHZt/dBlu3TFPib njchf4RPC0X5FQ/SkhsG6rZ9b02CueGh+UvofhJ5Usr8mCNzIohTsp3YLJoK2W6CgyY7 QjRQj3/BpfHReUuaWmpaNY73Fs+wW4NmKNYkJRrviMwNFcDRQQnL4wJAf0/MgMC5GHEg tJgw== 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=v5ff/3V5zCDHnxLgjmtWFllBH95eypHAvqX8wSVf7ns=; b=F9FQUIEbaD3a3K8fhX7Dn8hZhtx0KV2BxJ+w/4YxG7iQmavodl9AtYR2SHw5ZEZ1lt bAOBRAATWE+1S1K38hkL5sLFIPpmMPpALlh4AE1bsxE+tuYNz7/F41rbUleTBeCSqJuB oQ0fY6sM63XoNglMO605Qtmr+ZXq8baaHMVkLZ5lHNbhHw4XLMOwjUlSTZSEn/0LDWiq 9E2FtOzQ1ioJwOeaJYc++L6icfFA3+rJhtJcWOiveRyys81HxPByq58YudvoR8vEw6Do TvzEV/BTPuXT9A/KKvMr0gdzTQx34doIGXIWAbtZbL2wD36m3rOePtJO+9OwVF6zVzm3 dPCg== X-Gm-Message-State: AOAM532daW8ZwKdi/Xljxk+sfRQLzyYjUulFgceKvpt9/wTTGsbC7ZSc IlXYqgVrC0QJzpvETxktX2kigfxEPbk= X-Google-Smtp-Source: ABdhPJxHz5JKJlWWjctgn3i/Yzwu/X4q/nTznJxMsoH33ORd19C3p/ivpK/J6r1Ekz8iWpTOQcYIuA== X-Received: by 2002:adf:8b09:: with SMTP id n9mr4269392wra.180.1607542890864; Wed, 09 Dec 2020 11:41:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b12sm5559885wmj.2.2020.12.09.11.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:30 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:18 +0000 Subject: [PATCH 02/11] merge-ort: add initial outline for basic rename detection 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 Signed-off-by: Elijah Newren --- merge-ort.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 90baedac407..92b765dd3f0 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -617,20 +617,72 @@ static int handle_content_merge(struct merge_options *opt, /*** Function Grouping: functions related to regular rename detection ***/ +static int process_renames(struct merge_options *opt, + struct diff_queue_struct *renames) +{ + die("Not yet implemented."); +} + +static int compare_pairs(const void *a_, const void *b_) +{ + die("Not yet implemented."); +} + +/* Call diffcore_rename() to compute which files have changed on given side */ +static void detect_regular_renames(struct merge_options *opt, + struct tree *merge_base, + struct tree *side, + unsigned side_index) +{ + die("Not yet implemented."); +} + +/* + * Get information of all renames which occurred in 'side_pairs', discarding + * non-renames. + */ +static int collect_renames(struct merge_options *opt, + struct diff_queue_struct *result, + unsigned side_index) +{ + die("Not yet implemented."); +} + static int detect_and_process_renames(struct merge_options *opt, struct tree *merge_base, struct tree *side1, struct tree *side2) { - int clean = 1; + struct diff_queue_struct combined; + struct rename_info *renames = opt->priv->renames; + int s, clean = 1; + + memset(&combined, 0, sizeof(combined)); + + detect_regular_renames(opt, merge_base, side1, 1); + detect_regular_renames(opt, merge_base, side2, 2); + + ALLOC_GROW(combined.queue, + renames->pairs[1].nr + renames->pairs[2].nr, + combined.alloc); + clean &= collect_renames(opt, &combined, 1); + clean &= collect_renames(opt, &combined, 2); + QSORT(combined.queue, combined.nr, compare_pairs); + + clean &= process_renames(opt, &combined); + + /* Free memory for renames->pairs[] and combined */ + for (s = 1; s <= 2; s++) { + free(renames->pairs[s].queue); + DIFF_QUEUE_CLEAR(&renames->pairs[s]); + } + if (combined.nr) { + int i; + for (i = 0; i < combined.nr; i++) + diff_free_filepair(combined.queue[i]); + free(combined.queue); + } - /* - * Rename detection works by detecting file similarity. Here we use - * a really easy-to-implement scheme: files are similar IFF they have - * the same filename. Therefore, by this scheme, there are no renames. - * - * TODO: Actually implement a real rename detection scheme. - */ return clean; } From patchwork Wed Dec 9 19:41:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962317 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,URIBL_BLOCKED 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 D00A7C4167B for ; Wed, 9 Dec 2020 19:42:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 917D623C92 for ; Wed, 9 Dec 2020 19:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727162AbgLITme (ORCPT ); Wed, 9 Dec 2020 14:42:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732302AbgLITmO (ORCPT ); Wed, 9 Dec 2020 14:42:14 -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 8FCBBC061794 for ; Wed, 9 Dec 2020 11:41:33 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id r7so3031595wrc.5 for ; Wed, 09 Dec 2020 11:41:33 -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=nOg+LmwailRaVuyEjDjA0uYgU3WumywkoJgRf7dQFBQ=; b=bwXY1szCvxAKDYaFBxVhdWVWCGYVC9MnKWMrVvE00qddC0gkcaqqMLRjK7FEYrri73 zlzBp9MaTmxqDyx6M/3klZ156gNi09FuChKTVpIzQ/1t0Y65JDaaTVx4vwpLCuZ4GQvH p6+Ui6pBThYMGYIH2HJyjdA7b80DJS00pghxiXpMdKVnNwqXH7MQlTM8eqWVT2ydrW6m y2+dOk7uEGWwucF5sPTby24u8IO119Zc9WKzSOhgV8GsXpn2JZbH9qwOmKlPINeuIRoA ZiywFJXExH2J6J5nmwvds+kmw6QlNzImA8kOlClp75QNNpvI30qiQHDdr4uPV3RfZvs0 hRHA== 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=nOg+LmwailRaVuyEjDjA0uYgU3WumywkoJgRf7dQFBQ=; b=PXwoosMhnpGq9FKF7Ejw8SiET8Ot9nm6sFEI/vJ86zcnc9Bx5ldXRELWkyKC3S2q7J SxxjVcdmYrVb4KzX/J02qUgkaz058T4huLz3XFFR3HYwlCtTMIpJkHZlpkXh0guigtTv RAVsZ5u11uzmVvfnRIxLJF+TPMB3CI6nn8FlmZzQxI4cYQonUNTlP+b/L9aJrtXwRYpt NSibrCpYmVc6auEIwj+uZDLYi0CpuCoWKfHKxt+5H6QJRnrc+CUepDIxd0m0PMKPzh41 k2bYbxnIUK1pERhCx82UqRF1XjMOSUU2+EMFeWZvjYEJcDjFt679hqSXKiBC+H5zV6iy LoIg== X-Gm-Message-State: AOAM533WBOeuDPTWN9p74OgPEqxD4ho8a5xK5Gbw/D0tXBQfJKQJRVxB mO3D+7MTi9bl6wTlBguCK2v83HJjSw0= X-Google-Smtp-Source: ABdhPJyO3mFudcZ+eV/oVQg/jzICLjtD+l70UdAzBDCGFMnDNNoVi9lwh7e40j4kfRKAJnm+4wcsPQ== X-Received: by 2002:adf:db44:: with SMTP id f4mr4475707wrj.97.1607542891974; Wed, 09 Dec 2020 11:41:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y130sm5745779wmc.22.2020.12.09.11.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:31 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:19 +0000 Subject: [PATCH 03/11] merge-ort: implement detect_regular_renames() 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 Based heavily on merge-recursive's get_diffpairs() function. Signed-off-by: Elijah Newren --- merge-ort.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 92b765dd3f0..1ff637e57af 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -634,7 +634,33 @@ static void detect_regular_renames(struct merge_options *opt, struct tree *side, unsigned side_index) { - die("Not yet implemented."); + struct diff_options diff_opts; + struct rename_info *renames = opt->priv->renames; + + repo_diff_setup(opt->repo, &diff_opts); + diff_opts.flags.recursive = 1; + diff_opts.flags.rename_empty = 0; + diff_opts.detect_rename = DIFF_DETECT_RENAME; + diff_opts.rename_limit = opt->rename_limit; + if (opt->rename_limit <= 0) + diff_opts.rename_limit = 1000; + diff_opts.rename_score = opt->rename_score; + diff_opts.show_rename_progress = opt->show_rename_progress; + diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT; + diff_setup_done(&diff_opts); + diff_tree_oid(&merge_base->object.oid, &side->object.oid, "", + &diff_opts); + diffcore_std(&diff_opts); + + if (diff_opts.needed_rename_limit > opt->priv->renames->needed_limit) + opt->priv->renames->needed_limit = diff_opts.needed_rename_limit; + + renames->pairs[side_index] = diff_queued_diff; + + diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT; + diff_queued_diff.nr = 0; + diff_queued_diff.queue = NULL; + diff_flush(&diff_opts); } /* @@ -1379,6 +1405,10 @@ void merge_switch_to_result(struct merge_options *opt, printf("%s", sb->buf); } string_list_clear(&olist, 0); + + /* Also include needed rename limit adjustment now */ + diff_warn_rename_limit("merge.renamelimit", + opti->renames->needed_limit, 0); } merge_finalize(opt, result); From patchwork Wed Dec 9 19:41:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962315 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 5055DC433FE for ; Wed, 9 Dec 2020 19:42:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CFDB23C91 for ; Wed, 9 Dec 2020 19:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732038AbgLITmb (ORCPT ); Wed, 9 Dec 2020 14:42:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387855AbgLITmO (ORCPT ); Wed, 9 Dec 2020 14:42:14 -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 7078DC06179C for ; Wed, 9 Dec 2020 11:41:34 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id v14so2579289wml.1 for ; Wed, 09 Dec 2020 11:41:34 -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=9o26fS35UK0LREBqC+PayUR5LfFCNU4XZ7QxCHWU0xo=; b=Zc2clqDjlyo1lDDsoAl2Nt0IBtgfJMdSFJQyeV88D/mlrjtis13OP8GwLMj2Pz9m2T St/YRnMYvwf3FnW32UxZSwpt/L/pL9s39GQoZ0K1cSexSJmil41lXTww1vYGUK4SGQQz 94QfUUHx31qMLroear9yr+OnZcjYn219VxU5qMFb4ZGxOxEqdSlQWYDVO8Vcm74XvpQJ YibJhPJpx74IDxQaCti1qNbtvUbbwaYTHWlLliaPhWM7T6ILZ2qJpPK4D/c1CFP+AUyl LxX/l8hbl7HM172Yvx7Gi0XmcODkJzF7gKx4Gt7uFql0OntEN/DWsK0cdKcuerCTZcMB LkxA== 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=9o26fS35UK0LREBqC+PayUR5LfFCNU4XZ7QxCHWU0xo=; b=tY0UmoOwWdbdyV9SXngGlDvDWt1t1ero1Es2+FiMDvNGuFwkQe5ORUkyLiLX0TiGz/ z9jWcLwdsW9N8+DPQLBGI1YN7E9t/xKvgrrN/29PIkUA1wZbqfVeNl+WHhnAqgvLk4Zl PaL7ikVKzorakKctKBvAQaxn1XTV5RJP0K+SdVGjaDkK7jXnkvMKPTssYmYY2gr/kjeX 1Z3Z2cUr7rzbnKs/rGAkxmca7qTl44lVzYOlC2lbGJ8SJZEBjCL6muSe8Yz9I4Ofo8w4 oECRyC5BGumw6uVAMu8P3nNLyMP5taui7vP/kENQf0lXoQBWqPzrYZqbS3HqKr3OlfXu YfRw== X-Gm-Message-State: AOAM532DwE8AFv/rIrm8sCULPaDl/d3k4buyLNy0Ejs/H0FFT/Jc1/s9 TYEWm/5N9fltE/glIcXrefCOyP/7t7E= X-Google-Smtp-Source: ABdhPJwzyAnY87kqhZPMloQWP6/pwTormJKmZ5rMP6LJ7gsuAewpZh8R6Cj4M7Y7yEaGvjw2O/RhGQ== X-Received: by 2002:a1c:b4c4:: with SMTP id d187mr4408800wmf.38.1607542893051; Wed, 09 Dec 2020 11:41:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4sm5245769wrw.16.2020.12.09.11.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:32 -0800 (PST) Message-Id: <207bb9a837cb855721daa88caaad80e37cb40ffe.1607542887.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:20 +0000 Subject: [PATCH 04/11] merge-ort: implement compare_pairs() and collect_renames() 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 Signed-off-by: Elijah Newren --- merge-ort.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 1ff637e57af..3cdf8124b85 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -625,7 +625,13 @@ static int process_renames(struct merge_options *opt, static int compare_pairs(const void *a_, const void *b_) { - die("Not yet implemented."); + const struct diff_filepair *a = *((const struct diff_filepair **)a_); + const struct diff_filepair *b = *((const struct diff_filepair **)b_); + + int cmp = strcmp(a->one->path, b->one->path); + if (cmp) + return cmp; + return a->score - b->score; } /* Call diffcore_rename() to compute which files have changed on given side */ @@ -671,7 +677,24 @@ static int collect_renames(struct merge_options *opt, struct diff_queue_struct *result, unsigned side_index) { - die("Not yet implemented."); + int i, clean = 1; + struct diff_queue_struct *side_pairs; + struct rename_info *renames = opt->priv->renames; + + side_pairs = &renames->pairs[side_index]; + + for (i = 0; i < side_pairs->nr; ++i) { + struct diff_filepair *p = side_pairs->queue[i]; + + if (p->status != 'R') { + diff_free_filepair(p); + continue; + } + p->score = side_index; + result->queue[result->nr++] = p; + } + + return clean; } static int detect_and_process_renames(struct merge_options *opt, From patchwork Wed Dec 9 19:41:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962343 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 846A2C2BB40 for ; Wed, 9 Dec 2020 19:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 462D923BC6 for ; Wed, 9 Dec 2020 19:46:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387911AbgLITnG (ORCPT ); Wed, 9 Dec 2020 14:43:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387861AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BA5FC0617A6 for ; Wed, 9 Dec 2020 11:41:35 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id e25so2946641wme.0 for ; Wed, 09 Dec 2020 11:41:35 -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=B52IU9V4ss2EkKr2r35b5RX2v2fmhnZiFbREOn0Pscw=; b=Qb39KNG1whyOThI/K71SLv6uqObG8ku9gb8v2Sx7zehFpLw4CR60+rg9G198HAF/no 3I/pTh6PhiDm0PwNV4YcKbaYk/ISMTtavg+M8fSnsNdycqPCYVWVtKvsiqGYE4isUuFl R8KvLM2FSUKWesC6XcsIpX82NCFpmRCxnN1evodYy5HjkKraON2x1nnVYwANBISKCpwK 7W2d3u/aHiT+qyWrOmKqxOagK6nJf2k2PHVuTGF7gOmfRw3jNg4wEW3C8fD8IumPLKPm zCy+1U3xTFbgFxQtpT/pPFWjWOPrMtUcnSH4y3hUdcHkHf5m56GGm7fiJKjd7iGQbVtu iy0Q== 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=B52IU9V4ss2EkKr2r35b5RX2v2fmhnZiFbREOn0Pscw=; b=kPehJKbH34L2gTSW2dEOVGUPW0sR3xBbpKkk3be/PwJB5S94AjNx7W0susRIaGNj10 DfRKbXrkFx5dORa06Pi+LYc9A0IDsPLlpTjPlDTP7sQtcauO3FwZoj8106f4p3Vg4vy4 qwSVhkBiKFySbUz6jlb2jPpakkR8f4gSHON88Qx53lc23e4SnCEjApKc8e6pufpDqfqh ta6CmP2EZzAZorpLmd9bkYxPABBFnH6h98A8sFVEw/22Ti91I/QnMUrHTxoxg2vAw4R5 hcHIaeLi1BrsxTLjx3Fjt0NxFaOa4rmLbRvDAjXbIIe1LvsGx2P0FJRQ2hgYgUzBVyVT HtBA== X-Gm-Message-State: AOAM5332AV8f15DWEbaUtzXASMfYRBZLGHJMIjiSlGA6+qzzvGz93BHu GLJHohy7wqc17343Yoz5fQs7v4/lNC0= X-Google-Smtp-Source: ABdhPJyegOdSGz+sy8ry7LkjKXXp+rF/u5yg7PRD40CF04Fv6p6q+o8xIMtKK6+laELuWJuzGA2vrw== X-Received: by 2002:a1c:de41:: with SMTP id v62mr4501500wmg.135.1607542893908; Wed, 09 Dec 2020 11:41:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m81sm5569307wmf.29.2020.12.09.11.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:33 -0800 (PST) Message-Id: <35b070b9b7c495caed758362dcdaa61b724c1644.1607542887.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:21 +0000 Subject: [PATCH 05/11] merge-ort: add basic outline for process_renames() 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 Add code which determines which kind of special rename case each rename corresponds to, but leave the handling of each type unimplemented for now. Future commits will implement each one. There is some tenuous resemblance to merge-recursive's process_renames(), but comparing the two is very unlikely to yield any insights. merge-ort's process_renames() is a bit complex and I would prefer if I could simplify it more, but it is far easier to grok than merge-recursive's function of the same name in my opinion. Plus, merge-ort handles more rename conflict types than merge-recursive does. Signed-off-by: Elijah Newren --- merge-ort.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 3cdf8124b85..faec29db955 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -620,7 +620,103 @@ static int handle_content_merge(struct merge_options *opt, static int process_renames(struct merge_options *opt, struct diff_queue_struct *renames) { - die("Not yet implemented."); + int clean_merge = 1, i; + + for (i = 0; i < renames->nr; ++i) { + const char *oldpath = NULL, *newpath; + struct diff_filepair *pair = renames->queue[i]; + struct conflict_info *oldinfo = NULL, *newinfo = NULL; + struct strmap_entry *old_ent, *new_ent; + unsigned int old_sidemask; + int target_index, other_source_index; + int source_deleted, collision, type_changed; + + old_ent = strmap_get_entry(&opt->priv->paths, pair->one->path); + oldpath = old_ent->key; + oldinfo = old_ent->value; + + new_ent = strmap_get_entry(&opt->priv->paths, pair->two->path); + newpath = new_ent->key; + newinfo = new_ent->value; + + /* + * diff_filepairs have copies of pathnames, thus we have to + * use standard 'strcmp()' (negated) instead of '=='. + */ + if (i+1 < renames->nr && + !strcmp(oldpath, renames->queue[i+1]->one->path)) { + /* Handle rename/rename(1to2) or rename/rename(1to1) */ + const char *pathnames[3]; + + pathnames[0] = oldpath; + pathnames[1] = newpath; + pathnames[2] = renames->queue[i+1]->two->path; + + if (!strcmp(pathnames[1], pathnames[2])) { + /* Both sides renamed the same way. */ + die("Not yet implemented"); + + /* We handled both renames, i.e. i+1 handled */ + i++; + /* Move to next rename */ + continue; + } + + /* This is a rename/rename(1to2) */ + die("Not yet implemented"); + + i++; /* We handled both renames, i.e. i+1 handled */ + continue; + } + + VERIFY_CI(oldinfo); + VERIFY_CI(newinfo); + target_index = pair->score; /* from append_rename_pairs() */ + assert(target_index == 1 || target_index == 2); + other_source_index = 3-target_index; + old_sidemask = (1 << other_source_index); /* 2 or 4 */ + source_deleted = (oldinfo->filemask == 1); + collision = ((newinfo->filemask & old_sidemask) != 0); + type_changed = !source_deleted && + (S_ISREG(oldinfo->stages[other_source_index].mode) != + S_ISREG(newinfo->stages[target_index].mode)); + if (type_changed && collision) { + /* special handling so later blocks can handle this */ + die("Not yet implemented"); + } + + assert(source_deleted || oldinfo->filemask & old_sidemask); + + /* Need to check for special types of rename conflicts... */ + if (collision && !source_deleted) { + /* collision: rename/add or rename/rename(2to1) */ + die("Not yet implemented"); + } else if (collision && source_deleted) { + /* rename/add/delete or rename/rename(2to1)/delete */ + die("Not yet implemented"); + } else { + /* a few different cases... */ + if (type_changed) { + /* rename vs. typechange */ + die("Not yet implemented"); + } else if (source_deleted) { + /* rename/delete */ + die("Not yet implemented"); + } else { + /* normal rename */ + die("Not yet implemented"); + } + } + + if (!type_changed) { + /* Mark the original as resolved by removal */ + oldinfo->merged.is_null = 1; + oldinfo->merged.clean = 1; + } + + } + + return clean_merge; } static int compare_pairs(const void *a_, const void *b_) From patchwork Wed Dec 9 19:41:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962345 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 1E05EC4167B for ; Wed, 9 Dec 2020 19:47:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0B9823BC6 for ; Wed, 9 Dec 2020 19:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387900AbgLITnG (ORCPT ); Wed, 9 Dec 2020 14:43:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387859AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CE55C0617A7 for ; Wed, 9 Dec 2020 11:41:36 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id a12so3024990wrv.8 for ; Wed, 09 Dec 2020 11:41:36 -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=koxMBDcb1fAdRxwvk1liqoKIKXbP2FQzrjy1Xyv+aiA=; b=WElcu2yqQg5/F0FFpZAAIRXNUlluEIAxGJGw9fEO81fPLWOAQv1ysIUrIV0fDuSitp ynUzyKVHZfudw2WBbFqYUw+PCYdSIhaNfBcGqrtqMntq5si1WRsTGjXOd4rJu9eD4Hmg gFps9Sc2YFHh7WBXPqqPE13b/QH8ScpFR6yFoV0UvLRlxvC+DL90YhVrmgWhDbef8WU0 eW+9U9z6YJe7rNj+1d5CwZ3mz1uc7mlCwvfDLHKnc7fYfpLFJEBrwvAjtWrevh+5CkXO smM0zOxBfS02/aaoYeWZHtMKXa1abaHNlPRI+7G4QXaU1X3a5ctPV35IcHt8Ug4QKXXD 0xOQ== 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=koxMBDcb1fAdRxwvk1liqoKIKXbP2FQzrjy1Xyv+aiA=; b=ZFOm3EXyNbKNGnGW7pzfqr1gwnZ1l7m5SAD0k59jGt7NbOhnLLzJ3YYJenloxBFATT /AcnMcpyvyA1N9VOTHXH/cC1nF11kmv2L/Fhm7gnURaU96RGyCUCSlkumFV+WLNj4Z57 fU+it2gQ8PDjYljak/NksCykGv8POj+VWOrHaTnGDslpnOi5JzzXFlkS0HtwUArG0NE1 zg+Mnqh4zcWWfuRaHHvesAMo4VH9Af4mEYaDuiVlJCWX2G4qpAVPUZmoNvTrPNuhnvqA nzAOXDRGKwDLOy/u06l2vhekceydJYUCoRwv+pqWuMr7u5Ev9CuqoQibpDcYI6zW9Mwn +0/A== X-Gm-Message-State: AOAM532b5oHdv16/kKj7B+lwXx3AS7gsII3T2B37kIhX9Dx8Xj83Mhyt FLtTfNXsnYsPQJnLc343iB+X+IKOCNA= X-Google-Smtp-Source: ABdhPJyS8wk5HvbKXgxJqGgdK3A4QRrDsnwkhpZj6DKz3qQJtDWRJMk415Q/RtzUU+9fMbSBwCTW0Q== X-Received: by 2002:a5d:6351:: with SMTP id b17mr4367693wrw.80.1607542894896; Wed, 09 Dec 2020 11:41:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z22sm4649495wml.1.2020.12.09.11.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:34 -0800 (PST) Message-Id: <9c79b9f4a096afeef620ff4fc1f85525923e3d02.1607542887.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:22 +0000 Subject: [PATCH 06/11] merge-ort: add implementation of both sides renaming identically 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 Implement rename/rename(1to1) handling, i.e. both sides of history renaming a file but renaming the same way. This code replaces the following from merge-recurisve.c: * all the 1to1 code in process_renames() * the RENAME_ONE_FILE_TO_ONE case of process_entry() Also, there is some shared code from merge-recursive.c for multiple different rename cases which we will no longer need for this case (or other rename cases): * handle_rename_normal() * setup_rename_conflict_info() The consolidation of four separate codepaths into one is made possible by a change in design: process_renames() tweaks the conflict_info entries within opt->priv->paths such that process_entry() can then handle all the non-rename conflict types (directory/file, modify/delete, etc.) orthogonally. This means we're much less likely to miss special implementation of some kind of combination of conflict types (see commits brought in by 66c62eaec6 ("Merge branch 'en/merge-tests'", 2020-11-18), especially commit ef52778708 ("merge tests: expect improved directory/file conflict handling in ort", 2020-10-26) for more details). That, together with letting worktree/index updating be handled orthogonally in the merge_switch_to_result() function, dramatically simplifies the code for various special rename cases. Signed-off-by: Elijah Newren --- merge-ort.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index faec29db955..085e81196a5 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -647,14 +647,31 @@ static int process_renames(struct merge_options *opt, !strcmp(oldpath, renames->queue[i+1]->one->path)) { /* Handle rename/rename(1to2) or rename/rename(1to1) */ const char *pathnames[3]; + struct version_info merged; + struct conflict_info *base, *side1, *side2; + unsigned was_binary_blob = 0; pathnames[0] = oldpath; pathnames[1] = newpath; pathnames[2] = renames->queue[i+1]->two->path; + base = strmap_get(&opt->priv->paths, pathnames[0]); + side1 = strmap_get(&opt->priv->paths, pathnames[1]); + side2 = strmap_get(&opt->priv->paths, pathnames[2]); + + VERIFY_CI(base); + VERIFY_CI(side1); + VERIFY_CI(side2); + if (!strcmp(pathnames[1], pathnames[2])) { - /* Both sides renamed the same way. */ - die("Not yet implemented"); + /* Both sides renamed the same way */ + assert(side1 == side2); + memcpy(&side1->stages[0], &base->stages[0], + sizeof(merged)); + side1->filemask |= (1 << 0); + /* Mark base as resolved by removal */ + base->merged.is_null = 1; + base->merged.clean = 1; /* We handled both renames, i.e. i+1 handled */ i++; From patchwork Wed Dec 9 19:41:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962397 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 E2403C4167B for ; Wed, 9 Dec 2020 19:51:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5DFE23BEF for ; Wed, 9 Dec 2020 19:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388068AbgLITvJ (ORCPT ); Wed, 9 Dec 2020 14:51:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387864AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -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 73E15C0617B0 for ; Wed, 9 Dec 2020 11:41:37 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id q75so2934725wme.2 for ; Wed, 09 Dec 2020 11:41:37 -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=YVnZBn6o8XC0Dr0Xepza4NR0AZgejyZfAJ8PWNUX5LE=; b=QiPZfFFTxOxoFhcQshmaNd/hxlKZjKx4ExdaMjToIavj4ntD10o2LRG3T/DfBADYG0 V2lKl5op6RaBWhjlqaXK7ngszKORjOU9Xu0lmSpLkRgtyBqg4KpBiWi44Eo3gLHmj/av VvUbo3OW+48hdgzixn1mN3VxGjMvhOMrvYHilVTgd1/9jNakotcmYu8sRUU9K3sxaGrD dJ7Wc3exjy8BlE6U1D4YhOXm59EoSnFJSA7b4PPbrGcl+aG6JDM4VDd6245swmJnQzP9 S/4CvmTQdtFhiKARrGg4uzbT0M+ul0/q+1X3jLaHd6M/PzDO0dwVjY6RN95kYp/B5vyg CZjw== 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=YVnZBn6o8XC0Dr0Xepza4NR0AZgejyZfAJ8PWNUX5LE=; b=b9WuCrUMbK4UEsB2YHlWrrAkmaq5b/tK7CO39o5Spuh7Wsm1/LHzDJ0+5YVyJnMvZP jvn2N/VJ6wosxVvP26ilVBd4cfW8sjpSlGTn9I2Wsd3wNmJTDNkpKy0Kn0cCXLsx3xyb vag2GW42/lvxORYBwa1IcOC20p6iicYGJf5aJze6TSsLnbtfkuWo+EOcYJ/bYK9UymzQ QqInfmMtc3thnKauDet2CRkuFBkmewNyYes2SY8SjnflJx8qKNSecleV0wzXqWSvfmzo 4nPGHOejbnqNhbNO2+9FcHvJR+E7Ynzmgqpi2ZsrqhX3WfltzkT7lLsqXB7jQpDIbNGZ JuQg== X-Gm-Message-State: AOAM531CdLD3QXjrcDpfClPC3/zkC8dxg0xirN4tBKU7Xsn/QZzZmNNi vPZ18/idysKP3rLgUX1Ke/3UmnrXzSU= X-Google-Smtp-Source: ABdhPJwpz5m2N1LLOGZ++qCSy4ZLyt+YZzRyYBplxr2VUTnnvuAP0dz3X+rkqJveyq6cijzCjsGahQ== X-Received: by 2002:a1c:4c07:: with SMTP id z7mr4367036wmf.142.1607542895911; Wed, 09 Dec 2020 11:41:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i8sm4531967wma.32.2020.12.09.11.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:35 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:23 +0000 Subject: [PATCH 07/11] merge-ort: add implementation of both sides renaming differently 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 Implement rename/rename(1to2) handling, i.e. both sides of history renaming a file and rename it differently. This code replaces the following from merge-recurisve.c: * all the 1to2 code in process_renames() * the RENAME_ONE_FILE_TO_TWO case of process_entry() * handle_rename_rename_1to2() Also, there is some shared code from merge-recursive.c for multiple different rename cases which we will no longer need for this case (or other rename cases): * handle_file_collision() * setup_rename_conflict_info() The consolidation of five separate codepaths into one is made possible by a change in design: process_renames() tweaks the conflict_info entries within opt->priv->paths such that process_entry() can then handle all the non-rename conflict types (directory/file, modify/delete, etc.) orthogonally. This means we're much less likely to miss special implementation of some kind of combination of conflict types (see commits brought in by 66c62eaec6 ("Merge branch 'en/merge-tests'", 2020-11-18), especially commit ef52778708 ("merge tests: expect improved directory/file conflict handling in ort", 2020-10-26) for more details). That, together with letting worktree/index updating be handled orthogonally in the merge_switch_to_result() function, dramatically simplifies the code for various special rename cases. To be fair, there is a _slight_ tweak to process_entry() here to make sure that the two different paths aren't marked as clean but are left in a conflicted state. So process_renames() and process_entry() aren't quite entirely orthogonal, but they are pretty close. Signed-off-by: Elijah Newren --- merge-ort.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 085e81196a5..75e638a23eb 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -680,7 +680,59 @@ static int process_renames(struct merge_options *opt, } /* This is a rename/rename(1to2) */ - die("Not yet implemented"); + clean_merge = handle_content_merge(opt, + pair->one->path, + &base->stages[0], + &side1->stages[1], + &side2->stages[2], + pathnames, + 1 + 2 * opt->priv->call_depth, + &merged); + if (!clean_merge && + merged.mode == side1->stages[1].mode && + oideq(&merged.oid, &side1->stages[1].oid)) { + was_binary_blob = 1; + } + memcpy(&side1->stages[1], &merged, sizeof(merged)); + if (was_binary_blob) { + /* + * Getting here means we were attempting to + * merge a binary blob. + * + * Since we can't merge binaries, + * handle_content_merge() just takes one + * side. But we don't want to copy the + * contents of one side to both paths. We + * used the contents of side1 above for + * side1->stages, let's use the contents of + * side2 for side2->stages below. + */ + oidcpy(&merged.oid, &side2->stages[2].oid); + merged.mode = side2->stages[2].mode; + } + memcpy(&side2->stages[2], &merged, sizeof(merged)); + + side1->path_conflict = 1; + side2->path_conflict = 1; + /* + * TODO: For renames we normally remove the path at the + * old name. It would thus seem consistent to do the + * same for rename/rename(1to2) cases, but we haven't + * done so traditionally and a number of the regression + * tests now encode an expectation that the file is + * left there at stage 1. If we ever decide to change + * this, add the following two lines here: + * base->merged.is_null = 1; + * base->merged.clean = 1; + * and remove the setting of base->path_conflict to 1. + */ + base->path_conflict = 1; + path_msg(opt, oldpath, 0, + _("CONFLICT (rename/rename): %s renamed to " + "%s in %s and to %s in %s."), + pathnames[0], + pathnames[1], opt->branch1, + pathnames[2], opt->branch2); i++; /* We handled both renames, i.e. i+1 handled */ continue; @@ -1257,13 +1309,13 @@ static void process_entry(struct merge_options *opt, int side = (ci->filemask == 4) ? 2 : 1; ci->merged.result.mode = ci->stages[side].mode; oidcpy(&ci->merged.result.oid, &ci->stages[side].oid); - ci->merged.clean = !ci->df_conflict; + ci->merged.clean = !ci->df_conflict && !ci->path_conflict; } else if (ci->filemask == 1) { /* Deleted on both sides */ ci->merged.is_null = 1; ci->merged.result.mode = 0; oidcpy(&ci->merged.result.oid, &null_oid); - ci->merged.clean = 1; + ci->merged.clean = !ci->path_conflict; } /* From patchwork Wed Dec 9 19:41:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962353 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 12E88C4361B for ; Wed, 9 Dec 2020 19:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAB0F23B45 for ; Wed, 9 Dec 2020 19:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388043AbgLITvA (ORCPT ); Wed, 9 Dec 2020 14:51:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387865AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DC85C06138C for ; Wed, 9 Dec 2020 11:41:38 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id t16so3037891wra.3 for ; Wed, 09 Dec 2020 11:41:38 -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=0VyEQXT13srAIfFtThM3gDHUbX8RH79WPD4e3lC2j0Q=; b=A5Nx3MW3nX1nzKNHUY+8t8CEQwW2P2/VFJF/pwXqVPznsMY8dDrWYgDJHfe02y2EZa Y72uqhfgk4Um3bg0vaJ30xd4XAiPBSAPPtVeEWBFhhha7yskbRedUlo/sD1B99lfHoXp Ht8oPrC/ja/6obOXT8zz5agNO3jcGUCN38f2kbC9lKDiFBeA8HZoKFlHMINa03E0rMfw e1CUARC6vLHrqKEcfyETSVasyKWujdednziLJdOaKwxuX6D/iBCXhGmhayZ1UgfawR1f 6am+uv+Pp8Lkd4Tid+yiCcRu9LNPwWCJJK3+zksJs7uElTSOEYryBGRCeHJyPYzv1YbS 2i6Q== 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=0VyEQXT13srAIfFtThM3gDHUbX8RH79WPD4e3lC2j0Q=; b=n+T9pIj5On+IEYOenSoGmw9WaPcrdY/hIYEebmi0TVavW6IfXfUIYbSTJ1V95PBi93 d4wOwDle1f65GJ8F0hmDz3Vfl/xPW5RRhCR8OgVZHficwjhNJ4LMdKIaRS5IEuld0Ldt 5PDluHebsuwz19xsplSi1+cJc1UP/gGoJAzJQ2Im0kwJdnFnUzmQpXsXMb42T/gfEgaN JHAMjVU70avlkHv5BNJpUCye8d4m9tgxsEYpHuNTR67JlKX0MydCIT4wey9S9DO12Pm8 9iRkzVXqisqnYH0EOcV9aCASUwHkEwBMwhQ5OaC/kNtONWyxL0Ucfp2fFWJQBZEGdSaD uCeg== X-Gm-Message-State: AOAM5306EBk066qgwk7JmFRmz3mRVraKRLdX0/htWQm1nYfCySdgFMaX bVWTOFDuNlmfqL/zXSNoMcpka1mWUsw= X-Google-Smtp-Source: ABdhPJwLtJmmA/35QzpkzgS7yGMoK+JZJtp6SsP901uE8l4qZ+y3DB3VHGUVI3PndiTOwHX5KB5oqg== X-Received: by 2002:adf:eeca:: with SMTP id a10mr4368707wrp.186.1607542896816; Wed, 09 Dec 2020 11:41:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u10sm5067854wmd.43.2020.12.09.11.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:36 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:24 +0000 Subject: [PATCH 08/11] merge-ort: add implementation of rename collisions 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 Implement rename/rename(2to1) and rename/add handling, i.e. a file is renamed into a location where another file is added (with that other file either being a plain add or itself coming from a rename). Note that rename collisions can also have a special case stacked on top: the file being renamed on one side of history is deleted on the other (yielding either a rename/add/delete conflict or perhaps a rename/rename(2to1)/delete[/delete]) conflict. One thing to note here is that when there is a double rename, the code in question only handles one of them at a time; a later iteration through the loop will handle the other. After they've both been handled, process_entry()'s normal add/add code can handle the collision. This code replaces the following from merge-recurisve.c: * all the 2to1 code in process_renames() * the RENAME_TWO_FILES_TO_ONE case of process_entry() * handle_rename_rename_2to1() * handle_rename_add() Also, there is some shared code from merge-recursive.c for multiple different rename cases which we will no longer need for this case (or other rename cases): * handle_file_collision() * setup_rename_conflict_info() The consolidation of six separate codepaths into one is made possible by a change in design: process_renames() tweaks the conflict_info entries within opt->priv->paths such that process_entry() can then handle all the non-rename conflict types (directory/file, modify/delete, etc.) orthogonally. This means we're much less likely to miss special implementation of some kind of combination of conflict types (see commits brought in by 66c62eaec6 ("Merge branch 'en/merge-tests'", 2020-11-18), especially commit ef52778708 ("merge tests: expect improved directory/file conflict handling in ort", 2020-10-26) for more details). That, together with letting worktree/index updating be handled orthogonally in the merge_switch_to_result() function, dramatically simplifies the code for various special rename cases. Signed-off-by: Elijah Newren --- merge-ort.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 75e638a23eb..4ec6b0701f1 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -759,10 +759,58 @@ static int process_renames(struct merge_options *opt, /* Need to check for special types of rename conflicts... */ if (collision && !source_deleted) { /* collision: rename/add or rename/rename(2to1) */ - die("Not yet implemented"); + const char *pathnames[3]; + struct version_info merged; + + struct conflict_info *base, *side1, *side2; + unsigned clean; + + pathnames[0] = oldpath; + pathnames[other_source_index] = oldpath; + pathnames[target_index] = newpath; + + base = strmap_get(&opt->priv->paths, pathnames[0]); + side1 = strmap_get(&opt->priv->paths, pathnames[1]); + side2 = strmap_get(&opt->priv->paths, pathnames[2]); + + VERIFY_CI(base); + VERIFY_CI(side1); + VERIFY_CI(side2); + + clean = handle_content_merge(opt, pair->one->path, + &base->stages[0], + &side1->stages[1], + &side2->stages[2], + pathnames, + 1 + 2*opt->priv->call_depth, + &merged); + + memcpy(&newinfo->stages[target_index], &merged, + sizeof(merged)); + if (!clean) { + path_msg(opt, newpath, 0, + _("CONFLICT (rename involved in " + "collision): rename of %s -> %s has " + "content conflicts AND collides " + "with another path; this may result " + "in nested conflict markers."), + oldpath, newpath); + } } else if (collision && source_deleted) { - /* rename/add/delete or rename/rename(2to1)/delete */ - die("Not yet implemented"); + /* + * rename/add/delete or rename/rename(2to1)/delete: + * since oldpath was deleted on the side that didn't + * do the rename, there's not much of a content merge + * we can do for the rename. oldinfo->merged.is_null + * was already set, so we just leave things as-is so + * they look like an add/add conflict. + */ + + newinfo->path_conflict = 1; + path_msg(opt, newpath, 0, + _("CONFLICT (rename/delete): %s renamed " + "to %s in %s, but deleted in %s."), + oldpath, newpath, rename_branch, delete_branch); } else { /* a few different cases... */ if (type_changed) { From patchwork Wed Dec 9 19:41:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962349 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 51EB7C433FE for ; Wed, 9 Dec 2020 19:49:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EC8822B51 for ; Wed, 9 Dec 2020 19:49:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387881AbgLITnE (ORCPT ); Wed, 9 Dec 2020 14:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387860AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F569C061282 for ; Wed, 9 Dec 2020 11:41:39 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id i9so3040150wrc.4 for ; Wed, 09 Dec 2020 11:41:39 -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=462xvpJKv8UgDJkU5159/TIxilz6ywPmSQkF4WNoaEU=; b=vazZ0RyJF2w3bCApIQOsQ6jBkEkyN80ABD2T/Z/OZ2ZLhhMcri4qzaKZQfyx4q49wz LpWykVqr5NNQzrK4tfGwZkjP/O7LiLYquiEC2EU7BGLcw0C5buDJALHaoD0fd/75T+SV Q/WRP9z/gxYx4D7W7mA0QXcxy8q93RsOgolmSA9raJMAQ4gmzyQ9TGpX0OtmGBTOi/x0 7MVVx6f6fI1Xz5R7UdGh/49k4NfzlVAfQKCgo0Q9FstP36kQNeLVAExvVqeOA/B33IyH 7DpBlmS1JbKNowTpsFhNArK1eixwb9u9Y97YJVy8e2ZFMprzH64LJFSRdiCdrSNnLwJs RfiA== 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=462xvpJKv8UgDJkU5159/TIxilz6ywPmSQkF4WNoaEU=; b=rv82IfpiwZZAyyr2FuFeDoVOrkWuChVaVeI3khlvydWbu9E3CljoTWEu70LLM3owJe fhHaWNlwVhkbaCe4nv2zvNo1/x91FlkciQPhBJBe+VhR1d93OTCKDvJtFYxGjkNX0p6V wME8VpOTvGTQMg6LFU0DsbbUPbDWsTGarO3+hsXS+64f/xvEt+MU3wyuwI+iWiM1iB7E FBIeRg4T0mrz5eubKC7G27wVOh3eep9GT4rPTwavlHCmfiSDug+NiAnmk7m/pHu9h/Rr MFysWEoGsuE0/etsZag4tR7WBaDXSbOmaT/AiQLo4BaM4iaHQ64Rq6wdoPtSLLxAbADC uRqA== X-Gm-Message-State: AOAM532haizEa0OdET8d3CXnIbNpGkVQy6qylt7f6P8vLJXnmv7osnQh cqCx7AFY0J6xvSk3nmiKUI2cFOlK5sE= X-Google-Smtp-Source: ABdhPJxOno4kPNz/zy1tzlQI2VVBO5dDFqHIJluLk7/Mh8XYk+665F+eQQf6h6p6aPmXhyFgZ33r/g== X-Received: by 2002:a5d:6cad:: with SMTP id a13mr4310106wra.275.1607542897738; Wed, 09 Dec 2020 11:41:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j15sm5210468wrr.85.2020.12.09.11.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:37 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:25 +0000 Subject: [PATCH 09/11] merge-ort: add implementation of rename/delete conflicts 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 Implement rename/delete conflicts, i.e. one side renames a file and the other deletes the file. This code replaces the following from merge-recurisve.c: * the code relevant to RENAME_DELETE in process_renames() * the RENAME_DELETE case of process_entry() * handle_rename_delete() Also, there is some shared code from merge-recursive.c for multiple different rename cases which we will no longer need for this case (or other rename cases): * handle_change_delete() * setup_rename_conflict_info() The consolidation of five separate codepaths into one is made possible by a change in design: process_renames() tweaks the conflict_info entries within opt->priv->paths such that process_entry() can then handle all the non-rename conflict types (directory/file, modify/delete, etc.) orthogonally. This means we're much less likely to miss special implementation of some kind of combination of conflict types (see commits brought in by 66c62eaec6 ("Merge branch 'en/merge-tests'", 2020-11-18), especially commit ef52778708 ("merge tests: expect improved directory/file conflict handling in ort", 2020-10-26) for more details). That, together with letting worktree/index updating be handled orthogonally in the merge_switch_to_result() function, dramatically simplifies the code for various special rename cases. To be fair, there is a _slight_ tweak to process_entry() here, because rename/delete cases will also trigger the modify/delete codepath. However, we only want a modify/delete message to be printed for a rename/delete conflict if there is a content change in the renamed file in addition to the rename. So process_renames() and process_entry() aren't quite fully orthogonal, but they are pretty close. Signed-off-by: Elijah Newren --- merge-ort.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 4ec6b0701f1..412a3b1da76 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -630,6 +630,7 @@ static int process_renames(struct merge_options *opt, unsigned int old_sidemask; int target_index, other_source_index; int source_deleted, collision, type_changed; + const char *rename_branch = NULL, *delete_branch = NULL; old_ent = strmap_get_entry(&opt->priv->paths, pair->one->path); oldpath = old_ent->key; @@ -752,6 +753,14 @@ static int process_renames(struct merge_options *opt, if (type_changed && collision) { /* special handling so later blocks can handle this */ die("Not yet implemented"); + if (source_deleted) { + if (target_index == 1) { + rename_branch = opt->branch1; + delete_branch = opt->branch2; + } else { + rename_branch = opt->branch2; + delete_branch = opt->branch1; + } } assert(source_deleted || oldinfo->filemask & old_sidemask); @@ -812,13 +821,26 @@ static int process_renames(struct merge_options *opt, "to %s in %s, but deleted in %s."), oldpath, newpath, rename_branch, delete_branch); } else { - /* a few different cases... */ + /* + * a few different cases...start by copying the + * existing stage(s) from oldinfo over the newinfo + * and update the pathname(s). + */ + memcpy(&newinfo->stages[0], &oldinfo->stages[0], + sizeof(newinfo->stages[0])); + newinfo->filemask |= (1 << 0); + newinfo->pathnames[0] = oldpath; if (type_changed) { /* rename vs. typechange */ die("Not yet implemented"); } else if (source_deleted) { /* rename/delete */ - die("Not yet implemented"); + newinfo->path_conflict = 1; + path_msg(opt, newpath, 0, + _("CONFLICT (rename/delete): %s renamed" + " to %s in %s, but deleted in %s."), + oldpath, newpath, + rename_branch, delete_branch); } else { /* normal rename */ die("Not yet implemented"); @@ -1346,12 +1368,21 @@ static void process_entry(struct merge_options *opt, 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); + if (ci->path_conflict && + oideq(&ci->stages[0].oid, &ci->stages[side].oid)) { + /* + * This came from a rename/delete; no action to take, + * but avoid printing "modify/delete" conflict notice + * since the contents were not modified. + */ + } else { + 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; From patchwork Wed Dec 9 19:41:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962347 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 48C64C2BBCA for ; Wed, 9 Dec 2020 19:48:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B23423BC6 for ; Wed, 9 Dec 2020 19:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387892AbgLITnF (ORCPT ); Wed, 9 Dec 2020 14:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387862AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -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 7BDC9C061285 for ; Wed, 9 Dec 2020 11:41:40 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id l9so3013520wrt.13 for ; Wed, 09 Dec 2020 11:41:40 -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=hyvwgKigN49SfW+u94jG33nqWjb5pbiDPIv9LvaOhYc=; b=STlDTH9IhcbK2/nUpqrDdePTDLxK5WSyCOnQn+6BtjTMFn5g5x9mHQvNDx7cwIQeBs 6lYp7ocvU6tLX5//KuANNj9LmwxWC7k7V1elzSTQRHDnyyk2TNjB4n+vAThJ9VGcXB61 YFTDkGem828yJ0aY1LKnnqMxlxOLBhYkMnpKPhQ2yEkijGDtHZOjdsmb6JclfLWt8Y8j /kT+qc43faX+JJqvi2aqGdjSed1XwMLwylq7Qx42sqRIXvWivMGpSziMzj6T9DgQ/+Gi 7h0Rb4YXa6zqKhJx/c84RC0vMvPjHH8eHs2pI5//csG+RN2TSyPk+ezNoroGyr5QLDlk aOMw== 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=hyvwgKigN49SfW+u94jG33nqWjb5pbiDPIv9LvaOhYc=; b=IyBszgzp+zuADWOv4GVuhaMsv4FFJat+xa3GonmGjmqZRyzWFRzNCahS07jFCBD8A9 TJ3Y2mme2f1VXKgZFH6tzB1KUE9LHCjbEeqyV7BN9BNQSai9fSVEBHFGl78qzPPVbsHn otSx6fjB//Kiu18wm9+h9RfeIcKQkhxdS7gxBeh080fy363mpBVKMZ5bUa5BMDHKj6xn q4qvCvYE3B7HHc54GLfBP6MWZCQ5APdhMsm0iPzTClnJ4Pdf6dWtJcMNLabYAPLV79c6 lH6KPmoqOMraT1MX2+NXAjG3gZOwpWeMsvOUlR7zSfz//8E6k41JjcmpNbxhhdMl0SP/ h2rw== X-Gm-Message-State: AOAM531FM3+I2aIQBduLG9x/t9WmhLF1yf5m560s58bmWoTNtqJzMYKx MLXmk7hMFUmUbUK3eR4zfHKu8Q1b/HI= X-Google-Smtp-Source: ABdhPJxkqAFc5RLP2iWZ+x+U91Ne0tcCufgUTzgcQr8+u9k3ooTX7w9JAn6RchnE9jyhU5J+DoMSaw== X-Received: by 2002:a5d:5385:: with SMTP id d5mr484949wrv.384.1607542898614; Wed, 09 Dec 2020 11:41:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k18sm6186905wrd.45.2020.12.09.11.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:38 -0800 (PST) Message-Id: <14baa5874afc12f3ba9534c71b9d70f2c481c465.1607542887.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:26 +0000 Subject: [PATCH 10/11] merge-ort: add implementation of normal rename handling 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 Implement handling of normal renames. This code replaces the following from merge-recurisve.c: * the code relevant to RENAME_NORMAL in process_renames() * the RENAME_NORMAL case of process_entry() Also, there is some shared code from merge-recursive.c for multiple different rename cases which we will no longer need for this case (or other rename cases): * handle_rename_normal() * setup_rename_conflict_info() The consolidation of four separate codepaths into one is made possible by a change in design: process_renames() tweaks the conflict_info entries within opt->priv->paths such that process_entry() can then handle all the non-rename conflict types (directory/file, modify/delete, etc.) orthogonally. This means we're much less likely to miss special implementation of some kind of combination of conflict types (see commits brought in by 66c62eaec6 ("Merge branch 'en/merge-tests'", 2020-11-18), especially commit ef52778708 ("merge tests: expect improved directory/file conflict handling in ort", 2020-10-26) for more details). That, together with letting worktree/index updating be handled orthogonally in the merge_switch_to_result() function, dramatically simplifies the code for various special rename cases. (To be fair, the code for handling normal renames wasn't all that complicated beforehand, but it's still much simpler now.) Signed-off-by: Elijah Newren --- merge-ort.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 412a3b1da76..f2e4edf6506 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -843,7 +843,11 @@ static int process_renames(struct merge_options *opt, rename_branch, delete_branch); } else { /* normal rename */ - die("Not yet implemented"); + memcpy(&newinfo->stages[other_source_index], + &oldinfo->stages[other_source_index], + sizeof(newinfo->stages[0])); + newinfo->filemask |= (1 << other_source_index); + newinfo->pathnames[other_source_index] = oldpath; } } From patchwork Wed Dec 9 19:41:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11962395 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 CF64BC4361B for ; Wed, 9 Dec 2020 19:51:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A4172337F for ; Wed, 9 Dec 2020 19:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388070AbgLITvP (ORCPT ); Wed, 9 Dec 2020 14:51:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387866AbgLITm4 (ORCPT ); Wed, 9 Dec 2020 14:42:56 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D15C061257 for ; Wed, 9 Dec 2020 11:41:41 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id g25so1493918wmh.1 for ; Wed, 09 Dec 2020 11:41:41 -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=7l9C4hKG0uP1LLJpc/apFcMTDSU1D6v9u9ZiVBlN6VY=; b=a66RTLgt/br72WCjaxcDz41cWMXvtZkpy30m4pONFYiWjqfdgY+qpUQRyF4c5aiaA5 Jc0kvghUVSVKlWSUADlowGApFdD7joVJXTTSL9QS3XC5uJNb9V6PLHxWQ94JuxrE9MOW 7c/jD0v0IcKmOjZ47GUFJYAc/cbAWbI/auotqLa7Y/5oz+MjQ2CKgYXP1g33I4g2Anqz dBHhAugm94/rvLbWjztnJ1HboPLHZLJQjlkQVzc+yxFFKOkNdULnGWom7PmfJ9V/ABU2 j2LPzOdJcsi9PAlXbS9Gj8hjOWqIJZ9HvDAjMVmoFwubh7uWmg7uK38Giu+vjSpNyz9Q 3TbA== 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=7l9C4hKG0uP1LLJpc/apFcMTDSU1D6v9u9ZiVBlN6VY=; b=jJMy2zQmJUO8KSqVsSl/wH/ve4o5/N52W0XywxbssUVPRj0fl/jyJ8OlmAVLpJxsWA SxSRcRtq415O1WgIgFtmmm0xJVZ6xQof6/y/Qkmt4UYyZVwA5nvqeUaW0/1EgHL+Tjus lgQC8u/vpFjq9y46LtA2fH3RyZV35BtmmgumQaq+ad4hKzGBgZKWLLGC5zoBHB4rwzDW DeiJQTQUdspFxcPzsSVE3TZHMPXtslpa2FnXoiXtf/c7AiWq5W8AM2w7SLds8zdwjHJx NPFXBx7nW/mny+Y9r77eeN2fwLKUBIUyRdLpiGDUmrD0E0/So0hyREdA+k6TOKfuM3gz RAVg== X-Gm-Message-State: AOAM531dcAdZZqqADKgTfNOeuhhte9npBsUywrEuZfvh7l9MgZI7m/RY htbVSYczdRmcgVbjOFsA6Xg1O6oADjY= X-Google-Smtp-Source: ABdhPJyAw7YXS2uWrkD8Q6SEeZJhaNwi6YIuhWka9ZrjuEBhRPuLe1IYiQrTfxElKSsZ43g29uebPA== X-Received: by 2002:a1c:55ca:: with SMTP id j193mr4459299wmb.87.1607542899978; Wed, 09 Dec 2020 11:41:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r2sm5179379wrn.83.2020.12.09.11.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 11:41:39 -0800 (PST) Message-Id: <476553e2b2049452db0b453150ecab40d011ab0d.1607542887.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 09 Dec 2020 19:41:27 +0000 Subject: [PATCH 11/11] merge-ort: add implementation of type-changed rename handling 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 Implement cases where renames are involved in type changes (i.e. the side of history that didn't rename the file changed its type from a regular file to a symlink or submodule). There was some code to handle this in merge-recursive but only in the special case when the renamed file had no content changes. The code here works differently -- it knows process_entry() can handle mode conflicts, so it does a few minimal tweaks to ensure process_entry() can just finish the job as needed. Signed-off-by: Elijah Newren --- merge-ort.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index f2e4edf6506..64b23c8aa2a 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -752,7 +752,32 @@ static int process_renames(struct merge_options *opt, S_ISREG(newinfo->stages[target_index].mode)); if (type_changed && collision) { /* special handling so later blocks can handle this */ - die("Not yet implemented"); + /* + * if type_changed && collision are both true, then this + * was really a double rename, but one side wasn't + * detected due to lack of break detection. I.e. + * something like + * orig: has normal file 'foo' + * side1: renames 'foo' to 'bar', adds 'foo' symlink + * side2: renames 'foo' to 'bar' + * In this case, the foo->bar rename on side1 won't be + * detected because the new symlink named 'foo' is + * there and we don't do break detection. But we detect + * this here because we don't want to merge the content + * of the foo symlink with the foo->bar file, so we + * have some logic to handle this special case. The + * easiest way to do that is make 'bar' on side1 not + * be considered a colliding file but the other part + * of a normal rename. If the file is very different, + * well we're going to get content merge conflicts + * anyway so it doesn't hurt. And if the colliding + * file also has a different type, that'll be handled + * by the content merge logic in process_entry() too. + * + * See also t6430, 'rename vs. rename/symlink' + */ + collision = 0; + } if (source_deleted) { if (target_index == 1) { rename_branch = opt->branch1; @@ -832,7 +857,11 @@ static int process_renames(struct merge_options *opt, newinfo->pathnames[0] = oldpath; if (type_changed) { /* rename vs. typechange */ - die("Not yet implemented"); + /* Mark the original as resolved by removal */ + memcpy(&oldinfo->stages[0].oid, &null_oid, + sizeof(oldinfo->stages[0].oid)); + oldinfo->stages[0].mode = 0; + oldinfo->filemask &= 0x06; } else if (source_deleted) { /* rename/delete */ newinfo->path_conflict = 1;