From patchwork Fri Jul 26 15:52: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: 11061273 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 CAEC3912 for ; Fri, 26 Jul 2019 15:53:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA59A28AF7 for ; Fri, 26 Jul 2019 15:53:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE6AA28B01; Fri, 26 Jul 2019 15:53:08 +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 59BF228AF7 for ; Fri, 26 Jul 2019 15:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387442AbfGZPxH (ORCPT ); Fri, 26 Jul 2019 11:53:07 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36976 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726791AbfGZPxH (ORCPT ); Fri, 26 Jul 2019 11:53:07 -0400 Received: by mail-pl1-f196.google.com with SMTP id b3so24934399plr.4 for ; Fri, 26 Jul 2019 08:53: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=aSum+Jh11Oyos5gFJ/QTMvDCeh3RcHbNa4clahepe4g=; b=NSCLTJ9yPJS6XrM3IlneZzUibqgbARaBm8diCTO+Y82C9XIBXU0Oz3X6+zTiClS2u6 pFzk5oQdKSl03PRFkRGituzZM3BXpROGwtmBBgQaJaH1iydVhbxBS/ixoSiSCHj6w1hk 6KhMvNWhbbvT1MOBK9YsIqacU/pxL5iuYkGoeIld4xredUwPYHkQ8zRza9bpb9LyqBWT LUi4RTLMD1yi62y0Mr7hqLPIii6eEMz4ebOwGFTA0MTJgR1iweeLHJC91i8rXWqEQnQi hSiGFFNKktx16ZzvRT6bK7KlaPlSdgeOCSzZNDqyTi97pg7Pul8gQyVVyzEwog+WeWB5 qjbA== 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=aSum+Jh11Oyos5gFJ/QTMvDCeh3RcHbNa4clahepe4g=; b=Opfwt6LfLDX0yyOM4BY85ZYY8ngRDJSj5+MLWz0VNjBxIrE2eh7fVDw/K/UOcRMt2X U/bAAszc/WSHSO9r9BwTFxRE8YvqeAbk294HOgkmerUc2WUEM6NWT5AeVH3xkfWEsxru WgTBimGumhUUfbjrA7gmksePeoFGdrpm5wWnS8lHAWYkTfy/0u670nNJd4gZRncOXSxL TDnpURa1oNE9F5xppwKNfBn5D6s+J98q04Cu28T+OeKSKffcONw9dwzK2W7B7Lfz87cy xe1J3B8kuIeiQksd+RUE+5vszD2YGQbVtg/ymUS6RJXd6KYFcF3RLFBFW/E3btCMughh 3ANQ== X-Gm-Message-State: APjAAAXsYH7RxshsX3Bzn8dgAcJT6/gLjj+ZsT9rB/QH1Uhk5GWiktpD p2B/K6oB3TsYjPZp3Iyw8hnn1wbC X-Google-Smtp-Source: APXvYqwthATnV2SLqkk8ie8bENrq1lTvE6vOKipXLCrSg93y7abSFzy72QFldwLBsZzVjufREiCigw== X-Received: by 2002:a17:902:4c:: with SMTP id 70mr96695625pla.308.1564156385939; Fri, 26 Jul 2019 08:53:05 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:05 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 01/20] merge-recursive: fix minor memory leak in error condition Date: Fri, 26 Jul 2019 08:52:39 -0700 Message-Id: <20190726155258.28561-2-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 Returning before freeing the allocated buffer is suboptimal; as with elsewhere in the same function, make sure buf gets free'd. 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 12300131fc..1163508811 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 Fri Jul 26 15:52: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: 11061277 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 33AFA912 for ; Fri, 26 Jul 2019 15:53:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2465128A56 for ; Fri, 26 Jul 2019 15:53:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18EE328AFC; Fri, 26 Jul 2019 15:53: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 BB71A28A56 for ; Fri, 26 Jul 2019 15:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726791AbfGZPxK (ORCPT ); Fri, 26 Jul 2019 11:53:10 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45969 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387453AbfGZPxI (ORCPT ); Fri, 26 Jul 2019 11:53:08 -0400 Received: by mail-pl1-f195.google.com with SMTP id y8so24927703plr.12 for ; Fri, 26 Jul 2019 08:53: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=7jI6bJznoT1kUHH+hGFs83qAIbvycj3Rophq/FX+N/Y=; b=c9YLxGNK05/ORAplEEI1BGNOgaL6wJvWtE0ob8BU+upNI8ov+w0vGCh4MLug6l9QBo vEfplESi5Sdk33n3iomSrlw+oE+uBfElsY7w+duRTkzt9ut4deBhbSO9YvCymiqO+5h+ 5YqMZ8w8x0mcyOdkE0vNPkaXmza/3ljD2yOpDA0/xjOO8Vtizb9keR9hsyaAjC/O6yfi nc+mmQ5N33h4p9TJ+yq/j/QOyEzhV4Qfdp1uVJ2XhSxWSL8/pFLh3AeG7a65FpBD5NZq 5WfAMOxnGVupVaDi2QHwWakSByXS96BNPVZA5dxd/t6qhiTCMClc6J9nfqjKz6DKNTqE UVvA== 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=7jI6bJznoT1kUHH+hGFs83qAIbvycj3Rophq/FX+N/Y=; b=GhjDmCSr6oe6y/Nxh/1jD5nrrwFNT2FttKfUS1mXuO9np6ed4J8jtOwIaO1R6JJh+4 qS5F/a9pDQzt1a3Ol4RSK/WHJ8Cw53RRxsWekbvnXhq7Zfj0wjGWvhsPMRExrg5iK0Pm Mv1W3HWAclneeXdB6txNkuHmABnKWh1m492GihMPk6+I2MJN43qL6wW+zXOpE1sBO4NJ xm9sbxQEBpjTRbc8nyZlIwzz4E9IDfTBuD8QHLn2/ufzmqwGREROtrmP2pXO3Fr6Rz9Z qS8IS9VU2AlaVWftsSnf08Sso9RPZa4k6RFWshZkkMt7UEMAnVOBpoky37mkm0ZMH++O 8tOg== X-Gm-Message-State: APjAAAVa7WJfJfix9AMsFwGt6uNZo6h3JoXoKtdWSlH9a1NKRHY5FOkO HRCPxSng0+AsilmCEQGwMhZ8W/dU X-Google-Smtp-Source: APXvYqwxasokWx4yTa94DCIuoY//V0VDy3ysx84Ef8Nn77d66FR1dsGUM6Oyrj4CuHHYNpj39Ph+zg== X-Received: by 2002:a17:902:381:: with SMTP id d1mr94834754pld.331.1564156387148; Fri, 26 Jul 2019 08:53:07 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:06 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 02/20] merge-recursive: remove another implicit dependency on the_repository Date: Fri, 26 Jul 2019 08:52:40 -0700 Message-Id: <20190726155258.28561-3-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 1163508811..37bb94fb4d 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3571,8 +3571,11 @@ int merge_recursive(struct merge_options *opt, repo_read_index(opt->repo); opt->ancestor = "merged common ancestors"; - 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); if (clean < 0) { flush_output(opt); From patchwork Fri Jul 26 15:52: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: 11061275 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 AFB441580 for ; Fri, 26 Jul 2019 15:53:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E76028A56 for ; Fri, 26 Jul 2019 15:53:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92CB828AFC; Fri, 26 Jul 2019 15:53: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 E5B0A28AF7 for ; Fri, 26 Jul 2019 15:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387459AbfGZPxK (ORCPT ); Fri, 26 Jul 2019 11:53:10 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46038 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387474AbfGZPxJ (ORCPT ); Fri, 26 Jul 2019 11:53:09 -0400 Received: by mail-pf1-f193.google.com with SMTP id r1so24710661pfq.12 for ; Fri, 26 Jul 2019 08:53: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=7aHwsVPCloq1BjfIdiLlin1Nkuz/HLYOHpUFYNdeFDg=; b=neXxbpYmfDe39d9XSfB2RNKbqGnG6mKpS5Emeo+Dyqd6q+kXurHOXiqpMYITOm8OZz I0tJyIAJDTUxUzyTYsEO5npfbDWbC9wvWbUFYZF8Al1DHsOXxjlGy5/lSNIyD2rPYnG5 egKqsInOGfSjQRYGsWYWNYhIIwLc/JJHXfdGKYMmOK7IVI7eVyr5SG+9xL0RQ8q3a/dN VmL+U7z1vuhD+AxIRj8EXERm9iFk4uQfZqPEr3zOQzWv8hKEJ8vTkkMwxwNwhGQxJmdw PJUrSstGDLTRjL2f8RSjv+AF7RtR6loFbuIUKsvOWTwMRkVXS/rzfEXQcGhLxLoXjnEJ cSGw== 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=7aHwsVPCloq1BjfIdiLlin1Nkuz/HLYOHpUFYNdeFDg=; b=fD3R7vUH+7FH4O77eLtWaynmFw2W56RquD2ADvB7uLpdBdJkBSA9/gjbfKAYqMF58N 1wCwMH7AHWpEBN+bzdsPszD+QRFPXRz5yhc6M1YTuDT0b/CQM3GsfdFQqUNbC3JQ+f3+ GneS6a1JOABG64qGklNV/YupO33gAKfNFKytCdAcEsRwS4xBAWwM7ZqYUBKqNbiOeUzo OycZDzIuKd/hEczRsM8D4SSAZbw9aGGvfChS9aBw+QGAGpNH1tHFpUVLA+gCi0RUjPwS tekFW+rzXaIMX93p1PNVgs+jRvIqxzqkyTLbynbUagb4TKtc5Ln1UHecMsBrkt2BkpiD FE+g== X-Gm-Message-State: APjAAAVetMEkp255t5hn8zuf7ugr81VMn+I/TujdRzPTllBvCKfRG+EH FBpk6J07ivAbKhMwzQB/GFEQn68s X-Google-Smtp-Source: APXvYqw9pBPQjM7SGkGs0bHvwgXXvocrXlKFsFTCL1XEuXbvh5JvBBupYPrRWkZ5AggPAMB0FsvHpg== X-Received: by 2002:a65:6691:: with SMTP id b17mr76602505pgw.217.1564156388249; Fri, 26 Jul 2019 08:53:08 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:07 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 03/20] Ensure index matches head before invoking merge machinery, round N Date: Fri, 26 Jul 2019 08:52:41 -0700 Message-Id: <20190726155258.28561-4-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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). 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 Fri Jul 26 15:52: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: 11061281 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 E31681398 for ; Fri, 26 Jul 2019 15:53:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0BF528A56 for ; Fri, 26 Jul 2019 15:53:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C517E28AFC; Fri, 26 Jul 2019 15:53: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 4BB0128A56 for ; Fri, 26 Jul 2019 15:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387537AbfGZPxM (ORCPT ); Fri, 26 Jul 2019 11:53:12 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33940 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387474AbfGZPxL (ORCPT ); Fri, 26 Jul 2019 11:53:11 -0400 Received: by mail-pg1-f195.google.com with SMTP id n9so18754611pgc.1 for ; Fri, 26 Jul 2019 08:53: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=DRBC4jeovfP/by6OUKLTEmYT5x28WX0DGW0cYJwYbZo=; b=T2ZwZSb1QOusvptFo4Y0/e+FbhNLOMJofoUuBYwZ+WvcLvt4d3lgjpOW2KsHSgSDhM 4GfZHXqIh2YLbkpfud30rlefrVCSznOQtkPemcYV4d+tCJ5x6FgTDpxkh2O0qzKgU3w1 Qzv3+h8+omM/a2tozk/iMl9uQft+ok1p0qn4yheRqb9tvNbSyfc02No57TKewb/6VTNQ AReT/naM7L7J3Fgal/nJAoqxXLmdOH35KOCDJjqc2ENhIOIKH8HuMBoz4f/lLDn33PGQ 99HmdoayZPNJNaiM1LhMSzITuCNqBTwC7JctkgqwT8MTYB14+hZ0bl12zMEhfyOdR++9 iKzg== 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=DRBC4jeovfP/by6OUKLTEmYT5x28WX0DGW0cYJwYbZo=; b=AC1tf1JUMK9XNgS5XiBGAHDTUMLiIWC7cMZMx+xJ/A43Vq7nSkUsEvkuU+rPbRVWXZ sAzigW5FtmHkbxMIjhiK0FeMBIm0Zw2uxtojaaIfH82YJiWASinrZb+sCHx21dC1hMat i4d2v0QfHRkIaH+jFuCajCq+iFWv4KOfbGWd0Y3eGcPtQOY6Uxrmpzfmh7ajll1jge6e FdfMhl7iVsj3Z1xk7N11XW8lBhM2T3EqyEA/D7xCtNyCuP0y4YaqUHnuTRvSe5OOZN+Q iwJUBex6tovw2A1EucC7qzSeu26fZd0ZQ7BoPAmJnYsCOz3jFyPl6xVoCPXbtYfi9o4h 3bDg== X-Gm-Message-State: APjAAAUU8ePY92xnnJ5pzJzadPUzlEoh2wY7LL3ea5a3PxIqwKFSojvB c+/KESrgMJdkfqoLiaMRg+YnYFx9 X-Google-Smtp-Source: APXvYqwYR5RM+0lUSoaqwNAv1sQ5BKujTNzgLvzQPEdCtnz+w2nhF4Vkg7/0IoUMZhUJcEhzrvvz4g== X-Received: by 2002:a63:d90f:: with SMTP id r15mr72004559pgg.259.1564156389349; Fri, 26 Jul 2019 08:53:09 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:08 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 04/20] merge-recursive: exit early if index != head Date: Fri, 26 Jul 2019 08:52:42 -0700 Message-Id: <20190726155258.28561-5-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 | 94 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 37bb94fb4d..f5cf21e2e0 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3381,21 +3381,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; - - 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); @@ -3499,11 +3492,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; @@ -3555,7 +3548,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; @@ -3571,12 +3564,12 @@ int merge_recursive(struct merge_options *opt, repo_read_index(opt->repo); opt->ancestor = "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); + 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); if (clean < 0) { flush_output(opt); return clean; @@ -3596,6 +3589,59 @@ 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; + + assert(opt->branch1 && opt->branch2); + + 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; + + 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; + + 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 Fri Jul 26 15:52: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: 11061283 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 8CD311580 for ; Fri, 26 Jul 2019 15:53:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B54628A56 for ; Fri, 26 Jul 2019 15:53:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FA9828AFC; Fri, 26 Jul 2019 15:53: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 F414E28A56 for ; Fri, 26 Jul 2019 15:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbfGZPxM (ORCPT ); Fri, 26 Jul 2019 11:53:12 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:46297 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387519AbfGZPxL (ORCPT ); Fri, 26 Jul 2019 11:53:11 -0400 Received: by mail-pl1-f196.google.com with SMTP id c2so24889422plz.13 for ; Fri, 26 Jul 2019 08:53: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=NODzgMqxao3TCJOa+1mG/Bja6y8OnVzOyvIszUVJcAA=; b=TjBAuwqm0N/WMRpEcPce+/9isjd04pSRihszZAVTwVRlxIqhqwaGWsJRhpDuTihfEx 9GnFDyjQEhytfi6LeI2qrJEzDp19YGE+NNg9q10LG9Hp4nXJar6LHJSBnMenWak1s2wu tRPJ7eWhUmhP764qfH+wbNKsnmE/WbHjVg3nromx6bvLX1hPsLq1WcIelxYSof5PUUWD XxLEqjgTOL0l0KRB/lQtKgN47/9j+2hiahN2dO/arPtJXdda/ghm+qNpwOqVyuO8XstH jsV2ll8HhWL/erqXLlW9dmdDjscqywoP/NwS48pC9STYBWfEnGGwT5RtCJ5jjhf29VUi u1Kg== 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=NODzgMqxao3TCJOa+1mG/Bja6y8OnVzOyvIszUVJcAA=; b=FVYKMPu/8tfZtMzRbA67SxPGu/1J85HNFvlsO+ouu2qlGKmx2gJ5iw08SRzEV1lgI0 bufguYQiaO5+CN2G0LYzA3KNlRY4PLIRybHXB5i5Y5veBkHqdRbNSqtWZa7QK743uDHg T5pEsL8l9bTWYmXatJetKx4gBBYgzZXGG/3wgIj9/H4K3Ls+sACwQ/mgjGrjBDPmYJ8x BTCQhase0FOCXHFmP8eHyZ6UiTfy0D40MRnIbUu+VPNEFeW5qaBD4+sXfIlwK/lI40Ih l3//dQ7QrtWeYhohJbobbMjOh5sj0Zk1XiXhMJWr/CNFZp+RnrTfv1JhvXdOCYXPWchq H70A== X-Gm-Message-State: APjAAAU+HCDMgfMh4czVlZCcd4VIVjcxNpnziPzJDBuMujqlhRJzvEco 8QBrNvzT/BDKZet+kU3YHLPwF9jv X-Google-Smtp-Source: APXvYqznHoylGM34myFc3zUY07MNoj1jeoK4dIBa70fNh4qFQ1dG3aRaW1B2bIOjscifZuZm+qDLhQ== X-Received: by 2002:a17:902:b70c:: with SMTP id d12mr93244520pls.314.1564156390229; Fri, 26 Jul 2019 08:53:10 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:09 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 05/20] merge-recursive: remove useless parameter in merge_trees() Date: Fri, 26 Jul 2019 08:52:43 -0700 Message-Id: <20190726155258.28561-6-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 91f8509f85..20e38c5edc 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; @@ -773,8 +772,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 f5cf21e2e0..4a481c3929 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3613,14 +3613,14 @@ 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; 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 c2b7bb65c6..812c456f1b 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -70,19 +70,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 Fri Jul 26 15:52: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: 11061289 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 BAE0B1398 for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F6B28A56 for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D4C228AFC; Fri, 26 Jul 2019 15:53: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 460D028AF7 for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387728AbfGZPxO (ORCPT ); Fri, 26 Jul 2019 11:53:14 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44906 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbfGZPxM (ORCPT ); Fri, 26 Jul 2019 11:53:12 -0400 Received: by mail-pl1-f193.google.com with SMTP id t14so24888329plr.11 for ; Fri, 26 Jul 2019 08:53: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=VCZxsILUVcitpoGXsTjVqdvtgRMVgTPW5fsCj5O6VH8=; b=g9C3lOwCNFtsuPapfmGAVX7CVkmtm00PNjdlMxmIBdNv+sV/ddTs87TFbLcNqB+r27 Bghyu7m92oYKmEDc3/M4xHNNl9CfaXS+wqucai1+zUAIqHo8tATzkMJdn2EWfXIIEqfj O1oziFpJaAHT+yK4yjWv2FZhfABVmSiSIzaYY8iv479LpQYkfBo0gqKK3bCQxsPFxMoJ 6EnNjKJiAzO1IfwpWbgcCwbaXbllfydrJ/0td/G6g0QWk+0mXavvdj7sanjddDfyp7VX bFHDgFY7dGCRG/H0M4PldcYhI0IPntqpnz9jf0D3zX08FJcHwtsg+P9UhkSls5aUeG+t QnGw== 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=VCZxsILUVcitpoGXsTjVqdvtgRMVgTPW5fsCj5O6VH8=; b=iW4cRj4vYMAblSUcf0HgTL/Bhf0Xsw0DNHmnjF51rGytlL/YkkuQzFzcytYreOh3Zw DRwsqgTOWkOcH0PrCiAI8tdDomwTRltCM276Nt52qWpKys2k34wB58NvS3AXJQEgrwL/ Z+gyxJBJhmD1v1bI1Noaseu3zdCRQ4t887vRea+7Xep9bO3KQLZkbIbi8gTiUFmM6Feh ZaAKXY17qaHkWlJFXwLs7S/bZWIUdnyGaUjqhw9q0zIs9tU/hBKEFam3IbUsITQdqTlj TCKvMLyZSBreMdDCduiqmEfUX8r1mSOtRSBgP+5qAqwveE0CDC5czVCjD+ldIwL4hKsV EX5A== X-Gm-Message-State: APjAAAWsuEikM/CktDpMfgV3BURh0mK2lM4s8NwhifGqWaFntADG48fL x4ADekfOm64WUzSO/YcBDK3NEeia X-Google-Smtp-Source: APXvYqy3uq3kwtu+np0fgGrsX8v3ujYVCqsVXZyxtPxdUFRmisrcelZwDd5BzYZ7md/BPJnZ8NadMA== X-Received: by 2002:a17:902:44e:: with SMTP id 72mr97000358ple.326.1564156391516; Fri, 26 Jul 2019 08:53:11 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:10 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 06/20] merge-recursive: don't force external callers to do our logging Date: Fri, 26 Jul 2019 08:52:44 -0700 Message-Id: <20190726155258.28561-7-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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. 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 4a481c3929..308e350ff1 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3583,9 +3583,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; } @@ -3607,7 +3604,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 Fri Jul 26 15:52:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061285 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 2856C912 for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15BB628B01 for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05FE228B08; Fri, 26 Jul 2019 15:53: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 5CB9028AF7 for ; Fri, 26 Jul 2019 15:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387801AbfGZPxP (ORCPT ); Fri, 26 Jul 2019 11:53:15 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42897 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387474AbfGZPxO (ORCPT ); Fri, 26 Jul 2019 11:53:14 -0400 Received: by mail-pl1-f195.google.com with SMTP id ay6so24952985plb.9 for ; Fri, 26 Jul 2019 08:53: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=cr+0X2cCWipVZOQ1XruJ+iMulc8IUJhByrpKZQ1WgHk=; b=TSgccGBdye2izW6OzHlzqry15NTl30uegG55AUERxtBXCThewhzJd6+CmxJ6PiUz60 f+mfhjsLPP+rWHwqQSMAyygszbYjL7PjoATZ+AVpXWzD2dBr99UIoDk164cLeUFL6vX1 P5Ae5fxDONszRjg9ngQoV2E4S8o5X92gyvFKtVJdEeTMaJPv2dug2dTpeyYLz7waeXNT VtAdZZARfJPirQh52y5WvtuYYygdvmnliReTHUw7uFmrpJ4ffG7jVLuk7NQp7yeWALD0 zj+B+L/25Gpu666QN+ezjr7QtDVaC9NNQ35fnH3fGuxfi3rAN8HpjdmxL2xQoFQnn2hJ 8scQ== 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=cr+0X2cCWipVZOQ1XruJ+iMulc8IUJhByrpKZQ1WgHk=; b=FiEtzrsrbPt2nmra9uo/xNTu/IwMvLNjvTl17VlULM2P+ICt5E6ObDGPAEBTe5VXxV bDi2iODFOX64Mi8SHSyYZrKnWBawNT17l2mID6nSGQGCnt3QI57qV+O5VMyjgrxXIrQx W3WjBTlhDBiwSKx01NvGzjPahnQjSe75IJfoIs/V41mC190P/AVqL32ZAasKNfasyLfm JwkmFM4m1J+zdxycYst5p10U94N7EOZwmumT2dUTT6pzZKcMBaKW4jcW6a7z3K+j5dJA qplyMVCHhAo0eOc1jdE48Ap/1rnXf5BwMchza9PgVKRibdq6CH5OAr7KCGPRmk4Dh/mH 96+w== X-Gm-Message-State: APjAAAWAobeC87gXSyhy2h9OKwEr+/Tm2Z5rCnPz4+tqKN05l8pD4cqI UQYA/ZKmz9kCp1gwjjk7vqe0GaH3 X-Google-Smtp-Source: APXvYqzr+s5nGbljC0SdR1FP68/O7IRjVTPGNpGyrswdKa8d+k8t22+GlVJdi4b6rqDj62kWzN2rvQ== X-Received: by 2002:a17:902:8203:: with SMTP id x3mr97769328pln.304.1564156392546; Fri, 26 Jul 2019 08:53:12 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:11 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 07/20] Use write_index_as_tree() in lieu of write_tree_from_memory() Date: Fri, 26 Jul 2019 08:52:45 -0700 Message-Id: <20190726155258.28561-8-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 had a slightly different call structure but the big 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. Add a flag to allow using the in-memory index, and then switch over to write_index_as_tree(). Signed-off-by: Elijah Newren --- builtin/checkout.c | 6 +++++- cache-tree.c | 36 +++++++++++++++++++++++------------- cache-tree.h | 3 ++- merge-recursive.c | 42 +++++++++--------------------------------- merge-recursive.h | 1 - 5 files changed, 39 insertions(+), 49 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 20e38c5edc..a7b6454061 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -709,6 +709,7 @@ static int merge_working_tree(const struct checkout_opts *opts, * whether the merge flag was used. */ struct tree *work; + struct object_id work_oid; struct tree *old_tree; struct merge_options o; struct strbuf sb = STRBUF_INIT; @@ -759,7 +760,10 @@ 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); + if (write_index_as_tree(&work_oid, &the_index, NULL, + WRITE_TREE_FROM_MEMORY, NULL) || + !(work = lookup_tree(the_repository, &work_oid))) + die(_("error building trees")); ret = reset_tree(new_tree, opts, 1, diff --git a/cache-tree.c b/cache-tree.c index 706ffcf188..99144b1704 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -613,14 +613,19 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, int entries, was_valid; struct lock_file lock_file = LOCK_INIT; int ret = 0; + int access_disk = !(flags & WRITE_TREE_FROM_MEMORY); - hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); + if (access_disk) { + hold_lock_file_for_update(&lock_file, index_path, + LOCK_DIE_ON_ERROR); - entries = read_index_from(index_state, index_path, get_git_dir()); - if (entries < 0) { - ret = WRITE_TREE_UNREADABLE_INDEX; - goto out; + entries = read_index_from(index_state, index_path, get_git_dir()); + if (entries < 0) { + ret = WRITE_TREE_UNREADABLE_INDEX; + goto out; + } } + if (flags & WRITE_TREE_IGNORE_CACHE_TREE) cache_tree_free(&index_state->cache_tree); @@ -633,13 +638,16 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, ret = WRITE_TREE_UNMERGED_INDEX; goto out; } - 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 - * ends up using the old index with unupdated cache-tree part - * it misses the work we did here, but that is just a - * performance penalty and not a big deal. - */ + if (access_disk) { + 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 ends up using the old index with + * unupdated cache-tree part it misses the work we + * did here, but that is just a performance penalty + * and not a big deal. + */ + } } if (prefix) { @@ -655,7 +663,9 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, oidcpy(oid, &index_state->cache_tree->oid); out: - rollback_lock_file(&lock_file); + if (access_disk) + rollback_lock_file(&lock_file); + return ret; } diff --git a/cache-tree.h b/cache-tree.h index 757bbc48bc..481ec45dfa 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -34,12 +34,13 @@ 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 #define WRITE_TREE_SILENT 8 #define WRITE_TREE_REPAIR 16 +#define WRITE_TREE_FROM_MEMORY 32 /* error return codes */ #define WRITE_TREE_UNREADABLE_INDEX (-1) diff --git a/merge-recursive.c b/merge-recursive.c index 308e350ff1..6c38c02e3f 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) @@ -3471,8 +3440,15 @@ static int merge_trees_internal(struct merge_options *opt, unpack_trees_finish(opt); - if (opt->call_depth && !(*result = write_tree_from_memory(opt))) - return -1; + if (opt->call_depth) { + struct object_id tree_id; + if (write_index_as_tree(&tree_id, opt->repo->index, NULL, + WRITE_TREE_FROM_MEMORY, NULL) || + !(*result = lookup_tree(opt->repo, &tree_id))) { + err(opt, _("error building trees")); + return -1; + } + } return clean; } diff --git a/merge-recursive.h b/merge-recursive.h index 812c456f1b..b3394502c7 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -109,7 +109,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 Fri Jul 26 15:52:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061287 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 71A5D17EF for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D1C228A56 for ; Fri, 26 Jul 2019 15:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E69628B01; Fri, 26 Jul 2019 15:53: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 C2E3128AFC for ; Fri, 26 Jul 2019 15:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387757AbfGZPxP (ORCPT ); Fri, 26 Jul 2019 11:53:15 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43472 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387588AbfGZPxO (ORCPT ); Fri, 26 Jul 2019 11:53:14 -0400 Received: by mail-pl1-f196.google.com with SMTP id 4so17927528pld.10 for ; Fri, 26 Jul 2019 08:53: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=wDvG3V7NiVhTVVBozAoR4JYHAo/KmrUjMTjlxPdBknA=; b=HZt/2iIf4Fc1+1U4Sp/MNt1SUlY21JcF8yuG22W1Rt+rD5Byrer84fBpUn3pt7SVNe yCmKMaO/cKV/YpHCqD7bO4k0IuJPrrsH9vuLssKx++dxiY4haYmQL/Rh9ab4DEl0uOMU kSl5Zs1V+8p2DUeYw+FToQjrpQ8hVc5H73wX+fkY+F4D5YtgMqEthJAc6BJVDPVOYKS/ 8/b06eoFn1sMrQqMFf7XT7kvDs4UEjAgC2oWlzAmHdy/uqt+FDYsEkTLMuGbqDb8wlln gfe40G/IcbL1BRWE/u6vd9DeMipXIuwWjPY5vOs/QGSBhk5r6sA/kZGSaxwLxl8chUrI 3E6w== 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=wDvG3V7NiVhTVVBozAoR4JYHAo/KmrUjMTjlxPdBknA=; b=Llk5rg0y1MzKpns5FEi7D/ojQ0iYMUuDKaQD8SaWOm9nCCBpf+BxkaeoVQjqXZTNcc qsvPM5H029olIwLmwImiHv+R2LuYWMpj0sqrEOsm15Ye4fhxmMbxCxi9jBQyroTcFTzG 492mZjFG6WQe+LhbHvbwZo3N5xgNYC2IDWXDAEAHaZlR5dBDqZgSQn+Twp2Y5SiWkC+p ZQyZ55YD2lNsDvelzSUCPBP5ojsbBCCSUCJneLhIRkJvs3P0EZQxeYCztAmyOI9K6+9j CLAfPP7Fk7d1goWNiE7Am1lPxQYpsUhRm4A64hSvi8mWhN64znJK32MNkUyofo9J79ob 9hAA== X-Gm-Message-State: APjAAAU2pdFQsBPXQusIiXCv7FvcHOyQLkeV0I1g5lVOsynUWT6rynbc A1fqMAD6mgdXoeuxrq6ujEIcRXNx X-Google-Smtp-Source: APXvYqzYBjJuWpHmmZwgwsTomeLB5Mk0uTCn7YUHQg7YZ4C1VaqfafJGxl1W8FRevEXEB3aCeGgxPw== X-Received: by 2002:a17:902:8548:: with SMTP id d8mr97530426plo.100.1564156393546; Fri, 26 Jul 2019 08:53:13 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:12 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 08/20] merge-recursive: fix some overly long lines Date: Fri, 26 Jul 2019 08:52:46 -0700 Message-Id: <20190726155258.28561-9-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 6c38c02e3f..e81dec8f1f 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); @@ -3392,7 +3395,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); @@ -3505,7 +3509,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"); } for (iter = ca; iter; iter = iter->next) { @@ -3617,7 +3622,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; @@ -3652,7 +3658,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 Fri Jul 26 15:52:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061295 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 AFC5F912 for ; Fri, 26 Jul 2019 15:53:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E7A628A56 for ; Fri, 26 Jul 2019 15:53:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92FA128AFC; Fri, 26 Jul 2019 15:53: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 DFFCB28A56 for ; Fri, 26 Jul 2019 15:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387835AbfGZPxS (ORCPT ); Fri, 26 Jul 2019 11:53:18 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36385 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387759AbfGZPxQ (ORCPT ); Fri, 26 Jul 2019 11:53:16 -0400 Received: by mail-pl1-f195.google.com with SMTP id k8so24930965plt.3 for ; Fri, 26 Jul 2019 08:53: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=tBNLQrgmljLmHLDoIaW4cusFjH9sy+B2r4+GPhhLV9Q=; b=kkZ5Xk5KUOW6dO5AkYFB7zqEKye9h0+TaRCIf3Y19dFdb/8PJka9wcvPXCOE6MJAMu iolNh58+oeaZEIA62KmsuNOC50yZg20ubxiZD1FM6qnQ8fKDsmCoXBk06yLgQtWAXwZK iM1dn9c+y8C0kNecuehaMItvc1JcLKEe3onVw+d6g0sJ70mm59fABKttLD789SYvamZj lfBwTc65HIgCP9hDU5fXxvdwrqrsDYvHHYf55FVn3me62dKXN1otR3CTt8u+tLtxRpZC 7nJBNK9JS5DrnPZfxwp4FSb8iKtDORAkH7CsbtrzHE4P6z8LUQrRBlrqM4DIvrYwD6t1 gkVA== 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=tBNLQrgmljLmHLDoIaW4cusFjH9sy+B2r4+GPhhLV9Q=; b=Mv9B4BOOlFZE/ceKz56iSflOP6zX7oWW6PO4D0SF9VuOMBPYJ+L1gPF/69OZkWCk6P OUEAr2DnIdL2p0ZafcbLHX3KcDtUO7rKLzw9b016Asd3B6GLknD0UoqJ9pBvCCPEiGgt kJJRxvqPkFivJSmWonctEqdtshzd0skBJDP3AqfgYjqGgRk4/SBt4jPtmMGXsxd3zS1b bj7HYzfxUT2gz7AYYZfUdctAfEz94cj2+qqxkZSxoETw/WJ4911rHY1zJIjXk1yenywx X66IvmQy6zseLwcgNz+/NatWwsK41QEdKeV0+7g53bGVUjxKZMQ0deKPVY91WAZYb8hB 9DYw== X-Gm-Message-State: APjAAAUAjq3L5VDchwH3Zi9mZY5zBfdcjl8Mn1OovyNioK0Idz6dKjsq QwmSYC1vX0eRYBydfHr3CGalaKyM X-Google-Smtp-Source: APXvYqxydo2AbNVXV+OMmGY6g0JmGBWRiEfAQOet7LdeWFOtvSPjpWPpEK6O7V+x2h+heUaDEMqvbg== X-Received: by 2002:a17:902:ff10:: with SMTP id f16mr2629057plj.141.1564156394608; Fri, 26 Jul 2019 08:53:14 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:13 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 09/20] merge-recursive: use common name for ancestors/common/base_list Date: Fri, 26 Jul 2019 08:52:47 -0700 Message-Id: <20190726155258.28561-10-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 | 68 ++++++++++++++++++++++++----------------------- merge-recursive.h | 14 +++++----- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index e81dec8f1f..8114e77b98 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3356,24 +3356,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) @@ -3401,7 +3403,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) @@ -3475,11 +3477,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; @@ -3489,31 +3491,31 @@ 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"); } - for (iter = ca; iter; iter = iter->next) { + for (iter = merge_bases; iter; iter = iter->next) { const char *saved_b1, *saved_b2; opt->call_depth++; /* @@ -3529,14 +3531,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")); } @@ -3549,7 +3551,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); if (clean < 0) { flush_output(opt); @@ -3593,14 +3595,14 @@ 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; 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; @@ -3609,14 +3611,14 @@ 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; 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; @@ -3644,8 +3646,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; @@ -3654,14 +3656,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 b3394502c7..c7ba8d0a71 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -77,14 +77,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); /* @@ -94,7 +94,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 @@ -103,8 +103,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 Fri Jul 26 15:52:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061293 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 3676E912 for ; Fri, 26 Jul 2019 15:53:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2719228A56 for ; Fri, 26 Jul 2019 15:53:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B6AA28AF7; Fri, 26 Jul 2019 15:53: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 C273A28B01 for ; Fri, 26 Jul 2019 15:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727985AbfGZPxT (ORCPT ); Fri, 26 Jul 2019 11:53:19 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42135 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387474AbfGZPxR (ORCPT ); Fri, 26 Jul 2019 11:53:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id q10so24705442pff.9 for ; Fri, 26 Jul 2019 08:53:16 -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=jBhHPgtxODdD8djD550WnXUjkZobaTeU989dQBu38Ug=; b=QOG8ekogU0xsW+ctK3G7Hn7H74eQbLKXrMl7CDuAkFahY6WektjeXIIdzN1iuzEJmD FNguU+2uFAeSZ9kfwHPwYm0zFEoo86CDHbpr6cfpr3NOKi8bZxjxBm/LdeODgm8dDV1I 9M3pf5xldR8sVH7bL7/UKxcRlhb5tWRkPxm89FaWni1xY+t1M0qcD0BGcRY/WXkRTyew ZUTJ6DM63kCoHj9s43tFZGY3AaqCUWFw8YT30Z/gyj6+J8nibs8z8oEmubQXc88Z6c5T Pl2zogUGjMz6UAcREacNZ3lGkNaCIHJvuEFlq0N7wFT8hSdUjceqKzbYFSFvGpOJXJf4 +h7g== 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=jBhHPgtxODdD8djD550WnXUjkZobaTeU989dQBu38Ug=; b=PjyLwToWcav1wY3LQAuaqmctXnM7krfcJVGWIQ2S3XxskZLrEL6YNVM2F/uytRoXX1 TeJEbHj3jEf8RcuIe58WnOe0RQCL6o+kU8myZ/uJVovGyS8wmnD23Htd8ClMGgP14BTU EHTRia42qkQLFcqP7nlgjTp1DUpa2chajIX8XxVM0l22AZa2ZIMVA0BGXRNk5t37n1Ny YMTRiE8PtVV+wERAQlGXD/cSNP+mG7xWIR+6y0DKf2igYax5RnyXfReL2rM/cmPMa2nf fTvZnPmG0N4zn9JgvPSMURELjxF2iK0ePvK+rwpisN/VRcXW99cejc1zQecKk0Ph/3NZ v8Jw== X-Gm-Message-State: APjAAAWUg4Odss/h/is3+9f1bf9oEk+8Vo9QYApGAXkqR16lna4GJ35O iUKQfEllXylkorDv37a7z69lKTYB X-Google-Smtp-Source: APXvYqzZ7SbuvFguHtlXxEqeuN62fka2K9VBSepo5JM+a1TMZYd+4+dquEMnbBqq1bieRBMo9OJaMw== X-Received: by 2002:a65:4b89:: with SMTP id t9mr22808596pgq.55.1564156395899; Fri, 26 Jul 2019 08:53:15 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:14 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 10/20] merge-recursive: rename 'mrtree' to 'result_tree', for clarity Date: Fri, 26 Jul 2019 08:52:48 -0700 Message-Id: <20190726155258.28561-11-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 8114e77b98..f36962b7b5 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3482,7 +3482,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; if (show(opt, 4)) { @@ -3552,14 +3552,15 @@ 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); if (clean < 0) { flush_output(opt); return clean; } 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 Fri Jul 26 15:52:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061291 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 C684C1398 for ; Fri, 26 Jul 2019 15:53:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6E9F28A56 for ; Fri, 26 Jul 2019 15:53:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB69628AFC; Fri, 26 Jul 2019 15:53: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 53A7A28A56 for ; Fri, 26 Jul 2019 15:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387858AbfGZPxS (ORCPT ); Fri, 26 Jul 2019 11:53:18 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36852 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387807AbfGZPxS (ORCPT ); Fri, 26 Jul 2019 11:53:18 -0400 Received: by mail-pf1-f194.google.com with SMTP id r7so24719401pfl.3 for ; Fri, 26 Jul 2019 08:53: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=3Oxwr0MkMxRcCbtTQYEQqKXqfQREqfqITvoyKi8Jut4=; b=OjH1zS13pcr+DdadLkspj/O5ukV5ihw8nRptt/4ISanUeyiQxuOeUfMLpn3dox8sb5 9FThFoU/nz8vaiOcwmHJVkYpJypLbtk60GldxotH107JgmnjrZ3TGTykWRx+Jj/sTlqq ZILTyHN1wRU2FVUuy9pZln5rDTkkRzYgkQJzd3VyWcBUSZ6EeDCjldWQLpaH9xTN7zKw fXV5EhQ2Jn5ooPPgBaTFnkGKCUaJnaDBU2le8KUC2XXYEhLYTQsTVuGfYl9NoVhw9+hQ o0U/2iSL0LX2bCoQD/dIuDRf6XOJGgZoyl5Ld3sBa2baOoj4+v7lvNX2SyssQQ5rIVJP UWsA== 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=3Oxwr0MkMxRcCbtTQYEQqKXqfQREqfqITvoyKi8Jut4=; b=RWWJJYPUHemH13UjcUSZ/n6PSzkkTRKEs0TfDvNF3g3H+u3YlKUjejLTfug3FJdA1X M+BbHyJZJmHx2Q1QXIelReHYUi6OKHqcIoZTFdF9tZOMPAA8wd1WDPoQYxTQmpMcaWeH GKbnTOZrWm62vCtl8HN9Pof7ES1vORsXETJzYjLuLJ30HLPm/xttgjbl0IHgKWiNh9Jl kELX0oMA0hsP7WAReVWjhtcn10FQ3+83pO5yB5tP3CKiY694u26Lq4LMy3rr1x4Vgyax fkErnhM5hFqAlROL+889/IDNJqEIvGwGSZPlytJCTkgxbe1v6EOg11CG7tuRJ+X44u4h gNxQ== X-Gm-Message-State: APjAAAVaercgwG/PzCwQAVcbl4kxmzp343gKgM1/QAvSLzPKsWS+LzhO 1dzBTLj8cJsppEevd8+dqtnecp3z X-Google-Smtp-Source: APXvYqzp13uMI9cJCnHyH/d+dWVNWsNYjgdmwqSUwD3S4R97PfUtgMqNcQ9ICOzibQyXQY8PsgFwkA== X-Received: by 2002:a63:c751:: with SMTP id v17mr76853836pgg.264.1564156397207; Fri, 26 Jul 2019 08:53:17 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:16 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 11/20] merge-recursive: rename merge_options argument to opt in header Date: Fri, 26 Jul 2019 08:52:49 -0700 Message-Id: <20190726155258.28561-12-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 c7ba8d0a71..c201de0fc3 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -64,10 +64,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; } /* @@ -81,7 +81,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, @@ -91,7 +91,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); @@ -100,16 +100,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 Fri Jul 26 15:52:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061303 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 A1EBC1398 for ; Fri, 26 Jul 2019 15:53:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9187128A56 for ; Fri, 26 Jul 2019 15:53:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8620828AFC; Fri, 26 Jul 2019 15:53:26 +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 E1DE528A56 for ; Fri, 26 Jul 2019 15:53:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbfGZPxW (ORCPT ); Fri, 26 Jul 2019 11:53:22 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39223 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbfGZPxT (ORCPT ); Fri, 26 Jul 2019 11:53:19 -0400 Received: by mail-pf1-f193.google.com with SMTP id f17so20724413pfn.6 for ; Fri, 26 Jul 2019 08:53: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=ps5Mv0xViWWM/7t8HZUEK3tY2SPHJIxjfUP8B/1IdFE=; b=AizV1/vI08qNKjuLIRmZKMVDvSafukGqa4zi1hMFa/8Rgjbe3OdlMI5Oq8CmK6tYrc Y26CSYZVFGqIfQ6tBLrh0gY6eG8dOn5y8aT3Gt08bPeJtqLqmYLmunUrHl2mXnIv8xFc KCHvCmFWsunWsxzkFdfM2OxSv+xxmqe6r3EbwAvnbUADzXMQ8vJzLtXGUAfTlUXix5BF nI64SPb85i3gEB3RS92wJzH1BiOeXv2sVns3jaUjCcVWSSkEbpwNxIzlpFTFj1/2pu5v V37W1iXdLw/C8XAoPp8RYz96jwffT14oe97b2SFxsNYY8M1jdyVNxu/Nj1CdAE9in5np FYYQ== 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=ps5Mv0xViWWM/7t8HZUEK3tY2SPHJIxjfUP8B/1IdFE=; b=N8+AezTCfnyr5f0U+rIGn4xnUifjXyX0WScloALvDY+igxpSd4kVcIKJuqj+1C5eqY SaipsgCoC9SVwDSMHbRhiaCUhdCZiGjkq20qatAlKphtgTcMNmhx2hAB//WlvL0DE2I+ j9QPZwo9iM/mfDezLYMfuCVRtUGNbU1/oEaq+aqhOPTVZ4q1NCBkD9gzBuVnf42AOiY9 89TSZbLfBoMy31KIFStKOcp4hMc3bj3+vyU5ouLyaiWfQ6L3Y1JENwOs54FMO3PI41JB A88nJocy/gqbJ8cRXbEqnKeQ3407olhJO+yS0cAhKVqSTHhjnSXkLSkh+PPr6CCmt89f LU0Q== X-Gm-Message-State: APjAAAXLBmU8YcrmeBzDq5s6i+J1sX05xOjT0nu4yggtNyzVAf5AbCn5 tU9FfCKAK12KZKJuasYQD7f22zvQ X-Google-Smtp-Source: APXvYqzBHJpiQHG18+29BIoisw0WfweLND9FMBawqaua1khOAHVK2YKyOlJH+ppHr4QMSWtk2sGy5Q== X-Received: by 2002:a17:90a:d998:: with SMTP id d24mr71362249pjv.89.1564156398286; Fri, 26 Jul 2019 08:53:18 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:17 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 12/20] merge-recursive: move some definitions around to clean up the header Date: Fri, 26 Jul 2019 08:52:50 -0700 Message-Id: <20190726155258.28561-13-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 f36962b7b5..6820578258 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 c201de0fc3..ebec855a65 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -39,47 +39,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, @@ -88,17 +91,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, @@ -107,9 +109,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 Fri Jul 26 15:52:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061299 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 15D941398 for ; Fri, 26 Jul 2019 15:53:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04E1A28AF7 for ; Fri, 26 Jul 2019 15:53:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAEC828AFC; Fri, 26 Jul 2019 15:53: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 6DF3928B01 for ; Fri, 26 Jul 2019 15:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387474AbfGZPxW (ORCPT ); Fri, 26 Jul 2019 11:53:22 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34323 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbfGZPxU (ORCPT ); Fri, 26 Jul 2019 11:53:20 -0400 Received: by mail-pf1-f196.google.com with SMTP id b13so24718239pfo.1 for ; Fri, 26 Jul 2019 08:53: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=k7S5o87maWG1/vTSvmmlzbacnkYN6ikr5gM9cNEzbGU=; b=SvG/Y3qNMPKnRSzD6B+vXy20snD9IG0rZVmGN9B9UK2HXEFcxq2sKwQDtHfqpQi5wF gyjQx/AcLYha/f4fAZOu/mav7uG1dwJdOwn5jiic9odlZ2KfNFVLudgzRXVlFAJUI8WZ Dr1vXnKiqg6qdCzx8ZX+IlXvrpL0ZWwG3wwBBmq80Wv4OXA3Gw1zaxq6nLJCnpXlxMNB H34RFOwigpZOWhstQ540oM7d0QkZ9csqNhDQZoCIV3bYVXVkOg/dm03IztSVNwZXW78q VEFa7iMVd1/dyoDn7RJRZHqnWfJpGwRRK1wxSVSeVXhOLyGuw9jR2k/FgnmnkzTYDCW5 R7PQ== 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=k7S5o87maWG1/vTSvmmlzbacnkYN6ikr5gM9cNEzbGU=; b=iTgzmAGnxO0FXo56hwWu6agvhxVhG2D3nHl89vci0wDalqsDjNCBhgT27PkRu0NQv6 ilqm6/EEA9ySqlV36oGs3YKCqGg3/HpJbG12fo9tsWP0Y647zWJT9tl5ilgjSGq01Ez8 T2mJLpQG1gEM6ycU/Jqfa2MS1fnF5exqgD7pU4Ho9u5VPLVs2p5XokLQfcksY+NynMx1 ETI5l459WLcPUDKJYvK2pj5ZsjoW3YOO06cTJ1Bt2eKEfPA0uavPLFLQtGOop9+f/A0/ eIitzjuZjRxNS6Y4hQyDpbKbV/9++NfKtRZcBLfFpxambIgaleLzS7P007gkNg1OXMIL bTaA== X-Gm-Message-State: APjAAAV685AR3CgbWq4ov2pqqh1eDMz6Qz8umYujUTC5g+ha2tQWHqst hbZj92Ujrdybj43ZXKfLNmrPWQSK X-Google-Smtp-Source: APXvYqxndJ8dEUkKP9sD52AiJM/OW4yPjIU5mSHeB+c5+WxiSTyqdB7V+ViHTVnm2oVh2BPgufifyg== X-Received: by 2002:a17:90a:b394:: with SMTP id e20mr97857068pjr.76.1564156399459; Fri, 26 Jul 2019 08:53:19 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:18 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 13/20] merge-recursive: consolidate unnecessary fields in merge_options Date: Fri, 26 Jul 2019 08:52:51 -0700 Message-Id: <20190726155258.28561-14-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 6820578258..bafac63c45 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 != -1) ? opt->detect_renames : 1; } static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree) @@ -1885,9 +1884,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 != -1) ? 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; @@ -3719,14 +3716,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)) { @@ -3749,11 +3746,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 = 1; merge_recursive_config(opt); merge_verbosity = getenv("GIT_MERGE_VERBOSITY"); @@ -3805,16 +3800,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 ebec855a65..b92a9ebce7 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -23,10 +23,8 @@ struct merge_options { long xdl_opts; int verbosity; int 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 Fri Jul 26 15:52:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061297 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 89CA2912 for ; Fri, 26 Jul 2019 15:53:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7954028A56 for ; Fri, 26 Jul 2019 15:53:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DEDB28AFC; Fri, 26 Jul 2019 15:53: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 0AA1628A56 for ; Fri, 26 Jul 2019 15:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728180AbfGZPxW (ORCPT ); Fri, 26 Jul 2019 11:53:22 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44413 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728032AbfGZPxV (ORCPT ); Fri, 26 Jul 2019 11:53:21 -0400 Received: by mail-pg1-f194.google.com with SMTP id i18so24976153pgl.11 for ; Fri, 26 Jul 2019 08:53: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=9QDbpvUfuAhsWqLbhNwyCSuBsrdxh9u9ZMASRXxN/vY=; b=OdFTyDRu/ACy/nFR8E23rKI3VsQkaxK7S5FIFAM/ug7Q0YDiP5SjS5ViblfFb8R+wL ftX3fWFlRHwfx+Lrq3CNNpiPJYCaNCSfdh+EiUWL522hFtKOdlXjqOdSU9VVBa4qf0SA OKvaAl+7vb3rleAmvOotwHyXM5H6/3MjUFqIUP81czSxScFaZOuddmB8dhrN9BIWWlYW Xztv+HODfnhCAOPn3RuAOW9iWODtTo8kV4l9vzjeIG+yefPQ+ANFSnTj725w9DkBnr+b tCc84WuRkzTAEMuusS6PK5VbOJftntZYAvudOiVApkfWV4WBFonFQv817bD3aR5L9sPR YRMg== 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=9QDbpvUfuAhsWqLbhNwyCSuBsrdxh9u9ZMASRXxN/vY=; b=oLpmjaxKmOWFjWXAjJAvNQXw+L/U8rCF9oO9Vg9OU47s5maZj/kPzvbaMDzhMTZPub /U1zPcCeRZdefVKdz5sHiazQFb39ioV/HLic23vAjlQ4T/plG1aZry8aS5juFmad7s6n 5vIzOR0k9obhpUq0ex10YrydNq9wvAP60yDz3D6nzLP2pbQ9ngPvjbDDafZ57zYMAKvR 9gHpCaPXcV8GwatvaOjQe927JCMjj7UxT9sDaA3zEaCccqJBOp9Y0kNLfq94+2Ys4gez 36Y4MiW4CgWGiPZmVJrsD8QkRi0wlNUxPHuq1BSwwsGsGrm1zj3+GPJwCJJQCSAD4wjw Ggcg== X-Gm-Message-State: APjAAAU/n0wXbH8qh+tm3gxpMTVyk/9vzQ7ZkoSuZDdco0xT7+dPtd5a 7wW9cI7R37oX+FH3b3D7X0IBhz0J X-Google-Smtp-Source: APXvYqzAIBKkxAoJQiCiUGOEOpefhAv4yiq9qI7jRcdnYIi3fggfgkmB+nB1WmV/5DqPekmGNcUQbg== X-Received: by 2002:aa7:9819:: with SMTP id e25mr22221934pfl.47.1564156400668; Fri, 26 Jul 2019 08:53:20 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:19 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 14/20] merge-recursive: comment and reorder the merge_options fields Date: Fri, 26 Jul 2019 08:52:52 -0700 Message-Id: <20190726155258.28561-15-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 | 34 +++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index bafac63c45..a8e4a6a531 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3743,21 +3743,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 = 1; + 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 = 1; + + 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 b92a9ebce7..b6d420960b 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -9,32 +9,44 @@ 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; + + /* rename related options */ + int detect_renames; + int detect_directory_renames; + int rename_limit; + int rename_score; + 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; - const char *subtree_shift; + + /* 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; - long xdl_opts; - int verbosity; - int detect_directory_renames; - int detect_renames; - int rename_limit; - int rename_score; - int needed_rename_limit; - int show_rename_progress; + + /* 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 Fri Jul 26 15:52:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061301 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 5889F1398 for ; Fri, 26 Jul 2019 15:53:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4888128AF7 for ; Fri, 26 Jul 2019 15:53:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CD2128B01; Fri, 26 Jul 2019 15:53:25 +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 CB2AF28AF7 for ; Fri, 26 Jul 2019 15:53:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387807AbfGZPxY (ORCPT ); Fri, 26 Jul 2019 11:53:24 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44916 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726191AbfGZPxW (ORCPT ); Fri, 26 Jul 2019 11:53:22 -0400 Received: by mail-pl1-f193.google.com with SMTP id t14so24888530plr.11 for ; Fri, 26 Jul 2019 08:53: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=z/e+7XtjTTBo60kW3wuP7FQLWxjFuMNMvLv6Z3cedZM=; b=OZeLvwI05hKoUvx0wW5Q5na8/pNp/2RXee3zohr7tK7uiaCk03NqnrW5oBnBj6yGf0 VNw6D4N2bBp51gq7aaKdkZ3mUVHkvA0E1PvtKYQiVKxxb+BRykZZv3EdFM8UVTUcv+dz we0L13fX37XxghHgLEDiRN6Tj5I33PwmJPmMdCe+C5C/5xB0vttmJjKvIwlhijA7njtK O8hk7v8DsrTa0Mn0HPxifqw6GQJGjpQBVu9irAjIDYvwEyj63zs/wNrQo4gx9zLXgilh k0t52X9+8t/TkkSIwdSj4LR0z7NDaZbTjKRP6PIX7G4PaIDxOPmDYjfNbaD4EGNO7nLE ItLw== 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=z/e+7XtjTTBo60kW3wuP7FQLWxjFuMNMvLv6Z3cedZM=; b=I9qdC0BSH7EsmY9baNpcQBeN5M3MI1Z/BCDr4+Wjz2Tt3n0quLgyisWF23ZH4mB5ou rwoEIgOyPVlyAN9PTMof5RcpjmcAvpkEeabR6ZZekjfAT50ze2nn6AYWV9rDEay3v/jO kAbgT5a+WpS/E57ZTaUllmDj05L3/Nyms+rcQuZkTV3QCL1/xvPBXKpF7GZQDYggyxgn g3WB1kdnFmxTOy/ciT5GmjlEtaO4aGHVxilyuPnkHSLNBEJ8MyueDsrOeJdzNoRyo4JP UXrGbqfxNcwAvrKPCc5T+ojE4s/anqbid7lCelUgP5I9Q4jlF5HShAor9Iv0kFsRzzDt m6hw== X-Gm-Message-State: APjAAAXJV5Djz4wJ9/Vr9U2612Bd69NOo0UI90gPYNxvYZ+r8THlSgLa 0Vc56/mcFmL2ZlFacX41NPooHzk+ X-Google-Smtp-Source: APXvYqz8SuNaKGonr147h1tPtpDkMhR2WIYf59OSAvMUBWQRgJqRga0H8Q3OkC/UiuzinML6Evwcxg== X-Received: by 2002:a17:902:8490:: with SMTP id c16mr99010434plo.1.1564156401657; Fri, 26 Jul 2019 08:53:21 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:20 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 15/20] merge-recursive: avoid losing output and leaking memory holding that output Date: Fri, 26 Jul 2019 08:52:53 -0700 Message-Id: <20190726155258.28561-16-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 a8e4a6a531..49c7de0379 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3592,9 +3592,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; } @@ -3616,6 +3613,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 b6d420960b..12249258ef 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -34,7 +34,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 Fri Jul 26 15:52:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061305 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 C8877912 for ; Fri, 26 Jul 2019 15:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B65F328A56 for ; Fri, 26 Jul 2019 15:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA52028B01; Fri, 26 Jul 2019 15:53: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 3385028A56 for ; Fri, 26 Jul 2019 15:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387874AbfGZPxZ (ORCPT ); Fri, 26 Jul 2019 11:53:25 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33674 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbfGZPxY (ORCPT ); Fri, 26 Jul 2019 11:53:24 -0400 Received: by mail-pl1-f194.google.com with SMTP id c14so24855900plo.0 for ; Fri, 26 Jul 2019 08:53: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=uy/EJx92p0YLrRcNn1SXSm10rhhfyumTTpmy9dD6Hqg=; b=l+D5+bM53DXxmd/uNmNC6g7U1yALxz9llU9YfA2kL/sxjPwwbadxxwGXqGDSQuRUza NbLgsJEJDeEf/H7N6p0p0BzxJYNEX4Ybz6SWWBVmpYks8zwcFUS4LvJpIG3dJrs+oYuk V4hY4qvpq2u90v3rQm+nhR7ghlrSLVH4WjwK6cmz8FBIEelmkYt7MClCak3Wa7+oeHG5 9xJUf7hnIDo5SzQhxLZxGIWLt8C9gxWyq4gUGnQyJaq4V6a5Q/sg0UmjHz3GL1H/2UuY vlrVmXbpUgdw555qSPPu+hx8D+mWPZ2oDckTeMiwMBl9RkVvV4FmrLUnqjrWtg5NsREZ vdkA== 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=uy/EJx92p0YLrRcNn1SXSm10rhhfyumTTpmy9dD6Hqg=; b=ePod1QpHYav4MIvwDacUnbfGU2thT+8Zek4I++ZLy258AYeUn5JWCMbymw23t8zkZx rn7QIXcl/pnB4zjhor/2wj/AiR4ua634iB4gZL7OM3LPyJgY9TS8J/vdb1/jPl1QuPTG UbbMOwdrpfWi1VO9kwnjGbepgZbiAn64y9a5yP+2DHvSebVRYzaiidWvGmQpbjJTweKe HMpq1ThpbHFmFDToMBoDAf0r+7SYRRzkoaOru746bAEn2MYz9r2lJ4AOLu3C+U2kfxkN QV5UfaJ+GNhLyudc6aieWm6AWhftcQosqyIYeOE/xeDw+xOgseFySijS25OeYB0pYUnp oS/g== X-Gm-Message-State: APjAAAVyOOZnGGUhwooGbE1XFrWhJNFQJ8TF0nTb6cQx47zDwMJKpFJg K12E41IoRA6j8YAoKTS3QtUug+wm X-Google-Smtp-Source: APXvYqyHQYajRvwaqi+keOc7kj4/EMwhB94jTmbzDXCMWFYsD79/gWi7xe3qQZhI3zGHX6mPSh2tMA== X-Received: by 2002:a17:902:e65:: with SMTP id 92mr92982988plw.13.1564156402799; Fri, 26 Jul 2019 08:53:22 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:22 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 16/20] merge-recursive: split internal fields into a separate struct Date: Fri, 26 Jul 2019 08:52:54 -0700 Message-Id: <20190726155258.28561-17-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 | 184 ++++++++++++++++++++++++---------------------- merge-recursive.h | 17 ++--- 2 files changed, 105 insertions(+), 96 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 49c7de0379..ba635ed753 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 { @@ -1164,7 +1174,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); @@ -1385,7 +1395,7 @@ static int handle_rename_via_dir(struct merge_options *opt, int mark_conflicted = (opt->detect_directory_renames == 1); 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; " @@ -1428,12 +1438,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 @@ -1508,14 +1518,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, @@ -1552,7 +1562,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)) @@ -1581,10 +1591,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 @@ -1626,12 +1636,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); @@ -1671,7 +1681,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); @@ -1689,7 +1699,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"), @@ -1720,17 +1730,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 @@ -1845,12 +1855,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); @@ -1891,8 +1901,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; @@ -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) { @@ -3332,7 +3342,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; @@ -3341,7 +3351,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 { @@ -3406,7 +3416,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)); @@ -3425,7 +3435,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); @@ -3462,7 +3472,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); @@ -3474,7 +3484,7 @@ static int merge_trees_internal(struct merge_options *opt, unpack_trees_finish(opt); - if (opt->call_depth) { + if (opt->priv->call_depth) { struct object_id tree_id; if (write_index_as_tree(&tree_id, opt->repo->index, NULL, WRITE_TREE_FROM_MEMORY, NULL) || @@ -3545,7 +3555,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 @@ -3564,14 +3574,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 = "merged common ancestors"; @@ -3586,7 +3596,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); @@ -3608,17 +3618,21 @@ 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(opt->priv); + opt->priv = NULL; } int merge_trees(struct merge_options *opt, @@ -3756,8 +3770,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 12249258ef..0d5e928832 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; @@ -41,13 +43,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 Fri Jul 26 15:52:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061307 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 451C4912 for ; Fri, 26 Jul 2019 15:53:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35F8328A56 for ; Fri, 26 Jul 2019 15:53:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A55E28AFC; Fri, 26 Jul 2019 15:53:31 +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 C651028A56 for ; Fri, 26 Jul 2019 15:53:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387883AbfGZPx2 (ORCPT ); Fri, 26 Jul 2019 11:53:28 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38178 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387864AbfGZPxY (ORCPT ); Fri, 26 Jul 2019 11:53:24 -0400 Received: by mail-pg1-f196.google.com with SMTP id f5so16156397pgu.5 for ; Fri, 26 Jul 2019 08:53: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=LaUZndmPjTAJX+NfTNj1j3eHLbwDbmNx6hO86Wr0Cag=; b=UYV6RzeBAL9xoQjvm3VrR51fcmdshOCLaay3gFNLYlEgbiI/xgkALiw/l6o9BWVlA0 SXIZaiWgzrYAIjUV8bR5BN6Dt9BK+MP3AcN8lSbqCr66jOWHzO88x8RWHplL1HX3NbIu 5jjDW5I8IvbGWGd9NRSERWKGgsTQZO4OKMp2yaq+VTA953Antp9Ae0EG2tc6QPOh+Bfe fmxhubf7Wfu5sM0vLWIHOliH5trX6K68vg58I05tPDuLmalVhuhcIDw+AjVfYiB8A83V PJnIvSs9vgB+lqvs1PB95jdIuvxoypQ9siVCjwSp489LrEVG44Y7KmP1iwFCCjL3ZY7d wxdg== 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=LaUZndmPjTAJX+NfTNj1j3eHLbwDbmNx6hO86Wr0Cag=; b=b6ct0pjqT/Y0/8ZUUDAzSCRhR62Io7dbdQlHdzltf/UzaZV1NT8IcgY/+/xjMVetaB Lsp8roNHFwCQR77c7bt5mKJRjfqn7L45HNuZ1oEIkfQaHTwnfLlA7IOfqD/rPQlE2dMx bsh087cSSOel78TX6H2gPKaSh/nc7uU+/acQPNtYeyz0B4HHT5YUzk76TIh8NBnaa9kr OpeHAqT3UV2vv5XA4fGN+Sut46kyHH9urOHIlySiKRCatILv7f4+UYCFg7tk4KU7Ni0N yECXvGBr0dbeCD5B6eCxgQ3Zb462s71o6E2dtvIe1Iz/Wnf8RqDieZ8O8h5ooOgtgqOM hljQ== X-Gm-Message-State: APjAAAXZOfD0hcwrYM3G+QPmH3WFqwBuhSSyasCjXYR/00JZoVfkQDbR qBeUFFpHgHLGQi0oD/g2c+IuJ6my X-Google-Smtp-Source: APXvYqwC2/FVVBU3DBtjM/v1ZCTPNsNPjPON1itg8LiNtfYEaDHInwR/eUkhbXDMw2ECi6oheKwhbg== X-Received: by 2002:aa7:8102:: with SMTP id b2mr23185220pfi.105.1564156403645; Fri, 26 Jul 2019 08:53:23 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:23 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 17/20] merge-recursive: alphabetize include list Date: Fri, 26 Jul 2019 08:52:55 -0700 Message-Id: <20190726155258.28561-18-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 ba635ed753..27e0bdf48c 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; From patchwork Fri Jul 26 15:52:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061309 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 23143912 for ; Fri, 26 Jul 2019 15:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 128F428A56 for ; Fri, 26 Jul 2019 15:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0620328AFC; Fri, 26 Jul 2019 15:53: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 A0E9F28A56 for ; Fri, 26 Jul 2019 15:53:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728320AbfGZPx2 (ORCPT ); Fri, 26 Jul 2019 11:53:28 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33676 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387870AbfGZPxZ (ORCPT ); Fri, 26 Jul 2019 11:53:25 -0400 Received: by mail-pl1-f193.google.com with SMTP id c14so24855927plo.0 for ; Fri, 26 Jul 2019 08:53: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=1Z6F9twMkSbreoW1v/Rpsvj7PeUmVMVkgcfx+om6qCU=; b=Fxq5m6ZPf7aXxUu6nJj8m6QQzGEx7wb5Jj0mUhRQ+tdOEWDm+rccAiVtnCTtaQUo9U ChlMb/oozVFVAhn9JrVY3Ux+RnYAwuNbRJvHlRigWTocPS+VX3JhEaiFdv05tGg/8kDG 00+JTJMx1HG57q0f9JrfvQvxAgZDr/GQISVbMyGxRRuBoFYUDWhHPfSZLryD0gEToYoZ fWQuRdOdUEygPPrECAbhSeLya1Zs/wbATZFDUycZKMjHK1Q1QyjifHmuxYRDJkA6sTD0 Z6clf0xm8VoubqeaOBixQSmeccBiTHy0GUSoE7QDmNKi1oOTWf3yKw5JAMItOKLfi0Yh IIkQ== 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=1Z6F9twMkSbreoW1v/Rpsvj7PeUmVMVkgcfx+om6qCU=; b=c0Ry7E8OOlN8YwDhxS7EaMxvO5Ks8+Y35baWDL4kXCHtl1ockZOaunvHGuvwkLphvM gcdCW2PeO+rhdQwam9fjL01cmxsCLRK2Afk03UGLn165iiTDR6xglIlicX2K4OX2MZC8 4P1x8ySISRJoWTC9vGh3ZU4wfogUNu32vnCwrXrPCqWMvP11/k+cnAupr3ZQJdJv2k92 vNI/yxH9CaSoLuUrOlAWT+nehl17hzerT7IlGmd0TWgY0eiskMa8pFfSdazWpISZY3Kn qKIA6xaDiTBQH3C3kYr9C20bO1ZBw+50DGHEiNl164P28DKIWCE3TyRCffcPvDhvGgMh ptGw== X-Gm-Message-State: APjAAAUxtPd4wxoM1xXDJgL1kUT347YkFY9vejUW6QVyxpWBFloHAjCn R8BWxyMBQELu3rtEX/TbjBOjG/nU X-Google-Smtp-Source: APXvYqxR5IS2Pc0aDhsBLw7dLCNWHxdEaVx+EpuDCTyF3va2Jp+dbt2esxoareQedN+vFRlOEqciSg== X-Received: by 2002:a17:902:8489:: with SMTP id c9mr98098002plo.327.1564156404798; Fri, 26 Jul 2019 08:53:24 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:23 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 18/20] merge-recursive: rename MERGE_RECURSIVE_* to MERGE_VARIANT_* Date: Fri, 26 Jul 2019 08:52:56 -0700 Message-Id: <20190726155258.28561-19-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 27e0bdf48c..49eb50c17b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1046,10 +1046,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: @@ -1359,15 +1359,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; } @@ -3786,9 +3786,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 0d5e928832..350fb43a01 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -28,9 +28,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 Fri Jul 26 15:52:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061313 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 9E16A1580 for ; Fri, 26 Jul 2019 15:53:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E19128A56 for ; Fri, 26 Jul 2019 15:53:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FF3428AF7; Fri, 26 Jul 2019 15:53: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 34F2928AF7 for ; Fri, 26 Jul 2019 15:53:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728270AbfGZPx2 (ORCPT ); Fri, 26 Jul 2019 11:53:28 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36398 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726191AbfGZPx0 (ORCPT ); Fri, 26 Jul 2019 11:53:26 -0400 Received: by mail-pl1-f194.google.com with SMTP id k8so24931130plt.3 for ; Fri, 26 Jul 2019 08:53:26 -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=Qztoah4mGPIon6k+tdJoMNxVI8q3qQtItB2s1j6xz+M=; b=CX/XIzkQYG9X8lt/BZKFe9/PpfHaOQF/6PnRjrOnrWxkb+Zwfq56YDUwyePyqM2CG7 k2iCIog5aGHDRLQoebnP3O1+X7MCSD9e6nwt1l+rK6tSnhnv845Qp0HwMuJNuWJEdvBB IIu0elf2QJv5OlWLJrJ2VNsHv7TZEmLAjpFQLIZZK0Op/ng3vsX8hEIHyyMiaF7xfptd L/XXLzYnkkupffAACF34uTujIgdkBSM9ZgfGy35O0g3GcIXUXmn/ohUpcozFpOng3l3C ALjNpHNjrFyAtL4wPtEpljk4KGW/dO14+5U/+HX5YIm7c2ZUoHvX4FpqJvy6jQagJtr2 cCqQ== 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=Qztoah4mGPIon6k+tdJoMNxVI8q3qQtItB2s1j6xz+M=; b=fu1Oyuhcvl/ral1Rp4djr+GBeL9+9WfjxAmCdmdYfPF3apsO6T0+DszmQcYYGhxNA5 e/1Zf6Qj6D5irmU4+ibHmmmqlMrNZ9wDZ6m7cqMypFzGKxR9obPyz+AxKB1C0dRtv2gu oa4s/J7KqnHLZaSKcoT97dswqxwgZKbfCE590iliW0UM6msFMDsWhz74gcKnPVQ9gFCo c3S27nqehVeIJGh/6KhwaWc3AKZMvHihVm+Ej6Wy9n3Zr6I6P46/xKR0stfSK4M1md0L izA1a7dLFhi/NLF44TA6tINf4gopcAZD/Ns5VKDqcvmZ8ZXKB18OKv3naF/RBjVHOCV/ Yzew== X-Gm-Message-State: APjAAAUomQ/wH4p2VHlLPmdNL80YI/DIQZEuH5+LzOd+WgaBsuYfLcDV UXilu768jSkPZxRRewD3OZDYO6Zm X-Google-Smtp-Source: APXvYqyR4FDNAiPmqksg0fpC5Ju1Ppmwi8+rQh/9bGEq7pwIdG69hVBIhX0HSr6Fhfqnu+7V/cvppA== X-Received: by 2002:a17:902:a9ca:: with SMTP id b10mr22952213plr.69.1564156406157; Fri, 26 Jul 2019 08:53:26 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:25 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 19/20] merge-recursive: be consistent with assert Date: Fri, 26 Jul 2019 08:52:57 -0700 Message-Id: <20190726155258.28561-20-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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 49eb50c17b..f1e2658457 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1058,7 +1058,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 Fri Jul 26 15:52:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 11061311 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 88F311398 for ; Fri, 26 Jul 2019 15:53:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7802628A56 for ; Fri, 26 Jul 2019 15:53:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B05B28B06; Fri, 26 Jul 2019 15:53: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 A177E28A56 for ; Fri, 26 Jul 2019 15:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387865AbfGZPxc (ORCPT ); Fri, 26 Jul 2019 11:53:32 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44926 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728192AbfGZPx2 (ORCPT ); Fri, 26 Jul 2019 11:53:28 -0400 Received: by mail-pl1-f195.google.com with SMTP id t14so24888631plr.11 for ; Fri, 26 Jul 2019 08:53:27 -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=YLTpY1gU5zWwk9q3BLg+ZtJwcdTQniKTPSSxYgicyOk=; b=ljyh1Fg0F8UcPfmq4LkgGGqutQK9cQJAyNDx7+ZLRPGQ9a4DMTFltvaVNdPvUb73dR XtEMXTuTA+KSVk1Q74ffPokJFrWd6B9HEEVtZEd+bt15BLyueKheCkK6LvfIbUIHFG/S yRjUpj6nNxaQHn3MO3r0up7Gj1IbN2YwEp3lqxcIzhevKfxa2E4JzdaX5dQN+qrgMRMe n3bzBo4Ocih2FEtKIiojl4pdHq/mUsOsUC2F5yOGJMvqMFgK1tm+hYeGefgD6Vk5/97r tSeI/aWXwM1ob9kpKQ8dfueY6h+VHOHGhMZ/Zv5mkEW4ranc5NfmhWvSNSU94nlbDoKF JFjg== 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=YLTpY1gU5zWwk9q3BLg+ZtJwcdTQniKTPSSxYgicyOk=; b=ANAyyx7DMTrVjKn+7hbEwfOWozTYF+cORrFgSxIltKZKB6Vl5hXonkMX0kcl8/ljBx gvPXrwGRZq7FcWJE4yvraZeksAw9wzBcuZnb2GOaFtXYi0AFNSYYwVUrveU93GZ4Sa+G JTPt/MWcEkDlOCRkHqLte0mN0J7cxXqah6KyINCnm0K7SUjEPVz8UJO+D9ThQlDc8DGi DIhR/Jy8eZAKln8UMJOcCc+mjMMX/XVcnG+ltfjVg6KW7WULiboRbvik4Y49wsDrxzE6 IzNtrPQfBXEIsStQjH3SFEsM+OGr4cR5edn/bsBR0ethc9emxoGUasnCERoyB2Lwd6Qp /XRg== X-Gm-Message-State: APjAAAW8yf5xwkRXZmfJhKxN1Lf+xBuGypmBREXjhS6Efz6WWzQoUwOA rC7iOz6o3SAsHNIJoJ5d3um1FnRX X-Google-Smtp-Source: APXvYqwdMGkuaFbjJfxwnRVnVGmSJr3W9BGFAeq+v4RBi5Blnp4nMkgqoYhMbHefr0I1PiTtq1CrjQ== X-Received: by 2002:a17:902:42d:: with SMTP id 42mr92551892ple.228.1564156407027; Fri, 26 Jul 2019 08:53:27 -0700 (PDT) Received: from newren2-linux.yojoe.local ([8.4.231.67]) by smtp.gmail.com with ESMTPSA id f27sm36669638pgm.60.2019.07.26.08.53.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jul 2019 08:53:26 -0700 (PDT) From: Elijah Newren To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Elijah Newren Subject: [PATCH v2 20/20] merge-recursive: provide a better label for diff3 common ancestor Date: Fri, 26 Jul 2019 08:52:58 -0700 Message-Id: <20190726155258.28561-21-newren@gmail.com> X-Mailer: git-send-email 2.22.0.550.g71c37a0928.dirty In-Reply-To: <20190726155258.28561-1-newren@gmail.com> References: <20190725174611.14802-1-newren@gmail.com> <20190726155258.28561-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: "" Also, the code in merge_3way making use of opt->ancestor was overly complex because it tried to handle the case of opt->ancestor being NULL. We always set it first, though, so just add an assert that opt->ancestor is not NULL and simplify the surrounding code. Tests have also been added to check that we get the right ancestor name for each of the three cases. Signed-off-by: Elijah Newren --- merge-recursive.c | 39 ++++-- t/t6036-recursive-corner-cases.sh | 8 +- t/t6047-diff3-conflict-markers.sh | 189 ++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 14 deletions(-) create mode 100755 t/t6047-diff3-conflict-markers.sh diff --git a/merge-recursive.c b/merge-recursive.c index f1e2658457..6d5dce17fc 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1034,7 +1034,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; @@ -1058,16 +1058,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); } @@ -1076,11 +1073,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); @@ -3523,6 +3520,8 @@ static int merge_recursive_internal(struct merge_options *opt, struct commit *merged_merge_bases; struct tree *result_tree; int clean; + int num_merge_bases; + struct strbuf merge_base_abbrev = STRBUF_INIT; if (show(opt, 4)) { output(opt, 4, _("Merging:")); @@ -3544,6 +3543,7 @@ static int merge_recursive_internal(struct merge_options *opt, output_commit_title(opt, iter->item); } + num_merge_bases = commit_list_count(merge_bases); merged_merge_bases = pop_commit(&merge_bases); if (merged_merge_bases == NULL) { /* if there is no common ancestor, use an empty tree */ @@ -3585,13 +3585,26 @@ static int merge_recursive_internal(struct merge_options *opt, if (!opt->priv->call_depth) repo_read_index(opt->repo); - opt->ancestor = "merged common ancestors"; + switch (num_merge_bases) { + case 0: + opt->ancestor = ""; + break; + case 1: + strbuf_add_unique_abbrev(&merge_base_abbrev, + &merged_merge_bases->object.oid, + DEFAULT_ABBREV); + opt->ancestor = merge_base_abbrev.buf; + break; + default: + opt->ancestor = "merged common ancestors"; + } 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_merge_bases), &result_tree); + strbuf_release(&merge_base_abbrev); if (clean < 0) { flush_output(opt); return clean; @@ -3644,6 +3657,8 @@ int merge_trees(struct merge_options *opt, int clean; struct tree *ignored; + assert(opt->ancestor != NULL); + if (merge_start(opt, head)) return -1; clean = merge_trees_internal(opt, head, merge, merge_base, &ignored); @@ -3660,6 +3675,8 @@ int merge_recursive(struct merge_options *opt, { 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, merge_bases, result); 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..f69c8256bc --- /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 "|||||| " 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