From patchwork Sat Aug 17 18:41:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 799141510 for ; Sat, 17 Aug 2019 18:42:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61CCB284F1 for ; Sat, 17 Aug 2019 18:42:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51A972892E; Sat, 17 Aug 2019 18:42:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE227284F1 for ; Sat, 17 Aug 2019 18:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726080AbfHQSmB (ORCPT ); Sat, 17 Aug 2019 14:42:01 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33997 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbfHQSmB (ORCPT ); Sat, 17 Aug 2019 14:42:01 -0400 Received: by mail-pl1-f193.google.com with SMTP id d3so1968772plr.1 for ; Sat, 17 Aug 2019 11:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nSKGB0GuHLighFHkeVNGSxxY8rv4BjolX5UrR9B88t8=; b=dKcTldGE0G7Kr+BYTqt1EwcCq9aEfZPbzV+QmIZlU/SwSZzjT8XrHUJcVTmFVIvXIQ tO8/6PTkLOTNgZ0QBtMRm9oS20dF4ZbUNwUWSKzUAp52eF9ePmsLPhPthCA7O/wqnpdR pM4MAvoIQNMqMV3+KERXcIzhdXIvW0ActDKVG6Cyens5t+VIgi6+e4EIHXXGWeKkX2Cs vx6CzMMsqOGpNlUH13omROrrhAwB0qmaNUS6vlylzkdv9sNsA4poKzrtaSkYZ9CKsgiB xmZf+8Uba14dJ3PAH8b/S/b8nrzB/ufkpzVUgC9L59w3VwZu2kS+33o7jtkxAq0imSY2 SBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nSKGB0GuHLighFHkeVNGSxxY8rv4BjolX5UrR9B88t8=; b=skMe1KvQDLh71SpI1c/tCa7k/Jr+d2oAScsm2JS95c4KkFTifayQlu63qc2Ga1P7bj L4EakMYvTWIYLix4KaVzClx0es5wVs+cRZqfnotVzg8Wp/ca8X36ZSq2IdVMjp6QxtwT 1bZSRZJwixngHjLML/xkRNG5mK6zdST5bJhhmCTC8A6uYmW0pWfR1Naf9EvNQ9Jt5TOu Ho/Tu8Jo/GZRmKsjp1tuQj/l/07rmYiB+EnQScUY+eHXaHcuAPJaVyPSSv60Ep92RQSV f6I/aFaqJZvwpwHgpGImPgWFf5oZ2rdzNundjeYNxsQ0yBP8+7Av4jlJhcvLWYwUf2RE 85rQ== X-Gm-Message-State: APjAAAVLW5uVMoSe5Pz6y3mlYZGFE0TX+C04AlYZsHhOxLUUVhjASJfm ESthE1VeoQVjy5RVi9hh+Cqjx6Gw X-Google-Smtp-Source: APXvYqyMZxZtPgYpNj8Cyi3Zdk9zoMK+3UGnh2YbSI9bByAuJqdxBaxFP+Zvrnsh87yHxQ9ZhnUMoA== X-Received: by 2002:a17:902:246:: with SMTP id 64mr9803979plc.112.1566067320406; Sat, 17 Aug 2019 11:42:00 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:41:59 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 01/24] merge-recursive: be consistent with assert Date: Sat, 17 Aug 2019 11:41:21 -0700 Message-Id: <20190817184144.32179-2-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In commit 8daec1df03de ("merge-recursive: switch from (oid,mode) pairs to a diff_filespec", 2019-04-05), an assertion on a->path && b->path was added for code readability to document that these both needed to be non-NULL at this point in the code. However, the subsequent lines also read o->path, so it should be included in the assert. Signed-off-by: Elijah Newren --- merge-recursive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/merge-recursive.c b/merge-recursive.c index 6b812d67e3..1d960fa64b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1043,7 +1043,7 @@ static int merge_3way(struct merge_options *opt, } } - assert(a->path && b->path); + assert(a->path && b->path && o->path); if (strcmp(a->path, b->path) || (opt->ancestor != NULL && strcmp(a->path, o->path) != 0)) { base_name = opt->ancestor == NULL ? NULL : From patchwork Sat Aug 17 18:41:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099219 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CA1B174A for ; Sat, 17 Aug 2019 18:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DFE7284F1 for ; Sat, 17 Aug 2019 18:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 319392892D; Sat, 17 Aug 2019 18:42:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C853C2892E for ; Sat, 17 Aug 2019 18:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726103AbfHQSmD (ORCPT ); Sat, 17 Aug 2019 14:42:03 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39691 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbfHQSmC (ORCPT ); Sat, 17 Aug 2019 14:42:02 -0400 Received: by mail-pf1-f194.google.com with SMTP id f17so4807005pfn.6 for ; Sat, 17 Aug 2019 11:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bEfuFzv6GSQu8bO0b16Ske6zvIUfiovZ+xO7W1H2whA=; b=vKFisq9T+jZMREOSmVUkGv4BmTRJn8GGKB6NGFIkSvZ0aNikBdHwOg+FIP8boU0lid mFrCygTEGTMLQZYfztQmBRo+MZpM6Z+THsyqbSZbsU6EpT4TK1tQn0VcM6SjpWSnnLC5 3dmaIB7uVdaxgwsLmOAAu0JYxk1Jar/7V8auuvbljwK+/fhss6nsXy/2p4af/e68ZrlV KW6G9+I6ROn4iv/BlmfjhEIyJjMHwDc38NSY7fi4GVpC4iQ+sflHNHN96mM2x2DbYhHe AZgqkRUSTE8MiJeWDsjOKQxQ4PUOGfBtLzwiXYh+gSiXLNqu5oXSgNnZHfrx3g22zaZl Rkfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bEfuFzv6GSQu8bO0b16Ske6zvIUfiovZ+xO7W1H2whA=; b=YAv3Sa3JGCQKMAlhcD0GMLmAHifaMw1kvf7ZTTS7ME0c6Wo12yLFXnYZpg1tF2eW0k 8symQ2U10smprfOeCIQKYHMsQl9hg6ju468pqjE7nv47N21M/jXyRISXM3OZsh4apc64 6vAnvGeMhiqFatRaPtP+XrddWNeAv/eF/O7LhSQDAAavvBKmks0n4MvEP65X5/SyECc2 e8/bxg5ZccQiuk12T1GMemr78cL+yDEZH7fszT09PjYT19ITorxJzUXtV4E6ZU3Ppzve 1buI/lWQekAZfUHYtFvaRNvY4qy5F5sP/8bc/HBPsG/gSUztFi5Ovz/M5GWK8B0mU3Mt 2dSQ== X-Gm-Message-State: APjAAAVKzMtiCQad91IGVJopg+oCYUX4vgjbFRyBmzLBLt6JH1rAxIYv 6OtAY1JQ6HQYl/MAm/rP02JAtTwK X-Google-Smtp-Source: APXvYqyE2P92L1LZm5xb/6qpbcA05f3h/klMYvze7IuCSqtRgSIiSJar+HEvNfr9WHzU4fqDznV5ww== X-Received: by 2002:a63:f941:: with SMTP id q1mr13030928pgk.350.1566067321275; Sat, 17 Aug 2019 11:42:01 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:00 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 02/24] checkout: provide better conflict hunk description with detached HEAD Date: Sat, 17 Aug 2019 11:41:22 -0700 Message-Id: <20190817184144.32179-3-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When running 'git checkout -m' and using diff3 style conflict markers, we want all the conflict hunks (left-side, "common" or "merge base", and right-side) to have label markers letting the user know where each came from. The "common" hunk label (o.ancestor) came from old_branch_info->name, but that is NULL when HEAD is detached, which resulted in a blank label. Check for that case and provide an abbreviated commit hash instead. (Incidentally, this was the only case in the git codebase where merge_trees() was called with opt->ancestor being NULL. A subsequent commit will prevent similar problems by enforcing that merge_trees() always be called with opt->ancestor != NULL.) Signed-off-by: Elijah Newren --- builtin/checkout.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builtin/checkout.c b/builtin/checkout.c index 6123f732a2..d5b946dc3a 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -713,6 +713,7 @@ static int merge_working_tree(const struct checkout_opts *opts, struct tree *old_tree; struct merge_options o; struct strbuf sb = STRBUF_INIT; + struct strbuf old_commit_shortname = STRBUF_INIT; if (!opts->merge) return 1; @@ -768,6 +769,12 @@ static int merge_working_tree(const struct checkout_opts *opts, if (ret) return ret; o.ancestor = old_branch_info->name; + if (old_branch_info->name == NULL) { + strbuf_add_unique_abbrev(&old_commit_shortname, + &old_branch_info->commit->object.oid, + DEFAULT_ABBREV); + o.ancestor = old_commit_shortname.buf; + } o.branch1 = new_branch_info->name; o.branch2 = "local"; ret = merge_trees(&o, @@ -781,6 +788,7 @@ static int merge_working_tree(const struct checkout_opts *opts, opts, 0, writeout_error); strbuf_release(&o.obuf); + strbuf_release(&old_commit_shortname); if (ret) return ret; } From patchwork Sat Aug 17 18:41:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099221 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 065931510 for ; Sat, 17 Aug 2019 18:42:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC93A284F1 for ; Sat, 17 Aug 2019 18:42:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E07102892E; Sat, 17 Aug 2019 18:42:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DE99284F1 for ; Sat, 17 Aug 2019 18:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726173AbfHQSmF (ORCPT ); Sat, 17 Aug 2019 14:42:05 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42689 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbfHQSmD (ORCPT ); Sat, 17 Aug 2019 14:42:03 -0400 Received: by mail-pf1-f194.google.com with SMTP id i30so4799960pfk.9 for ; Sat, 17 Aug 2019 11:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jmiFH5dseSuCwb7G5Y/Qo6cZt6qnwyVrWFv9QGPkwDA=; b=DL7umkttWL2nlIXyQBlZPK5elc35DxyC4vPEYqImDwbom8mr1fpujDs/9Zz5RxJXDf 4a575/gfva4pRy8rFDTF3fIaeujlhihjtOrL6Bmur7YXlq9GPls8peIUsS8W4mPpSsOI oCACHI9oSD90v35M+2kFlMnEKR/vkWo9paPdsTSLjxNlVFDXpwo7RcRFYSxJDlaO6C9B YXDEiCrLY+e/iQMB4QfUsmGVAnY2RJsG3l+fz1yZL/fFfW2HkucbI0B3+vdYUPZYu9OT lyT+Jt6JPZo1aJuttf1Uavo2y/53KDQKVZvj7QCTU5zEDI2o5jEMpyiVuIsoTknWdnz8 VnLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jmiFH5dseSuCwb7G5Y/Qo6cZt6qnwyVrWFv9QGPkwDA=; b=JgMg4gHRr/extBkhqgdEOcSEiRqjHRnTukUI5pSf88AF1onnO5QIOEIbkwx7iQZl13 Ueg3tEkXoLEzh7As0tmK7jGj4xBAj8yfHsuuW1rmDqvWaHq8eqRxqE0JxdX3z1sou5fv BlkyQZltlt8iBbK/1qwjNs4A/7ZgWJ/K71Z1DBcrYVB3t4Dq2vScX7PM22uLPc7S3Qdn H+OTedCe1+ZwLYOKYI7Kb5UnJ2xEigpk7mK5is+au62trBxvTrCyJF385JzfPdTSeXJs jrVmrB2q7Ds+fz5LiNEfF24sCXm/5XGcF1lzaJxkfGRWnSbP/UJdYYQ7TDHDYl5nCJ6X B2OA== X-Gm-Message-State: APjAAAXgkgQn72T5l5h6bAyG++P45W5njTrJbgDv/NmnM4Ks1uTK8srD +236/DdMuayc19gv/JyEy3c2Gqwg X-Google-Smtp-Source: APXvYqxcqP+/y1BGmZ/gXJ3CZPZtD1Jf8vkNMlXfnev5uZ+erugAMuZWvkZXbUYADy6/fBSIxPY74g== X-Received: by 2002:aa7:9ab8:: with SMTP id x24mr16343545pfi.98.1566067322355; Sat, 17 Aug 2019 11:42:02 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:01 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 03/24] merge-recursive: enforce opt->ancestor != NULL when calling merge_trees() Date: Sat, 17 Aug 2019 11:41:23 -0700 Message-Id: <20190817184144.32179-4-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We always want our conflict hunks to be labelled so that users can know where each came from. The previous commit fixed the one caller in the codebase which was not setting opt->ancestor (and thus not providing a label for the "merge base" conflict hunk in diff3-style conflict markers); add an assertion to prevent future codepaths from also overlooking this requirement. Enforcing this requirement also allows us to simplify the code for labelling the conflict hunks by no longer checking if the ancestor label is NULL. Signed-off-by: Elijah Newren --- merge-recursive.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 1d960fa64b..a67ea4957a 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1019,7 +1019,7 @@ static int merge_3way(struct merge_options *opt, { mmfile_t orig, src1, src2; struct ll_merge_options ll_opts = {0}; - char *base_name, *name1, *name2; + char *base, *name1, *name2; int merge_status; ll_opts.renormalize = opt->renormalize; @@ -1043,16 +1043,13 @@ static int merge_3way(struct merge_options *opt, } } - assert(a->path && b->path && o->path); - if (strcmp(a->path, b->path) || - (opt->ancestor != NULL && strcmp(a->path, o->path) != 0)) { - base_name = opt->ancestor == NULL ? NULL : - mkpathdup("%s:%s", opt->ancestor, o->path); + assert(a->path && b->path && o->path && opt->ancestor); + if (strcmp(a->path, b->path) || strcmp(a->path, o->path) != 0) { + base = mkpathdup("%s:%s", opt->ancestor, o->path); name1 = mkpathdup("%s:%s", branch1, a->path); name2 = mkpathdup("%s:%s", branch2, b->path); } else { - base_name = opt->ancestor == NULL ? NULL : - mkpathdup("%s", opt->ancestor); + base = mkpathdup("%s", opt->ancestor); name1 = mkpathdup("%s", branch1); name2 = mkpathdup("%s", branch2); } @@ -1061,11 +1058,11 @@ static int merge_3way(struct merge_options *opt, read_mmblob(&src1, &a->oid); read_mmblob(&src2, &b->oid); - merge_status = ll_merge(result_buf, a->path, &orig, base_name, + merge_status = ll_merge(result_buf, a->path, &orig, base, &src1, name1, &src2, name2, opt->repo->index, &ll_opts); - free(base_name); + free(base); free(name1); free(name2); free(orig.ptr); @@ -3390,6 +3387,8 @@ int merge_trees(struct merge_options *opt, int code, clean; struct strbuf sb = STRBUF_INIT; + assert(opt->ancestor != NULL); + if (!opt->call_depth && repo_index_has_changes(opt->repo, head, &sb)) { err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"), sb.buf); From patchwork Sat Aug 17 18:41:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67F96112C for ; Sat, 17 Aug 2019 18:42:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59211284F1 for ; Sat, 17 Aug 2019 18:42:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D7ED2892E; Sat, 17 Aug 2019 18:42:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 924B7284F1 for ; Sat, 17 Aug 2019 18:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726256AbfHQSmH (ORCPT ); Sat, 17 Aug 2019 14:42:07 -0400 Received: from mail-pg1-f172.google.com ([209.85.215.172]:33242 "EHLO mail-pg1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbfHQSmE (ORCPT ); Sat, 17 Aug 2019 14:42:04 -0400 Received: by mail-pg1-f172.google.com with SMTP id n190so4601556pgn.0 for ; Sat, 17 Aug 2019 11:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q8NEdZdHHPpWmcNTCZY6MyqU5TzeFA22NYSYoq9eKqM=; b=OpceAtHvzm10nYhPDxU7I5e79aEFiALdXhMK1p/Cr6hGEvotluFwRHrX0QHd1DkiLV CG8HQbga/rdfa+oyN/SKbIhBonF5keFepoXuxggujnBsw7yhGGREnNEhCAc8PVB1DXQJ DdY2b3HRODXwlYfsNSPV1tt2AI3BYHEH+1gPnizDHUpoueWhJBtwUg7F0h1Yh4BXMiDQ hl4DvqBqYXi+3L3hyWF6jhnjmwALzgFydCEx1Zo5jGJuamcM9ivyvH4GysMTCKkcxXyh l9CHdoaQ414InaS8xW3OYTPfChkGC/Vv6VbK/cAkvmz3HdcQaJMPoBIhsHLuN6muH5NA dIZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q8NEdZdHHPpWmcNTCZY6MyqU5TzeFA22NYSYoq9eKqM=; b=Z68ZCFkVE1jupWaw/5xdo5nixBrqwMojzTJV+rjD3jVSVzutZNCCSQm1C4VM/W/Sj7 q2qBhaScy8zPPggelspjKA2MdXCFUfPG8IG28xz8B2gVVX3fMQfK3xVzrnw1kv+yNJYw rTukyC30G/GtNfJFW7OAcAQ+RaRbWtjuMRhOS6JoXBqbe5KQvPFCro/mZeRD8gV0qeNB UB2yrwXK3UermFxJ9foWEvvtLx8CxtEk4SwAYWNTWIUec2Jvqpj2JvO/ZKgZ+SbsgdRg a/9tDlxa7DZNAGMTGPqi4nHjPbNHDF+TkalO7EsPM5W/l3rRhb3cEUMMKxYFOgNd3o4H xhuw== X-Gm-Message-State: APjAAAU2a6VhruCVE34oGq/K2hjzWH9KIfRtWWy+vtT3iOw1K3h2G5jY IrcQJQtW/i8mcVqv1wBhDqQeeHv7 X-Google-Smtp-Source: APXvYqyoN+rxpYk6j96xFiLfVGnRuVfrPt6poLwsGvRCGQtVx9Iy0b6v1icTMC/kV+MvkqlNkPZ8aw== X-Received: by 2002:a63:4042:: with SMTP id n63mr2486156pga.75.1566067323291; Sat, 17 Aug 2019 11:42:03 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:02 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 04/24] merge-recursive: provide a better label for diff3 common ancestor Date: Sat, 17 Aug 2019 11:41:24 -0700 Message-Id: <20190817184144.32179-5-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In commit 7ca56aa07619 ("merge-recursive: add a label for ancestor", 2010-03-20), a label was added for the '||||||' line to make it have the more informative heading '|||||| merged common ancestors', with the statement: It would be nicer to use a more informative label. Perhaps someone will provide one some day. This chosen label was perfectly reasonable when recursiveness kicks in, i.e. when there are multiple merge bases. (I can't think of a better label in such cases.) But it is actually somewhat misleading when there is a unique merge base or no merge base. Change this based on the number of merge bases: >=2: "merged common ancestors" 1: 0: "" Tests have also been added to check that we get the right ancestor name for each of the three cases. Also, since merge_recursive() and merge_trees() have polar opposite pre-conditions for opt->ancestor, document merge_recursive()'s pre-condition with an assertion. (An assertion was added to merge_trees() already a few commits ago.) The differences in pre-conditions stem from two factors: (1) merge_trees() does not recurse and thus does not have multiple sub-merges to worry about -- each of which would require a different value for opt->ancestor, (2) merge_trees() is only passed trees rather than commits and thus cannot internally guess as good of a label. Thus, while external callers of merge_trees() are required to provide a non-NULL opt->ancestor, merge_recursive() expects to set this value itself. Signed-off-by: Elijah Newren --- merge-recursive.c | 16 ++- t/t6036-recursive-corner-cases.sh | 8 +- t/t6047-diff3-conflict-markers.sh | 189 ++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+), 4 deletions(-) create mode 100755 t/t6047-diff3-conflict-markers.sh diff --git a/merge-recursive.c b/merge-recursive.c index a67ea4957a..e6b84db2ef 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3507,6 +3507,11 @@ int merge_recursive(struct merge_options *opt, struct commit *merged_common_ancestors; struct tree *mrtree; int clean; + const char *ancestor_name; + struct strbuf merge_base_abbrev = STRBUF_INIT; + + if (!opt->call_depth) + assert(opt->ancestor == NULL); if (show(opt, 4)) { output(opt, 4, _("Merging:")); @@ -3535,6 +3540,14 @@ int merge_recursive(struct merge_options *opt, tree = lookup_tree(opt->repo, opt->repo->hash_algo->empty_tree); merged_common_ancestors = make_virtual_commit(opt->repo, tree, "ancestor"); + ancestor_name = "empty tree"; + } else if (ca) { + ancestor_name = "merged common ancestors"; + } else { + strbuf_add_unique_abbrev(&merge_base_abbrev, + &merged_common_ancestors->object.oid, + DEFAULT_ABBREV); + ancestor_name = merge_base_abbrev.buf; } for (iter = ca; iter; iter = iter->next) { @@ -3568,10 +3581,11 @@ int merge_recursive(struct merge_options *opt, if (!opt->call_depth) repo_read_index(opt->repo); - opt->ancestor = "merged common ancestors"; + opt->ancestor = ancestor_name; clean = merge_trees(opt, get_commit_tree(h1), get_commit_tree(h2), get_commit_tree(merged_common_ancestors), &mrtree); + strbuf_release(&merge_base_abbrev); if (clean < 0) { flush_output(opt); return clean; diff --git a/t/t6036-recursive-corner-cases.sh b/t/t6036-recursive-corner-cases.sh index d23b948f27..7fddcc8c73 100755 --- a/t/t6036-recursive-corner-cases.sh +++ b/t/t6036-recursive-corner-cases.sh @@ -1562,6 +1562,7 @@ test_expect_success 'check nested conflicts' ' cd nested_conflicts && git clean -f && + MASTER=$(git rev-parse --short master) && git checkout L2^0 && # Merge must fail; there is a conflict @@ -1582,7 +1583,7 @@ test_expect_success 'check nested conflicts' ' git cat-file -p R1:a >theirs && test_must_fail git merge-file --diff3 \ -L "Temporary merge branch 1" \ - -L "merged common ancestors" \ + -L "$MASTER" \ -L "Temporary merge branch 2" \ ours \ base \ @@ -1594,7 +1595,7 @@ test_expect_success 'check nested conflicts' ' git cat-file -p R1:b >theirs && test_must_fail git merge-file --diff3 \ -L "Temporary merge branch 1" \ - -L "merged common ancestors" \ + -L "$MASTER" \ -L "Temporary merge branch 2" \ ours \ base \ @@ -1732,6 +1733,7 @@ test_expect_success 'check virtual merge base with nested conflicts' ' ( cd virtual_merge_base_has_nested_conflicts && + MASTER=$(git rev-parse --short master) && git checkout L3^0 && # Merge must fail; there is a conflict @@ -1760,7 +1762,7 @@ test_expect_success 'check virtual merge base with nested conflicts' ' cp left merged-once && test_must_fail git merge-file --diff3 \ -L "Temporary merge branch 1" \ - -L "merged common ancestors" \ + -L "$MASTER" \ -L "Temporary merge branch 2" \ merged-once \ base \ diff --git a/t/t6047-diff3-conflict-markers.sh b/t/t6047-diff3-conflict-markers.sh new file mode 100755 index 0000000000..3fb68e0aae --- /dev/null +++ b/t/t6047-diff3-conflict-markers.sh @@ -0,0 +1,189 @@ +#!/bin/sh + +test_description='recursive merge diff3 style conflict markers' + +. ./test-lib.sh + +# Setup: +# L1 +# \ +# ? +# / +# R1 +# +# Where: +# L1 and R1 both have a file named 'content' but have no common history +# + +test_expect_success 'setup no merge base' ' + test_create_repo no_merge_base && + ( + cd no_merge_base && + + git checkout -b L && + test_commit A content A && + + git checkout --orphan R && + test_commit B content B + ) +' + +test_expect_success 'check no merge base' ' + ( + cd no_merge_base && + + git checkout L^0 && + + test_must_fail git -c merge.conflictstyle=diff3 merge --allow-unrelated-histories -s recursive R^0 && + + grep "|||||| empty tree" content + ) +' + +# Setup: +# L1 +# / \ +# master ? +# \ / +# R1 +# +# Where: +# L1 and R1 have modified the same file ('content') in conflicting ways +# + +test_expect_success 'setup unique merge base' ' + test_create_repo unique_merge_base && + ( + cd unique_merge_base && + + test_commit base content "1 +2 +3 +4 +5 +" && + + git branch L && + git branch R && + + git checkout L && + test_commit L content "1 +2 +3 +4 +5 +7" && + + git checkout R && + git rm content && + test_commit R renamed "1 +2 +3 +4 +5 +six" + ) +' + +test_expect_success 'check unique merge base' ' + ( + cd unique_merge_base && + + git checkout L^0 && + MASTER=$(git rev-parse --short master) && + + test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 && + + grep "|||||| $MASTER:content" renamed + ) +' + +# Setup: +# L1---L2--L3 +# / \ / \ +# master X1 ? +# \ / \ / +# R1---R2--R3 +# +# Where: +# commits L1 and R1 have modified the same file in non-conflicting ways +# X1 is an auto-generated merge-base used when merging L1 and R1 +# commits L2 and R2 are merges of R1 and L1 into L1 and R1, respectively +# commits L3 and R3 both modify 'content' in conflicting ways +# + +test_expect_success 'setup multiple merge bases' ' + test_create_repo multiple_merge_bases && + ( + cd multiple_merge_bases && + + test_commit initial content "1 +2 +3 +4 +5" && + + git branch L && + git branch R && + + # Create L1 + git checkout L && + test_commit L1 content "0 +1 +2 +3 +4 +5" && + + # Create R1 + git checkout R && + test_commit R1 content "1 +2 +3 +4 +5 +6" && + + # Create L2 + git checkout L && + git merge R1 && + + # Create R2 + git checkout R && + git merge L1 && + + # Create L3 + git checkout L && + test_commit L3 content "0 +1 +2 +3 +4 +5 +A" && + + # Create R3 + git checkout R && + git rm content && + test_commit R3 renamed "0 +2 +3 +4 +5 +six" + ) +' + +test_expect_success 'check multiple merge bases' ' + ( + cd multiple_merge_bases && + + git checkout L^0 && + + test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 && + + grep "|||||| merged common ancestors:content" renamed + ) +' + +test_done From patchwork Sat Aug 17 18:41:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE73A1510 for ; Sat, 17 Aug 2019 18:42:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DF832892D for ; Sat, 17 Aug 2019 18:42:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 920F62893A; Sat, 17 Aug 2019 18:42:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EE312892D for ; Sat, 17 Aug 2019 18:42:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbfHQSmI (ORCPT ); Sat, 17 Aug 2019 14:42:08 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37944 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbfHQSmF (ORCPT ); Sat, 17 Aug 2019 14:42:05 -0400 Received: by mail-pf1-f196.google.com with SMTP id o70so4812470pfg.5 for ; Sat, 17 Aug 2019 11:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZgRaETQ/I0RilKLbq76Nx+w+n9xogRK5VVIrBGj94JE=; b=pNA2xJ8WNaoi4LD49MzSOsDZ+x/OEexVDP0sLPKhpTEUtJ6AAE4+6Qi14GhC0yxKnQ AT1QEZfVCIZXt8zvwJv4xMtHuyL5Fc7oe8KecGrLoQdaBXkkTb2wapQl+J+M/kc+HwtY PFYto+TOYDn8UBqendwW90g/x8AXAs92lisftbkw1EY6H4dXyd45XxvRrEThUSP6OHeC uS3SZy3Hd/pW1XQPVZ9Aku7DhHS9SEt5sEqEWZ15jd58DpbEy4E79ztziXWUhlW8vU1z mAi3M9aejOxLhEry4QxT9lILSHVeQjPjeLWkbqTqS/oC8C4gzti25aA0ZobyyIIWZOy5 BEgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZgRaETQ/I0RilKLbq76Nx+w+n9xogRK5VVIrBGj94JE=; b=BjejBc8gNWPspTzn1Tplz/4qy/4oqGD8GDocPCVQHPbI7/rn2oFzRErKAIe+drvYWc JeFAAJkrpdiCxc3/U7yJ2yfRBAUeOh9Aqa45y6+vvWGo0wpu3E19zCNOVAAIszBQGpJt DJrnSVfrzaQhkumyd4Gp18h5XiPCmPQQMpvdxlvc3Xool1cKdOErNblh58gSx7GJr/8e Q8rXoPPUpeXXQd7DHlLr/3Af6jqrdawKtS8H1c1EFysUlLCNukxzRU/31BZb7iKR3n75 CN2typ8OF6oINMjtNLTvJTxY+cufkD8FRkXqZ4lK20kIKZGUrG0a6QD7eBPuEN+kmsrI zjNQ== X-Gm-Message-State: APjAAAVHw1MLOLmtOiwQ0avvCTwenejjkRIBvhHm/D8nYywNQ/OCcvN1 /1uDWNwnHsWi57X7t2jPx3vokFNM X-Google-Smtp-Source: APXvYqy7dc266/0Uj2JJY2AcIdtys3RDFuL8AM35O8YHUNlg/MtgsIq+73evU1H92tROLwWyhuxYsg== X-Received: by 2002:a62:83c9:: with SMTP id h192mr16322134pfe.57.1566067324537; Sat, 17 Aug 2019 11:42:04 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:03 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Derrick Stolee , Elijah Newren Subject: [PATCH v4 05/24] merge-recursive: introduce an enum for detect_directory_renames values Date: Sat, 17 Aug 2019 11:41:25 -0700 Message-Id: <20190817184144.32179-6-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Derrick Stolee Improve code readability by introducing an enum to replace the not-quite-boolean values taken on by detect_directory_renames. Signed-off-by: Derrick Stolee Signed-off-by: Elijah Newren --- builtin/am.c | 2 +- merge-recursive.c | 24 +++++++++++++++--------- merge-recursive.h | 6 +++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 1aea657a7f..037e828efe 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1538,7 +1538,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa o.branch1 = "HEAD"; their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg); o.branch2 = their_tree_name; - o.detect_directory_renames = 0; + o.detect_directory_renames = MERGE_DIRECTORY_RENAMES_NONE; if (state->quiet) o.verbosity = 0; diff --git a/merge-recursive.c b/merge-recursive.c index e6b84db2ef..9622781612 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1375,7 +1375,8 @@ static int handle_rename_via_dir(struct merge_options *opt, const struct rename *ren = ci->ren1; const struct diff_filespec *dest = ren->pair->two; char *file_path = dest->path; - int mark_conflicted = (opt->detect_directory_renames == 1); + int mark_conflicted = (opt->detect_directory_renames == + MERGE_DIRECTORY_RENAMES_CONFLICT); assert(ren->dir_rename_original_dest); if (!opt->call_depth && would_lose_untracked(opt, dest->path)) { @@ -2860,8 +2861,9 @@ static int detect_and_process_renames(struct merge_options *opt, head_pairs = get_diffpairs(opt, common, head); merge_pairs = get_diffpairs(opt, common, merge); - if ((opt->detect_directory_renames == 2) || - (opt->detect_directory_renames == 1 && !opt->call_depth)) { + if ((opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE) || + (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT && + !opt->call_depth)) { dir_re_head = get_directory_renames(head_pairs); dir_re_merge = get_directory_renames(merge_pairs); @@ -3119,7 +3121,8 @@ static int handle_rename_normal(struct merge_options *opt, clean = handle_content_merge(&mfi, opt, path, was_dirty(opt, path), o, a, b, ci); - if (clean && opt->detect_directory_renames == 1 && + if (clean && + opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT && ren->dir_rename_original_dest) { if (update_stages(opt, path, NULL, @@ -3164,12 +3167,12 @@ static int warn_about_dir_renamed_entries(struct merge_options *opt, return clean; /* Sanity checks */ - assert(opt->detect_directory_renames > 0); + assert(opt->detect_directory_renames > MERGE_DIRECTORY_RENAMES_NONE); assert(ren->dir_rename_original_type == 'A' || ren->dir_rename_original_type == 'R'); /* Check whether to treat directory renames as a conflict */ - clean = (opt->detect_directory_renames == 2); + clean = (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE); is_add = (ren->dir_rename_original_type == 'A'); if (ren->dir_rename_original_type == 'A' && clean) { @@ -3679,9 +3682,12 @@ static void merge_recursive_config(struct merge_options *opt) if (!git_config_get_string("merge.directoryrenames", &value)) { int boolval = git_parse_maybe_bool(value); if (0 <= boolval) { - opt->detect_directory_renames = boolval ? 2 : 0; + opt->detect_directory_renames = boolval ? + MERGE_DIRECTORY_RENAMES_TRUE : + MERGE_DIRECTORY_RENAMES_NONE; } else if (!strcasecmp(value, "conflict")) { - opt->detect_directory_renames = 1; + opt->detect_directory_renames = + MERGE_DIRECTORY_RENAMES_CONFLICT; } /* avoid erroring on values from future versions of git */ free(value); } @@ -3701,7 +3707,7 @@ void init_merge_options(struct merge_options *opt, opt->renormalize = 0; opt->diff_detect_rename = -1; opt->merge_detect_rename = -1; - opt->detect_directory_renames = 1; + opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT; merge_recursive_config(opt); merge_verbosity = getenv("GIT_MERGE_VERBOSITY"); if (merge_verbosity) diff --git a/merge-recursive.h b/merge-recursive.h index c2b7bb65c6..f1b6ef38ae 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -22,7 +22,11 @@ struct merge_options { unsigned renormalize : 1; long xdl_opts; int verbosity; - int detect_directory_renames; + enum { + MERGE_DIRECTORY_RENAMES_NONE = 0, + MERGE_DIRECTORY_RENAMES_CONFLICT = 1, + MERGE_DIRECTORY_RENAMES_TRUE = 2 + } detect_directory_renames; int diff_detect_rename; int merge_detect_rename; int diff_rename_limit; From patchwork Sat Aug 17 18:41:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099227 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF01F1510 for ; Sat, 17 Aug 2019 18:42:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C452892D for ; Sat, 17 Aug 2019 18:42:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4DD92893A; Sat, 17 Aug 2019 18:42:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 785BB2892D for ; Sat, 17 Aug 2019 18:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbfHQSmH (ORCPT ); Sat, 17 Aug 2019 14:42:07 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44514 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726198AbfHQSmG (ORCPT ); Sat, 17 Aug 2019 14:42:06 -0400 Received: by mail-pg1-f193.google.com with SMTP id i18so4577633pgl.11 for ; Sat, 17 Aug 2019 11:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DbKESkiGpf9yu8BtF3RE9rIrceYn5i9Y2JdbozNrRyE=; b=tluUkgl+dyVmI/5BAX18tLsvSLPCuQq367OEB7KhBHhgVrSlwRoCr1gY+yLmSh2vcP ecyaIsuytmUkXKvqJ1kGunY241mUFcni8ngCivcyd7JKYsFiceFzAU4+ZLyLhRw0s0X+ KcIzpiKmHN6MJER5sckowNQ5bnjIfGK5u3XvZw94KT2nP/7oj7mvicP9pthqRfUFcE/s rAEdXGXhUWdUZwKnA0xpictz+/xOLy6AwYlHzz7J8QXHfR+SSJE/JNOmqi8SUadEwDrd riB+5ryDXBDg/chSZinTQ1nMMgrxfMK5BOO+IRVqEc0GZhS17ouzJesKKqCXQk0Vz77S C+TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DbKESkiGpf9yu8BtF3RE9rIrceYn5i9Y2JdbozNrRyE=; b=HnkGLQwgxgo+dZzJ40X5V6zCQ3jf9vGWUcQbX9lYOreogtbhFYQCg72jiGt5RZ0ieF 62Ug8poYYJAlxrrUiDPoyTWmvvyJldVdggMF+BFpqYrMofm+zWym+xjHarsA4EGgS9+D yw22lRlvcC/NF9ce7Ukip2FnidwSq9kW6hhKxaegdLENWYf1eycIShrcPRXVYwsbQxOu 6U18jC55oW/hNjrD4bhNX91VsBUqzWX4HfuWU1oB1Ef66cROYxlO+vSTVIaahK8347Q3 /OwvCtPf4WCE+NbKHfXjuLz5asUrmFNgwh6eSZb6VcpT7K5KKtJQz1848dn8Gr4Fy2sX j8tw== X-Gm-Message-State: APjAAAW834Ly/RzzHOPxWOBR8gzYx+ifktAuOoNRyhwoCY1Uo3lSwiQn +gjgh9OrpoiVtzvTcXMvTRstrywp X-Google-Smtp-Source: APXvYqxZvmbyHmhFmN5kJ3X6ca8MfSLY5e5aFe09+MBxzPGdWpU+u6qhe/8pURtA6+ClPkAle+KRwQ== X-Received: by 2002:a65:6458:: with SMTP id s24mr12820482pgv.158.1566067325438; Sat, 17 Aug 2019 11:42:05 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:04 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 06/24] merge-recursive: future-proof update_file_flags() against memory leaks Date: Sat, 17 Aug 2019 11:41:26 -0700 Message-Id: <20190817184144.32179-7-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a 'free_buf' label to which all but one of the error paths in update_file_flags() jump; that error case involves a NULL buf and is thus not a memory leak. However, make that error case execute the same deallocation code anyway so that if anyone adds any additional memory allocations or deallocations, then all error paths correctly deallocate resources. Signed-off-by: Elijah Newren --- merge-recursive.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 9622781612..1d4df952e5 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -934,9 +934,11 @@ static int update_file_flags(struct merge_options *opt, } buf = read_object_file(&contents->oid, &type, &size); - if (!buf) - return err(opt, _("cannot read object %s '%s'"), - oid_to_hex(&contents->oid), path); + if (!buf) { + ret = err(opt, _("cannot read object %s '%s'"), + oid_to_hex(&contents->oid), path); + goto free_buf; + } if (type != OBJ_BLOB) { ret = err(opt, _("blob expected for %s '%s'"), oid_to_hex(&contents->oid), path); From patchwork Sat Aug 17 18:41:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FBB6112C for ; Sat, 17 Aug 2019 18:42:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91469284F1 for ; Sat, 17 Aug 2019 18:42:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 855892892E; Sat, 17 Aug 2019 18:42:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39072284F1 for ; Sat, 17 Aug 2019 18:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726389AbfHQSmS (ORCPT ); Sat, 17 Aug 2019 14:42:18 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40255 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbfHQSmH (ORCPT ); Sat, 17 Aug 2019 14:42:07 -0400 Received: by mail-pf1-f194.google.com with SMTP id w16so4812124pfn.7 for ; Sat, 17 Aug 2019 11:42:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WzwAiJvrVxNndBuz9+KfGMQSYkmf1xJJYbzB7FpP28o=; b=C++iokm0DkDchkTd5D5SWervDjd+Ch2RjodHZKwx92YLvRUNsV2sfHZAh9G59nyZUf 96WWRzab4cEGBKoiLBPwajKXG2XDlW5efkCrUVoKcHdHqPCg/fy2kqWwwNCAAMlcJwcF 3Z3h1bWLUbsx0t4yt918ostBnX3Pm2/j92LVZsR4qsBKaFygMJV0qoBUf7XJApoNGSTg bwoUIIiFZY5JlOjX2K1GmIlKtORH3+hig3QCErFycSmzmOyBtSrUPJGuP21IaFHI7Vn1 zmqSBAoCNzoFRogXn/dhqM/RV5ife3X7mqnHVSNHeKz4iKZL1riyBwQZGta41dIKiLkn unZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WzwAiJvrVxNndBuz9+KfGMQSYkmf1xJJYbzB7FpP28o=; b=UoL5xrvJcN/qr0R56uBF6RCD5PDJxTUbihKlvjuAADPQOj/LwYoROwtdvFikUJmyTP JP3lisuxENcTidckmbWk6M4pH/VHKs+TQTJtu5a3dr2Y4nRCwlrTLN35fynCRaNd/6Ns fPpXBTm6rr8D077ydv01drlKfU3KYpV5PmHacuPeO2b9W0Z/XS1zvD4v5DAwEyDX712j E8LhfM3yImsn9BWdlZdX2G1g7eF3kwirOUoozgF4/kf0fDV277vr9WkyG2qlNd8vqbQx 1XzVw5AuiFMqjS3beOCoAYTZMCexPpGEmdHxeGYrJTIEii1qrvZwd5CV95eV5psMcdN/ 4EvQ== X-Gm-Message-State: APjAAAWJPDn1lEKfFSxPBd3jvei+5BSmvgiZ71zbLKzYqHv2cdzCf8M7 Vq628rm2pYLMLgDS4fc9E/AcAFGV X-Google-Smtp-Source: APXvYqzO85GdaA0LN1uv95hlHb2zZFs0KtDh8aVUCxxENk09kJhG5yhvunL6Tkxb8IpgoA0iF8geNg== X-Received: by 2002:a65:50c8:: with SMTP id s8mr12883658pgp.339.1566067326577; Sat, 17 Aug 2019 11:42:06 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:05 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 07/24] merge-recursive: remove another implicit dependency on the_repository Date: Sat, 17 Aug 2019 11:41:27 -0700 Message-Id: <20190817184144.32179-8-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit d7cf3a96e9a0 ("merge-recursive.c: remove implicit dependency on the_repository", 2019-01-12) and follow-ups like commit 34e7771bc644 ("Use the right 'struct repository' instead of the_repository", 2019-06-27), removed most implicit uses of the_repository. Convert calls to get_commit_tree() to instead use repo_get_commit_tree() to get rid of another. Signed-off-by: Elijah Newren --- merge-recursive.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 1d4df952e5..88a33e6e72 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3587,8 +3587,11 @@ int merge_recursive(struct merge_options *opt, repo_read_index(opt->repo); opt->ancestor = ancestor_name; - clean = merge_trees(opt, get_commit_tree(h1), get_commit_tree(h2), - get_commit_tree(merged_common_ancestors), + clean = merge_trees(opt, + repo_get_commit_tree(opt->repo, h1), + repo_get_commit_tree(opt->repo, h2), + repo_get_commit_tree(opt->repo, + merged_common_ancestors), &mrtree); strbuf_release(&merge_base_abbrev); if (clean < 0) { From patchwork Sat Aug 17 18:41:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D885F1510 for ; Sat, 17 Aug 2019 18:42:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C77D4284F1 for ; Sat, 17 Aug 2019 18:42:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB4F52892E; Sat, 17 Aug 2019 18:42:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140FD284F1 for ; Sat, 17 Aug 2019 18:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbfHQSmK (ORCPT ); Sat, 17 Aug 2019 14:42:10 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36043 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfHQSmJ (ORCPT ); Sat, 17 Aug 2019 14:42:09 -0400 Received: by mail-pg1-f195.google.com with SMTP id l21so4591015pgm.3 for ; Sat, 17 Aug 2019 11:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LBkj3NMQq0zQs0xakJ9FWCnbbLrRMRMSBvog15+djNU=; b=maxqp/yKgkxT51q35a3vqlwV9HzpXWWMmTqbpdhSVyAIKPAkwnvsC2gb6sFdBXaDi2 +ZSEMKxTttuvnCmpiC3PrlJrup9h0Z1BppwAh3vLMn8+Ld9EzQ3axDByAFa/5VFk56ER 1qV4GtEqcVWE8kEjZAqrLHIHLJPzjXqJHGeMxsvIzzpppLPT76KVKHkfw5VCv33gIFTs nLVD/cWtKRFTWWd0nTt9md1Q+r6XJqFurIzEunYXC33baRwoTv01PwvqD1eg9PnAtjSD +d5o9XFOBWjFkDyk8SFcmHCZlXH5FxbBVrSRRXPCnfRmxVHWscYRt4HVXIKGYbsnPc6L tpXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LBkj3NMQq0zQs0xakJ9FWCnbbLrRMRMSBvog15+djNU=; b=Pz9oQATCZZLRr/cKcXbZNp/z+icNKcMi0X8jgmMWh7kX3kpeZsUp/96a1Vj0oyfvfU YHS7DLH6d6BPh8zozaWqKtR4IbjXS2tI2zOUkGVqBj2AN/uFomyh/lAE+ctdYFWMP0MJ FrMG6m0ERNJDHsjJBCtHU5oUY22s1jNoAj2mk/IaR42FYAAZ3e/oit17xJQK/p0kI8kW +V/HwoWFn/qhs7P90sSXw9yHUVx1i1hNGKflEyAXinCnvGx6PaPieJ3xjgnCLlP1uj+h jClSSh9I2QfzdyHENM2zKhPsiNAknWbGCBj3mQ0CIcERWFzbIt3luPJIPHfEFxwWcQ/A p+VA== X-Gm-Message-State: APjAAAVLQiKRB0rv6GIjsSC6dcCp/zbvbYgoYZ1ZPtjyqa/8W6sq6rY/ v0W79dRoWwPm3tcGe3KpFOHGceAz X-Google-Smtp-Source: APXvYqy4NTwWa3PXG558+8XB31Zy0Fg2CeeAqsBdnSKasfmT/n/iPxgxoHN2zZ/dMDqg8OjUTlki5A== X-Received: by 2002:a63:2148:: with SMTP id s8mr12705259pgm.336.1566067327589; Sat, 17 Aug 2019 11:42:07 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:07 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 08/24] Ensure index matches head before invoking merge machinery, round N Date: Sat, 17 Aug 2019 11:41:28 -0700 Message-Id: <20190817184144.32179-9-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is the bug that just won't die; there always seems to be another form of it somewhere. See the commit message of 55f39cf7551b ("merge: fix misleading pre-merge check documentation", 2018-06-30) for a more detailed explanation), but in short: builtin/merge.c contains this important requirement for merge strategies: ...the index must be in sync with the head commit. The strategies are responsible to ensure this. This condition is important to enforce because there are two likely failure cases when the index isn't in sync with the head commit: * we silently throw away changes the user had staged before the merge * we accidentally (and silently) include changes in the merge that were not part of either of the branches/trees being merged Discarding users' work and mis-merging are both bad outcomes, especially when done silently, so naturally this rule was stated sternly -- but, unfortunately totally ignored in practice unless and until actual bugs were found. But, fear not: the bugs from this were fixed in commit ee6566e8d70d ("[PATCH] Rewrite read-tree", 2005-09-05) through a rewrite of read-tree (again, commit 55f39cf7551b has a more detailed explanation of how this affected merge). And it was fixed again in commit 160252f81626 ("git-merge-ours: make sure our index matches HEAD", 2005-11-03) ...and it was fixed again in commit 3ec62ad9ffba ("merge-octopus: abort if index does not match HEAD", 2016-04-09) ...and again in commit 65170c07d466 ("merge-recursive: avoid incorporating uncommitted changes in a merge", 2017-12-21) ...and again in commit eddd1a411d93 ("merge-recursive: enforce rule that index matches head before merging", 2018-06-30) ...with multiple testcases added to the testsuite that could be enumerated in even more commits. Then, finally, in a patch in the same series as the last fix above, the documentation about this requirement was fixed in commit 55f39cf7551b ("merge: fix misleading pre-merge check documentation", 2018-06-30), and we all lived happily ever after... Unfortunately, "ever after" apparently denotes a limited time and it expired today. The merge-recursive rule to enforce that index matches head was at the beginning of merge_trees() and would only trigger when opt->call_depth was 0. Since merge_recursive() doesn't call merge_trees() until after returning from recursing, this meant that the check wasn't triggered by merge_recursive() until it had first finished all the intermediate merges to create virtual merge bases. That is a potentially HUGE amount of computation (and writing of intermediate merge results into the .git/objects directory) before it errors out and says, in effect, "Sorry, I can't do any merging because you have some local changes that would be overwritten." Trying to enforce that all of merge_trees(), merge_recursive(), and merge_recursive_generic() checked the index == head condition earlier resulted in a bunch of broken tests. It turns out that merge_recursive() has code to drop and reload the cache while recursing to create intermediate virtual merge bases, but unfortunately that code runs even when no recursion is necessary. This unconditional dropping and reloading of the cache masked a few bugs: * builtin/merge-recursive.c: didn't even bother loading the index. * builtin/stash.c: feels like a fake 'builtin' because it repeatedly invokes git subprocesses all over the place, mixed with other operations. In particular, invoking "git reset" will reset the index on disk, but the parent process that invoked it won't automatically have its in-memory index updated. * t3030-merge-recursive.h: this test has always been broken in that it didn't make sure to make index match head before running. But, it didn't care about the index or even the merge result, just the verbose output while running. While commit eddd1a411d93 ("merge-recursive: enforce rule that index matches head before merging", 2018-06-30) should have uncovered this broken test, it used a test_must_fail wrapper around the merge-recursive call because it was known that the merge resulted in a rename/rename conflict. Thus, that fix only made this test fail for a different reason, and since the index == head check didn't happen until after coming all the way back out of the recursion, the testcase had enough information to pass the one check that it did perform. So, load the index in builtin/merge-recursive.c, reload the in-memory index in builtin/stash.c, and modify the t3030 testcase to correctly setup the index and make sure that the test fails in the expected way (meaning it reports a rename/rename conflict). This makes sure that all callers actually make the index match head. The next commit will then enforce the condition that index matches head earlier so this problem doesn't return in the future. Signed-off-by: Elijah Newren --- builtin/merge-recursive.c | 4 ++++ builtin/stash.c | 2 ++ t/t3030-merge-recursive.sh | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index 5b910e351e..a4bfd8fc51 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -1,3 +1,4 @@ +#include "cache.h" #include "builtin.h" #include "commit.h" #include "tag.h" @@ -63,6 +64,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix) if (argc - i != 3) /* "--" "" "" */ die(_("not handling anything other than two heads merge.")); + if (repo_read_index_unmerged(the_repository)) + die_resolve_conflict("merge"); + o.branch1 = argv[++i]; o.branch2 = argv[++i]; diff --git a/builtin/stash.c b/builtin/stash.c index b5a301f24d..4aa47785f9 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -427,6 +427,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, return error(_("could not save index tree")); reset_head(); + discard_cache(); + read_cache(); } } diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh index ff641b348a..a37bcc58a0 100755 --- a/t/t3030-merge-recursive.sh +++ b/t/t3030-merge-recursive.sh @@ -667,15 +667,22 @@ test_expect_success 'merging with triple rename across D/F conflict' ' test_expect_success 'merge-recursive remembers the names of all base trees' ' git reset --hard HEAD && + # make the index match $c1 so that merge-recursive below does not + # fail early + git diff --binary HEAD $c1 -- | git apply --cached && + # more trees than static slots used by oid_to_hex() for commit in $c0 $c2 $c4 $c5 $c6 $c7 do git rev-parse "$commit^{tree}" done >trees && - # ignore the return code -- it only fails because the input is weird + # ignore the return code; it only fails because the input is weird... test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out && + # ...but make sure it fails in the expected way + test_i18ngrep CONFLICT.*rename/rename out && + # merge-recursive prints in reverse order, but we do not care sort expect && sed -n "s/^virtual //p" out | sort >actual && From patchwork Sat Aug 17 18:41:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB9C4112C for ; Sat, 17 Aug 2019 18:42:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B898F284F1 for ; Sat, 17 Aug 2019 18:42:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC71E2892E; Sat, 17 Aug 2019 18:42:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20A5E284F1 for ; Sat, 17 Aug 2019 18:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726314AbfHQSmL (ORCPT ); Sat, 17 Aug 2019 14:42:11 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35890 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbfHQSmK (ORCPT ); Sat, 17 Aug 2019 14:42:10 -0400 Received: by mail-pf1-f193.google.com with SMTP id w2so4820284pfi.3 for ; Sat, 17 Aug 2019 11:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7E63A/FNjEydNDVdsvlcmOvaDHi1GZ9+a2sm/BWwLIo=; b=HChvwJ6PwUmCk7SQg5owbP0Jl0v0Iv80u47t+1cKulxd92gevXEjmY8LPaapxATYIb ry6roJW2R4kGIuesHNuTqbrsObecDXHyTSBvXsQH3R/gAyvhdRldi+1weeBM8eRBHKq/ 5xVyu57uA1s481FYxbY7F6KG/Eex6vci0VVu40nO0tWvX8pPheGkJu+k+n0xh/vsxxQZ IlPFQJhhGDZi+XdBc3733Hk2yxSb+SeMtOUjhZx5nIOBV/JQbMPUl2tj9zYVcEwZLY8w ePFnKWoxhtVURLwNGQkqM942AmXJiIsOrUR2hn2mabhLJh61XbMeozxYtI7vGEmr5XvM cziA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7E63A/FNjEydNDVdsvlcmOvaDHi1GZ9+a2sm/BWwLIo=; b=tCwSAspGyl3LVvXJ54s4NbQgLwgQukjKJeEc68A+nRR8I+hSyx2jq6Va+Q0oIUzxvx PaTjwdx2TVc31okksvrGAnmKq0hZ5eQTISovLfv815g1PLJBMr2BvecaYw9JnoeW/9Ir X0GV8akouJawRZuFtl/bwjww34YYhl4pwzHwr4TbeFhd0qN8ua+tB9R0o1tySz+IIb0U wyKTxEcuoYvcAo5FxcwokKgmunaO+dImyL028rnvtoL/ZmDyUcwRPUPeEKc460VrxOR7 xnQHTRrmYGZPDcB2aONVdnsdFgvjisKGQBAHApVVXKvGyqXRzwMkBpF5sOcirxfRql0w G/oQ== X-Gm-Message-State: APjAAAXQ0KmZ1EmjeyjhAaionBVja9J2uBRkz7BNjmSXWunsT0fhbvIJ hvcfVDTmBRelduia6yNvYyyuhMY5 X-Google-Smtp-Source: APXvYqw6l6ZAF782LZc9rGxafODWE1ip6MOxR2V/aSzdaS/Yd3hjjiNUQOWQBTdC3MA0BA9MyulkSA== X-Received: by 2002:a63:62c6:: with SMTP id w189mr12886456pgb.312.1566067328828; Sat, 17 Aug 2019 11:42:08 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:08 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 09/24] merge-recursive: exit early if index != head Date: Sat, 17 Aug 2019 11:41:29 -0700 Message-Id: <20190817184144.32179-10-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We had a rule to enforce that the index matches head, but it was found at the beginning of merge_trees() and would only trigger when opt->call_depth was 0. Since merge_recursive() doesn't call merge_trees() until after returning from recursing, this meant that the check wasn't triggered by merge_recursive() until it had first finished all the intermediate merges to create virtual merge bases. That is a potentially huge amount of computation (and writing of intermediate merge results into the .git/objects directory) before it errors out and says, in effect, "Sorry, I can't do any merging because you have some local changes that would be overwritten." Further, not enforcing this requirement earlier allowed other bugs (such as an unintentional unconditional dropping and reloading of the index in merge_recursive() even when no recursion was necessary), to mask bugs in other callers (which were fixed in the commit prior to this one). Make sure we do the index == head check at the beginning of the merge, and error out immediately if it fails. While we're at it, fix a small leak in the show-the-error codepath. Signed-off-by: Elijah Newren --- merge-recursive.c | 101 +++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 29 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 88a33e6e72..2a254d5563 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3382,23 +3382,14 @@ static int process_entry(struct merge_options *opt, return clean_merge; } -int merge_trees(struct merge_options *opt, - struct tree *head, - struct tree *merge, - struct tree *common, - struct tree **result) +static int merge_trees_internal(struct merge_options *opt, + struct tree *head, + struct tree *merge, + struct tree *common, + struct tree **result) { struct index_state *istate = opt->repo->index; int code, clean; - struct strbuf sb = STRBUF_INIT; - - assert(opt->ancestor != NULL); - - if (!opt->call_depth && repo_index_has_changes(opt->repo, head, &sb)) { - err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"), - sb.buf); - return -1; - } if (opt->subtree_shift) { merge = shift_tree_object(opt->repo, head, merge, opt->subtree_shift); @@ -3502,11 +3493,11 @@ static struct commit_list *reverse_commit_list(struct commit_list *list) * Merge the commits h1 and h2, return the resulting virtual * commit object and a flag indicating the cleanness of the merge. */ -int merge_recursive(struct merge_options *opt, - struct commit *h1, - struct commit *h2, - struct commit_list *ca, - struct commit **result) +static int merge_recursive_internal(struct merge_options *opt, + struct commit *h1, + struct commit *h2, + struct commit_list *ca, + struct commit **result) { struct commit_list *iter; struct commit *merged_common_ancestors; @@ -3515,9 +3506,6 @@ int merge_recursive(struct merge_options *opt, const char *ancestor_name; struct strbuf merge_base_abbrev = STRBUF_INIT; - if (!opt->call_depth) - assert(opt->ancestor == NULL); - if (show(opt, 4)) { output(opt, 4, _("Merging:")); output_commit_title(opt, h1); @@ -3571,7 +3559,7 @@ int merge_recursive(struct merge_options *opt, saved_b2 = opt->branch2; opt->branch1 = "Temporary merge branch 1"; opt->branch2 = "Temporary merge branch 2"; - if (merge_recursive(opt, merged_common_ancestors, iter->item, + if (merge_recursive_internal(opt, merged_common_ancestors, iter->item, NULL, &merged_common_ancestors) < 0) return -1; opt->branch1 = saved_b1; @@ -3587,12 +3575,12 @@ int merge_recursive(struct merge_options *opt, repo_read_index(opt->repo); opt->ancestor = ancestor_name; - clean = merge_trees(opt, - repo_get_commit_tree(opt->repo, h1), - repo_get_commit_tree(opt->repo, h2), - repo_get_commit_tree(opt->repo, - merged_common_ancestors), - &mrtree); + clean = merge_trees_internal(opt, + repo_get_commit_tree(opt->repo, h1), + repo_get_commit_tree(opt->repo, h2), + repo_get_commit_tree(opt->repo, + merged_common_ancestors), + &mrtree); strbuf_release(&merge_base_abbrev); if (clean < 0) { flush_output(opt); @@ -3613,6 +3601,61 @@ int merge_recursive(struct merge_options *opt, return clean; } +static int merge_start(struct merge_options *opt, struct tree *head) +{ + struct strbuf sb = STRBUF_INIT; + + if (repo_index_has_changes(opt->repo, head, &sb)) { + err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"), + sb.buf); + strbuf_release(&sb); + return -1; + } + + return 0; +} + +static void merge_finalize(struct merge_options *opt) +{ + /* Common code for wrapping up merges will be added here later */ +} + +int merge_trees(struct merge_options *opt, + struct tree *head, + struct tree *merge, + struct tree *common, + struct tree **result) +{ + int clean; + + assert(opt->ancestor != NULL); + + if (merge_start(opt, head)) + return -1; + clean = merge_trees_internal(opt, head, merge, common, result); + merge_finalize(opt); + + return clean; +} + +int merge_recursive(struct merge_options *opt, + struct commit *h1, + struct commit *h2, + struct commit_list *ca, + struct commit **result) +{ + int clean; + + assert(opt->ancestor == NULL); + + if (merge_start(opt, repo_get_commit_tree(opt->repo, h1))) + return -1; + clean = merge_recursive_internal(opt, h1, h2, ca, result); + merge_finalize(opt); + + return clean; +} + static struct commit *get_ref(struct repository *repo, const struct object_id *oid, const char *name) { From patchwork Sat Aug 17 18:41:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA5D71510 for ; Sat, 17 Aug 2019 18:42:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C46C284F1 for ; Sat, 17 Aug 2019 18:42:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9092F2892E; Sat, 17 Aug 2019 18:42:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2211F284F1 for ; Sat, 17 Aug 2019 18:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726330AbfHQSmM (ORCPT ); Sat, 17 Aug 2019 14:42:12 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42662 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbfHQSmL (ORCPT ); Sat, 17 Aug 2019 14:42:11 -0400 Received: by mail-pl1-f195.google.com with SMTP id y1so3809131plp.9 for ; Sat, 17 Aug 2019 11:42:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hyZuF/HKfohsTUwMDEAUBg5jUagV96LrohKlEzQFMU8=; b=KHvEVhtDKVYN0Vzvp58Ltt25RJKx2fKqW/tbyslmwAIy2yX+kOXy8LW+xRy0vrPHfT 0f8yQoq97x8egoppqnitSgYEGmXm6mqfe4gNzAaCYUjkyLYmIxXWLPQbCeRafJ7+geLB hZzZs1vv9JZv3mSOp3CdIt/IeAzTwa5ZZgywRBzPYJZlXtANMmKU/Wp0bp1BHjO3jG3+ m8REOAzn28XEFznoxSuOCv3KHCfTlz9FvFRgOiKKeLa8qzWEcdNe4YKelx3KyYYwvCAz SQ/Y0EbICSpSnTfbGnUPsdVIxxHwh/QC7dIFH2k7rZwc7IeV2q8dNFgt2Wk2SH+UyI6s We3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hyZuF/HKfohsTUwMDEAUBg5jUagV96LrohKlEzQFMU8=; b=JjbJ3WOXODi8QuEKw13xtpWOlE+x1u+CSQONo0kC99/HgZ0XOieqaiIoqyv1bSwQqL NBjUCLlJkNU1CoprooTGMFgNSaIV+eglAszYepv1gQAZUWCPNHRGePz842XXwCjKFpZP set304gaDjv822wlBOjPkmqrmHrSyGTd/n8Hv0jkaCgdivLfRsCifYB5M4CJDeT15741 7aMDXowvn+19Sqd9wsPy6UKDvVn01/ZzpukBS7QI1laK5R4VRMPQGK73xBgs6sWIsGPQ NEhhJYye8Ou6n9NnVKGw0WMmB0Q+GJ9mgPc+HFMoOE4VwrtNWc/u1qVEUQKCGFWouEYp y9tQ== X-Gm-Message-State: APjAAAXBYjb56QLDVadhb/MMRZZJrOfw1K1U4sOcuxdqxrkiiQfWjAan J2pRJFvRjTDpWHdQhUl5TYqpHz9e X-Google-Smtp-Source: APXvYqyqopeRjz2jOTnd/TsQLF0yT+PZea9+ni3BqvYaK2MVNxt3fwO83pSDXE/XEigTqDPlJe0hkA== X-Received: by 2002:a17:902:900a:: with SMTP id a10mr15432817plp.281.1566067329900; Sat, 17 Aug 2019 11:42:09 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:09 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 10/24] merge-recursive: remove useless parameter in merge_trees() Date: Sat, 17 Aug 2019 11:41:30 -0700 Message-Id: <20190817184144.32179-11-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP merge_trees() took a results parameter that would only be written when opt->call_depth was positive, which is never the case now that merge_trees_internal() has been split from merge_trees(). Remove the misleading and unused parameter from merge_trees(). While at it, add some comments explaining how the output of merge_trees() and merge_recursive() differ. Signed-off-by: Elijah Newren --- builtin/checkout.c | 4 +--- merge-recursive.c | 6 +++--- merge-recursive.h | 20 ++++++++++++++++---- sequencer.c | 4 ++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index d5b946dc3a..90e0eaf25e 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -708,7 +708,6 @@ static int merge_working_tree(const struct checkout_opts *opts, * give up or do a real merge, depending on * whether the merge flag was used. */ - struct tree *result; struct tree *work; struct tree *old_tree; struct merge_options o; @@ -780,8 +779,7 @@ static int merge_working_tree(const struct checkout_opts *opts, ret = merge_trees(&o, new_tree, work, - old_tree, - &result); + old_tree); if (ret < 0) exit(128); ret = reset_tree(new_tree, diff --git a/merge-recursive.c b/merge-recursive.c index 2a254d5563..4ce783dbfa 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3623,16 +3623,16 @@ static void merge_finalize(struct merge_options *opt) int merge_trees(struct merge_options *opt, struct tree *head, struct tree *merge, - struct tree *common, - struct tree **result) + struct tree *common) { int clean; + struct tree *ignored; assert(opt->ancestor != NULL); if (merge_start(opt, head)) return -1; - clean = merge_trees_internal(opt, head, merge, common, result); + clean = merge_trees_internal(opt, head, merge, common, &ignored); merge_finalize(opt); return clean; diff --git a/merge-recursive.h b/merge-recursive.h index f1b6ef38ae..18012fff9d 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -74,19 +74,31 @@ static inline int merge_detect_rename(struct merge_options *o) o->diff_detect_rename >= 0 ? o->diff_detect_rename : 1; } -/* merge_trees() but with recursive ancestor consolidation */ +/* + * merge_recursive is like merge_trees() but with recursive ancestor + * consolidation, and when successful, it creates an actual commit + * and writes its address to *result. + * + * NOTE: empirically, about a decade ago it was determined that with more + * than two merge bases, optimal behavior was found when the + * ancestors were passed in the order of oldest merge base to newest + * one. Also, ancestors will be consumed (emptied) so make a copy if + * you need it. + */ int merge_recursive(struct merge_options *o, struct commit *h1, struct commit *h2, struct commit_list *ancestors, struct commit **result); -/* rename-detecting three-way merge, no recursion */ +/* + * rename-detecting three-way merge, no recursion; result of merge is written + * to opt->repo->index. + */ int merge_trees(struct merge_options *o, struct tree *head, struct tree *merge, - struct tree *common, - struct tree **result); + struct tree *common); /* * "git-merge-recursive" can be fed trees; wrap them into diff --git a/sequencer.c b/sequencer.c index 34ebf8ed94..c4ed30f1b4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -586,7 +586,7 @@ static int do_recursive_merge(struct repository *r, struct replay_opts *opts) { struct merge_options o; - struct tree *result, *next_tree, *base_tree, *head_tree; + struct tree *next_tree, *base_tree, *head_tree; int clean; char **xopt; struct lock_file index_lock = LOCK_INIT; @@ -613,7 +613,7 @@ static int do_recursive_merge(struct repository *r, clean = merge_trees(&o, head_tree, - next_tree, base_tree, &result); + next_tree, base_tree); if (is_rebase_i(opts) && clean <= 0) fputs(o.obuf.buf, stdout); strbuf_release(&o.obuf); From patchwork Sat Aug 17 18:41:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C55ED112C for ; Sat, 17 Aug 2019 18:42:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A79284F1 for ; Sat, 17 Aug 2019 18:42:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9B862892E; Sat, 17 Aug 2019 18:42:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48CBD284F1 for ; Sat, 17 Aug 2019 18:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726357AbfHQSmO (ORCPT ); Sat, 17 Aug 2019 14:42:14 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44522 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbfHQSmM (ORCPT ); Sat, 17 Aug 2019 14:42:12 -0400 Received: by mail-pg1-f195.google.com with SMTP id i18so4577707pgl.11 for ; Sat, 17 Aug 2019 11:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iXiiIlQMqcCviuDYjOffVk+ojpLauEx41TtFe4Xh1Mk=; b=Zmnh3DKIFKPwW0pwnpQ95IofdHMHqWl2R8pPvIx0XrIbJvDWpjqlOZNWVocEswq8UM 3SHElH9Rx9r5AttaXBn22eBXOvGRHT3SqLGFbpySWCmDlTVJlS8+pTO1uJZShe829Pxq 25gIGd4tL0MULm5gSI5rerLD5yCN75v4AbokoSznGEO96A8GtrVwqsjezMtEpmPCa7ro rAykk0CQNdriu4t+UKaoB1cgGduUhqDE4ZnJMvMvYBjKU9mY1foIO8qlW1PP5Pe3PJm2 13CzU+OCHs0eSKx7Rt6a4WbBPHHi+furPIkgZJ6/gTPCTvw4/6a7I2pwwP5W7Nw+uqkx cc2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iXiiIlQMqcCviuDYjOffVk+ojpLauEx41TtFe4Xh1Mk=; b=r/l3jotUJ59uPfljqFlv1/Njx2gNPOyl7eSGnnumMxjtKzSMv4zxbhJVZfbYD66rQc 7NYTy+kAoxApfDKSFBJqaMGrsQxb+h6t3CusOAvU9aPobfZZ9Tt7PF4V1jxHSpELP/jc panj27lDsbS5wm59DLCxOxwDJKujoCTAe27Qa7FDjXYL91qx4MkUVCi8VhbXj4rJB7iD 62XaEgJ+9cyYA98cbsfoxx8O8ZNbkf2dMRwzDmwOit7562UeAAK9o8V3pFGDc5evLj3s V6aIMvLUHoYtxrszgVdTjGMnXMJl5HlpOawC0dPj0K28gAVENNSkaouQW/A5ZAp7GgTw 9tZA== X-Gm-Message-State: APjAAAWjY3mOVwfQzMlPVPGs6tz7l1P5W9fnUduS0WLOpG7NHFXYOVex uefKqnVtyltkEyhEsGR/zAVJdpR9 X-Google-Smtp-Source: APXvYqy5e2v85sOtzgtZlakjSGXvPuaFaD5csgV5cVhIUsY8JSmdiTc9RmVV2wa78gxTkDeQl0ODwQ== X-Received: by 2002:a65:6401:: with SMTP id a1mr12938831pgv.42.1566067331020; Sat, 17 Aug 2019 11:42:11 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:10 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 11/24] merge-recursive: don't force external callers to do our logging Date: Sat, 17 Aug 2019 11:41:31 -0700 Message-Id: <20190817184144.32179-12-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Alternatively, you can view this as "make the merge functions behave more similarly." merge-recursive has three different entry points: merge_trees(), merge_recursive(), and merge_recursive_generic(). Two of these would call diff_warn_rename_limit(), but merge_trees() didn't. This lead to callers of merge_trees() needing to manually call diff_warn_rename_limit() themselves. Move this to the new merge_finalize() function to make sure that all three entry points run this function. Note that there are two external callers of merge_trees(), one in sequencer.c and one in builtin/checkout.c. The one in sequencer.c is cleaned up by this patch and just transfers where the call to diff_warn_rename_limit() is made; the one in builtin/checkout.c is for switching to a different commit and in the very rare case where the warning might be triggered, it would probably be helpful to include (e.g. if someone is modifying a file that has been renamed in moving to the other commit, but there are so many renames between the commits that the limit kicks in and none are detected, it may help to have an explanation about why they got a delete/modify conflict instead of a proper content merge in a renamed file). Signed-off-by: Elijah Newren --- merge-recursive.c | 7 +++---- sequencer.c | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 4ce783dbfa..fda67dd371 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3595,9 +3595,6 @@ static int merge_recursive_internal(struct merge_options *opt, flush_output(opt); if (!opt->call_depth && opt->buffer_output < 2) strbuf_release(&opt->obuf); - if (show(opt, 2)) - diff_warn_rename_limit("merge.renamelimit", - opt->needed_rename_limit, 0); return clean; } @@ -3617,7 +3614,9 @@ static int merge_start(struct merge_options *opt, struct tree *head) static void merge_finalize(struct merge_options *opt) { - /* Common code for wrapping up merges will be added here later */ + if (show(opt, 2)) + diff_warn_rename_limit("merge.renamelimit", + opt->needed_rename_limit, 0); } int merge_trees(struct merge_options *opt, diff --git a/sequencer.c b/sequencer.c index c4ed30f1b4..094a4dd03d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -617,7 +617,6 @@ static int do_recursive_merge(struct repository *r, if (is_rebase_i(opts) && clean <= 0) fputs(o.obuf.buf, stdout); strbuf_release(&o.obuf); - diff_warn_rename_limit("merge.renamelimit", o.needed_rename_limit, 0); if (clean < 0) { rollback_lock_file(&index_lock); return clean; From patchwork Sat Aug 17 18:41:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9691A1510 for ; Sat, 17 Aug 2019 18:42:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 870B1284F1 for ; Sat, 17 Aug 2019 18:42:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ADBB2892E; Sat, 17 Aug 2019 18:42:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFE09284F1 for ; Sat, 17 Aug 2019 18:42:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726384AbfHQSmR (ORCPT ); Sat, 17 Aug 2019 14:42:17 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36395 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfHQSmN (ORCPT ); Sat, 17 Aug 2019 14:42:13 -0400 Received: by mail-pl1-f193.google.com with SMTP id g4so3834973plo.3 for ; Sat, 17 Aug 2019 11:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=svTCqw8bhIJBNIHlB2Dx/Hi5zEMw9Nn1HDbpu30uCws=; b=oLUQZGSZaEF+tXM99stP1wY+ejoT6a7zLIsbOfarFEDyA1WKz+9cgpc7D4EYrIcZhn KRSe1pMxk1YIaIR6c6yaJ0033yxBQMLK4NhXzQQGXj/1DRHUNC5loHe1+kieoDt2Z3Pl MG6RU0jguBce7dHwTUuUdsW51DJBy0ud15liOxPg2vY+U4Xqj2Es8o6+m9DGt1UIMraX WS7rPNHu3Qvm86V5HFmIuGVug62/APcdA2Bb+g5Zk4mjNnG+WKAyFAUHLeMjRHF6gFnR Z7VFPlyhjb7IUx4+gWZFPmReldP39/S/n9tnIgcM03+C59+4oAstF+px4kL/aI05mEHf zpOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=svTCqw8bhIJBNIHlB2Dx/Hi5zEMw9Nn1HDbpu30uCws=; b=ok+rLR2sgDmbleQvLUH1OrErzO7AC6EQbiCBQ/v+KoMUvXQnulDSpXPtrq4CAfie6Q g82h1VjJLSYs74DVL4aN7wlE1ztxkR2e9vkZ7B8MDi3SouFvrlx4JtzEwjmEFcjesUXo k/ppZ/bYQyGNpzh9x62hjkhC3BdPJPrnunTzyeSopSJn0mRgow0TGRIbR8bHf4ltJ4gw +aZxkg6asuYl4S3cqs4BLC1ip6qSWnUjspFceM25UjSJT8JYh+z4B2mJcrT5NKprk5rj Dx9CdbsqCgl4Hv8TwZ5gfaHKLr/J5kXhY/BWrUZH7ySZG6LZfOdgIohocogTR4h+Lkp8 baQg== X-Gm-Message-State: APjAAAVFEjDYJGDQgVoriRDXWKTSLGd9BFlgQ7FCws8frzI46Rzj7o22 KlwDKGPXaAb2Y2g/b8Uv7zZMfkuN X-Google-Smtp-Source: APXvYqxqC9iF6sx86mg5ELNwOKCAVty27JHz0myDlUk4jsB7AXEtIAE9GkTciBrvEjYw4chTs8QUmw== X-Received: by 2002:a17:902:1027:: with SMTP id b36mr14562692pla.203.1566067332132; Sat, 17 Aug 2019 11:42:12 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:11 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 12/24] cache-tree: share code between functions writing an index as a tree Date: Sat, 17 Aug 2019 11:41:32 -0700 Message-Id: <20190817184144.32179-13-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP write_tree_from_memory() appeared to be a merge-recursive special that basically duplicated write_index_as_tree(). The two have a different signature, but the bigger difference was just that write_index_as_tree() would always unconditionally read the index off of disk instead of working on the current in-memory index. So: * split out common code into write_index_as_tree_internal() * rename write_tree_from_memory() to write_inmemory_index_as_tree(), make it call write_index_as_tree_internal(), and move it to cache-tree.c Signed-off-by: Elijah Newren --- builtin/checkout.c | 2 +- cache-tree.c | 85 +++++++++++++++++++++++++++++++++------------- cache-tree.h | 3 +- merge-recursive.c | 34 ++----------------- merge-recursive.h | 1 - 5 files changed, 67 insertions(+), 58 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 90e0eaf25e..5e41fc1c01 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -760,7 +760,7 @@ static int merge_working_tree(const struct checkout_opts *opts, */ init_merge_options(&o, the_repository); o.verbosity = 0; - work = write_tree_from_memory(&o); + work = write_in_core_index_as_tree(the_repository); ret = reset_tree(new_tree, opts, 1, diff --git a/cache-tree.c b/cache-tree.c index 706ffcf188..fbb5252521 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -608,11 +608,66 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat return it; } +static int write_index_as_tree_internal(struct object_id *oid, + struct index_state *index_state, + int cache_tree_valid, + int flags, + const char *prefix) +{ + if (flags & WRITE_TREE_IGNORE_CACHE_TREE) { + cache_tree_free(&index_state->cache_tree); + cache_tree_valid = 0; + } + + if (!index_state->cache_tree) + index_state->cache_tree = cache_tree(); + + if (!cache_tree_valid && cache_tree_update(index_state, flags) < 0) + return WRITE_TREE_UNMERGED_INDEX; + + if (prefix) { + struct cache_tree *subtree; + subtree = cache_tree_find(index_state->cache_tree, prefix); + if (!subtree) + return WRITE_TREE_PREFIX_ERROR; + oidcpy(oid, &subtree->oid); + } + else + oidcpy(oid, &index_state->cache_tree->oid); + + return 0; +} + +struct tree* write_in_core_index_as_tree(struct repository *repo) { + struct object_id o; + int was_valid, ret; + + struct index_state *index_state = repo->index; + was_valid = index_state->cache_tree && + cache_tree_fully_valid(index_state->cache_tree); + + ret = write_index_as_tree_internal(&o, index_state, was_valid, 0, NULL); + if (ret == WRITE_TREE_UNMERGED_INDEX) { + int i; + fprintf(stderr, "BUG: There are unmerged index entries:\n"); + for (i = 0; i < index_state->cache_nr; i++) { + const struct cache_entry *ce = index_state->cache[i]; + if (ce_stage(ce)) + fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce), + (int)ce_namelen(ce), ce->name); + } + BUG("unmerged index entries when writing inmemory index"); + } + + return lookup_tree(repo, &index_state->cache_tree->oid); +} + + int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix) { int entries, was_valid; struct lock_file lock_file = LOCK_INIT; - int ret = 0; + int ret; hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); @@ -621,18 +676,14 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, ret = WRITE_TREE_UNREADABLE_INDEX; goto out; } - if (flags & WRITE_TREE_IGNORE_CACHE_TREE) - cache_tree_free(&index_state->cache_tree); - if (!index_state->cache_tree) - index_state->cache_tree = cache_tree(); + was_valid = !(flags & WRITE_TREE_IGNORE_CACHE_TREE) && + index_state->cache_tree && + cache_tree_fully_valid(index_state->cache_tree); - was_valid = cache_tree_fully_valid(index_state->cache_tree); - if (!was_valid) { - if (cache_tree_update(index_state, flags) < 0) { - ret = WRITE_TREE_UNMERGED_INDEX; - goto out; - } + ret = write_index_as_tree_internal(oid, index_state, was_valid, flags, + prefix); + if (!ret && !was_valid) { write_locked_index(index_state, &lock_file, COMMIT_LOCK); /* Not being able to write is fine -- we are only interested * in updating the cache-tree part, and if the next caller @@ -642,18 +693,6 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, */ } - if (prefix) { - struct cache_tree *subtree; - subtree = cache_tree_find(index_state->cache_tree, prefix); - if (!subtree) { - ret = WRITE_TREE_PREFIX_ERROR; - goto out; - } - oidcpy(oid, &subtree->oid); - } - else - oidcpy(oid, &index_state->cache_tree->oid); - out: rollback_lock_file(&lock_file); return ret; diff --git a/cache-tree.h b/cache-tree.h index 757bbc48bc..639bfa5340 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -34,7 +34,7 @@ int cache_tree_fully_valid(struct cache_tree *); int cache_tree_update(struct index_state *, int); void cache_tree_verify(struct repository *, struct index_state *); -/* bitmasks to write_cache_as_tree flags */ +/* bitmasks to write_index_as_tree flags */ #define WRITE_TREE_MISSING_OK 1 #define WRITE_TREE_IGNORE_CACHE_TREE 2 #define WRITE_TREE_DRY_RUN 4 @@ -46,6 +46,7 @@ void cache_tree_verify(struct repository *, struct index_state *); #define WRITE_TREE_UNMERGED_INDEX (-2) #define WRITE_TREE_PREFIX_ERROR (-3) +struct tree* write_in_core_index_as_tree(struct repository *repo); int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix); void prime_cache_tree(struct repository *, struct index_state *, struct tree *); diff --git a/merge-recursive.c b/merge-recursive.c index fda67dd371..ae509357f7 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -412,37 +412,6 @@ static void unpack_trees_finish(struct merge_options *opt) clear_unpack_trees_porcelain(&opt->unpack_opts); } -struct tree *write_tree_from_memory(struct merge_options *opt) -{ - struct tree *result = NULL; - struct index_state *istate = opt->repo->index; - - if (unmerged_index(istate)) { - int i; - fprintf(stderr, "BUG: There are unmerged index entries:\n"); - for (i = 0; i < istate->cache_nr; i++) { - const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce)) - fprintf(stderr, "BUG: %d %.*s\n", ce_stage(ce), - (int)ce_namelen(ce), ce->name); - } - BUG("unmerged index entries in merge-recursive.c"); - } - - if (!istate->cache_tree) - istate->cache_tree = cache_tree(); - - if (!cache_tree_fully_valid(istate->cache_tree) && - cache_tree_update(istate, 0) < 0) { - err(opt, _("error building trees")); - return NULL; - } - - result = lookup_tree(opt->repo, &istate->cache_tree->oid); - - return result; -} - static int save_files_dirs(const struct object_id *oid, struct strbuf *base, const char *path, unsigned int mode, int stage, void *context) @@ -3472,7 +3441,8 @@ static int merge_trees_internal(struct merge_options *opt, unpack_trees_finish(opt); - if (opt->call_depth && !(*result = write_tree_from_memory(opt))) + if (opt->call_depth && + !(*result = write_in_core_index_as_tree(opt->repo))) return -1; return clean; diff --git a/merge-recursive.h b/merge-recursive.h index 18012fff9d..0a3033bdb0 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -113,7 +113,6 @@ int merge_recursive_generic(struct merge_options *o, void init_merge_options(struct merge_options *o, struct repository *repo); -struct tree *write_tree_from_memory(struct merge_options *o); int parse_merge_opt(struct merge_options *out, const char *s); From patchwork Sat Aug 17 18:41:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 000E41510 for ; Sat, 17 Aug 2019 18:42:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4502284F1 for ; Sat, 17 Aug 2019 18:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D854A2892E; Sat, 17 Aug 2019 18:42:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76A25284F1 for ; Sat, 17 Aug 2019 18:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726366AbfHQSmQ (ORCPT ); Sat, 17 Aug 2019 14:42:16 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40244 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726353AbfHQSmO (ORCPT ); Sat, 17 Aug 2019 14:42:14 -0400 Received: by mail-pl1-f193.google.com with SMTP id h3so452283pls.7 for ; Sat, 17 Aug 2019 11:42:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VQ2J8FNN0rIIgDddYStkzeBGjyBYSJZXa0CgsFbbsbM=; b=IcK0CxdeTXWBgEd/MEPAOfFteHkc7JZc/ABITkEM0wE49S83XhomOLZsI+Ke07pFeA nfSZdO3cFf3OFAwQKmkYMA+hyd4sSmES8EEzWBnYnTIlL9AO/xmgyz6kfAM2beEKp1ej n++gTtlmeXWwzLlAcJWVkZ/0TLQIZRQ36JvSd9huApk8a5S+ttPGjRoPvRZNdmvCwtQB IV7K859NzrHrqwCxFuBtEP99ld+q2CotY8C+rLc4Nq9Msj58V7Aqpda86rYdwLX9GExP zkkf7w3F2MMW3QxvLkBCjctR+RoiOVYskym7GLI1AaML3bED3scnrY2ddK2cYHkGWQg5 1FLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VQ2J8FNN0rIIgDddYStkzeBGjyBYSJZXa0CgsFbbsbM=; b=GtJH8Vm63cOugTDMx4W51qKIvUWI57cb8kExO149iY56zNexo2BFZUQjkeNiKygA7o nYWiGqI2dzZYueJMwVwhzA4U89ArgjUGXtsa0lsdeAnL7cP3hnYpQgS/38fdOBk/88Bm eQX+3IKonuRgzevKJpmM+6PyupKKTCDQVDLQESDiZQOK2Z3NOjI5XosIiAtg4u44AgFf 2smvx6ri+WpoaRPOMKfaOQg6CGY3Wvzv5jlZ1dDpi+7+5+oN5FJLWvxYzLApIPYWB4CX Y9I7BJ/2BrAHMj/MdvPd0aDdYccEk2wUbETr1FGLlOmiUQqno1HxgX9oP7SyxT9q6Mu8 gOVg== X-Gm-Message-State: APjAAAV8lEk9a27Edcgen0dQLraKzJ4ZsM4HqVf6s4SIb0YxBnOKaHE8 gnXn6Hk4+afGdeHlV8XeCd4MbpI0 X-Google-Smtp-Source: APXvYqz542kALraEX+iXwy118Np5yofKNgRuPhLKj5j3UOcFkpZVYejDbamlqmkkLeJ9H7yLhdMHzA== X-Received: by 2002:a17:902:bcc2:: with SMTP id o2mr15119228pls.127.1566067333279; Sat, 17 Aug 2019 11:42:13 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:12 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 13/24] merge-recursive: fix some overly long lines Date: Sat, 17 Aug 2019 11:41:33 -0700 Message-Id: <20190817184144.32179-14-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No substantive code change, just add some line breaks to fix lines that have grown in length due to various refactorings. Most remaining lines of excessive length in merge-recursive include error messages and it's not clear that splitting those improves things. Signed-off-by: Elijah Newren --- merge-recursive.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index ae509357f7..720678c21d 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -681,7 +681,9 @@ static void add_flattened_path(struct strbuf *out, const char *s) out->buf[i] = '_'; } -static char *unique_path(struct merge_options *opt, const char *path, const char *branch) +static char *unique_path(struct merge_options *opt, + const char *path, + const char *branch) { struct path_hashmap_entry *entry; struct strbuf newpath = STRBUF_INIT; @@ -915,7 +917,8 @@ static int update_file_flags(struct merge_options *opt, } if (S_ISREG(contents->mode)) { struct strbuf strbuf = STRBUF_INIT; - if (convert_to_working_tree(opt->repo->index, path, buf, size, &strbuf)) { + if (convert_to_working_tree(opt->repo->index, + path, buf, size, &strbuf)) { free(buf); size = strbuf.len; buf = strbuf_detach(&strbuf, NULL); @@ -3393,7 +3396,8 @@ static int merge_trees_internal(struct merge_options *opt, * opposed to decaring a local hashmap is for convenience * so that we don't have to pass it to around. */ - hashmap_init(&opt->current_file_dir_set, path_hashmap_cmp, NULL, 512); + hashmap_init(&opt->current_file_dir_set, path_hashmap_cmp, + NULL, 512); get_files_dirs(opt, head); get_files_dirs(opt, merge); @@ -3502,7 +3506,8 @@ static int merge_recursive_internal(struct merge_options *opt, struct tree *tree; tree = lookup_tree(opt->repo, opt->repo->hash_algo->empty_tree); - merged_common_ancestors = make_virtual_commit(opt->repo, tree, "ancestor"); + merged_common_ancestors = make_virtual_commit(opt->repo, + tree, "ancestor"); ancestor_name = "empty tree"; } else if (ca) { ancestor_name = "merged common ancestors"; @@ -3625,7 +3630,8 @@ int merge_recursive(struct merge_options *opt, return clean; } -static struct commit *get_ref(struct repository *repo, const struct object_id *oid, +static struct commit *get_ref(struct repository *repo, + const struct object_id *oid, const char *name) { struct object *object; @@ -3660,7 +3666,8 @@ int merge_recursive_generic(struct merge_options *opt, int i; for (i = 0; i < num_base_list; ++i) { struct commit *base; - if (!(base = get_ref(opt->repo, base_list[i], oid_to_hex(base_list[i])))) + if (!(base = get_ref(opt->repo, base_list[i], + oid_to_hex(base_list[i])))) return err(opt, _("Could not parse object '%s'"), oid_to_hex(base_list[i])); commit_list_insert(base, &ca); From patchwork Sat Aug 17 18:41:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8876C112C for ; Sat, 17 Aug 2019 18:42:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7957C284F1 for ; Sat, 17 Aug 2019 18:42:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D3052892E; Sat, 17 Aug 2019 18:42:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3914284F1 for ; Sat, 17 Aug 2019 18:42:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726391AbfHQSmS (ORCPT ); Sat, 17 Aug 2019 14:42:18 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36400 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbfHQSmP (ORCPT ); Sat, 17 Aug 2019 14:42:15 -0400 Received: by mail-pl1-f196.google.com with SMTP id g4so3835000plo.3 for ; Sat, 17 Aug 2019 11:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=smKPkZrQK/U2IZRn17MXgKLLKjP2S2i661SIG0zHlM4=; b=hQhz0L3l1mi4eaD9mq7jwnWd9xDNoeBESn17DoCRsCNNsBpJdeiA0ALrp/uQcKJJ2F utWF7wULkx/B7IriAp4a3TBp64dScVHqsuVKVsXD9l3Pnycyq8ik+m+jZgI/kJ9dxT/4 w+M5HDBryfM4QBFa6N1RiPoFJ8cQA9+fehAFSQjQTObn9p5vS5yUN9AQRt9i6oZ3nYPz yXw9A6rezukl4mUPaBA3h5IrIqCZ0JYOpYKA5qjFvLvk8qubegHnxiCnXMpYZHQjf1yR z4K5yR4J37NWn4Hrk98YyMJ8ZLyipomglFwIVemiQeOI96huLrIL2efiSOJ2yrBuiynQ Qddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=smKPkZrQK/U2IZRn17MXgKLLKjP2S2i661SIG0zHlM4=; b=cVkCe5mOeUZ0p24BBoQxOT/EckFcOpVllZL0U36cnnT0Fsbm4T6Y5/QFyGRl8cxByd N1xBu68mEUAe4aAxL1m8JbjF/WTmcf3ErgrMTyAiIOSNS9gjQP6qlYSgPhJbwuqXPC4d Jlh4/X6JIqaoINwV3vP8wog3prFMZhswGn7OLRvaKZw2RHp7P2UUBnOXQaQWwtmECO1U 943WMco2t8fUhsmoxBJ15AbdYxYhR7MqTB2onH7L4txT1H1mCKfpWpH9RCILLfOIckW5 e9bMDZY5doWRX6XRC+GBGp777YHIsxGql/06kCFaxbxRu0gpUCl1iQ2r5jrcrTvpYCNa xxLw== X-Gm-Message-State: APjAAAUZGVL+XwKaKnkvitsN0Xyl21WHyP3QPjPOKslsg/ulo0eYilXP rMh2PTL5gQbG9EnDE4K8xarvvjGZ X-Google-Smtp-Source: APXvYqxLzL5AAPhSGlEHB7FlsT969UsHmR1qmXO5qZpGGwWfglDRky8TNelGJ0n493U1Hm2g0ZVkqw== X-Received: by 2002:a17:902:f81:: with SMTP id 1mr14947629plz.191.1566067334153; Sat, 17 Aug 2019 11:42:14 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:13 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 14/24] merge-recursive: use common name for ancestors/common/base_list Date: Sat, 17 Aug 2019 11:41:34 -0700 Message-Id: <20190817184144.32179-15-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP merge_trees(), merge_recursive(), and merge_recursive_generic() in their function headers used four different names for the merge base or list of merge bases they were passed: * 'common' * 'ancestors' * 'ca' * 'base_list' They were able to refer to it four different ways instead of only three by using a different name in the signature for the .c file than the .h file. Change all of these to 'merge_base' or 'merge_bases'. Signed-off-by: Elijah Newren --- merge-recursive.c | 72 ++++++++++++++++++++++++----------------------- merge-recursive.h | 14 ++++----- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 720678c21d..32871132a6 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3357,24 +3357,26 @@ static int process_entry(struct merge_options *opt, static int merge_trees_internal(struct merge_options *opt, struct tree *head, struct tree *merge, - struct tree *common, + struct tree *merge_base, struct tree **result) { struct index_state *istate = opt->repo->index; int code, clean; if (opt->subtree_shift) { - merge = shift_tree_object(opt->repo, head, merge, opt->subtree_shift); - common = shift_tree_object(opt->repo, head, common, opt->subtree_shift); + merge = shift_tree_object(opt->repo, head, merge, + opt->subtree_shift); + merge_base = shift_tree_object(opt->repo, head, merge_base, + opt->subtree_shift); } - if (oid_eq(&common->object.oid, &merge->object.oid)) { + if (oid_eq(&merge_base->object.oid, &merge->object.oid)) { output(opt, 0, _("Already up to date!")); *result = head; return 1; } - code = unpack_trees_start(opt, common, head, merge); + code = unpack_trees_start(opt, merge_base, head, merge); if (code != 0) { if (show(opt, 4) || opt->call_depth) @@ -3402,7 +3404,7 @@ static int merge_trees_internal(struct merge_options *opt, get_files_dirs(opt, merge); entries = get_unmerged(opt->repo->index); - clean = detect_and_process_renames(opt, common, head, merge, + clean = detect_and_process_renames(opt, merge_base, head, merge, entries, &re_info); record_df_conflict_files(opt, entries); if (clean < 0) @@ -3470,11 +3472,11 @@ static struct commit_list *reverse_commit_list(struct commit_list *list) static int merge_recursive_internal(struct merge_options *opt, struct commit *h1, struct commit *h2, - struct commit_list *ca, + struct commit_list *merge_bases, struct commit **result) { struct commit_list *iter; - struct commit *merged_common_ancestors; + struct commit *merged_merge_bases; struct tree *mrtree; int clean; const char *ancestor_name; @@ -3486,39 +3488,39 @@ static int merge_recursive_internal(struct merge_options *opt, output_commit_title(opt, h2); } - if (!ca) { - ca = get_merge_bases(h1, h2); - ca = reverse_commit_list(ca); + if (!merge_bases) { + merge_bases = get_merge_bases(h1, h2); + merge_bases = reverse_commit_list(merge_bases); } if (show(opt, 5)) { - unsigned cnt = commit_list_count(ca); + unsigned cnt = commit_list_count(merge_bases); output(opt, 5, Q_("found %u common ancestor:", "found %u common ancestors:", cnt), cnt); - for (iter = ca; iter; iter = iter->next) + for (iter = merge_bases; iter; iter = iter->next) output_commit_title(opt, iter->item); } - merged_common_ancestors = pop_commit(&ca); - if (merged_common_ancestors == NULL) { + merged_merge_bases = pop_commit(&merge_bases); + if (merged_merge_bases == NULL) { /* if there is no common ancestor, use an empty tree */ struct tree *tree; tree = lookup_tree(opt->repo, opt->repo->hash_algo->empty_tree); - merged_common_ancestors = make_virtual_commit(opt->repo, - tree, "ancestor"); + merged_merge_bases = make_virtual_commit(opt->repo, tree, + "ancestor"); ancestor_name = "empty tree"; - } else if (ca) { + } else if (merge_bases) { ancestor_name = "merged common ancestors"; } else { strbuf_add_unique_abbrev(&merge_base_abbrev, - &merged_common_ancestors->object.oid, + &merged_merge_bases->object.oid, DEFAULT_ABBREV); ancestor_name = merge_base_abbrev.buf; } - for (iter = ca; iter; iter = iter->next) { + for (iter = merge_bases; iter; iter = iter->next) { const char *saved_b1, *saved_b2; opt->call_depth++; /* @@ -3534,14 +3536,14 @@ static int merge_recursive_internal(struct merge_options *opt, saved_b2 = opt->branch2; opt->branch1 = "Temporary merge branch 1"; opt->branch2 = "Temporary merge branch 2"; - if (merge_recursive_internal(opt, merged_common_ancestors, iter->item, - NULL, &merged_common_ancestors) < 0) + if (merge_recursive_internal(opt, merged_merge_bases, iter->item, + NULL, &merged_merge_bases) < 0) return -1; opt->branch1 = saved_b1; opt->branch2 = saved_b2; opt->call_depth--; - if (!merged_common_ancestors) + if (!merged_merge_bases) return err(opt, _("merge returned no commit")); } @@ -3554,7 +3556,7 @@ static int merge_recursive_internal(struct merge_options *opt, repo_get_commit_tree(opt->repo, h1), repo_get_commit_tree(opt->repo, h2), repo_get_commit_tree(opt->repo, - merged_common_ancestors), + merged_merge_bases), &mrtree); strbuf_release(&merge_base_abbrev); if (clean < 0) { @@ -3597,7 +3599,7 @@ static void merge_finalize(struct merge_options *opt) int merge_trees(struct merge_options *opt, struct tree *head, struct tree *merge, - struct tree *common) + struct tree *merge_base) { int clean; struct tree *ignored; @@ -3606,7 +3608,7 @@ int merge_trees(struct merge_options *opt, if (merge_start(opt, head)) return -1; - clean = merge_trees_internal(opt, head, merge, common, &ignored); + clean = merge_trees_internal(opt, head, merge, merge_base, &ignored); merge_finalize(opt); return clean; @@ -3615,7 +3617,7 @@ int merge_trees(struct merge_options *opt, int merge_recursive(struct merge_options *opt, struct commit *h1, struct commit *h2, - struct commit_list *ca, + struct commit_list *merge_bases, struct commit **result) { int clean; @@ -3624,7 +3626,7 @@ int merge_recursive(struct merge_options *opt, if (merge_start(opt, repo_get_commit_tree(opt->repo, h1))) return -1; - clean = merge_recursive_internal(opt, h1, h2, ca, result); + clean = merge_recursive_internal(opt, h1, h2, merge_bases, result); merge_finalize(opt); return clean; @@ -3652,8 +3654,8 @@ static struct commit *get_ref(struct repository *repo, int merge_recursive_generic(struct merge_options *opt, const struct object_id *head, const struct object_id *merge, - int num_base_list, - const struct object_id **base_list, + int num_merge_bases, + const struct object_id **merge_bases, struct commit **result) { int clean; @@ -3662,14 +3664,14 @@ int merge_recursive_generic(struct merge_options *opt, struct commit *next_commit = get_ref(opt->repo, merge, opt->branch2); struct commit_list *ca = NULL; - if (base_list) { + if (merge_bases) { int i; - for (i = 0; i < num_base_list; ++i) { + for (i = 0; i < num_merge_bases; ++i) { struct commit *base; - if (!(base = get_ref(opt->repo, base_list[i], - oid_to_hex(base_list[i])))) + if (!(base = get_ref(opt->repo, merge_bases[i], + oid_to_hex(merge_bases[i])))) return err(opt, _("Could not parse object '%s'"), - oid_to_hex(base_list[i])); + oid_to_hex(merge_bases[i])); commit_list_insert(base, &ca); } } diff --git a/merge-recursive.h b/merge-recursive.h index 0a3033bdb0..6f351098a5 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -81,14 +81,14 @@ static inline int merge_detect_rename(struct merge_options *o) * * NOTE: empirically, about a decade ago it was determined that with more * than two merge bases, optimal behavior was found when the - * ancestors were passed in the order of oldest merge base to newest - * one. Also, ancestors will be consumed (emptied) so make a copy if - * you need it. + * merge_bases were passed in the order of oldest commit to newest + * commit. Also, merge_bases will be consumed (emptied) so make a + * copy if you need it. */ int merge_recursive(struct merge_options *o, struct commit *h1, struct commit *h2, - struct commit_list *ancestors, + struct commit_list *merge_bases, struct commit **result); /* @@ -98,7 +98,7 @@ int merge_recursive(struct merge_options *o, int merge_trees(struct merge_options *o, struct tree *head, struct tree *merge, - struct tree *common); + struct tree *merge_base); /* * "git-merge-recursive" can be fed trees; wrap them into @@ -107,8 +107,8 @@ int merge_trees(struct merge_options *o, int merge_recursive_generic(struct merge_options *o, const struct object_id *head, const struct object_id *merge, - int num_ca, - const struct object_id **ca, + int num_merge_bases, + const struct object_id **merge_bases, struct commit **result); void init_merge_options(struct merge_options *o, From patchwork Sat Aug 17 18:41:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52E351510 for ; Sat, 17 Aug 2019 18:42:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43240284F1 for ; Sat, 17 Aug 2019 18:42:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 370492892E; Sat, 17 Aug 2019 18:42:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6F15284F1 for ; Sat, 17 Aug 2019 18:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbfHQSmU (ORCPT ); Sat, 17 Aug 2019 14:42:20 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34947 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbfHQSmQ (ORCPT ); Sat, 17 Aug 2019 14:42:16 -0400 Received: by mail-pg1-f193.google.com with SMTP id n4so4602456pgv.2 for ; Sat, 17 Aug 2019 11:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7VWzNJ897IQ/+Pe/a92f7onUVWLrqB8+tLQYZjmRZaM=; b=dOF85R31fYYGxFdvF9ms/QG/zmeRrRTSRy7BQOW+tMMDcBboP9BSDNcyDd1cFbGaD7 WkVtEdi+MmH29jsZBa3mEB4Iz//PhgCj4dJz1YnCvrSNOchvSG9y6Xx2K0taf8l5eqaS TZ1UqsXhi2/rDikQhSErRXjoqPfbWH5aJWH+gysnVsUQ+McP7rmQNUlcU3Cug3UFpdqe nFYEG5f+jiChDBLp1uSgJUWoLNP315w5Kh7MifsC64KqP4YoUW86MT0cvmrMHR7aNIvf Qr0NHbzYxG+UhOoJbpR6O3QjQumHWLyRlAzbr+VQ9kIN2cZKkzVlvnmazLDtqIi1aq5i UUhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7VWzNJ897IQ/+Pe/a92f7onUVWLrqB8+tLQYZjmRZaM=; b=T58g57FIFwtK1pggzAdgN7WEpo0Y49VXJE3YvONZNz2AghmB9YJmHAQ8LTaVYfNgqS LLiLeLF/25+QWCg+LmhYhLPwzkiPdBhNuIDtF60r8N+wVA0XMHknnAHseKbppD2I3YWR nBVaefWnSmySPiFdsRYhQWt6xngPxkRnje6km9g6YKrNz15VL+Oc/T0kyTBqq85lRioI WB05v5gZk5XpyqWhhlK0RGpvnG3EtEc8uzzbG+DhoI3nNTjoZ7IaEbQe/eqbQgpDbWs/ 22w7msvyED7JLBuaSPHnFxpyEZFJn3s/QFu/5on6ZKj00mIxvEKL2KYVAbDjzqWl7IKo e6oA== X-Gm-Message-State: APjAAAW1y2xF2gppvJgga5WmYqprfL8liZsQOn5/N8lPXJxEiYzO48xI VAWfUeHTDEyh88ZBE5MrHoB66TZx X-Google-Smtp-Source: APXvYqxkTbF7ZvMAkBX6NTEzOmuI+TUCXtmC1qosS9oRWCG1pGlpjCXYVSrlDru1k6NxLCGGeFzU9A== X-Received: by 2002:a63:b60b:: with SMTP id j11mr1697231pgf.283.1566067335146; Sat, 17 Aug 2019 11:42:15 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:14 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 15/24] merge-recursive: rename 'mrtree' to 'result_tree', for clarity Date: Sat, 17 Aug 2019 11:41:35 -0700 Message-Id: <20190817184144.32179-16-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is not at all clear what 'mr' was supposed to stand for, at least not to me. Pick a clearer name for this variable. Signed-off-by: Elijah Newren --- merge-recursive.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 32871132a6..1823a87706 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3477,7 +3477,7 @@ static int merge_recursive_internal(struct merge_options *opt, { struct commit_list *iter; struct commit *merged_merge_bases; - struct tree *mrtree; + struct tree *result_tree; int clean; const char *ancestor_name; struct strbuf merge_base_abbrev = STRBUF_INIT; @@ -3557,7 +3557,7 @@ static int merge_recursive_internal(struct merge_options *opt, repo_get_commit_tree(opt->repo, h2), repo_get_commit_tree(opt->repo, merged_merge_bases), - &mrtree); + &result_tree); strbuf_release(&merge_base_abbrev); if (clean < 0) { flush_output(opt); @@ -3565,7 +3565,8 @@ static int merge_recursive_internal(struct merge_options *opt, } if (opt->call_depth) { - *result = make_virtual_commit(opt->repo, mrtree, "merged tree"); + *result = make_virtual_commit(opt->repo, result_tree, + "merged tree"); commit_list_insert(h1, &(*result)->parents); commit_list_insert(h2, &(*result)->parents->next); } From patchwork Sat Aug 17 18:41:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 486EA112C for ; Sat, 17 Aug 2019 18:42:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A5A4284F1 for ; Sat, 17 Aug 2019 18:42:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E1052892E; Sat, 17 Aug 2019 18:42:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50C6D284F1 for ; Sat, 17 Aug 2019 18:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726435AbfHQSmY (ORCPT ); Sat, 17 Aug 2019 14:42:24 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35759 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfHQSmR (ORCPT ); Sat, 17 Aug 2019 14:42:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id d85so4828227pfd.2 for ; Sat, 17 Aug 2019 11:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UKPxK25y+eu7hDqNSk9jPOQDjCr6wx6XuXJ7Tm4Uw/E=; b=LCsUnBcxNobjbELxOS4hHxlF7LhX11K3aXZVuMAmqqu1br4Hn/n5s2chzo5GBcLyaP C5Qwv32n84OjY1/STcE1FzCiuzlIbQ0fyoCNaj9NJrCNyy4O6Nc9fxHCaaU6Rim/xU2G UjDI5Z81b4gBmKTJbGZBJLGoFdnX6LrJHpnhYWBMEVaXan6x3hQRlmy60liTTgzqAlym aPntTTdfQPBs5vtg1KPq1ak+jaowZb1hVAp5UoqK0lhzNrNqinYdK3wwf7fHtnFlnRVB o5+A55Aa31t4gkDt6D2RoUmS0hR/xfJKFuRmIYK7nggU7kO0Wk4lvpCezPRnUKp2P/Gv jZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UKPxK25y+eu7hDqNSk9jPOQDjCr6wx6XuXJ7Tm4Uw/E=; b=JwUr5j2IE/X1hRqqo6SG4yJ37YD33igOglqfTwBhE1pYQ+iDJlIe+bB1z/+wqndsts w20TP9aEVErDymUm76f+6pV8DUaE//1evXCvLjQTnvYYj/UVs+2RfXvSTjM7VgepwCMI nRwCbdf1SmivNyjZZ0kwwASWyJtKy0Yc7+CVkomXtdZmpoOr5Cz26+G4w5P6p+Ao/djY m790UbelC90NJYLoSnMuRSMN56tON2eYat+78C+3kSAKLk1sD8G3JmynfB3s32ciI+dY cn1dIs7SGMUm8cjKQgvlwqIQgDM5IB3pf3WjUpeYaE9UyBZS4WTDcCIn/wR5F8TkR1FK wQwg== X-Gm-Message-State: APjAAAUpxpznPMF2D2BT5W39lQ4wdAXwJMZweMJTOildTL16TGt5kQk9 q/cTcWt4C6lDgSaw+r2He1MgSbzv X-Google-Smtp-Source: APXvYqxo/xuUbCNQqnEbY1BoLpkdh3iK0YFKUcgCTK/UJfqD07nALOP3MUGsSqUpDz0BJn8TUfhJeA== X-Received: by 2002:a17:90a:b395:: with SMTP id e21mr13057606pjr.76.1566067336442; Sat, 17 Aug 2019 11:42:16 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:15 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 16/24] merge-recursive: rename merge_options argument to opt in header Date: Sat, 17 Aug 2019 11:41:36 -0700 Message-Id: <20190817184144.32179-17-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In commit 259ccb6cc324 ("merge-recursive: rename merge_options argument from 'o' to 'opt'", 2019-04-05), I renamed a bunch of function arguments in merge-recursive.c, but forgot to make that same change to merge-recursive.h. Make the two match. Signed-off-by: Elijah Newren --- merge-recursive.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/merge-recursive.h b/merge-recursive.h index 6f351098a5..2cb3844ad9 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -68,10 +68,10 @@ struct collision_entry { unsigned reported_already:1; }; -static inline int merge_detect_rename(struct merge_options *o) +static inline int merge_detect_rename(struct merge_options *opt) { - return o->merge_detect_rename >= 0 ? o->merge_detect_rename : - o->diff_detect_rename >= 0 ? o->diff_detect_rename : 1; + return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename : + opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1; } /* @@ -85,7 +85,7 @@ static inline int merge_detect_rename(struct merge_options *o) * commit. Also, merge_bases will be consumed (emptied) so make a * copy if you need it. */ -int merge_recursive(struct merge_options *o, +int merge_recursive(struct merge_options *opt, struct commit *h1, struct commit *h2, struct commit_list *merge_bases, @@ -95,7 +95,7 @@ int merge_recursive(struct merge_options *o, * rename-detecting three-way merge, no recursion; result of merge is written * to opt->repo->index. */ -int merge_trees(struct merge_options *o, +int merge_trees(struct merge_options *opt, struct tree *head, struct tree *merge, struct tree *merge_base); @@ -104,16 +104,16 @@ int merge_trees(struct merge_options *o, * "git-merge-recursive" can be fed trees; wrap them into * virtual commits and call merge_recursive() proper. */ -int merge_recursive_generic(struct merge_options *o, +int merge_recursive_generic(struct merge_options *opt, const struct object_id *head, const struct object_id *merge, int num_merge_bases, const struct object_id **merge_bases, struct commit **result); -void init_merge_options(struct merge_options *o, +void init_merge_options(struct merge_options *opt, struct repository *repo); -int parse_merge_opt(struct merge_options *out, const char *s); +int parse_merge_opt(struct merge_options *opt, const char *s); #endif From patchwork Sat Aug 17 18:41:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099247 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEEA31510 for ; Sat, 17 Aug 2019 18:42:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFE4C284F1 for ; Sat, 17 Aug 2019 18:42:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B3C2892E; Sat, 17 Aug 2019 18:42:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37910284F1 for ; Sat, 17 Aug 2019 18:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbfHQSmU (ORCPT ); Sat, 17 Aug 2019 14:42:20 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41036 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfHQSmS (ORCPT ); Sat, 17 Aug 2019 14:42:18 -0400 Received: by mail-pg1-f193.google.com with SMTP id x15so4581323pgg.8 for ; Sat, 17 Aug 2019 11:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fLtjfjVSwf1iIxIP8Fe28GktKoGFCcz97TWeMQ84cP0=; b=WyV3qbcNVKfHM6jAWrOcIGEUhCI46UjjHldJCfS990Sxmh+vVj/4uyAyxezFn2iABS oBbX8ndrFHxtnswzBWSaf/fX9y48HNIB8ncEEi0r/pRVa2SyI0cPxVGuG37D1/z7bsXh B2LFHR6j+xhLCF+TjTAjY0givH/Bsr/Eu9qmZov7PPUDAenSklHoemH/esjmLX2AXU4W 8sUFV7FMR4hPl00b8U+O25YKR9KHyjFXJz/2uOq4Cm+WEl+3vsKs7O++9rfk1xzcnFJv XvD7uwkiw3C3C0R/ithclOu1gwf08phUvyTAXm2tE6vMLXai0eFvI91/ZEz91BSRuT7/ 3RVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fLtjfjVSwf1iIxIP8Fe28GktKoGFCcz97TWeMQ84cP0=; b=rHvSO+VgFgC3ta9GxOhhInS9j6Rran2Bmf7kELEdl2SJzJLJc1NAwjPJK6XfyQrXew X17HhlZpSh2/23NaACehvY3JHEqOw4e/8lQ0kS2PvashH52e/HXzgn24K+hGpJ5sVKM0 aDKcEheMwRadtINDTTD+eOdd1+rlfGMjcGAm1SnTxpIWkllyJOp6Zyencj7Joc5qi7C8 nda6fUm6n86YwVJVW8SWDSd1phAGjvKJxNSDuA6o4jyA/86+SP6rtPRPlLnHRBIzqMhr WZaMUOu42F5tU3ah46Y1L8N2KYUvXyrZv8/hqafmMpRAeAp6fWbG09vAjZQa8FmGmQuk /qRA== X-Gm-Message-State: APjAAAVN6kvTbPZeGnBABi42mw/8p+FaAoCrHmII4Wu3IF0dEeDPa3+D Ah6u8sDSQFd23VmrcvofGrhQy4u4 X-Google-Smtp-Source: APXvYqzrHlfT6DpbzZnNT5tzNulrAEgi18y4nZuO4A26t4Bz+TFYuFbeS4+yjUfNN7ZWGkE3xfT8Pw== X-Received: by 2002:a63:20d:: with SMTP id 13mr13214830pgc.253.1566067337402; Sat, 17 Aug 2019 11:42:17 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:16 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 17/24] merge-recursive: move some definitions around to clean up the header Date: Sat, 17 Aug 2019 11:41:37 -0700 Message-Id: <20190817184144.32179-18-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No substantive code changes (view this with diff --color-moved), but a few small code cleanups: * Move structs and an inline function only used by merge-recursive.c into merge-recursive.c * Re-order function declarations to be more logical * Add or fix some explanatory comments Signed-off-by: Elijah Newren --- merge-recursive.c | 31 +++++++++++++++++ merge-recursive.h | 87 +++++++++++++++++++++++------------------------ 2 files changed, 73 insertions(+), 45 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 1823a87706..9807b24c65 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -54,6 +54,24 @@ static unsigned int path_hash(const char *path) return ignore_case ? strihash(path) : strhash(path); } +/* + * For dir_rename_entry, directory names are stored as a full path from the + * toplevel of the repository and do not include a trailing '/'. Also: + * + * dir: original name of directory being renamed + * non_unique_new_dir: if true, could not determine new_dir + * new_dir: final name of directory being renamed + * possible_new_dirs: temporary used to help determine new_dir; see comments + * in get_directory_renames() for details + */ +struct dir_rename_entry { + struct hashmap_entry ent; /* must be the first member! */ + char *dir; + unsigned non_unique_new_dir:1; + struct strbuf new_dir; + struct string_list possible_new_dirs; +}; + static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap, char *dir) { @@ -92,6 +110,13 @@ static void dir_rename_entry_init(struct dir_rename_entry *entry, string_list_init(&entry->possible_new_dirs, 0); } +struct collision_entry { + struct hashmap_entry ent; /* must be the first member! */ + char *target_file; + struct string_list source_files; + unsigned reported_already:1; +}; + static struct collision_entry *collision_find_entry(struct hashmap *hashmap, char *target_file) { @@ -358,6 +383,12 @@ static int add_cacheinfo(struct merge_options *opt, return ret; } +static inline int merge_detect_rename(struct merge_options *opt) +{ + return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename : + opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1; +} + static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree) { parse_tree(tree); diff --git a/merge-recursive.h b/merge-recursive.h index 2cb3844ad9..0fdae904dd 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -43,47 +43,50 @@ struct merge_options { struct repository *repo; }; +void init_merge_options(struct merge_options *opt, struct repository *repo); + +/* parse the option in s and update the relevant field of opt */ +int parse_merge_opt(struct merge_options *opt, const char *s); + /* - * For dir_rename_entry, directory names are stored as a full path from the - * toplevel of the repository and do not include a trailing '/'. Also: - * - * dir: original name of directory being renamed - * non_unique_new_dir: if true, could not determine new_dir - * new_dir: final name of directory being renamed - * possible_new_dirs: temporary used to help determine new_dir; see comments - * in get_directory_renames() for details + * RETURN VALUES: All the merge_* functions below return a value as follows: + * > 0 Merge was clean + * = 0 Merge had conflicts + * < 0 Merge hit an unexpected and unrecoverable problem (e.g. disk + * full) and aborted merge part-way through. */ -struct dir_rename_entry { - struct hashmap_entry ent; /* must be the first member! */ - char *dir; - unsigned non_unique_new_dir:1; - struct strbuf new_dir; - struct string_list possible_new_dirs; -}; - -struct collision_entry { - struct hashmap_entry ent; /* must be the first member! */ - char *target_file; - struct string_list source_files; - unsigned reported_already:1; -}; -static inline int merge_detect_rename(struct merge_options *opt) -{ - return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename : - opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1; -} +/* + * rename-detecting three-way merge, no recursion. + * + * Outputs: + * - See RETURN VALUES above + * - No commit is created + * - opt->repo->index has the new index + * - $GIT_INDEX_FILE is not updated + * - The working tree is updated with results of the merge + */ +int merge_trees(struct merge_options *opt, + struct tree *head, + struct tree *merge, + struct tree *merge_base); /* * merge_recursive is like merge_trees() but with recursive ancestor - * consolidation, and when successful, it creates an actual commit - * and writes its address to *result. + * consolidation and, if the commit is clean, creation of a commit. * * NOTE: empirically, about a decade ago it was determined that with more * than two merge bases, optimal behavior was found when the * merge_bases were passed in the order of oldest commit to newest * commit. Also, merge_bases will be consumed (emptied) so make a * copy if you need it. + * + * Outputs: + * - See RETURN VALUES above + * - If merge is clean, a commit is created and its address written to *result + * - opt->repo->index has the new index + * - $GIT_INDEX_FILE is not updated + * - The working tree is updated with results of the merge */ int merge_recursive(struct merge_options *opt, struct commit *h1, @@ -92,17 +95,16 @@ int merge_recursive(struct merge_options *opt, struct commit **result); /* - * rename-detecting three-way merge, no recursion; result of merge is written - * to opt->repo->index. - */ -int merge_trees(struct merge_options *opt, - struct tree *head, - struct tree *merge, - struct tree *merge_base); - -/* - * "git-merge-recursive" can be fed trees; wrap them into - * virtual commits and call merge_recursive() proper. + * merge_recursive_generic can operate on trees instead of commits, by + * wrapping the trees into virtual commits, and calling merge_recursive(). + * It also writes out the in-memory index to disk if the merge is successful. + * + * Outputs: + * - See RETURN VALUES above + * - If merge is clean, a commit is created and its address written to *result + * - opt->repo->index has the new index + * - $GIT_INDEX_FILE is updated + * - The working tree is updated with results of the merge */ int merge_recursive_generic(struct merge_options *opt, const struct object_id *head, @@ -111,9 +113,4 @@ int merge_recursive_generic(struct merge_options *opt, const struct object_id **merge_bases, struct commit **result); -void init_merge_options(struct merge_options *opt, - struct repository *repo); - -int parse_merge_opt(struct merge_options *opt, const char *s); - #endif From patchwork Sat Aug 17 18:41:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 016F2174A for ; Sat, 17 Aug 2019 18:42:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6F15284F1 for ; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DADC22892E; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F437284F1 for ; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726470AbfHQSm2 (ORCPT ); Sat, 17 Aug 2019 14:42:28 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37851 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbfHQSmU (ORCPT ); Sat, 17 Aug 2019 14:42:20 -0400 Received: by mail-pg1-f193.google.com with SMTP id d1so3995653pgp.4 for ; Sat, 17 Aug 2019 11:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y7mnXMhjArvZX+slKut5E+j3BeiYKO20yPJjbPgTK8o=; b=tpw141HAfwVQn23+c6EEuCtO7uByP8etKJlWw5JboAb5zBgdixeLEaVuz94QPDnITw Io6eV34G9sx18ZGnGZ8Bu56rPvQJPef3hqtxDfeygn7hYodT9+pjpctuTkVj0yIK0TGN Ehu3ZvVIooFrSRbfeWtbeoEgJTlje70tQHLVhkClSO4Q3e6fC1Lszo10IjwTQdt4S5jJ rCUEawHQuyK3m45qHGBmNElAEpSY2JKWq2kZkjNnJe0Td70tiJSrWdPoLaE0TgS/g2Fn QUObHoJ4NR6P3ivNHxwstHdqzpZi1cJnueMH0xwZKqBJyKSSDGaSE6iTrR0wZXUvPuDt wKMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y7mnXMhjArvZX+slKut5E+j3BeiYKO20yPJjbPgTK8o=; b=cidEIrkZl96RF6QLB84PQJq8FAg8MtuLEScBcZePemjfmyV8VgBErK7GxQXkC6PDSv LrW5EnaNg0xW+8LBTwQRWizl5yTD+lIvtmoKReyYao3eMOvhpnv++/M9skHK9bFgnTUS i5s7GlqvGMgSBKy+AwtWZj8ehsYhzW2uLsxOfvl5wh4GRLnZz9vZCSsn3OBWsw2VYbcy JluIGY80u0j/KLZ5u6L/EGVlVOt/r8Y4lBct09/J++CG12c7YYl4+DAL3Y+1FwCWiJCH w2SOkZ6CPUUrGZH72MARphAc1FUQFa8ssnvyXX1w6KGb2meiuQJ5XZoZRX6CRth52vo/ 9IXA== X-Gm-Message-State: APjAAAVQhT6vPGNbOZH2sz97SX5UDsyZQlunWkT1GYOQH8ALPYofzh6y 8JfpzNY057kbwSwSDbmWg97kQA09 X-Google-Smtp-Source: APXvYqyDFiNwL/oRBcgKIVNv8wCGy+u0yAVe7rfGnxuIuVv6kau/tzWwV8pqHxH80hl/KfmV+X4a5g== X-Received: by 2002:a63:29c4:: with SMTP id p187mr13212544pgp.330.1566067338585; Sat, 17 Aug 2019 11:42:18 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:17 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 18/24] merge-recursive: consolidate unnecessary fields in merge_options Date: Sat, 17 Aug 2019 11:41:38 -0700 Message-Id: <20190817184144.32179-19-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We provided users with the ability to state whether they wanted rename detection, and to put a limit on how much CPU would be spent. Both of these fields had multiple configuration parameters for setting them, with one being a fallback and the other being an override. However, instead of implementing the logic for how to combine the multiple source locations into the appropriate setting at config loading time, we loaded and tracked both values and then made the code combine them every time it wanted to check the overall value. This had a few minor drawbacks: * it seems more complicated than necessary * it runs the risk of people using the independent settings in the future and breaking the intent of how the options are used together * it makes merge_options more complicated than necessary for other potential users of the API Fix these problems by moving the logic for combining the pairs of options into a single value; make it apply at time-of-config-loading instead of each-time-of-use. Signed-off-by: Elijah Newren --- merge-recursive.c | 27 +++++++++++---------------- merge-recursive.h | 6 ++---- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 9807b24c65..0f0b952c04 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -385,8 +385,7 @@ static int add_cacheinfo(struct merge_options *opt, static inline int merge_detect_rename(struct merge_options *opt) { - return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename : - opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1; + return (opt->detect_renames >= 0) ? opt->detect_renames : 1; } static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree) @@ -1883,9 +1882,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *opt, */ if (opts.detect_rename > DIFF_DETECT_RENAME) opts.detect_rename = DIFF_DETECT_RENAME; - opts.rename_limit = opt->merge_rename_limit >= 0 ? opt->merge_rename_limit : - opt->diff_rename_limit >= 0 ? opt->diff_rename_limit : - 1000; + opts.rename_limit = (opt->rename_limit >= 0) ? opt->rename_limit : 1000; opts.rename_score = opt->rename_score; opts.show_rename_progress = opt->show_rename_progress; opts.output_format = DIFF_FORMAT_NO_OUTPUT; @@ -3727,14 +3724,14 @@ static void merge_recursive_config(struct merge_options *opt) { char *value = NULL; git_config_get_int("merge.verbosity", &opt->verbosity); - git_config_get_int("diff.renamelimit", &opt->diff_rename_limit); - git_config_get_int("merge.renamelimit", &opt->merge_rename_limit); + git_config_get_int("diff.renamelimit", &opt->rename_limit); + git_config_get_int("merge.renamelimit", &opt->rename_limit); if (!git_config_get_string("diff.renames", &value)) { - opt->diff_detect_rename = git_config_rename("diff.renames", value); + opt->detect_renames = git_config_rename("diff.renames", value); free(value); } if (!git_config_get_string("merge.renames", &value)) { - opt->merge_detect_rename = git_config_rename("merge.renames", value); + opt->detect_renames = git_config_rename("merge.renames", value); free(value); } if (!git_config_get_string("merge.directoryrenames", &value)) { @@ -3760,11 +3757,9 @@ void init_merge_options(struct merge_options *opt, opt->repo = repo; opt->verbosity = 2; opt->buffer_output = 1; - opt->diff_rename_limit = -1; - opt->merge_rename_limit = -1; + opt->rename_limit = -1; opt->renormalize = 0; - opt->diff_detect_rename = -1; - opt->merge_detect_rename = -1; + opt->detect_renames = -1; opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT; merge_recursive_config(opt); merge_verbosity = getenv("GIT_MERGE_VERBOSITY"); @@ -3816,16 +3811,16 @@ int parse_merge_opt(struct merge_options *opt, const char *s) else if (!strcmp(s, "no-renormalize")) opt->renormalize = 0; else if (!strcmp(s, "no-renames")) - opt->merge_detect_rename = 0; + opt->detect_renames = 0; else if (!strcmp(s, "find-renames")) { - opt->merge_detect_rename = 1; + opt->detect_renames = 1; opt->rename_score = 0; } else if (skip_prefix(s, "find-renames=", &arg) || skip_prefix(s, "rename-threshold=", &arg)) { if ((opt->rename_score = parse_rename_score(&arg)) == -1 || *arg != 0) return -1; - opt->merge_detect_rename = 1; + opt->detect_renames = 1; } /* * Please update $__git_merge_strategy_options in diff --git a/merge-recursive.h b/merge-recursive.h index 0fdae904dd..f4bdfbc897 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -27,10 +27,8 @@ struct merge_options { MERGE_DIRECTORY_RENAMES_CONFLICT = 1, MERGE_DIRECTORY_RENAMES_TRUE = 2 } detect_directory_renames; - int diff_detect_rename; - int merge_detect_rename; - int diff_rename_limit; - int merge_rename_limit; + int detect_renames; + int rename_limit; int rename_score; int needed_rename_limit; int show_rename_progress; From patchwork Sat Aug 17 18:41:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B420174A for ; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0780284F1 for ; Sat, 17 Aug 2019 18:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E462228947; Sat, 17 Aug 2019 18:42:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68799284F1 for ; Sat, 17 Aug 2019 18:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726466AbfHQSm1 (ORCPT ); Sat, 17 Aug 2019 14:42:27 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41491 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbfHQSmU (ORCPT ); Sat, 17 Aug 2019 14:42:20 -0400 Received: by mail-pf1-f195.google.com with SMTP id 196so4805179pfz.8 for ; Sat, 17 Aug 2019 11:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jcv0PXbPMTi5vCUZzskmH3oSjqL1OIJiC1N5z1hG800=; b=Ty2vEYrZ+aVc8YSjwILvZQGb+R9hue+x3GFbAkaWi/CQIzr9D6aH3eosbGFKYJgG8w kfMeyccxBtPaQNZR7KFmVPPkLYhPwI5XwhL9oADj4GLGqB5MyWk0ueUdoHXR2Tzohk7U zf1vZRjeamr6oLdYoHNgQo8iO2aUZXxgp+jAXEYuiY4r4BK2UjOtLj8e6/CZG+Ix8j8+ lLgQUhb3JZCmz3gUrq1PP/FspVdHu7O/hkdXbxwzhGI5t3sHwz//7/0zb091IlmXTYTJ WmGFRc6G73qraPEqaVKrwehWwiRkZ5AYF/CwUWmEHEO8CJ1bK/xlkV31AbT55a7lfCW9 iyNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jcv0PXbPMTi5vCUZzskmH3oSjqL1OIJiC1N5z1hG800=; b=fXd10PC9T/Uckj83noxM1yJ16xXG9J511BAP0EOOalKIrOWhhqF/NP9Sqa29ZjLWth BVuMSjyX7JacOUSDefPiWr7s4pJZU3uDm346GOrS07DPL9qcNFpYDteKlr7qKnXENPAW oXRtzZLNE6QFK5M0j8GECJXBOKj0go88oo7WWyAX0Y5g7n+4mSLJSVpaMGqadMNJ1qSL SUvmD/Y+s2pwRUattPKxMGoBjLBShKyvY365opSdfoReimjM39VCQGTePmWheXUZz8Vo JJWlT+XRHDUAc/2VtBZ0dNAdfev/wBBlI0Ry5qAMibTYhBZ4yj2uaBligzDVVj+EVqWT vNRQ== X-Gm-Message-State: APjAAAUulgAwRZZ85Sv45tu7vcRrR4N52Ffb9ZLVg/VdscY+IFW53han KPEhGsbS+zK0mLGO9XFQdyxfVkQX X-Google-Smtp-Source: APXvYqwuBJVAdUT6ac0ThinHHwyTUFOVss1dKZNENa4IHPdLNqDE0bMu2X6I3sykR2uG8lPOedGzDg== X-Received: by 2002:a65:68c9:: with SMTP id k9mr12709073pgt.17.1566067339671; Sat, 17 Aug 2019 11:42:19 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:19 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 19/24] merge-recursive: comment and reorder the merge_options fields Date: Sat, 17 Aug 2019 11:41:39 -0700 Message-Id: <20190817184144.32179-20-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The merge_options struct had lots of fields, making it a little imposing, but the options naturally fall into multiple different groups. Grouping similar options and adding a comment or two makes it easier to read, easier for new folks to figure out which options are related, and thus easier for them to find the options they need. Signed-off-by: Elijah Newren --- merge-recursive.c | 16 +++++++++++----- merge-recursive.h | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 0f0b952c04..43dec3307e 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3754,21 +3754,27 @@ void init_merge_options(struct merge_options *opt, { const char *merge_verbosity; memset(opt, 0, sizeof(struct merge_options)); + opt->repo = repo; + + opt->detect_renames = -1; + opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT; + opt->rename_limit = -1; + opt->verbosity = 2; opt->buffer_output = 1; - opt->rename_limit = -1; + strbuf_init(&opt->obuf, 0); + opt->renormalize = 0; - opt->detect_renames = -1; - opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT; + + string_list_init(&opt->df_conflict_file_set, 1); + merge_recursive_config(opt); merge_verbosity = getenv("GIT_MERGE_VERBOSITY"); if (merge_verbosity) opt->verbosity = strtol(merge_verbosity, NULL, 10); if (opt->verbosity >= 5) opt->buffer_output = 0; - strbuf_init(&opt->obuf, 0); - string_list_init(&opt->df_conflict_file_set, 1); } int parse_merge_opt(struct merge_options *opt, const char *s) diff --git a/merge-recursive.h b/merge-recursive.h index f4bdfbc897..9e040608fe 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -9,36 +9,48 @@ struct commit; struct repository; struct merge_options { + struct repository *repo; + + /* ref names used in console messages and conflict markers */ const char *ancestor; const char *branch1; const char *branch2; - enum { - MERGE_RECURSIVE_NORMAL = 0, - MERGE_RECURSIVE_OURS, - MERGE_RECURSIVE_THEIRS - } recursive_variant; - const char *subtree_shift; - unsigned buffer_output; /* 1: output at end, 2: keep buffered */ - unsigned renormalize : 1; - long xdl_opts; - int verbosity; + + /* rename related options */ + int detect_renames; enum { MERGE_DIRECTORY_RENAMES_NONE = 0, MERGE_DIRECTORY_RENAMES_CONFLICT = 1, MERGE_DIRECTORY_RENAMES_TRUE = 2 } detect_directory_renames; - int detect_renames; int rename_limit; int rename_score; - int needed_rename_limit; int show_rename_progress; + + /* xdiff-related options (patience, ignore whitespace, ours/theirs) */ + long xdl_opts; + enum { + MERGE_RECURSIVE_NORMAL = 0, + MERGE_RECURSIVE_OURS, + MERGE_RECURSIVE_THEIRS + } recursive_variant; + + /* console output related options */ + int verbosity; + unsigned buffer_output; /* 1: output at end, 2: keep buffered */ + struct strbuf obuf; /* output buffer */ + + /* miscellaneous control options */ + const char *subtree_shift; + unsigned renormalize : 1; + + /* internal fields used by the implementation (do NOT set these) */ int call_depth; - struct strbuf obuf; + int needed_rename_limit; struct hashmap current_file_dir_set; struct string_list df_conflict_file_set; struct unpack_trees_options unpack_opts; struct index_state orig_index; - struct repository *repo; }; void init_merge_options(struct merge_options *opt, struct repository *repo); From patchwork Sat Aug 17 18:41:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76B7F1510 for ; Sat, 17 Aug 2019 18:42:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6990F2892D for ; Sat, 17 Aug 2019 18:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E3E62892E; Sat, 17 Aug 2019 18:42:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F20B8284F1 for ; Sat, 17 Aug 2019 18:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726464AbfHQSm0 (ORCPT ); Sat, 17 Aug 2019 14:42:26 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37961 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfHQSmV (ORCPT ); Sat, 17 Aug 2019 14:42:21 -0400 Received: by mail-pf1-f193.google.com with SMTP id o70so4812707pfg.5 for ; Sat, 17 Aug 2019 11:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ce5RPs4QMW6M4OMn98TeAGg3EatRdbceKilb0wk89zQ=; b=qEJ2HoN2F9Zi1gTJMK3w3gFf3q23cUAoE74EDh/312L6vxK5+ZE5gsIctmTh79XfX0 /nJkcJG8ztIy/kX/iLiAUKfUkeeTkRRSyE3PKURIM2yjH1cDq5UcN9nuEYqebAtg5UuT 0hmPg2R6TmyrYMbCrxXUyo7HJhFWfE32IP5WkwxYv8+QmYtr1c3nKl6nny56Za+4Y2XL yzcI7+GXi2fg77SOXq7Y1Ev4pYBxMkGf1C36sw0dMMh7ck4itPY73NmKG2rZYka6Csrb cSHgpClPpHu69pQ6pSIIy/qmauzJO+MJZo5usu9pQO+HxVqHtgSKjl1MzVkF4PKOX9iR fvKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ce5RPs4QMW6M4OMn98TeAGg3EatRdbceKilb0wk89zQ=; b=nFGytezrr04P07iqIUDuVcxqdqa8hDYEhFn9ajpjM62ind9D9NshemvEUZvp1duD35 8rfYMZs6xB+/yzuoWN7F7ruLqcfaI5YWOA6YU91cu/gSW+uNUD5QFoZvhR/rw3lW8UxP 5yAhpeBav3Hs09DVoVFOQy4JlBWvqYetnNWGSrIpEyeSAdAmJuRWI9XmG7u0LaXH55ae IdB29IPt7g+kYDflr9XgxaI/I2U7bdRtRl6Jk//Pr9mD2Ou/FKmWweWxe9xUWJ1y+ttb IlJZ6KouKh/L52FPlzv6hSVYixAf/r8KtV/Zn90d6DPlggd6G7atDjQjd0JSSfqw9xoF aVtA== X-Gm-Message-State: APjAAAVmC0US85M9F+LeW54UC7+Wn0hRlOBRGv7pNfS0kgNRaep5ZnT5 ULXlaGU/jpHQVV/sq+EJ/eEWvWzk X-Google-Smtp-Source: APXvYqxNyS6xJ1c1e61Hm6aWETBndD7tHGAcoiRWIYYJepxKpd4Cxwfoob3ntGwjURr2EVO7/p3Peg== X-Received: by 2002:a17:90a:e2d2:: with SMTP id fr18mr3421258pjb.98.1566067340916; Sat, 17 Aug 2019 11:42:20 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:20 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 20/24] merge-recursive: avoid losing output and leaking memory holding that output Date: Sat, 17 Aug 2019 11:41:40 -0700 Message-Id: <20190817184144.32179-21-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If opt->buffer_output is less than 2, then merge_trees(), merge_recursive(), and merge_recursive_generic() are all supposed to flush the opt->obuf output buffer to stdout and release any memory it holds. merge_trees() did not do this. Move the logic that handles this for merge_recursive_internal() to merge_finalize() so that all three methods handle this requirement. Note that this bug didn't cause any problems currently, because there are only two callers of merge_trees() right now (a git grep for 'merge_trees(' is misleading because builtin/merge-tree.c also defines a 'merge_tree' function that is unrelated), and only one of those is called with buffer_output less than 2 (builtin/checkout.c), but it set opt->verbosity to 0, for which there is only currently one non-error message that would be shown: "Already up to date!". However, that one message can only occur when the merge is utterly trivial (the merge base tree exactly matches the merge tree), and builtin/checkout.c already attempts a trivial merge via unpack_trees() before falling back to merge_trees(). Also, if opt->buffer_output is 2, then the caller is responsible to handle showing any output in opt->obuf and for free'ing it. This requirement might be easy to overlook, so add a comment to merge-recursive.h pointing it out. (There are currently two callers that set buffer_output to 2, both in sequencer.c, and both of which handle this correctly.) Signed-off-by: Elijah Newren --- merge-recursive.c | 6 +++--- merge-recursive.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 43dec3307e..262db8bebb 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3598,9 +3598,6 @@ static int merge_recursive_internal(struct merge_options *opt, commit_list_insert(h1, &(*result)->parents); commit_list_insert(h2, &(*result)->parents->next); } - flush_output(opt); - if (!opt->call_depth && opt->buffer_output < 2) - strbuf_release(&opt->obuf); return clean; } @@ -3620,6 +3617,9 @@ static int merge_start(struct merge_options *opt, struct tree *head) static void merge_finalize(struct merge_options *opt) { + flush_output(opt); + if (!opt->call_depth && opt->buffer_output < 2) + strbuf_release(&opt->obuf); if (show(opt, 2)) diff_warn_rename_limit("merge.renamelimit", opt->needed_rename_limit, 0); diff --git a/merge-recursive.h b/merge-recursive.h index 9e040608fe..933d6e7642 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -38,7 +38,8 @@ struct merge_options { /* console output related options */ int verbosity; unsigned buffer_output; /* 1: output at end, 2: keep buffered */ - struct strbuf obuf; /* output buffer */ + struct strbuf obuf; /* output buffer; if buffer_output == 2, caller + * must handle and call strbuf_release */ /* miscellaneous control options */ const char *subtree_shift; From patchwork Sat Aug 17 18:41:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC89F112C for ; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CDC92892D for ; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 914132892E; Sat, 17 Aug 2019 18:42:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 467CD2893A for ; Sat, 17 Aug 2019 18:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbfHQSm0 (ORCPT ); Sat, 17 Aug 2019 14:42:26 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45226 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726416AbfHQSmX (ORCPT ); Sat, 17 Aug 2019 14:42:23 -0400 Received: by mail-pf1-f195.google.com with SMTP id w26so4788156pfq.12 for ; Sat, 17 Aug 2019 11:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6CJBCvJF8oU1RYoVyDBDuuQX5NuYJf05WU2Awmw9v7s=; b=nQc3yT5Q+SSKPccT6evg3MJMioNYWoOnoJGzreEzD2N6YECft33R8JGpFu6s35N8cv qTVyYLbJPSgUZ9vR29zwNbqzTEvrVyoU8FzVfEiXrszsHN3BTfeqGItCoJY8Kg8JAzxB BNkACp8Bgu9zF2Y+wN7EI8iBNUpXvotXyL+nfm3zPCyhbVM8RvHbi2OrxTUcFM4BJyBo b/HjTa7kllwIQCwZGwnypdpEn5WdoBAIJ6vK1Dxe4EXtCJ+UEw14/tvykeSezKORFiS2 nB9wRgw+H+69kRMB8kdebzmLRKD4X/6RBARFkdad5T3i2mhqLDCyqu7fb3uj9C/9w3Yj 5qPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6CJBCvJF8oU1RYoVyDBDuuQX5NuYJf05WU2Awmw9v7s=; b=kyHh76btWivJJVLl3VtW8qgbIjq7aM82jPhB2BzqIsNoygbdV2gfY5snfS+to5CrHK VR20MleSvlce4IPoii+w9zGukndaAAhHXoXLqUHxbshRIGJ07W4IJPAbz3QGQgcVkn8O MknawV7yU6P0iER7MET8WJw5wRXTckITfNbDJdja0bXnPU9mmYSikF15YBnx2vstPn5R 45yY4osBe8e1jsqMb0/542ldylVJxAgQ4KpGWYj7rzketBLsNyg4igmu6g57H0X89jpR Yuvq6+5pbUteFqBBZx3qxpkK5N7Tpm0Ab8tDA0uX27UCM48mW+Q3tI2783XPxLJOo8WX fn3Q== X-Gm-Message-State: APjAAAVZJs1JAeyRWNwJtv8nAVTeTiaL9HvwdSnJ9vBopgOUKyBgpeM/ +mC5L230UntNLeGSQ2dElCcI7TT2 X-Google-Smtp-Source: APXvYqzEWj0kMO0BhT1+yB+Ha9L4ReWFUFFqhP6yaQVC5mD5aime5Npxb7dj2XXJmbkiLC2kHt/JDw== X-Received: by 2002:a17:90a:9f46:: with SMTP id q6mr12666822pjv.110.1566067341892; Sat, 17 Aug 2019 11:42:21 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:21 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 21/24] merge-recursive: split internal fields into a separate struct Date: Sat, 17 Aug 2019 11:41:41 -0700 Message-Id: <20190817184144.32179-22-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP merge_options has several internal fields that should not be set or read by external callers. This just complicates the API. Move them into an opaque merge_options_internal struct that is defined only in merge-recursive.c and keep these out of merge-recursive.h. Signed-off-by: Elijah Newren --- merge-recursive.c | 185 ++++++++++++++++++++++++---------------------- merge-recursive.h | 17 ++--- 2 files changed, 105 insertions(+), 97 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 262db8bebb..c92993e8f0 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -29,6 +29,15 @@ #include "revision.h" #include "commit-reach.h" +struct merge_options_internal { + int call_depth; + int needed_rename_limit; + struct hashmap current_file_dir_set; + struct string_list df_conflict_file_set; + struct unpack_trees_options unpack_opts; + struct index_state orig_index; +}; + struct path_hashmap_entry { struct hashmap_entry e; char path[FLEX_ARRAY]; @@ -309,7 +318,8 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type, static int show(struct merge_options *opt, int v) { - return (!opt->call_depth && opt->verbosity >= v) || opt->verbosity >= 5; + return (!opt->priv->call_depth && opt->verbosity >= v) || + opt->verbosity >= 5; } __attribute__((format (printf, 3, 4))) @@ -320,7 +330,7 @@ static void output(struct merge_options *opt, int v, const char *fmt, ...) if (!show(opt, v)) return; - strbuf_addchars(&opt->obuf, ' ', opt->call_depth * 2); + strbuf_addchars(&opt->obuf, ' ', opt->priv->call_depth * 2); va_start(ap, fmt); strbuf_vaddf(&opt->obuf, fmt, ap); @@ -335,7 +345,7 @@ static void output_commit_title(struct merge_options *opt, struct commit *commit { struct merge_remote_desc *desc; - strbuf_addchars(&opt->obuf, ' ', opt->call_depth * 2); + strbuf_addchars(&opt->obuf, ' ', opt->priv->call_depth * 2); desc = merge_remote_util(commit); if (desc) strbuf_addf(&opt->obuf, "virtual %s\n", desc->name); @@ -403,43 +413,43 @@ static int unpack_trees_start(struct merge_options *opt, struct tree_desc t[3]; struct index_state tmp_index = { NULL }; - memset(&opt->unpack_opts, 0, sizeof(opt->unpack_opts)); - if (opt->call_depth) - opt->unpack_opts.index_only = 1; + memset(&opt->priv->unpack_opts, 0, sizeof(opt->priv->unpack_opts)); + if (opt->priv->call_depth) + opt->priv->unpack_opts.index_only = 1; else - opt->unpack_opts.update = 1; - opt->unpack_opts.merge = 1; - opt->unpack_opts.head_idx = 2; - opt->unpack_opts.fn = threeway_merge; - opt->unpack_opts.src_index = opt->repo->index; - opt->unpack_opts.dst_index = &tmp_index; - opt->unpack_opts.aggressive = !merge_detect_rename(opt); - setup_unpack_trees_porcelain(&opt->unpack_opts, "merge"); + opt->priv->unpack_opts.update = 1; + opt->priv->unpack_opts.merge = 1; + opt->priv->unpack_opts.head_idx = 2; + opt->priv->unpack_opts.fn = threeway_merge; + opt->priv->unpack_opts.src_index = opt->repo->index; + opt->priv->unpack_opts.dst_index = &tmp_index; + opt->priv->unpack_opts.aggressive = !merge_detect_rename(opt); + setup_unpack_trees_porcelain(&opt->priv->unpack_opts, "merge"); init_tree_desc_from_tree(t+0, common); init_tree_desc_from_tree(t+1, head); init_tree_desc_from_tree(t+2, merge); - rc = unpack_trees(3, t, &opt->unpack_opts); + rc = unpack_trees(3, t, &opt->priv->unpack_opts); cache_tree_free(&opt->repo->index->cache_tree); /* - * Update opt->repo->index to match the new results, AFTER saving a copy - * in opt->orig_index. Update src_index to point to the saved copy. - * (verify_uptodate() checks src_index, and the original index is - * the one that had the necessary modification timestamps.) + * Update opt->repo->index to match the new results, AFTER saving a + * copy in opt->priv->orig_index. Update src_index to point to the + * saved copy. (verify_uptodate() checks src_index, and the original + * index is the one that had the necessary modification timestamps.) */ - opt->orig_index = *opt->repo->index; + opt->priv->orig_index = *opt->repo->index; *opt->repo->index = tmp_index; - opt->unpack_opts.src_index = &opt->orig_index; + opt->priv->unpack_opts.src_index = &opt->priv->orig_index; return rc; } static void unpack_trees_finish(struct merge_options *opt) { - discard_index(&opt->orig_index); - clear_unpack_trees_porcelain(&opt->unpack_opts); + discard_index(&opt->priv->orig_index); + clear_unpack_trees_porcelain(&opt->priv->unpack_opts); } static int save_files_dirs(const struct object_id *oid, @@ -454,7 +464,7 @@ static int save_files_dirs(const struct object_id *oid, FLEX_ALLOC_MEM(entry, path, base->buf, base->len); hashmap_entry_init(entry, path_hash(entry->path)); - hashmap_add(&opt->current_file_dir_set, entry); + hashmap_add(&opt->priv->current_file_dir_set, entry); strbuf_setlen(base, baselen); return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); @@ -585,7 +595,7 @@ static void record_df_conflict_files(struct merge_options *opt, * If we're merging merge-bases, we don't want to bother with * any working directory changes. */ - if (opt->call_depth) + if (opt->priv->call_depth) return; /* Ensure D/F conflicts are adjacent in the entries list. */ @@ -597,7 +607,7 @@ static void record_df_conflict_files(struct merge_options *opt, df_sorted_entries.cmp = string_list_df_name_compare; string_list_sort(&df_sorted_entries); - string_list_clear(&opt->df_conflict_file_set, 1); + string_list_clear(&opt->priv->df_conflict_file_set, 1); for (i = 0; i < df_sorted_entries.nr; i++) { const char *path = df_sorted_entries.items[i].string; int len = strlen(path); @@ -613,7 +623,7 @@ static void record_df_conflict_files(struct merge_options *opt, len > last_len && memcmp(path, last_file, last_len) == 0 && path[last_len] == '/') { - string_list_insert(&opt->df_conflict_file_set, last_file); + string_list_insert(&opt->priv->df_conflict_file_set, last_file); } /* @@ -680,8 +690,8 @@ static void update_entry(struct stage_data *entry, static int remove_file(struct merge_options *opt, int clean, const char *path, int no_wd) { - int update_cache = opt->call_depth || clean; - int update_working_directory = !opt->call_depth && !no_wd; + int update_cache = opt->priv->call_depth || clean; + int update_working_directory = !opt->priv->call_depth && !no_wd; if (update_cache) { if (remove_file_from_index(opt->repo->index, path)) @@ -724,16 +734,16 @@ static char *unique_path(struct merge_options *opt, add_flattened_path(&newpath, branch); base_len = newpath.len; - while (hashmap_get_from_hash(&opt->current_file_dir_set, + while (hashmap_get_from_hash(&opt->priv->current_file_dir_set, path_hash(newpath.buf), newpath.buf) || - (!opt->call_depth && file_exists(newpath.buf))) { + (!opt->priv->call_depth && file_exists(newpath.buf))) { strbuf_setlen(&newpath, base_len); strbuf_addf(&newpath, "_%d", suffix++); } FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len); hashmap_entry_init(entry, path_hash(entry->path)); - hashmap_add(&opt->current_file_dir_set, entry); + hashmap_add(&opt->priv->current_file_dir_set, entry); return strbuf_detach(&newpath, NULL); } @@ -775,7 +785,7 @@ static int dir_in_way(struct index_state *istate, const char *path, static int was_tracked_and_matches(struct merge_options *opt, const char *path, const struct diff_filespec *blob) { - int pos = index_name_pos(&opt->orig_index, path, strlen(path)); + int pos = index_name_pos(&opt->priv->orig_index, path, strlen(path)); struct cache_entry *ce; if (0 > pos) @@ -783,7 +793,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path, return 0; /* See if the file we were tracking before matches */ - ce = opt->orig_index.cache[pos]; + ce = opt->priv->orig_index.cache[pos]; return (oid_eq(&ce->oid, &blob->oid) && ce->ce_mode == blob->mode); } @@ -792,7 +802,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path, */ static int was_tracked(struct merge_options *opt, const char *path) { - int pos = index_name_pos(&opt->orig_index, path, strlen(path)); + int pos = index_name_pos(&opt->priv->orig_index, path, strlen(path)); if (0 <= pos) /* we were tracking this path before the merge */ @@ -849,12 +859,12 @@ static int was_dirty(struct merge_options *opt, const char *path) struct cache_entry *ce; int dirty = 1; - if (opt->call_depth || !was_tracked(opt, path)) + if (opt->priv->call_depth || !was_tracked(opt, path)) return !dirty; - ce = index_file_exists(opt->unpack_opts.src_index, + ce = index_file_exists(opt->priv->unpack_opts.src_index, path, strlen(path), ignore_case); - dirty = verify_uptodate(ce, &opt->unpack_opts) != 0; + dirty = verify_uptodate(ce, &opt->priv->unpack_opts) != 0; return dirty; } @@ -864,8 +874,8 @@ static int make_room_for_path(struct merge_options *opt, const char *path) const char *msg = _("failed to create path '%s'%s"); /* Unlink any D/F conflict files that are in the way */ - for (i = 0; i < opt->df_conflict_file_set.nr; i++) { - const char *df_path = opt->df_conflict_file_set.items[i].string; + for (i = 0; i < opt->priv->df_conflict_file_set.nr; i++) { + const char *df_path = opt->priv->df_conflict_file_set.items[i].string; size_t pathlen = strlen(path); size_t df_pathlen = strlen(df_path); if (df_pathlen < pathlen && @@ -875,7 +885,7 @@ static int make_room_for_path(struct merge_options *opt, const char *path) _("Removing %s to make room for subdirectory\n"), df_path); unlink(df_path); - unsorted_string_list_delete_item(&opt->df_conflict_file_set, + unsorted_string_list_delete_item(&opt->priv->df_conflict_file_set, i, 0); break; } @@ -916,7 +926,7 @@ static int update_file_flags(struct merge_options *opt, { int ret = 0; - if (opt->call_depth) + if (opt->priv->call_depth) update_wd = 0; if (update_wd) { @@ -1001,7 +1011,7 @@ static int update_file(struct merge_options *opt, const char *path) { return update_file_flags(opt, contents, path, - opt->call_depth || clean, !opt->call_depth); + opt->priv->call_depth || clean, !opt->priv->call_depth); } /* Low level file merging, update and removal */ @@ -1030,7 +1040,7 @@ static int merge_3way(struct merge_options *opt, ll_opts.extra_marker_size = extra_marker_size; ll_opts.xdl_opts = opt->xdl_opts; - if (opt->call_depth) { + if (opt->priv->call_depth) { ll_opts.virtual_ancestor = 1; ll_opts.variant = 0; } else { @@ -1161,7 +1171,7 @@ static int merge_submodule(struct merge_options *opt, struct object_array merges; int i; - int search = !opt->call_depth; + int search = !opt->priv->call_depth; /* store a in result in case we fail */ oidcpy(result, a); @@ -1383,7 +1393,7 @@ static int handle_rename_via_dir(struct merge_options *opt, MERGE_DIRECTORY_RENAMES_CONFLICT); assert(ren->dir_rename_original_dest); - if (!opt->call_depth && would_lose_untracked(opt, dest->path)) { + if (!opt->priv->call_depth && would_lose_untracked(opt, dest->path)) { mark_conflicted = 1; file_path = unique_path(opt, dest->path, ren->branch); output(opt, 1, _("Error: Refusing to lose untracked file at %s; " @@ -1426,12 +1436,12 @@ static int handle_change_delete(struct merge_options *opt, const char *update_path = path; int ret = 0; - if (dir_in_way(opt->repo->index, path, !opt->call_depth, 0) || - (!opt->call_depth && would_lose_untracked(opt, path))) { + if (dir_in_way(opt->repo->index, path, !opt->priv->call_depth, 0) || + (!opt->priv->call_depth && would_lose_untracked(opt, path))) { update_path = alt_path = unique_path(opt, path, change_branch); } - if (opt->call_depth) { + if (opt->priv->call_depth) { /* * We cannot arbitrarily accept either a_sha or b_sha as * correct; since there is no true "middle point" between @@ -1506,14 +1516,14 @@ static int handle_rename_delete(struct merge_options *opt, opt->branch2 : opt->branch1); if (handle_change_delete(opt, - opt->call_depth ? orig->path : dest->path, - opt->call_depth ? NULL : orig->path, + opt->priv->call_depth ? orig->path : dest->path, + opt->priv->call_depth ? NULL : orig->path, orig, dest, rename_branch, delete_branch, _("rename"), _("renamed"))) return -1; - if (opt->call_depth) + if (opt->priv->call_depth) return remove_file_from_index(opt->repo->index, dest->path); else return update_stages(opt, dest->path, NULL, @@ -1550,7 +1560,7 @@ static int handle_file_collision(struct merge_options *opt, /* * In the recursive case, we just opt to undo renames */ - if (opt->call_depth && (prev_path1 || prev_path2)) { + if (opt->priv->call_depth && (prev_path1 || prev_path2)) { /* Put first file (a->oid, a->mode) in its original spot */ if (prev_path1) { if (update_file(opt, 1, a, prev_path1)) @@ -1579,10 +1589,10 @@ static int handle_file_collision(struct merge_options *opt, /* Remove rename sources if rename/add or rename/rename(2to1) */ if (prev_path1) remove_file(opt, 1, prev_path1, - opt->call_depth || would_lose_untracked(opt, prev_path1)); + opt->priv->call_depth || would_lose_untracked(opt, prev_path1)); if (prev_path2) remove_file(opt, 1, prev_path2, - opt->call_depth || would_lose_untracked(opt, prev_path2)); + opt->priv->call_depth || would_lose_untracked(opt, prev_path2)); /* * Remove the collision path, if it wouldn't cause dirty contents @@ -1624,12 +1634,12 @@ static int handle_file_collision(struct merge_options *opt, null.mode = 0; if (merge_mode_and_contents(opt, &null, a, b, collide_path, - branch1, branch2, opt->call_depth * 2, &mfi)) + branch1, branch2, opt->priv->call_depth * 2, &mfi)) return -1; mfi.clean &= !alt_path; if (update_file(opt, mfi.clean, &mfi.blob, update_path)) return -1; - if (!mfi.clean && !opt->call_depth && + if (!mfi.clean && !opt->priv->call_depth && update_stages(opt, collide_path, NULL, a, b)) return -1; free(alt_path); @@ -1669,7 +1679,7 @@ static int handle_rename_add(struct merge_options *opt, &ci->ren1->src_entry->stages[other_stage], prev_path_desc, opt->branch1, opt->branch2, - 1 + opt->call_depth * 2, &mfi)) + 1 + opt->priv->call_depth * 2, &mfi)) return -1; free(prev_path_desc); @@ -1687,7 +1697,7 @@ static char *find_path_for_conflict(struct merge_options *opt, const char *branch2) { char *new_path = NULL; - if (dir_in_way(opt->repo->index, path, !opt->call_depth, 0)) { + if (dir_in_way(opt->repo->index, path, !opt->priv->call_depth, 0)) { new_path = unique_path(opt, path, branch1); output(opt, 1, _("%s is a directory in %s adding " "as %s instead"), @@ -1718,17 +1728,17 @@ static int handle_rename_rename_1to2(struct merge_options *opt, "rename \"%s\"->\"%s\" in \"%s\"%s"), o->path, a->path, ci->ren1->branch, o->path, b->path, ci->ren2->branch, - opt->call_depth ? _(" (left unresolved)") : ""); + opt->priv->call_depth ? _(" (left unresolved)") : ""); path_desc = xstrfmt("%s and %s, both renamed from %s", a->path, b->path, o->path); if (merge_mode_and_contents(opt, o, a, b, path_desc, ci->ren1->branch, ci->ren2->branch, - opt->call_depth * 2, &mfi)) + opt->priv->call_depth * 2, &mfi)) return -1; free(path_desc); - if (opt->call_depth) { + if (opt->priv->call_depth) { /* * FIXME: For rename/add-source conflicts (if we could detect * such), this is wrong. We should instead find a unique @@ -1843,12 +1853,12 @@ static int handle_rename_rename_2to1(struct merge_options *opt, &ci->ren1->src_entry->stages[ostage1], path_side_1_desc, opt->branch1, opt->branch2, - 1 + opt->call_depth * 2, &mfi_c1) || + 1 + opt->priv->call_depth * 2, &mfi_c1) || merge_mode_and_contents(opt, b, &ci->ren2->src_entry->stages[ostage2], c2, path_side_2_desc, opt->branch1, opt->branch2, - 1 + opt->call_depth * 2, &mfi_c2)) + 1 + opt->priv->call_depth * 2, &mfi_c2)) return -1; free(path_side_1_desc); free(path_side_2_desc); @@ -1889,8 +1899,8 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *opt, diff_setup_done(&opts); diff_tree_oid(&o_tree->object.oid, &tree->object.oid, "", &opts); diffcore_std(&opts); - if (opts.needed_rename_limit > opt->needed_rename_limit) - opt->needed_rename_limit = opts.needed_rename_limit; + if (opts.needed_rename_limit > opt->priv->needed_rename_limit) + opt->priv->needed_rename_limit = opts.needed_rename_limit; ret = xmalloc(sizeof(*ret)); *ret = diff_queued_diff; @@ -2865,7 +2875,7 @@ static int detect_and_process_renames(struct merge_options *opt, if ((opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_TRUE) || (opt->detect_directory_renames == MERGE_DIRECTORY_RENAMES_CONFLICT && - !opt->call_depth)) { + !opt->priv->call_depth)) { dir_re_head = get_directory_renames(head_pairs); dir_re_merge = get_directory_renames(merge_pairs); @@ -3022,13 +3032,13 @@ static int handle_content_merge(struct merge_file_info *mfi, reason = _("add/add"); assert(o->path && a->path && b->path); - if (ci && dir_in_way(opt->repo->index, path, !opt->call_depth, + if (ci && dir_in_way(opt->repo->index, path, !opt->priv->call_depth, S_ISGITLINK(ci->ren1->pair->two->mode))) df_conflict_remains = 1; if (merge_mode_and_contents(opt, o, a, b, path, opt->branch1, opt->branch2, - opt->call_depth * 2, mfi)) + opt->priv->call_depth * 2, mfi)) return -1; /* @@ -3044,7 +3054,7 @@ static int handle_content_merge(struct merge_file_info *mfi, output(opt, 3, _("Skipped %s (merged same as existing)"), path); if (add_cacheinfo(opt, &mfi->blob, path, - 0, (!opt->call_depth && !is_dirty), 0)) + 0, (!opt->priv->call_depth && !is_dirty), 0)) return -1; /* * However, add_cacheinfo() will delete the old cache entry @@ -3052,8 +3062,8 @@ static int handle_content_merge(struct merge_file_info *mfi, * flag to avoid making the file appear as if it were * deleted by the user. */ - pos = index_name_pos(&opt->orig_index, path, strlen(path)); - ce = opt->orig_index.cache[pos]; + pos = index_name_pos(&opt->priv->orig_index, path, strlen(path)); + ce = opt->priv->orig_index.cache[pos]; if (ce_skip_worktree(ce)) { pos = index_name_pos(opt->repo->index, path, strlen(path)); ce = opt->repo->index->cache[pos]; @@ -3074,7 +3084,7 @@ static int handle_content_merge(struct merge_file_info *mfi, if (df_conflict_remains || is_dirty) { char *new_path; - if (opt->call_depth) { + if (opt->priv->call_depth) { remove_file_from_index(opt->repo->index, path); } else { if (!mfi->clean) { @@ -3333,7 +3343,7 @@ static int process_entry(struct merge_options *opt, conf = _("directory/file"); } if (dir_in_way(opt->repo->index, path, - !opt->call_depth && !S_ISGITLINK(a->mode), + !opt->priv->call_depth && !S_ISGITLINK(a->mode), 0)) { char *new_path = unique_path(opt, path, add_branch); clean_merge = 0; @@ -3342,7 +3352,7 @@ static int process_entry(struct merge_options *opt, conf, path, other_branch, path, new_path); if (update_file(opt, 0, contents, new_path)) clean_merge = -1; - else if (opt->call_depth) + else if (opt->priv->call_depth) remove_file_from_index(opt->repo->index, path); free(new_path); } else { @@ -3407,7 +3417,7 @@ static int merge_trees_internal(struct merge_options *opt, code = unpack_trees_start(opt, merge_base, head, merge); if (code != 0) { - if (show(opt, 4) || opt->call_depth) + if (show(opt, 4) || opt->priv->call_depth) err(opt, _("merging of trees %s and %s failed"), oid_to_hex(&head->object.oid), oid_to_hex(&merge->object.oid)); @@ -3426,7 +3436,7 @@ static int merge_trees_internal(struct merge_options *opt, * opposed to decaring a local hashmap is for convenience * so that we don't have to pass it to around. */ - hashmap_init(&opt->current_file_dir_set, path_hashmap_cmp, + hashmap_init(&opt->priv->current_file_dir_set, path_hashmap_cmp, NULL, 512); get_files_dirs(opt, head); get_files_dirs(opt, merge); @@ -3463,7 +3473,7 @@ static int merge_trees_internal(struct merge_options *opt, string_list_clear(entries, 1); free(entries); - hashmap_free(&opt->current_file_dir_set, 1); + hashmap_free(&opt->priv->current_file_dir_set, 1); if (clean < 0) { unpack_trees_finish(opt); @@ -3475,7 +3485,7 @@ static int merge_trees_internal(struct merge_options *opt, unpack_trees_finish(opt); - if (opt->call_depth && + if (opt->priv->call_depth && !(*result = write_in_core_index_as_tree(opt->repo))) return -1; @@ -3550,7 +3560,7 @@ static int merge_recursive_internal(struct merge_options *opt, for (iter = merge_bases; iter; iter = iter->next) { const char *saved_b1, *saved_b2; - opt->call_depth++; + opt->priv->call_depth++; /* * When the merge fails, the result contains files * with conflict markers. The cleanness flag is @@ -3569,14 +3579,14 @@ static int merge_recursive_internal(struct merge_options *opt, return -1; opt->branch1 = saved_b1; opt->branch2 = saved_b2; - opt->call_depth--; + opt->priv->call_depth--; if (!merged_merge_bases) return err(opt, _("merge returned no commit")); } discard_index(opt->repo->index); - if (!opt->call_depth) + if (!opt->priv->call_depth) repo_read_index(opt->repo); opt->ancestor = ancestor_name; @@ -3592,7 +3602,7 @@ static int merge_recursive_internal(struct merge_options *opt, return clean; } - if (opt->call_depth) { + if (opt->priv->call_depth) { *result = make_virtual_commit(opt->repo, result_tree, "merged tree"); commit_list_insert(h1, &(*result)->parents); @@ -3612,17 +3622,20 @@ static int merge_start(struct merge_options *opt, struct tree *head) return -1; } + opt->priv = xcalloc(1, sizeof(*opt->priv)); + string_list_init(&opt->priv->df_conflict_file_set, 1); return 0; } static void merge_finalize(struct merge_options *opt) { flush_output(opt); - if (!opt->call_depth && opt->buffer_output < 2) + if (!opt->priv->call_depth && opt->buffer_output < 2) strbuf_release(&opt->obuf); if (show(opt, 2)) diff_warn_rename_limit("merge.renamelimit", - opt->needed_rename_limit, 0); + opt->priv->needed_rename_limit, 0); + FREE_AND_NULL(opt->priv); } int merge_trees(struct merge_options *opt, @@ -3767,8 +3780,6 @@ void init_merge_options(struct merge_options *opt, opt->renormalize = 0; - string_list_init(&opt->df_conflict_file_set, 1); - merge_recursive_config(opt); merge_verbosity = getenv("GIT_MERGE_VERBOSITY"); if (merge_verbosity) diff --git a/merge-recursive.h b/merge-recursive.h index 933d6e7642..58a4c5238a 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -1,13 +1,15 @@ #ifndef MERGE_RECURSIVE_H #define MERGE_RECURSIVE_H -#include "string-list.h" -#include "unpack-trees.h" +#include "strbuf.h" struct commit; - +struct commit_list; +struct object_id; struct repository; +struct tree; +struct merge_options_internal; struct merge_options { struct repository *repo; @@ -45,13 +47,8 @@ struct merge_options { const char *subtree_shift; unsigned renormalize : 1; - /* internal fields used by the implementation (do NOT set these) */ - int call_depth; - int needed_rename_limit; - struct hashmap current_file_dir_set; - struct string_list df_conflict_file_set; - struct unpack_trees_options unpack_opts; - struct index_state orig_index; + /* internal fields used by the implementation */ + struct merge_options_internal *priv; }; void init_merge_options(struct merge_options *opt, struct repository *repo); From patchwork Sat Aug 17 18:41:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03B48112C for ; Sat, 17 Aug 2019 18:42:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8E75284F1 for ; Sat, 17 Aug 2019 18:42:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD4052892E; Sat, 17 Aug 2019 18:42:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B88D2284F1 for ; Sat, 17 Aug 2019 18:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726457AbfHQSm0 (ORCPT ); Sat, 17 Aug 2019 14:42:26 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37411 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726425AbfHQSmX (ORCPT ); Sat, 17 Aug 2019 14:42:23 -0400 Received: by mail-pf1-f196.google.com with SMTP id 129so4815274pfa.4 for ; Sat, 17 Aug 2019 11:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jvRWqFVyOHoucwg5J9Nf3LMAwNCSQ281wrX5Pg1DAhM=; b=d9CNBfeI+gYiShdSmJqKbJgEJvfFvNOtEQ+2pUxYkdyHWrmzZ9lVJM1Lz2zIN9n2QE DCZYKyf8Zy9+RUtpLwWkVVKFiTMrvEqFKws9FgGcUCK7FdrM5jsGnG8f6OTxSoBae/l1 JDY38I6pQdq9/thoUwzs1ZJhje6kM0lZlnzeDnk0lvmRN2LQRpgZSwAxl7NkyUqQO8Cs Hyij4mtnnkh8UzZ644LLI5vGMd+yc/UjT8INixywzH/AJ2u+pQYEAGEa5gOC3GcPoS5E ykr8vCx7bbqNeqmrfyDknLxX3K8SyUaVoEUMJfC/jTYjVZuev7jI8jfpdNn0PXwTtrQR 1PFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jvRWqFVyOHoucwg5J9Nf3LMAwNCSQ281wrX5Pg1DAhM=; b=U0Sq1Kd0K99KZYxIAQmO0jJvkuRVPWQBvPWKmwo4zho3lWkexEoB2sCT3E6ULFfrHz 9aB+35TtMVnOZJBYK8t0iPOhDNdFEXJVtjSLbWLFG+LZ54FWtZlCOAmwppg9ag8RbX/7 e1cPMK1QzwXMqXSnFqyTXJSAOWt/aecBowV6DwMTw7dUosThF/vzTtk15OopD7ac6Iv7 qAZatOD/XnlqMK9VOLw/0EztzyCmUKmW9I8S7XRyQ2DN23ENSj0i8KUpH0MLEJbz0kys G4yk8/os4HfLsnum4QVymChqMvgpNQ90bILNefxOipOjGvZvuNJnn2yCXNL1aoVOkjP/ d59w== X-Gm-Message-State: APjAAAUE7toW96KQPp90ECEW8/qujX2wT/RJks2aZeDJ/68I0Pd5M16Q J5t++4UWFflEQpSZKz80zf+GeD4u X-Google-Smtp-Source: APXvYqxx0RD8oPnoELnOjHzmhCABv7BI67My4SiTsfWxfJWnMwhRMkLxqSj0/taZxUJ6MEvdSpWLLw== X-Received: by 2002:a63:2887:: with SMTP id o129mr12731982pgo.179.1566067342790; Sat, 17 Aug 2019 11:42:22 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:22 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 22/24] merge-recursive: rename MERGE_RECURSIVE_* to MERGE_VARIANT_* Date: Sat, 17 Aug 2019 11:41:42 -0700 Message-Id: <20190817184144.32179-23-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I want to implement the same outward facing API as found within merge-recursive.h in a different merge strategy. However, that makes names like MERGE_RECURSIVE_{NORMAL,OURS,THEIRS} look a little funny; rename to MERGE_VARIANT_{NORMAL,OURS,THEIRS}. Signed-off-by: Elijah Newren --- merge-recursive.c | 14 +++++++------- merge-recursive.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index c92993e8f0..fa3f8eb0b2 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1045,10 +1045,10 @@ static int merge_3way(struct merge_options *opt, ll_opts.variant = 0; } else { switch (opt->recursive_variant) { - case MERGE_RECURSIVE_OURS: + case MERGE_VARIANT_OURS: ll_opts.variant = XDL_MERGE_FAVOR_OURS; break; - case MERGE_RECURSIVE_THEIRS: + case MERGE_VARIANT_THEIRS: ll_opts.variant = XDL_MERGE_FAVOR_THEIRS; break; default: @@ -1355,15 +1355,15 @@ static int merge_mode_and_contents(struct merge_options *opt, &b->oid); } else if (S_ISLNK(a->mode)) { switch (opt->recursive_variant) { - case MERGE_RECURSIVE_NORMAL: + case MERGE_VARIANT_NORMAL: oidcpy(&result->blob.oid, &a->oid); if (!oid_eq(&a->oid, &b->oid)) result->clean = 0; break; - case MERGE_RECURSIVE_OURS: + case MERGE_VARIANT_OURS: oidcpy(&result->blob.oid, &a->oid); break; - case MERGE_RECURSIVE_THEIRS: + case MERGE_VARIANT_THEIRS: oidcpy(&result->blob.oid, &b->oid); break; } @@ -3795,9 +3795,9 @@ int parse_merge_opt(struct merge_options *opt, const char *s) if (!s || !*s) return -1; if (!strcmp(s, "ours")) - opt->recursive_variant = MERGE_RECURSIVE_OURS; + opt->recursive_variant = MERGE_VARIANT_OURS; else if (!strcmp(s, "theirs")) - opt->recursive_variant = MERGE_RECURSIVE_THEIRS; + opt->recursive_variant = MERGE_VARIANT_THEIRS; else if (!strcmp(s, "subtree")) opt->subtree_shift = ""; else if (skip_prefix(s, "subtree=", &arg)) diff --git a/merge-recursive.h b/merge-recursive.h index 58a4c5238a..978847e672 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -32,9 +32,9 @@ struct merge_options { /* xdiff-related options (patience, ignore whitespace, ours/theirs) */ long xdl_opts; enum { - MERGE_RECURSIVE_NORMAL = 0, - MERGE_RECURSIVE_OURS, - MERGE_RECURSIVE_THEIRS + MERGE_VARIANT_NORMAL = 0, + MERGE_VARIANT_OURS, + MERGE_VARIANT_THEIRS } recursive_variant; /* console output related options */ From patchwork Sat Aug 17 18:41:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B62021510 for ; Sat, 17 Aug 2019 18:42:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7F7D284F1 for ; Sat, 17 Aug 2019 18:42:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C44F2892E; Sat, 17 Aug 2019 18:42:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B611284F1 for ; Sat, 17 Aug 2019 18:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726484AbfHQSmd (ORCPT ); Sat, 17 Aug 2019 14:42:33 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35766 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfHQSmZ (ORCPT ); Sat, 17 Aug 2019 14:42:25 -0400 Received: by mail-pf1-f194.google.com with SMTP id d85so4828298pfd.2 for ; Sat, 17 Aug 2019 11:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MKv15GAGuh8hc1pF4Q7oRQu73NxUzPXT1Rb01TgMISg=; b=Ue+0AFLHNrHKWo5oGYmnsuv7FOnDy9BDk+nJ6P5nq4Gum6V3kuUF9DHiUb57OtOMEe KrZPgBstkoq5ePdnGpPWSOY+aKlSq/cFwRjFgiyoBVG4ZRfZJfweSqmKFmIni7L9OSiF UtMIiMI2Xuo98b8MAMfmMs95JmnRMW5yUn963xBDvJ6molB3jLlAsCOqa6UTCbtzBFZx nYbzIPdlYGp6sQLuVrO+Tj8rLFTZ7vxaGg80xx3YzeDTUKT1nhHvgY5SzFnzKqdy5t0X kPUD671bYtJs2FBTsac2w18fnvGZZ1wVKkMWwZWmqGIyyqkKzo2uXpe8CvZ7LE4ykEN5 x2YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MKv15GAGuh8hc1pF4Q7oRQu73NxUzPXT1Rb01TgMISg=; b=qjCK7QF83rLZJg+E7x6FyE6MdNarVHW50ERJaLKTZPCZga2VJpi2gg74F+8u5f4GwA sHA+0+hul4DR+iHggrDHEgmVl67hjjH5COh7eDJsa32Xev2ijiLjqUmwDXDNzPJ9hZCp qEVJDWiE9wfC/rkn4IN41BaH/m1mR8985VFggu+YMGmIN4PB94fGL5QoAOyG6VzykV0m IOeGuznUS8xAybKQ6hK9mBdpRGZ8j5vfIQWFsRnGgr4iRZElabGMAcfLB3yeMN+NHMVU tktWVeDg8fglqR+gaeOmb224zxt0YybMIaubUioD0Lw5TWBb3TgVtcWJ2QASY9aU+5wJ mX8A== X-Gm-Message-State: APjAAAWwzJy39TG9yh5zLziUFm0GGVfwFpAHSxMxjTzmcOsr1zRUpEU1 TNfEZ3ekjmJXX9Qkjs5zu1sA3vHd X-Google-Smtp-Source: APXvYqzN12qWJkZEr12KCfaHRG5NM+0TMcl7XCam3hsfLNGrmEHc5JI2rnXKkXDQZyh8eG2FIrwHTA== X-Received: by 2002:a17:90b:14c:: with SMTP id em12mr13524649pjb.28.1566067343999; Sat, 17 Aug 2019 11:42:23 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:23 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 23/24] merge-recursive: add sanity checks for relevant merge_options Date: Sat, 17 Aug 2019 11:41:43 -0700 Message-Id: <20190817184144.32179-24-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are lots of options that callers can set, yet most have a limited range of valid values, some options are meant for output (e.g. opt->obuf, which is expected to start empty), and callers are expected to not set opt->priv. Add several sanity checks to ensure callers provide sane values. Signed-off-by: Elijah Newren --- merge-recursive.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/merge-recursive.c b/merge-recursive.c index fa3f8eb0b2..0231d7b049 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3615,6 +3615,30 @@ static int merge_start(struct merge_options *opt, struct tree *head) { struct strbuf sb = STRBUF_INIT; + /* Sanity checks on opt */ + assert(opt->repo); + + assert(opt->branch1 && opt->branch2); + + assert(opt->detect_renames >= -1 && + opt->detect_renames <= DIFF_DETECT_COPY); + assert(opt->detect_directory_renames >= MERGE_DIRECTORY_RENAMES_NONE && + opt->detect_directory_renames <= MERGE_DIRECTORY_RENAMES_TRUE); + assert(opt->rename_limit >= -1); + assert(opt->rename_score >= 0 && opt->rename_score <= MAX_SCORE); + assert(opt->show_rename_progress >= 0 && opt->show_rename_progress <= 1); + + assert(opt->xdl_opts >= 0); + assert(opt->recursive_variant >= MERGE_VARIANT_NORMAL && + opt->recursive_variant <= MERGE_VARIANT_THEIRS); + + assert(opt->verbosity >= 0 && opt->verbosity <= 5); + assert(opt->buffer_output <= 2); + assert(opt->obuf.len == 0); + + assert(opt->priv == NULL); + + /* Sanity check on repo state; index must match head */ if (repo_index_has_changes(opt->repo, head, &sb)) { err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"), sb.buf); From patchwork Sat Aug 17 18:41:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11099263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97116174A for ; Sat, 17 Aug 2019 18:42:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8789F284F1 for ; Sat, 17 Aug 2019 18:42:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BDA82892E; Sat, 17 Aug 2019 18:42:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27746284F1 for ; Sat, 17 Aug 2019 18:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726481AbfHQSmb (ORCPT ); Sat, 17 Aug 2019 14:42:31 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41495 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726437AbfHQSm0 (ORCPT ); Sat, 17 Aug 2019 14:42:26 -0400 Received: by mail-pf1-f193.google.com with SMTP id 196so4805246pfz.8 for ; Sat, 17 Aug 2019 11:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DstNdmycUb2JZhQmaD3K5ZRDoDByrjearqLDurh0Clo=; b=FWCmXHO6W3on1BxzPm3Yrg4NvH8Fgbqvd4WtJS1OVklWSmnR2DXRrSh0eGmeOixVdy 8fRww+Mr7VOkwQ3OoglxToDEu0ZAp/0hsxAkUnFPOD+l+zFgBA0HsHWrYzOanNI8U4GZ nZ1kI02z7k784/mIBduj5VqEuphFq/pZ2jMYhnvNZASl+yxvDG6j+1WEel2zhLbVBB+d GClASAbHfOuBDd7WXV46MnwyaNVoaVP6irWX1q36XNKCL1CV1Z2jhUjDovkDpSlNhZdS jCykI6J17XvW5laa9JOi3uW2u3UZrH71/o454II/taWI0KRf4RNSu+EctEKV80OTH1eN giMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DstNdmycUb2JZhQmaD3K5ZRDoDByrjearqLDurh0Clo=; b=Xbe7k5rARCoVU3I6psvTYYaPlCtjuK7oDqjZbCr2TkZrbfh7UuAzg3yt85bb5lNNVV E4zYlnGwirqslVeVXGTSnVxNIbyrf3HsP5TZr2Z5tn77377R4yDViRUVTePmadDr1yiO IeWCfiZh1wa+8UPKIcLmgx3pf37iVzXKP7efSRv3IS2xe02fKAqIwTS9W8Cwg6Y+IWlG D3a2j8xPDwRRnaY3oRbg32qDiuyXAM/TuTSvG0wCR9YIGW+NRHCJEo+EdefUD/RQZh5u GfMgGiP/OTzoMXt5m4DFYh/sfav8DeeaXiTu39W4e5HAe2MVp4BW6GG24ged21G7mtr9 J3ag== X-Gm-Message-State: APjAAAUV5GBdKHSjZVnKu80wtoLAq1XpjJlA9dOdBk3lXj6kNqEX3LQ/ Z6Bj9BU35C9l4OuxVStx9F09oNvR X-Google-Smtp-Source: APXvYqzxZn9DeuHe6OYal8n4KUFtVnpgoiYS5aXbZDo6a9r8xb9mfaMGQ+2oZGdftznpWma+2b93/w== X-Received: by 2002:a17:90a:fd8c:: with SMTP id cx12mr13173170pjb.95.1566067345156; Sat, 17 Aug 2019 11:42:25 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id j15sm9990422pfr.146.2019.08.17.11.42.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Aug 2019 11:42:24 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Elijah Newren Subject: [PATCH v4 24/24] merge-recursive: alphabetize include list Date: Sat, 17 Aug 2019 11:41:44 -0700 Message-Id: <20190817184144.32179-25-newren@gmail.com> X-Mailer: git-send-email 2.23.0.rc2.28.g5f89f15d7b.dirty In-Reply-To: <20190817184144.32179-1-newren@gmail.com> References: <20190815214053.16594-1-newren@gmail.com> <20190817184144.32179-1-newren@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Other than cache.h which needs to appear first, and merge-recursive.h which I want to be second so that we are more likely to notice if merge-recursive.h has any missing includes, the rest of the list is long and easier to look through if it's alphabetical. Signed-off-by: Elijah Newren --- merge-recursive.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 0231d7b049..b058741f00 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -4,30 +4,31 @@ * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006 */ #include "cache.h" -#include "config.h" +#include "merge-recursive.h" + #include "advice.h" -#include "lockfile.h" -#include "cache-tree.h" -#include "object-store.h" -#include "repository.h" -#include "commit.h" +#include "alloc.h" +#include "attr.h" #include "blob.h" #include "builtin.h" -#include "tree-walk.h" +#include "cache-tree.h" +#include "commit.h" +#include "commit-reach.h" +#include "config.h" #include "diff.h" #include "diffcore.h" +#include "dir.h" +#include "ll-merge.h" +#include "lockfile.h" +#include "object-store.h" +#include "repository.h" +#include "revision.h" +#include "string-list.h" +#include "submodule.h" #include "tag.h" -#include "alloc.h" +#include "tree-walk.h" #include "unpack-trees.h" -#include "string-list.h" #include "xdiff-interface.h" -#include "ll-merge.h" -#include "attr.h" -#include "merge-recursive.h" -#include "dir.h" -#include "submodule.h" -#include "revision.h" -#include "commit-reach.h" struct merge_options_internal { int call_depth;