From patchwork Sat Jan 29 18:07:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81201C433EF for ; Sat, 29 Jan 2022 18:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353007AbiA2SHV (ORCPT ); Sat, 29 Jan 2022 13:07:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352994AbiA2SHS (ORCPT ); Sat, 29 Jan 2022 13:07:18 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A890C06173B for ; Sat, 29 Jan 2022 10:07:17 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id e8so17240137wrc.0 for ; Sat, 29 Jan 2022 10:07:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=HsHj2KxDWTA9QM6TZSN11NDwemvgrQd3pHbka8fElO8=; b=p8OJnrhjeN6FRKHoNflXgrUCy41hpHiBXCko0rdzUBOwlKNEeEIhbH2FxNko4veTn4 Ae07fwHN3IvOKMhBcsOi5CZCraYVuigGQxSscajQu25jFSiUSZSvIv90Yhy0oLRye4QR 9z0vdF49SbZXw+3OmaeEcTKpYrsDb4l+W7pidrH4NZbKrGNkZNjdI2yfGcMpIR1do7pg /u25uq7Y+QQTHH+6DuxZjtvtlhtMDfRf7RHEy68NCQpJAGIop1z5yqjl+JBJ/OVgFfLf ba2q6HOB09SxJfyl6q3PoxUqJiAwAF41v8uWE/lAqndv/S5PaBB61ZSGQjiNP/BCqM7a 259g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=HsHj2KxDWTA9QM6TZSN11NDwemvgrQd3pHbka8fElO8=; b=z/YcjI9Qk7BltQn6T275qcmGsS5qjvTh1F3Ac98xZwC9Zm9ltwsKXY9VAO9BKsp43A hsy8wNCwo2odynNbNcaM9BqlYU7rmuKW6/rf+qT8qCCYKoYVp3pvB+SA5RsXpH18rqH/ XQUfBrL5Q8ti/4oaiRllAalI+xqSH1p3L5CIfSEqpDHXheWOTdomQAl/r5SG50W5uu/g QJYCf6GiibRtlOs25Bjoz2iHzdlKooYxPiENofQS0eGxN8rNJH1gSUNfeyVP8b1xhS1J QWrLfMXXPvNd9kAaTxEyUXHBFmn6M8tDYDOdtrNUKQebpKwwYtkI3jZ0ANS87MUtx2V5 8M+Q== X-Gm-Message-State: AOAM533V3ReuxZnEQnTbzrh3tSXZI+ZkzEPJeOFDIMUtLm6zwhR3V0qf 6SNR8tDVk5HDFdzOq5bwZs4usTapskI= X-Google-Smtp-Source: ABdhPJwY4RlBMAri+GRFGwMHZyLuzyb1N240ggMSpMvVzjl3L9aX3AgeXUOjrHG56GRVr4vftgHsTg== X-Received: by 2002:adf:fb4a:: with SMTP id c10mr10902820wrs.243.1643479635923; Sat, 29 Jan 2022 10:07:15 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x6sm8720770wrn.18.2022.01.29.10.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:15 -0800 (PST) Message-Id: <4a7cd5542bb2f89b4874e4115542ccee9c4639af.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:01 +0000 Subject: [PATCH v2 01/13] merge-tree: rename merge_trees() to trivial_merge_trees() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren merge-recursive.h defined its own merge_trees() function, different than the one found in builtin/merge-tree.c. That was okay in the past, but we want merge-tree to be able to use the merge-ort functions, which will end up including merge-recursive.h. Rename the function found in builtin/merge-tree.c to avoid the conflict. Signed-off-by: Elijah Newren --- builtin/merge-tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 5dc94d6f880..06f9eee9f78 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -28,7 +28,7 @@ static void add_merge_entry(struct merge_list *entry) merge_result_end = &entry->next; } -static void merge_trees(struct tree_desc t[3], const char *base); +static void trivial_merge_trees(struct tree_desc t[3], const char *base); static const char *explanation(struct merge_list *entry) { @@ -225,7 +225,7 @@ static void unresolved_directory(const struct traverse_info *info, buf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2)); #undef ENTRY_OID - merge_trees(t, newbase); + trivial_merge_trees(t, newbase); free(buf0); free(buf1); @@ -342,7 +342,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s return mask; } -static void merge_trees(struct tree_desc t[3], const char *base) +static void trivial_merge_trees(struct tree_desc t[3], const char *base) { struct traverse_info info; @@ -378,7 +378,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) buf1 = get_tree_descriptor(r, t+0, argv[1]); buf2 = get_tree_descriptor(r, t+1, argv[2]); buf3 = get_tree_descriptor(r, t+2, argv[3]); - merge_trees(t, ""); + trivial_merge_trees(t, ""); free(buf1); free(buf2); free(buf3); From patchwork Sat Jan 29 18:07:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5197FC433EF for ; Sat, 29 Jan 2022 18:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244514AbiA2SHW (ORCPT ); Sat, 29 Jan 2022 13:07:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352996AbiA2SHS (ORCPT ); Sat, 29 Jan 2022 13:07:18 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4C9C061741 for ; Sat, 29 Jan 2022 10:07:18 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id s18so17133637wrv.7 for ; Sat, 29 Jan 2022 10:07:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=s/FNUD3Nfv1aJ56di/sqnJE/jJBUPQEIKWoIKlAJYVg=; b=fqdWb86ba550I1HmmkCbs2tsxtkgABQEuT4GF+PFn+cpJN/cqxZTsRykBI5up48yfk ZPz+0YWAN3xWyvtQ1Pkx1djYydFEmO6ZIqxl1tSJPQW5RXXzfHgHZ3VWlpQOMTSMHomz pIKL+0PUAawVAT/g1AvYQsIx74rj6gBV+rv8C6wc1cgB9U+y7jF379VDkyhxU/1D0xSn COYnwr6tqw+esksfO9jb0YlPB5J8AJmpy7Zk2wUkOhM4IMyxlbQgXJI3f3Ege6UIxekI GSaRfNW0qRdpa6JyZDRWMuY4zD9eBz37e+RIRbM/xk1U0zbLp5gV/NHhL6iS3BOQ9onF cwpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=s/FNUD3Nfv1aJ56di/sqnJE/jJBUPQEIKWoIKlAJYVg=; b=J6uMZ7ufeW44/CCHkvL04roe1YF/2tWj6B7lEQDUUZJYs7GvxkuwWGMIAZsf3g5Vv+ TmHvPZBNXaSCfZC2BZELXDrrXDmLGUnDY3V/iTL2Rt+1b1yh42westdKO80bMRJ12ASA Yi4K9HupmF71+vBp3wS+tmsxYmVDFZHveoYImVwkWMoue3Dl8dZbDjXD+ntLqx/SRGE0 jLGhPLmRb/4GqlN/y3iVIVsk2ofNF2sFhR9/MMELVU/w+R7UdRJNSp3diJIevtkBr0wT 8MS30FLdJ6z1Qp3wnlKyJfnOr+EAbLeNjnARlZ6ADV0mckpmyIJ1ptm21brBY9yedN9q fm0g== X-Gm-Message-State: AOAM530oHB2FIyWmINbWfhFoRKh2PwUZKAtYpGcXKoqOmFTAwtSAXjnJ cSuvQlG6KwR8wO9FdKphYT0s35V8imI= X-Google-Smtp-Source: ABdhPJyFuOAeElBvhX+MgXwyUheNzoNfsSzWpsY4CTfavjAXr8WiRFaCjPXf3xXWJkRA96/mXgR5Vw== X-Received: by 2002:a5d:6486:: with SMTP id o6mr11154608wri.636.1643479636717; Sat, 29 Jan 2022 10:07:16 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t16sm7371269wrx.79.2022.01.29.10.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:16 -0800 (PST) Message-Id: <4780ff6784d426bf0a96859ef9bf9c14e87d5f50.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:02 +0000 Subject: [PATCH v2 02/13] merge-tree: move logic for existing merge into new function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren In preparation for adding a non-trivial merge capability to merge-tree, move the existing merge logic for trivial merges into a new function. Signed-off-by: Elijah Newren --- builtin/merge-tree.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 06f9eee9f78..914ec960b7e 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -366,15 +366,12 @@ static void *get_tree_descriptor(struct repository *r, return buf; } -int cmd_merge_tree(int argc, const char **argv, const char *prefix) +static int trivial_merge(int argc, const char **argv) { struct repository *r = the_repository; struct tree_desc t[3]; void *buf1, *buf2, *buf3; - if (argc != 4) - usage(merge_tree_usage); - buf1 = get_tree_descriptor(r, t+0, argv[1]); buf2 = get_tree_descriptor(r, t+1, argv[2]); buf3 = get_tree_descriptor(r, t+2, argv[3]); @@ -386,3 +383,10 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) show_result(); return 0; } + +int cmd_merge_tree(int argc, const char **argv, const char *prefix) +{ + if (argc != 4) + usage(merge_tree_usage); + return trivial_merge(argc, argv); +} From patchwork Sat Jan 29 18:07:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0862DC433F5 for ; Sat, 29 Jan 2022 18:07:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352996AbiA2SH1 (ORCPT ); Sat, 29 Jan 2022 13:07:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353001AbiA2SHT (ORCPT ); Sat, 29 Jan 2022 13:07:19 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1350EC061714 for ; Sat, 29 Jan 2022 10:07:19 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id u15so17184906wrt.3 for ; Sat, 29 Jan 2022 10:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=6oNLvE3Kf1AT5/coVfsEXJRsaPG9jKHHjbI8tr++geM=; b=lM6S5DkIYj/vABzYdlzp783hbErd2QQ7iHJ1hOulZAs+dAAYgXpReX6YuO9FDkoEfB l9ATUHl7BRjx1YXYYhu8gXwz8XYVwX4BrSWSPIdm1ThuInjcmnG6q3eEzMaGKzUtQuFk U50cIu92040pkV1dyn6BCuBTko9jaih/n69Tbixgi3jQrQKHUSUoH0OuazyWXs+a8RMM Noxp2y5CYcq7YvQdbeghULaesM93BCIi08yyhHoQPdF3RNMecKMCudNtchKs50eJ1AyM g1SXdZVvuIG38RoVHPulrxqSHJOnXUoPT1A4GqIqSwai1uUrrqfN5OeFbYwIF6hq6dr5 qcow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=6oNLvE3Kf1AT5/coVfsEXJRsaPG9jKHHjbI8tr++geM=; b=M8Wql7mtQ+rnquFDJApVc25NcinpibQLe3Xlk91jL3gtVOYgPtEnmKdzNIVkBvuFrv 3lPxPoZUyZZjDcpxFkeu6V6wp9hKnL3i+2lGXr3HeGem+byt18fFGWGWkk+mUd/Y8X57 jfe3cgMFVrzgXcoCZEjMqn6T8f61QPApZwozV14QpG0SEfGIdPMiDuabDUppUoCCwASj GZbSCi8vsiDqAoN69jfIW4sZSMJuZJH0HwGjO4idHKBepcMPqR4jCUhI8jTVAYLdpduW qDdzXKPWQuVf9bYzXEl3AK4RRGGk6uKFs+1f5HNkBT6LgZY7Cp2dxaleIaq37vfiHSgW XtBQ== X-Gm-Message-State: AOAM530BEelkd1vSUGSvMzSfjmrDd6PpU2uJtfryVG+SWrdbVy4YWLkq 4oCZ96nHKJ3MUdu4fklhO2fewBhpmWY= X-Google-Smtp-Source: ABdhPJx5QLDQh+ei6d41SK0LZteLvZzOy1aKJM0sPK1ARVkruD8QvGANCpbKrXsGSkfSpy/s0dMNTQ== X-Received: by 2002:a05:6000:186a:: with SMTP id d10mr10971228wri.621.1643479637521; Sat, 29 Jan 2022 10:07:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y15sm11242193wry.36.2022.01.29.10.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:17 -0800 (PST) Message-Id: <63f42df21aec5bda50e4414493eb59dcb64e5558.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:03 +0000 Subject: [PATCH v2 03/13] merge-tree: add option parsing and initial shell for real merge function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Let merge-tree accept a `--write-tree` parameter for choosing real merges instead of trivial merges, and accept an optional `--trivial-merge` option to get the traditional behavior. Note that these accept different numbers of arguments, though, so these names need not actually be used. Note that real merges differ from trivial merges in that they handle: - three way content merges - recursive ancestor consolidation - renames - proper directory/file conflict handling - etc. Basically all the stuff you'd expect from `git merge`, just without updating the index and working tree. The initial shell added here does nothing more than die with "real merges are not yet implemented", but that will be fixed in subsequent commits. Signed-off-by: Elijah Newren --- builtin/merge-tree.c | 61 +++++++++++++++++++++++++++++++++++++------- git.c | 2 +- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 914ec960b7e..e98ec8a9f1d 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -3,13 +3,12 @@ #include "tree-walk.h" #include "xdiff-interface.h" #include "object-store.h" +#include "parse-options.h" #include "repository.h" #include "blob.h" #include "exec-cmd.h" #include "merge-blobs.h" -static const char merge_tree_usage[] = "git merge-tree "; - struct merge_list { struct merge_list *next; struct merge_list *link; /* other stages for this object */ @@ -366,15 +365,17 @@ static void *get_tree_descriptor(struct repository *r, return buf; } -static int trivial_merge(int argc, const char **argv) +static int trivial_merge(const char *base, + const char *branch1, + const char *branch2) { struct repository *r = the_repository; struct tree_desc t[3]; void *buf1, *buf2, *buf3; - buf1 = get_tree_descriptor(r, t+0, argv[1]); - buf2 = get_tree_descriptor(r, t+1, argv[2]); - buf3 = get_tree_descriptor(r, t+2, argv[3]); + buf1 = get_tree_descriptor(r, t+0, base); + buf2 = get_tree_descriptor(r, t+1, branch1); + buf3 = get_tree_descriptor(r, t+2, branch2); trivial_merge_trees(t, ""); free(buf1); free(buf2); @@ -384,9 +385,51 @@ static int trivial_merge(int argc, const char **argv) return 0; } +struct merge_tree_options { + int mode; +}; + +static int real_merge(struct merge_tree_options *o, + const char *branch1, const char *branch2) +{ + die(_("real merges are not yet implemented")); +} + int cmd_merge_tree(int argc, const char **argv, const char *prefix) { - if (argc != 4) - usage(merge_tree_usage); - return trivial_merge(argc, argv); + struct merge_tree_options o = { 0 }; + int expected_remaining_argc; + + const char * const merge_tree_usage[] = { + N_("git merge-tree [--write-tree] "), + N_("git merge-tree [--trivial-merge] "), + NULL + }; + struct option mt_options[] = { + OPT_CMDMODE(0, "write-tree", &o.mode, + N_("do a real merge instead of a trivial merge"), + 'w'), + OPT_CMDMODE(0, "trivial-merge", &o.mode, + N_("do a trivial merge only"), 't'), + OPT_END() + }; + + /* Parse arguments */ + argc = parse_options(argc, argv, prefix, mt_options, + merge_tree_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (o.mode) { + expected_remaining_argc = (o.mode == 'w' ? 2 : 3); + if (argc != expected_remaining_argc) + usage_with_options(merge_tree_usage, mt_options); + } else { + if (argc < 2 || argc > 3) + usage_with_options(merge_tree_usage, mt_options); + o.mode = (argc == 2 ? 'w' : 't'); + } + + /* Do the relevant type of merge */ + if (o.mode == 'w') + return real_merge(&o, argv[0], argv[1]); + else + return trivial_merge(argv[0], argv[1], argv[2]); } diff --git a/git.c b/git.c index 5ff21be21f3..6090a1289db 100644 --- a/git.c +++ b/git.c @@ -558,7 +558,7 @@ static struct cmd_struct commands[] = { { "merge-recursive-ours", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, { "merge-recursive-theirs", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, { "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT }, - { "merge-tree", cmd_merge_tree, RUN_SETUP | NO_PARSEOPT }, + { "merge-tree", cmd_merge_tree, RUN_SETUP }, { "mktag", cmd_mktag, RUN_SETUP | NO_PARSEOPT }, { "mktree", cmd_mktree, RUN_SETUP }, { "multi-pack-index", cmd_multi_pack_index, RUN_SETUP }, From patchwork Sat Jan 29 18:07:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCE15C433FE for ; Sat, 29 Jan 2022 18:07:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352794AbiA2SH2 (ORCPT ); Sat, 29 Jan 2022 13:07:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244812AbiA2SHU (ORCPT ); Sat, 29 Jan 2022 13:07:20 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB367C061714 for ; Sat, 29 Jan 2022 10:07:19 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id m14so16918330wrg.12 for ; Sat, 29 Jan 2022 10:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=jiWw73ElfvDNzg9QG12H1L3cZ/9znWEQgBx121aVEwg=; b=MAofSWgOF+Omre6YE6okaq0olYX0Z3EtFPgqvIpB83R7Px4Ii8/c75l8WtaGB1PwCL GbaXGfSXAExVG5ur0Co97V6spSElgH8MIxiUFSjVRS697F5X2+sKOwFlAjn0GuvwcsS2 2h5yBrG80NlRLpzc7CQMf049tGqIB0Xp1Pkj9EIJjBCG1bJ6i74E0JcoyhFQxQ2lPT2s gZxHTkbnZgrpxs4WkniZH+6r/RIyQ6nUSFRe+BBF4akIA9MkFylV9dE0e0iIafnWVm4a AckH26dC/8E2O0wlN/LKyDyyquWduNLVxr9S2f6GEyS6g/TJF+dyTL6c9uMHOvAKJG9O LN3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=jiWw73ElfvDNzg9QG12H1L3cZ/9znWEQgBx121aVEwg=; b=sXC2cCBLcKpFJZbCiBy5u646LArIMVM4XP2kjd9pWVc2HVO1763HkJwjbbTBy+p6RA mjMkE84SAmPeRTPl45QoD1Zro6qesKR2MOmSl5F494mJ5RGfdqU5JLG8tc9aqvjrtU8G XEA0Zuvi62iHOzniZ66hMJH/EPHVqLeVZpiA5N0Qu7nKo2Vqq1l9FqqT2+SkiOmqcAFk pPCyLnTftBKJKljHRpMgpujDSdBOA9+zRvkyBSVxctHzwlClvHnDF235COjwwh6AbD97 v+NJvJgIcT3621sjlaf4EsJAgKUPmzlTyWH9RTqM4a6T/VhQJ/3iizr8xK3Hj8vbvNvD UGww== X-Gm-Message-State: AOAM532nZuDmNCeXYCCVIH5iYdHAz/cilWVvIfjNaHDzXmcbrxnRE3aM CuiAjlqyMenmHt6UTQNficRvwdiG77M= X-Google-Smtp-Source: ABdhPJwkY9IqIUClkFlmEwqj67G9lilZLhP1z2CmqchdWRev0J++s/ELUry9JlXvRdEF/Db8fq1bZw== X-Received: by 2002:a5d:598c:: with SMTP id n12mr11557187wri.176.1643479638268; Sat, 29 Jan 2022 10:07:18 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q2sm1501189wrw.14.2022.01.29.10.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:17 -0800 (PST) Message-Id: <02c29f920d0d5fde6d85f7b86a69be92e3f0f34d.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:04 +0000 Subject: [PATCH v2 04/13] merge-tree: implement real merges Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren This adds the ability to perform real merges rather than just trivial merges (meaning handling three way content merges, recursive ancestor consolidation, renames, proper directory/file conflict handling, and so forth). However, unlike `git merge`, the working tree and index are left alone and no branch is updated. The only output is: - the toplevel resulting tree printed on stdout - exit status of 0 (clean), 1 (conflicts present), anything else (merge could not be performed; unknown if clean or conflicted) This output is meant to be used by some higher level script, perhaps in a sequence of steps like this: NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) test $? -eq 0 || die "There were conflicts..." NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2) git update-ref $BRANCH1 $NEWCOMMIT Note that higher level scripts may also want to access the conflict/warning messages normally output during a merge, or have quick access to a list of files with conflicts. That is not available in this preliminary implementation, but subsequent commits will add that ability. This also marks the traditional trivial merge of merge-tree as deprecated. The trivial merge not only had limited applicability, the output format was also difficult to work with (and its format undocumented), and will generally be less performant than real merges. Signed-off-by: Elijah Newren --- Documentation/git-merge-tree.txt | 71 +++++++++++++++++++++----- builtin/merge-tree.c | 44 +++++++++++++++- t/t4301-merge-tree-write-tree.sh | 88 ++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 13 deletions(-) create mode 100755 t/t4301-merge-tree-write-tree.sh diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index 58731c19422..569485815a0 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -3,26 +3,73 @@ git-merge-tree(1) NAME ---- -git-merge-tree - Show three-way merge without touching index +git-merge-tree - Perform merge without touching index or working tree SYNOPSIS -------- [verse] -'git merge-tree' +'git merge-tree' [--write-tree] +'git merge-tree' [--trivial-merge] (deprecated) DESCRIPTION ----------- -Reads three tree-ish, and output trivial merge results and -conflicting stages to the standard output. This is similar to -what three-way 'git read-tree -m' does, but instead of storing the -results in the index, the command outputs the entries to the -standard output. - -This is meant to be used by higher level scripts to compute -merge results outside of the index, and stuff the results back into the -index. For this reason, the output from the command omits -entries that match the tree. + +Performs a merge, but does not make any new commits and does not read +from or write to either the working tree or index. + +The second form is deprecated and supported only for backward +compatibility. It will likely be removed in the future, and will not +be discussed further in this manual. + +The first form will merge the two branches, doing a real merge. A real +merge is distinguished from a trivial merge in that it includes: + + * three way content merges of individual files + * rename detection + * proper directory/file conflict handling + * recursive ancestor consolidation (i.e. when there is more than one + merge base, creating a virtual merge base by merging the merge bases) + * etc. + +After the merge completes, it will create a new toplevel tree object. +See `OUTPUT` below for details. + +OUTPUT +------ + +For either a successful or conflicted merge, the output from +git-merge-tree is simply one line: + + + +The printed tree object corresponds to what would be checked out in +the working tree at the end of `git merge`, and thus may have files +with conflict markers in them. + +EXIT STATUS +----------- + +For a successful, non-conflicted merge, the exit status is 0. When the +merge has conflicts, the exit status is 1. If the merge is not able to +complete (or start) due to some kind of error, the exit status is +something other than 0 or 1. + +USAGE NOTES +----------- + +git-merge-tree was written to be low-level plumbing, similar to +hash-object, mktree, commit-tree, update-ref, and mktag. Thus, it could +be used as a part of a series of steps such as + + NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) + test $? -eq 0 || die "There were conflicts..." + NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2) + git update-ref $BRANCH1 $NEWCOMMIT + +However, it does not quite fit into the same category of low-level +plumbing commands since the possibility of merge conflicts give it a +much higher chance of the command not succeeding. GIT --- diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index e98ec8a9f1d..d14c9f6e44e 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -2,6 +2,9 @@ #include "builtin.h" #include "tree-walk.h" #include "xdiff-interface.h" +#include "help.h" +#include "commit-reach.h" +#include "merge-ort.h" #include "object-store.h" #include "parse-options.h" #include "repository.h" @@ -392,7 +395,46 @@ struct merge_tree_options { static int real_merge(struct merge_tree_options *o, const char *branch1, const char *branch2) { - die(_("real merges are not yet implemented")); + struct commit *parent1, *parent2; + struct commit_list *common; + struct commit_list *merge_bases = NULL; + struct commit_list *j; + struct merge_options opt; + struct merge_result result = { 0 }; + + parent1 = get_merge_parent(branch1); + if (!parent1) + help_unknown_ref(branch1, "merge-tree", + _("not something we can merge")); + + parent2 = get_merge_parent(branch2); + if (!parent2) + help_unknown_ref(branch2, "merge-tree", + _("not something we can merge")); + + init_merge_options(&opt, the_repository); + + opt.show_rename_progress = 0; + + opt.branch1 = branch1; + opt.branch2 = branch2; + + /* + * Get the merge bases, in reverse order; see comment above + * merge_incore_recursive in merge-ort.h + */ + common = get_merge_bases(parent1, parent2); + if (!common) + die(_("refusing to merge unrelated histories")); + for (j = common; j; j = j->next) + commit_list_insert(j->item, &merge_bases); + + merge_incore_recursive(&opt, merge_bases, parent1, parent2, &result); + if (result.clean < 0) + die(_("failure to merge")); + puts(oid_to_hex(&result.tree->object.oid)); + merge_finalize(&opt, &result); + return !result.clean; /* result.clean < 0 handled above */ } int cmd_merge_tree(int argc, const char **argv, const char *prefix) diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh new file mode 100755 index 00000000000..66c3eaf2021 --- /dev/null +++ b/t/t4301-merge-tree-write-tree.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +test_description='git merge-tree --write-tree' + +. ./test-lib.sh + +# This test is ort-specific +if test "${GIT_TEST_MERGE_ALGORITHM}" != "ort" +then + skip_all="GIT_TEST_MERGE_ALGORITHM != ort" + test_done +fi + +test_expect_success setup ' + test_write_lines 1 2 3 4 5 >numbers && + echo hello >greeting && + echo foo >whatever && + git add numbers greeting whatever && + test_tick && + git commit -m initial && + + git branch side1 && + git branch side2 && + + git checkout side1 && + test_write_lines 1 2 3 4 5 6 >numbers && + echo hi >greeting && + echo bar >whatever && + git add numbers greeting whatever && + test_tick && + git commit -m modify-stuff && + + git checkout side2 && + test_write_lines 0 1 2 3 4 5 >numbers && + echo yo >greeting && + git rm whatever && + mkdir whatever && + >whatever/empty && + git add numbers greeting whatever/empty && + test_tick && + git commit -m other-modifications +' + +test_expect_success 'Content merge and a few conflicts' ' + git checkout side1^0 && + test_must_fail git merge side2 && + expected_tree=$(cat .git/AUTO_MERGE) && + + # We will redo the merge, while we are still in a conflicted state! + test_when_finished "git reset --hard" && + + test_expect_code 1 git merge-tree --write-tree side1 side2 >RESULT && + actual_tree=$(head -n 1 RESULT) && + + # Due to differences of e.g. "HEAD" vs "side1", the results will not + # exactly match. Dig into individual files. + + # Numbers should have three-way merged cleanly + test_write_lines 0 1 2 3 4 5 6 >expect && + git show ${actual_tree}:numbers >actual && + test_cmp expect actual && + + # whatever and whatever~ should have same HASHES + git rev-parse ${expected_tree}:whatever ${expected_tree}:whatever~HEAD >expect && + git rev-parse ${actual_tree}:whatever ${actual_tree}:whatever~side1 >actual && + test_cmp expect actual && + + # greeting should have a merge conflict + git show ${expected_tree}:greeting >tmp && + cat tmp | sed -e s/HEAD/side1/ >expect && + git show ${actual_tree}:greeting >actual && + test_cmp expect actual +' + +test_expect_success 'Barf on misspelled option, with exit code other than 0 or 1' ' + # Mis-spell with single "s" instead of double "s" + test_expect_code 129 git merge-tree --write-tree --mesages FOOBAR side1 side2 2>expect && + + grep "error: unknown option.*mesages" expect +' + +test_expect_success 'Barf on too many arguments' ' + test_expect_code 129 git merge-tree --write-tree side1 side2 side3 2>expect && + + grep "^usage: git merge-tree" expect +' + +test_done From patchwork Sat Jan 29 18:07:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12729596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09D1EC433F5 for ; Sat, 29 Jan 2022 18:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353020AbiA2SH3 (ORCPT ); Sat, 29 Jan 2022 13:07:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353002AbiA2SHU (ORCPT ); Sat, 29 Jan 2022 13:07:20 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79ED9C06173B for ; Sat, 29 Jan 2022 10:07:20 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id w11so17153434wra.4 for ; Sat, 29 Jan 2022 10:07:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=8ff3SKll/6mLNI1wP/QCcJvSviK5GLe8GjbN22wIpSY=; b=qG0lXCBYE2xzFtGZZo0KnH97nAGhF7ALZhrlK5UifvPvqmeOhEQ85PGHu7WBZ61ARW kE2XCx8rxVjw1KW19dADDLFUhZ69z9csENbwfyk9q9i1exTx8aWp7/O9qOv++OQ9LRdv XC+S/R4jzEmDjGyFnPKWSIurN0HL4Ac7mmnYZuFPRE+6816R4JuPgOj1kSEQAdSdcjFo R+oJvawQomtThNTqVPU/sjXv013GMa6wFhVWmpOaQFqGhYG/oChSSJu1JG5cAxZ5vYKA PNGVatbo2fjYbfTIIwb/N0I74MjbUH/GaqUatgMrr4LDOS/DSYcIY5qW0waJ6O1P+zfm roIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=8ff3SKll/6mLNI1wP/QCcJvSviK5GLe8GjbN22wIpSY=; b=10tBXC90W3C/1vBno7uEQ123LXMlop0nKW4NfgQt0nOo4BQsdGOT7/fzD2TobxnhCq j7C8pGcnF8A2/WkFgqwcQy/t38QjrnjzhQyiOAgaChGXsh+YpWK0N9S99uWQbapkHyE6 dR//zJ2z6F4FucUaim7hKKYAgkBCXF6/g//xsCsjz7lRcfw356LVZ/ZXm2cVTOeJMOBX FFE9pBIIZuDaVNIoGiSbKuwMneQexCI5IKr3Qj3FiVckqcYkHJXNeiCtnA7UzMFLKevA 4WXFyuhjSrx9VdfKjZBJFUyl/f9Gn1Ib2xK4qNsLwO29/hNKUzP7P1o7nb42dU68i6hU OJNQ== X-Gm-Message-State: AOAM531FrSDLA+tggJ4l7krmgSBRO/iCUUA0w6SHf1j/3nNgHIlHu9ea 2be7jtbpn5/IiqE36U3IlVk1UJYr6cs= X-Google-Smtp-Source: ABdhPJyDxJ6zPYDotLoH5T+Zq/n0HnDGxfqzVolaQbonPKShYg3N2JVOgfGjkUufJVwC0URWmQYi3Q== X-Received: by 2002:a05:6000:1acc:: with SMTP id i12mr10941493wry.413.1643479638989; Sat, 29 Jan 2022 10:07:18 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f16sm3743837wmg.28.2022.01.29.10.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:18 -0800 (PST) Message-Id: <6fb4f4580a581b2e43bc4b8deaa3d2d2bf4a8756.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:05 +0000 Subject: [PATCH v2 05/13] diff: allow diff_warn_rename_limit to write somewhere besides stdout Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin diff_warn_rename_limit() is hardcoded to write to stdout. Make it accept an output location parameter to make it more flexible. Signed-off-by: Johannes Schindelin Signed-off-by: Elijah Newren --- diff.c | 20 ++++++++++++++------ diff.h | 3 ++- merge-ort.c | 2 +- merge-recursive.c | 3 ++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/diff.c b/diff.c index 1bfb01c18ec..6952035046f 100644 --- a/diff.c +++ b/diff.c @@ -6377,17 +6377,25 @@ static const char rename_limit_advice[] = N_("you may want to set your %s variable to at least " "%d and retry the command."); -void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc) +void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc, + FILE *out) { - fflush(stdout); + const char *fmt = NULL; + if (degraded_cc) - warning(_(degrade_cc_to_c_warning)); + fmt = _(degrade_cc_to_c_warning); else if (needed) - warning(_(rename_limit_warning)); + fmt = _(rename_limit_warning); else return; if (0 < needed) - warning(_(rename_limit_advice), varname, needed); + fmt = _(rename_limit_advice); + + fflush(out); + if (out == stdout) + warning(fmt, varname, needed); + else + fprintf(out, fmt, varname, needed); } static void create_filepairs_for_header_only_notifications(struct diff_options *o) @@ -6870,7 +6878,7 @@ int diff_result_code(struct diff_options *opt, int status) diff_warn_rename_limit("diff.renameLimit", opt->needed_rename_limit, - opt->degraded_cc_to_c); + opt->degraded_cc_to_c, stdout); if (!opt->flags.exit_with_status && !(opt->output_format & DIFF_FORMAT_CHECKDIFF)) return status; diff --git a/diff.h b/diff.h index ce9e2cf2e4f..40c5b78fb0a 100644 --- a/diff.h +++ b/diff.h @@ -597,7 +597,8 @@ void diffcore_fix_diff_index(void); int diff_queue_is_empty(struct diff_options *o); void diff_flush(struct diff_options*); void diff_free(struct diff_options*); -void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc); +void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc, + FILE *out); /* diff-raw status letters */ #define DIFF_STATUS_ADDED 'A' diff --git a/merge-ort.c b/merge-ort.c index 9bf15a01db8..65618048b59 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4305,7 +4305,7 @@ void merge_switch_to_result(struct merge_options *opt, /* Also include needed rename limit adjustment now */ diff_warn_rename_limit("merge.renamelimit", - opti->renames.needed_limit, 0); + opti->renames.needed_limit, 0, stdout); trace2_region_leave("merge", "display messages", opt->repo); } diff --git a/merge-recursive.c b/merge-recursive.c index 9ec1e6d043a..d2eeca9fa20 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3738,7 +3738,8 @@ static void merge_finalize(struct merge_options *opt) strbuf_release(&opt->obuf); if (show(opt, 2)) diff_warn_rename_limit("merge.renamelimit", - opt->priv->needed_rename_limit, 0); + opt->priv->needed_rename_limit, 0, + stdout); FREE_AND_NULL(opt->priv); } From patchwork Sat Jan 29 18:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33016C433EF for ; Sat, 29 Jan 2022 18:07:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352949AbiA2SHb (ORCPT ); Sat, 29 Jan 2022 13:07:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353008AbiA2SHV (ORCPT ); Sat, 29 Jan 2022 13:07:21 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A585C061714 for ; Sat, 29 Jan 2022 10:07:21 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id c23so17159314wrb.5 for ; Sat, 29 Jan 2022 10:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=j6pXtRrQ5I7U6AZABoGpx0sRmJ81EY6GY7ESSrFm0DM=; b=gLtUqYP98r3jRp8dYTlUwj0+OGzdun5KRyTplfaCM/Go4BYGGbJ2ynIf313mnvZCy+ /bPT7zWCad2a6jDuslqvANriSRKjd/90uH7OeaftvF8/ybBXiQg+oQmSDSCwbdBd435t e2ysuL2f0wQ0k65UyJhEkJfC85+ClV7su4lWDCnGRk+95Kgz9Se2ETYDNxU8RFUYWfAo jQOzGgUmy1YzV3Jowq3mEN0AmNWY0KoxDDibKIBwnN1qJuq9Nawjxg4cpq8gRAMgDKHW Kx87FE4fWfNp+SV/Xa+V6t3blEb9nFaOsQraGQYIE3ZGBWDTZrwTeE3kqdLHKEO6n22+ VWog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=j6pXtRrQ5I7U6AZABoGpx0sRmJ81EY6GY7ESSrFm0DM=; b=WCSG81/I4e8WWEmbHeVwZF2w+HqVRuUBvNo4l5Xpejiol7yd37MrCZtP9lxDunS4sa 7tRJuN3O82P98JFOw5juMTFLRARu3Ht9zN2Oyqljfw/MBS+LsxfbSKO5NUQvTGkGo2hG 0qPHpByg7ccJmNDGOy+Ky+oxxvLyIViZwM2uoCC3tj6x3xuf7+F8Y5pf8BU9ExvSHlDL VW1e/G1M9TIV5cMqUUStoNSPpiws5LDa421GLHwjBvl/Y8AzOZNbtS0+a1+eWQQJkL+9 d75v0XT2NS05t4JBn5UcBSh2SSGpw1FjcPfJN50uBUl7rjfJAcSGfp7VFrvzZ8Wai/4Y nWRA== X-Gm-Message-State: AOAM533vwSWu0NsD3s/RcmNeS8nZ1tM5b4T0C4kBRkyFRLjP3bW6SSOV c6Jj2305oWHzS6aLSsbsy0pPMZwNO10= X-Google-Smtp-Source: ABdhPJxM9QjAlZbnuUWbbpg6QVtsjD4PSJZEAQY51B23USx3nKTRwkz72hy6A4QCZ56hJFwRVKZW5g== X-Received: by 2002:a5d:6d05:: with SMTP id e5mr10999423wrq.398.1643479639839; Sat, 29 Jan 2022 10:07:19 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e10sm9062296wrq.53.2022.01.29.10.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:19 -0800 (PST) Message-Id: <28368c03898047e2e5d3d3c4ad7ffef517ff2450.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:06 +0000 Subject: [PATCH v2 06/13] merge-ort: split out a separate display_update_messages() function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren This patch includes no new code; it simply moves a bunch of lines into a new function. As such, there are no functional changes. This is just a preparatory step to allow the printed messages to be handled differently by other callers, such as in `git merge-tree --write-tree`. (Patch best viewed with --color-moved --color-moved-ws=allow-indentation-change to see that it is a simple code movement.) Signed-off-by: Elijah Newren --- merge-ort.c | 77 ++++++++++++++++++++++++++++------------------------- merge-ort.h | 8 ++++++ 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 65618048b59..1ada3198390 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4235,6 +4235,45 @@ static int record_conflicted_index_entries(struct merge_options *opt) return errs; } +void merge_display_update_messages(struct merge_options *opt, + struct merge_result *result) +{ + struct merge_options_internal *opti = result->priv; + struct hashmap_iter iter; + struct strmap_entry *e; + struct string_list olist = STRING_LIST_INIT_NODUP; + int i; + + if (opt->record_conflict_msgs_as_headers) + BUG("Either display conflict messages or record them as headers, not both"); + + trace2_region_enter("merge", "display messages", opt->repo); + + /* Hack to pre-allocate olist to the desired size */ + ALLOC_GROW(olist.items, strmap_get_size(&opti->output), + olist.alloc); + + /* Put every entry from output into olist, then sort */ + strmap_for_each_entry(&opti->output, &iter, e) { + string_list_append(&olist, e->key)->util = e->value; + } + string_list_sort(&olist); + + /* Iterate over the items, printing them */ + for (i = 0; i < olist.nr; ++i) { + struct strbuf *sb = olist.items[i].util; + + printf("%s", sb->buf); + } + string_list_clear(&olist, 0); + + /* Also include needed rename limit adjustment now */ + diff_warn_rename_limit("merge.renamelimit", + opti->renames.needed_limit, 0, stdout); + + trace2_region_leave("merge", "display messages", opt->repo); +} + void merge_switch_to_result(struct merge_options *opt, struct tree *head, struct merge_result *result, @@ -4273,42 +4312,8 @@ void merge_switch_to_result(struct merge_options *opt, trace2_region_leave("merge", "write_auto_merge", opt->repo); } - if (display_update_msgs) { - struct merge_options_internal *opti = result->priv; - struct hashmap_iter iter; - struct strmap_entry *e; - struct string_list olist = STRING_LIST_INIT_NODUP; - int i; - - if (opt->record_conflict_msgs_as_headers) - BUG("Either display conflict messages or record them as headers, not both"); - - trace2_region_enter("merge", "display messages", opt->repo); - - /* Hack to pre-allocate olist to the desired size */ - ALLOC_GROW(olist.items, strmap_get_size(&opti->output), - olist.alloc); - - /* Put every entry from output into olist, then sort */ - strmap_for_each_entry(&opti->output, &iter, e) { - string_list_append(&olist, e->key)->util = e->value; - } - string_list_sort(&olist); - - /* Iterate over the items, printing them */ - for (i = 0; i < olist.nr; ++i) { - struct strbuf *sb = olist.items[i].util; - - printf("%s", sb->buf); - } - string_list_clear(&olist, 0); - - /* Also include needed rename limit adjustment now */ - diff_warn_rename_limit("merge.renamelimit", - opti->renames.needed_limit, 0, stdout); - - trace2_region_leave("merge", "display messages", opt->repo); - } + if (display_update_msgs) + merge_display_update_messages(opt, result); merge_finalize(opt, result); } diff --git a/merge-ort.h b/merge-ort.h index fe599b87868..e5aec45b18f 100644 --- a/merge-ort.h +++ b/merge-ort.h @@ -80,6 +80,14 @@ void merge_switch_to_result(struct merge_options *opt, int update_worktree_and_index, int display_update_msgs); +/* + * Display messages about conflicts and which files were 3-way merged. + * Automatically called by merge_switch_to_result() with stream == stdout, + * so only call this when bypassing merge_switch_to_result(). + */ +void merge_display_update_messages(struct merge_options *opt, + struct merge_result *result); + /* Do needed cleanup when not calling merge_switch_to_result() */ void merge_finalize(struct merge_options *opt, struct merge_result *result); From patchwork Sat Jan 29 18:07:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11C4DC433EF for ; Sat, 29 Jan 2022 18:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353008AbiA2SHc (ORCPT ); Sat, 29 Jan 2022 13:07:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238996AbiA2SHW (ORCPT ); Sat, 29 Jan 2022 13:07:22 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CE43C061749 for ; Sat, 29 Jan 2022 10:07:22 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id bg19-20020a05600c3c9300b0034565e837b6so5958439wmb.1 for ; Sat, 29 Jan 2022 10:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=EZj5VfrzAVp/cg0U4WT3oO9/KM+ihWSlfca29Ha9atg=; b=IBJNO855odHWn0DjckLP0KlgUWBu/Prz5vqlqhiHW72V9h7hkGSt9pgovQnjTk61rG Vk4j5IDBVZUr1/EuVDXrfGl1PVz96tkioLm2KT8ZBjDRnbe/TybTTTw7XckaaZtd1RyV UYtvC85OxRMk1KC9ghGtriu8PsjD97cbXFXTycw5qloHBL12eodBdLI4bg88w72EXrkS u3XRPc9iwJDyPqwtBQZ1NTbFRAru35AvpjjkikXK4x6qjmEj5pNvul0UVZt8K1f9qa0/ wxkFeKC3AhlTxpHaXJLYdVurJca9qjrFsSYUWlsr/GF61L4EBwWwGDW8llNdGvbx8Y8U VBFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=EZj5VfrzAVp/cg0U4WT3oO9/KM+ihWSlfca29Ha9atg=; b=Yh6DLYC3AeR8xsxjIVChIOIzDrZGRWSzllWM+2o9hQQFdaK7Z1z3cnWFlRYfImgTYh wegWWHRNqEmjDL6Jz5ZjybNChQw/3oAqqo/8TwlXY6ZPGfbu8VlOmshHgxTSWt0/KytO pHMv+t7UsmdrydbvF6bBnUulrd/nDb9xbbVAz/dL0o00uuxkIZEWJAZyuICkR3DbyL2b hqPr/wz86NUgmY+f0pS0eEaOllSsqrDPxslUi9KBqkHDPoxXhGD+rAtXwuL9EjoRQvnX 9FJ1quBwfX2kJr/BnwkUP8Oj/lpEW6UOLnMkrbqBF07RPAJCoo0RAsZ5BBSKSLydgcye Gi6g== X-Gm-Message-State: AOAM5305+ePUucQUnxkCODHPgtk8cVWAndrJPFQ4oLHM4FiEj6pHZoN9 lMFHh7dDNsaNwgTd/6wBxlkEOMKkaOM= X-Google-Smtp-Source: ABdhPJwVWMMjJXaqVlLCbVk+kKo3M5np+AK8Yc7gKxYHjpOO+x7tMWHIeVsCEny+OZ+IAKXWw58z6w== X-Received: by 2002:a7b:c4c5:: with SMTP id g5mr11726894wmk.139.1643479640608; Sat, 29 Jan 2022 10:07:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a6sm7525893wrx.101.2022.01.29.10.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:20 -0800 (PST) Message-Id: <593d0c00b574aa8097badd45d786097ec8601e18.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:07 +0000 Subject: [PATCH v2 07/13] merge-ort: allow update messages to be written to different file stream Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren This modifies the new display_update_messages() function to allow printing to somewhere other than stdout. Signed-off-by: Elijah Newren --- merge-ort.c | 9 +++++---- merge-ort.h | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 1ada3198390..d28d1721d14 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4236,7 +4236,8 @@ static int record_conflicted_index_entries(struct merge_options *opt) } void merge_display_update_messages(struct merge_options *opt, - struct merge_result *result) + struct merge_result *result, + FILE *stream) { struct merge_options_internal *opti = result->priv; struct hashmap_iter iter; @@ -4263,13 +4264,13 @@ void merge_display_update_messages(struct merge_options *opt, for (i = 0; i < olist.nr; ++i) { struct strbuf *sb = olist.items[i].util; - printf("%s", sb->buf); + strbuf_write(sb, stream); } string_list_clear(&olist, 0); /* Also include needed rename limit adjustment now */ diff_warn_rename_limit("merge.renamelimit", - opti->renames.needed_limit, 0, stdout); + opti->renames.needed_limit, 0, stream); trace2_region_leave("merge", "display messages", opt->repo); } @@ -4313,7 +4314,7 @@ void merge_switch_to_result(struct merge_options *opt, } if (display_update_msgs) - merge_display_update_messages(opt, result); + merge_display_update_messages(opt, result, stdout); merge_finalize(opt, result); } diff --git a/merge-ort.h b/merge-ort.h index e5aec45b18f..d643b47cb7c 100644 --- a/merge-ort.h +++ b/merge-ort.h @@ -86,7 +86,8 @@ void merge_switch_to_result(struct merge_options *opt, * so only call this when bypassing merge_switch_to_result(). */ void merge_display_update_messages(struct merge_options *opt, - struct merge_result *result); + struct merge_result *result, + FILE *stream); /* Do needed cleanup when not calling merge_switch_to_result() */ void merge_finalize(struct merge_options *opt, From patchwork Sat Jan 29 18:07:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B0EBC433FE for ; Sat, 29 Jan 2022 18:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353083AbiA2SHm (ORCPT ); Sat, 29 Jan 2022 13:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346206AbiA2SHX (ORCPT ); Sat, 29 Jan 2022 13:07:23 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 173C5C06173B for ; Sat, 29 Jan 2022 10:07:23 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id c2so7054198wml.1 for ; Sat, 29 Jan 2022 10:07:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ic5JyJUYhqiS8qLrTIu1x3UTrzMNVC/cJm9nrqcJlvg=; b=V8TbBpjjDBVHB7lFqGTeGR1Ua1B1k+FwqH7PzxBPo0hMjlfRLWcLTq5WlgvDUrdkMt Ag2k+QkoGAbgmTEo5OvqwxwE2teyQ7KHGbTRXmaPS0bKTo1Vgrr4PSjE9IvFxMe1kMHt jw8p4ISMLoCbyOBlzj7zcP5Gmq4y37WTCdkitqVa9Zj9/ID8Wtbc6/1C+Pe6kHKcNOvl mCLTrSueg47h3MdwCfwp6nPSlNhrWzqV3OYFEh6SzNPbQiYfaiu3ort35uuY9zasKgcj IAZzfMw/zFTfWKwGH+01JPtZGcC8u9maojLh/5wKGUXL0WuWVx4EaZAtnOlTIpCHULMt IDOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ic5JyJUYhqiS8qLrTIu1x3UTrzMNVC/cJm9nrqcJlvg=; b=4v8eiU/Pmx4GuShtK8PtAYsnJmzVWXUEk//TaMxQYLpCwXgNQTSMR+gVls6rKFI7uO hCPt5v8OOezADmFppj8fm8EjkGCQndZMoUeMGDytbFwjcxaO/5Chy3czP+iaUXMrS/xn fIkuTy/iJ6niy975thvHuoNVFdBEbsXnJcZQvnPMBtil5/WbBTjVUO6cMKkltxmDNhKC i/R2Z/fdw8MNXRVePJmKTkOjC43N1WOTWZejXpV4r9616VeJ20aR7YJhAp0pp/JlDNSU 8OMcoER7bwALVS06HVIm0L827mVb0B/PjEnOivwApt3KL97CEKaXbcZYC1KqRGn76y1R EUWg== X-Gm-Message-State: AOAM532ByXEP3Ytc978GEfjs0vR1MG4lyT6rw2okHOIkveKKDi872cMh h1aFzgRT/o2pdkMSrrDI84aQqsP1+AQ= X-Google-Smtp-Source: ABdhPJynujEedEJXCMEOf/CKAi24kiJd7KuAAj6iFDFVMcsXL1k3lnlZn65DyAuv8GudKKe7ptMeAQ== X-Received: by 2002:a05:600c:298:: with SMTP id 24mr20190321wmk.100.1643479641475; Sat, 29 Jan 2022 10:07:21 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p15sm7288870wrq.66.2022.01.29.10.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:21 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:08 +0000 Subject: [PATCH v2 08/13] merge-tree: support including merge messages in output Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren When running `git merge-tree --write-tree`, we previously would only return an exit status reflecting the cleanness of a merge, and print out the toplevel tree of the resulting merge. Merges also have informational messages, such as: * "Auto-merging " * "CONFLICT (content): ..." * "CONFLICT (file/directory)" * etc. In fact, when non-content conflicts occur (such as file/directory, modify/delete, add/add with differing modes, rename/rename (1to2), etc.), these informational messages may be the only notification the user gets since these conflicts are not representable in the contents of the file. Add a --[no-]messages option so that callers can request these messages be included at the end of the output. Include such messages by default when there are conflicts, and omit them by default when the merge is clean. Signed-off-by: Elijah Newren --- Documentation/git-merge-tree.txt | 45 +++++++++++++++++++++++++++----- builtin/merge-tree.c | 19 ++++++++++++-- t/t4301-merge-tree-write-tree.sh | 21 +++++++++++++++ 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index 569485815a0..42e0f8f6183 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -9,7 +9,7 @@ git-merge-tree - Perform merge without touching index or working tree SYNOPSIS -------- [verse] -'git merge-tree' [--write-tree] +'git merge-tree' [--write-tree] [] 'git merge-tree' [--trivial-merge] (deprecated) DESCRIPTION @@ -35,17 +35,47 @@ merge is distinguished from a trivial merge in that it includes: After the merge completes, it will create a new toplevel tree object. See `OUTPUT` below for details. +OPTIONS +------- + +--[no-]messages:: + Write any informational messages such as "Auto-merging " + or CONFLICT notices to the end of stdout. If unspecified, the + default is to include these messages if there are merge + conflicts, and to omit them otherwise. + OUTPUT ------ -For either a successful or conflicted merge, the output from -git-merge-tree is simply one line: +By default, for a successful merge, the output from git-merge-tree is +simply one line: + + + +Whereas for a conflicted merge, the output is by default of the form: + + +These are discussed individually below. + +OID of toplevel tree +~~~~~~~~~~~~~~~~~~~~ + +This is a tree object that represents what would be checked out in the +working tree at the end of `git merge`. If there were conflicts, then +files within this tree may have embedded conflict markers. + +Informational messages +~~~~~~~~~~~~~~~~~~~~~~ + +This always starts with a blank line to separate it from the previous +section, and then has free-form messages about the merge, such as: -The printed tree object corresponds to what would be checked out in -the working tree at the end of `git merge`, and thus may have files -with conflict markers in them. + * "Auto-merging " + * "CONFLICT (rename/delete): renamed...but deleted in..." + * "Failed to merge submodule ()" + * "Warning: cannot merge binary files: " EXIT STATUS ----------- @@ -69,7 +99,8 @@ be used as a part of a series of steps such as However, it does not quite fit into the same category of low-level plumbing commands since the possibility of merge conflicts give it a -much higher chance of the command not succeeding. +much higher chance of the command not succeeding (and NEWTREE containing +a bunch of stuff other than just a toplevel tree). GIT --- diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index d14c9f6e44e..6a556ab1c9c 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -390,6 +390,7 @@ static int trivial_merge(const char *base, struct merge_tree_options { int mode; + int show_messages; }; static int real_merge(struct merge_tree_options *o, @@ -432,18 +433,27 @@ static int real_merge(struct merge_tree_options *o, merge_incore_recursive(&opt, merge_bases, parent1, parent2, &result); if (result.clean < 0) die(_("failure to merge")); + + if (o->show_messages == -1) + o->show_messages = !result.clean; + puts(oid_to_hex(&result.tree->object.oid)); + if (o->show_messages) { + printf("\n"); + merge_display_update_messages(&opt, &result, stdout); + } merge_finalize(&opt, &result); return !result.clean; /* result.clean < 0 handled above */ } int cmd_merge_tree(int argc, const char **argv, const char *prefix) { - struct merge_tree_options o = { 0 }; + struct merge_tree_options o = { .show_messages = -1 }; int expected_remaining_argc; + int original_argc; const char * const merge_tree_usage[] = { - N_("git merge-tree [--write-tree] "), + N_("git merge-tree [--write-tree] [] "), N_("git merge-tree [--trivial-merge] "), NULL }; @@ -453,10 +463,13 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) 'w'), OPT_CMDMODE(0, "trivial-merge", &o.mode, N_("do a trivial merge only"), 't'), + OPT_BOOL(0, "messages", &o.show_messages, + N_("also show informational/conflict messages")), OPT_END() }; /* Parse arguments */ + original_argc = argc; argc = parse_options(argc, argv, prefix, mt_options, merge_tree_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (o.mode) { @@ -468,6 +481,8 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) usage_with_options(merge_tree_usage, mt_options); o.mode = (argc == 2 ? 'w' : 't'); } + if (o.mode == 't' && original_argc < argc) + die(_("--trivial-merge is incompatible with all other options")); /* Do the relevant type of merge */ if (o.mode == 'w') diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 66c3eaf2021..e2255711f9c 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -85,4 +85,25 @@ test_expect_success 'Barf on too many arguments' ' grep "^usage: git merge-tree" expect ' +test_expect_success 'test conflict notices and such' ' + test_expect_code 1 git merge-tree --write-tree side1 side2 >out && + sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual && + + # Expected results: + # "greeting" should merge with conflicts + # "numbers" should merge cleanly + # "whatever" has *both* a modify/delete and a file/directory conflict + cat <<-EOF >expect && + HASH + + Auto-merging greeting + CONFLICT (content): Merge conflict in greeting + Auto-merging numbers + CONFLICT (file/directory): directory in the way of whatever from side1; moving it to whatever~side1 instead. + CONFLICT (modify/delete): whatever~side1 deleted in side2 and modified in side1. Version side1 of whatever~side1 left in tree. + EOF + + test_cmp expect actual +' + test_done From patchwork Sat Jan 29 18:07:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F25D1C433EF for ; Sat, 29 Jan 2022 18:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353035AbiA2SHh (ORCPT ); Sat, 29 Jan 2022 13:07:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352974AbiA2SHZ (ORCPT ); Sat, 29 Jan 2022 13:07:25 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB6FC061749 for ; Sat, 29 Jan 2022 10:07:23 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id m14so16918466wrg.12 for ; Sat, 29 Jan 2022 10:07:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=PlInyUqRBx0ASPfJ5p3RLGlX6fpaPltpQjbFbwbFWcs=; b=UN4TpkgSIoh0btUwKqExlcSQoyaggFa2Te8RyObAnVbO3zxEeYiaN47yGSKdseE6M3 pjhx96IDUHIF4+Bg8+9U47oZwm/wPvl2P1Hav+lj6d6QFW+AqW/Kl8CSXZkaaOq9Wzfi p2fHvvJkrrRePS8tr9gbjK4KUg7ujAkdziCHahu4HkP1N0Ogof5SV2IfbSQVXM4fA/ZB RcLvs3VcSM7uhqari1Tgsyk4qAauayBL+qzh7IYyY5yDnKgR++jHTODkYGL01XP171hf LokKCX3qAxN7VYH4OrkJr/VZtfyodxaTgnhYMdFFFkjlMaptJBIWYczr0R+admzXID1x 6TrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=PlInyUqRBx0ASPfJ5p3RLGlX6fpaPltpQjbFbwbFWcs=; b=nlHjOHEYckpnjX5VRl46DekSYX/6wwjUa2sqMO5arwRALl2GjrBVvve3lipiD6HMlH 6O79ARS4gb9TbNBMnsM7sVAUXtfv7oLXL47SBv4WBCncv9FRGndDCvAPeHBjMUzLvWl4 +RFXE4ZdYL2jb3WqrD3gNY01cT3Ydvv5klEguO2QpCseD6D3GYR8PHCKxa3L3nOFVYqr vTjGUugItAtnRMplcx2tfkNiROcT22dvwDsyWQujIBc/1qSabpIU0aS0Ghbs398hI92L GxJtKIOrIt1yarv3lXVlBGPl/r+Cg9adv1b8TY7lNOqNOyGg2FyKDLIDUEZCC8UXBdQW O9AA== X-Gm-Message-State: AOAM530c4qOCO0gdTNI5cXIlcrAnyPEmu6HrtemXWUIPDmQzOBqWzYdk s28nTlfB0KZWhT6ellUPPdfaw7fYVF0= X-Google-Smtp-Source: ABdhPJwZxMzpe6iYI4JA8KeR0RZCQJJcx1y9MlEz9gzgumBTzxHvWhCun8BbKr+j/M5isBgrkao/mg== X-Received: by 2002:a5d:500c:: with SMTP id e12mr11621370wrt.187.1643479642255; Sat, 29 Jan 2022 10:07:22 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z13sm8606362wrm.90.2022.01.29.10.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:21 -0800 (PST) Message-Id: <9c2334ae9f294b92c0c34b3d13efc2b16eefecb4.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:09 +0000 Subject: [PATCH v2 09/13] merge-ort: provide a merge_get_conflicted_files() helper function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren After a merge, this function allows the user to extract the same information that would be printed by `ls-files -u`, which means files with their mode, oid, and stage. Signed-off-by: Elijah Newren --- merge-ort.c | 31 +++++++++++++++++++++++++++++++ merge-ort.h | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/merge-ort.c b/merge-ort.c index d28d1721d14..c4ce6027dc4 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4275,6 +4275,37 @@ void merge_display_update_messages(struct merge_options *opt, trace2_region_leave("merge", "display messages", opt->repo); } +void merge_get_conflicted_files(struct merge_result *result, + struct string_list *conflicted_files) +{ + struct hashmap_iter iter; + struct strmap_entry *e; + struct merge_options_internal *opti = result->priv; + + strmap_for_each_entry(&opti->conflicted, &iter, e) { + const char *path = e->key; + struct conflict_info *ci = e->value; + int i; + + VERIFY_CI(ci); + + for (i = MERGE_BASE; i <= MERGE_SIDE2; i++) { + struct stage_info *si; + + if (!(ci->filemask & (1ul << i))) + continue; + + si = xmalloc(sizeof(*si)); + si->stage = i+1; + si->mode = ci->stages[i].mode; + oidcpy(&si->oid, &ci->stages[i].oid); + string_list_append(conflicted_files, path)->util = si; + } + } + /* string_list_sort() uses a stable sort, so we're good */ + string_list_sort(conflicted_files); +} + void merge_switch_to_result(struct merge_options *opt, struct tree *head, struct merge_result *result, diff --git a/merge-ort.h b/merge-ort.h index d643b47cb7c..e635a294ea8 100644 --- a/merge-ort.h +++ b/merge-ort.h @@ -2,6 +2,7 @@ #define MERGE_ORT_H #include "merge-recursive.h" +#include "hash.h" struct commit; struct tree; @@ -89,6 +90,26 @@ void merge_display_update_messages(struct merge_options *opt, struct merge_result *result, FILE *stream); +struct stage_info { + struct object_id oid; + int mode; + int stage; +}; + +/* + * Provide a list of path -> {struct stage_info*} mappings for + * all conflicted files. Note that each path could appear up to three + * times in the list, corresponding to 3 different stage entries. In short, + * this basically provides the info that would be printed by `ls-files -u`. + * + * result should have been populated by a call to + * one of the merge_incore_[non]recursive() functions. + * + * conflicted_files should be empty before calling this function. + */ +void merge_get_conflicted_files(struct merge_result *result, + struct string_list *conflicted_files); + /* Do needed cleanup when not calling merge_switch_to_result() */ void merge_finalize(struct merge_options *opt, struct merge_result *result); From patchwork Sat Jan 29 18:07:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729600 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19FD8C433FE for ; Sat, 29 Jan 2022 18:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353031AbiA2SHg (ORCPT ); Sat, 29 Jan 2022 13:07:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352990AbiA2SHZ (ORCPT ); Sat, 29 Jan 2022 13:07:25 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95FC2C06174A for ; Sat, 29 Jan 2022 10:07:24 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso10619247wmj.2 for ; Sat, 29 Jan 2022 10:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=QUAEoi4aLmkdvqTyeW5+zkc86dJRK8t2CDOBRn9/dKI=; b=ShqTFqX7rqL780auB/jem5aJHr0Dmdb1DT9urDZ4L6e/TNP5oIZYSUVeDdk2DuK01o RqpnC0ZUct8/AY1fAkqgeADsnNGfMh3oYClom3wiMLRcjDPFYhdN7bBsF9sF+O58AWc3 ZQHDEft61fgE/As5TS/Ob32Fog1LIpy558dZaGv8P4w1ksRa3EV5Af3bj5UsQuO9sMPG mmx14RjvTUF31fm0LUZMcE/vSgmSycQYfNl7URcMuEi1QY4/ZNM2LhMbWk4UqoLGuhlm XzrdQdiozwPEq8k0dP41Uflzv7cpKrzdAyAxsyfh1JWz4TCtfgj3WMkfAWbDPQRUw0Yg Zrsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=QUAEoi4aLmkdvqTyeW5+zkc86dJRK8t2CDOBRn9/dKI=; b=rfM9R1V7pz847AyRRs/1l+2X8Z7+BeFDDpye7GB6PlSZIlOdgbGI3KnVnw4+Yw4bgL QnnqDsGFPfzos0RqXuC0hfgYaueSZdcTaiPa+XKuaigcLdNQh48g+IJBo5BfM3ZK3lJt ZwcPq+c8v6+4KNOj6Qlbb51CLjtWtZ+Zit9HtFSACkYeOGlms1CP1IgnY/JtSZtXIOyb h5p0GBOietn6nQoSqcja+gYo92sa31sAcxGQnKMD3HNX9U3kscmjzBpFrnkWybdV4wuB BzNG5ePCyjhrBfIhfwXuKHGHlXwE4RI3lEjwfSKRTD1YKq9EigQsyqyivfwYUcdLkBe+ /mnw== X-Gm-Message-State: AOAM533HZGZxUF58JUXNHjEQl/YGP5jfScr025oE55mMC+fzATX3NypX pqJVSe86GFGWm9o6cQwKkukTrl1Seu8= X-Google-Smtp-Source: ABdhPJwEEF+H3cV0roBmqOBwLwNeQ8vZ0DrFOEPRL1AL4rqxHTYPCv81gyJ105qeq2VMuqiy6OR+qw== X-Received: by 2002:a05:600c:1498:: with SMTP id c24mr12054442wmh.78.1643479643012; Sat, 29 Jan 2022 10:07:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o14sm4732963wmr.3.2022.01.29.10.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:22 -0800 (PST) Message-Id: <243134dc2478e21f67a6d9cb999d6754b616f6ee.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:10 +0000 Subject: [PATCH v2 10/13] merge-tree: provide a list of which files have conflicts Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Callers of `git merge-tree --write-tree` will often want to know which files had conflicts. While they could potentially attempt to parse the CONFLICT notices printed, those messages are not meant to be machine readable. Provide a simpler mechanism of just printing the files (in the same format as `git ls-files` with quoting, but restricted to unmerged files) in the output before the free-form messages. Signed-off-by: Elijah Newren --- Documentation/git-merge-tree.txt | 8 ++++++++ builtin/merge-tree.c | 24 ++++++++++++++++++++++-- t/t4301-merge-tree-write-tree.sh | 11 +++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index 42e0f8f6183..160e8f44b62 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -55,6 +55,7 @@ simply one line: Whereas for a conflicted merge, the output is by default of the form: + These are discussed individually below. @@ -66,6 +67,13 @@ This is a tree object that represents what would be checked out in the working tree at the end of `git merge`. If there were conflicts, then files within this tree may have embedded conflict markers. +Conflicted file list +~~~~~~~~~~~~~~~~~~~~ + +This is a sequence of lines containing a filename on each line, quoted +as explained for the configuration variable `core.quotePath` (see +linkgit:git-config[1]). + Informational messages ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 6a556ab1c9c..54dae018203 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -11,6 +11,9 @@ #include "blob.h" #include "exec-cmd.h" #include "merge-blobs.h" +#include "quote.h" + +static int line_termination = '\n'; struct merge_list { struct merge_list *next; @@ -394,7 +397,8 @@ struct merge_tree_options { }; static int real_merge(struct merge_tree_options *o, - const char *branch1, const char *branch2) + const char *branch1, const char *branch2, + const char *prefix) { struct commit *parent1, *parent2; struct commit_list *common; @@ -438,6 +442,22 @@ static int real_merge(struct merge_tree_options *o, o->show_messages = !result.clean; puts(oid_to_hex(&result.tree->object.oid)); + if (!result.clean) { + struct string_list conflicted_files = STRING_LIST_INIT_NODUP; + const char *last = NULL; + int i; + + merge_get_conflicted_files(&result, &conflicted_files); + for (i = 0; i < conflicted_files.nr; i++) { + const char *name = conflicted_files.items[i].string; + if (last && !strcmp(last, name)) + continue; + write_name_quoted_relative( + name, prefix, stdout, line_termination); + last = name; + } + string_list_clear(&conflicted_files, 1); + } if (o->show_messages) { printf("\n"); merge_display_update_messages(&opt, &result, stdout); @@ -486,7 +506,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) /* Do the relevant type of merge */ if (o.mode == 'w') - return real_merge(&o, argv[0], argv[1]); + return real_merge(&o, argv[0], argv[1], prefix); else return trivial_merge(argv[0], argv[1], argv[2]); } diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index e2255711f9c..7113d060bc5 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -95,6 +95,8 @@ test_expect_success 'test conflict notices and such' ' # "whatever" has *both* a modify/delete and a file/directory conflict cat <<-EOF >expect && HASH + greeting + whatever~side1 Auto-merging greeting CONFLICT (content): Merge conflict in greeting @@ -106,4 +108,13 @@ test_expect_success 'test conflict notices and such' ' test_cmp expect actual ' +test_expect_success 'Just the conflicted files without the messages' ' + test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out && + sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual && + + test_write_lines HASH greeting whatever~side1 >expect && + + test_cmp expect actual +' + test_done From patchwork Sat Jan 29 18:07:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E4F6C433F5 for ; Sat, 29 Jan 2022 18:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353029AbiA2SHg (ORCPT ); Sat, 29 Jan 2022 13:07:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353011AbiA2SH1 (ORCPT ); Sat, 29 Jan 2022 13:07:27 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF4EC061753 for ; Sat, 29 Jan 2022 10:07:25 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id m26so789403wms.0 for ; Sat, 29 Jan 2022 10:07:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=4vpK7gvSSTnnlTHW028zn/66BNp2/IopKxZgoFX/3Ek=; b=TdpYfuwQS/lh3xaO4/wohm2PxxVkefHjbkaSFQjXxkJr2FisY80NlAXAIY7GWO5ojq RTGrKVSoZzR05CRmL2pQEbMgXfs8wb2MWZAkGK7lJMquP2oZsdsbMTARgsfboRsd2YRo qjmqEX8ivYcYW4uXvvsI7rZB4zQgo3FSsS9T8qzeCCsX6Q5O7L6KLsANWjtechJIteIo lkd0WRr1PGWP+0j0cWGv2D4E4/4W3bQXHu9h/r0x16nDeMCqZHJF7V3rGairMBsH1Ct3 QZA04/4JSmlYtYQX9RDILJO2i+mnYXrZakpVT8TEiconj/k+LPIad3yiZ3IlDeWFktVT l9QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=4vpK7gvSSTnnlTHW028zn/66BNp2/IopKxZgoFX/3Ek=; b=iL7iFiSmepuwWGnoCcx6rqIdJS373LkGyRKKXaQEcfQhpxr3xwy+aaTnCOoCtB4Xqn e4x08bruOBW5pNqWjWDoVYIQVAh9bA2717RAX8OVHUd23B7+K9YgHT00P2Ttpa5KDspe vKeG+SxPlzHYhAOIIIlRH/4sRo3qShcxdT9KpL0rmRVT9W+y5d9HTwbsCi21VtfEWjGh 3MaU+Vm5EppewR7nEUBoXUsuBofpQHBqUdPyWVotcPYOptsNpegzd/x/0/f85M3awZGe lpmPf/9mrfoBw7OH7yNzyLohMFfistwR5KZHYDak9383ldsCTtV/DcCdAcMSaGCTJSmu LhQQ== X-Gm-Message-State: AOAM530u6WGSVdVZ97Uv/iP4npwo/6hL2GGwQ79gbOBVaGS0tis/+qUP IoCXjBTxctiFLgTqscH9wR9fWavcheo= X-Google-Smtp-Source: ABdhPJwF3CaaK2WIJIxsaksVAd0FaSRwO7PYFqLg521RisbQ+4QWd/MWGP0cwzW3Yxmn2eaA9YmlOw== X-Received: by 2002:a05:600c:4112:: with SMTP id j18mr20862125wmi.72.1643479643783; Sat, 29 Jan 2022 10:07:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n18sm7308682wrm.47.2022.01.29.10.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:23 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:11 +0000 Subject: [PATCH v2 11/13] merge-tree: provide easy access to `ls-files -u` style info Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Much like `git merge` updates the index with information of the form (mode, oid, stage, name) provide this output for conflicted files for merge-tree as well. Provide an --exclude-modes-oids-stages/-l option for users to exclude the mode, oid, and stage and only get the list of conflicted filenames. Signed-off-by: Elijah Newren --- Documentation/git-merge-tree.txt | 30 ++++++++++++++++++++++++------ builtin/merge-tree.c | 11 ++++++++++- t/t4301-merge-tree-write-tree.sh | 26 ++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index 160e8f44b62..55bb7bc61c1 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -38,6 +38,11 @@ See `OUTPUT` below for details. OPTIONS ------- +--exclude-oids-and-modes:: + Instead of writing a list of (mode, oid, stage, path) tuples + to output for conflicted files, just provide a list of + filenames with conflicts. + --[no-]messages:: Write any informational messages such as "Auto-merging " or CONFLICT notices to the end of stdout. If unspecified, the @@ -55,7 +60,7 @@ simply one line: Whereas for a conflicted merge, the output is by default of the form: - + These are discussed individually below. @@ -67,18 +72,23 @@ This is a tree object that represents what would be checked out in the working tree at the end of `git merge`. If there were conflicts, then files within this tree may have embedded conflict markers. -Conflicted file list +Conflicted file info ~~~~~~~~~~~~~~~~~~~~ -This is a sequence of lines containing a filename on each line, quoted -as explained for the configuration variable `core.quotePath` (see -linkgit:git-config[1]). +This is a sequence of lines with the format + + + +The filename will be quoted as explained for the configuration +variable `core.quotePath` (see linkgit:git-config[1]). However, if +the `--exclude-oids-and-modes` option is passed, the mode, object, and +stage will be omitted. Informational messages ~~~~~~~~~~~~~~~~~~~~~~ This always starts with a blank line to separate it from the previous -section, and then has free-form messages about the merge, such as: +sections, and then has free-form messages about the merge, such as: * "Auto-merging " * "CONFLICT (rename/delete): renamed...but deleted in..." @@ -110,6 +120,14 @@ plumbing commands since the possibility of merge conflicts give it a much higher chance of the command not succeeding (and NEWTREE containing a bunch of stuff other than just a toplevel tree). +git-merge-tree was written to provide users with the same information +that they'd have access to if using `git merge`: + * what would be written to the working tree (the ) + * the higher order stages that would be written to the index (the + ) + * any messages that would have been printed to stdout (the ) + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 54dae018203..dc52cd02dce 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -394,6 +394,7 @@ static int trivial_merge(const char *base, struct merge_tree_options { int mode; int show_messages; + int exclude_modes_oids_stages; }; static int real_merge(struct merge_tree_options *o, @@ -450,7 +451,11 @@ static int real_merge(struct merge_tree_options *o, merge_get_conflicted_files(&result, &conflicted_files); for (i = 0; i < conflicted_files.nr; i++) { const char *name = conflicted_files.items[i].string; - if (last && !strcmp(last, name)) + struct stage_info *c = conflicted_files.items[i].util; + if (!o->exclude_modes_oids_stages) + printf("%06o %s %d\t", + c->mode, oid_to_hex(&c->oid), c->stage); + else if (last && !strcmp(last, name)) continue; write_name_quoted_relative( name, prefix, stdout, line_termination); @@ -485,6 +490,10 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) N_("do a trivial merge only"), 't'), OPT_BOOL(0, "messages", &o.show_messages, N_("also show informational/conflict messages")), + OPT_BOOL_F('l', "exclude-modes-oids-stages", + &o.exclude_modes_oids_stages, + N_("list conflicted files without modes/oids/stages"), + PARSE_OPT_NONEG), OPT_END() }; diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 7113d060bc5..1572f460da0 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -47,6 +47,7 @@ test_expect_success 'Content merge and a few conflicts' ' expected_tree=$(cat .git/AUTO_MERGE) && # We will redo the merge, while we are still in a conflicted state! + git ls-files -u >conflicted-file-info && test_when_finished "git reset --hard" && test_expect_code 1 git merge-tree --write-tree side1 side2 >RESULT && @@ -86,7 +87,7 @@ test_expect_success 'Barf on too many arguments' ' ' test_expect_success 'test conflict notices and such' ' - test_expect_code 1 git merge-tree --write-tree side1 side2 >out && + test_expect_code 1 git merge-tree --write-tree --exclude-modes-oids-stages side1 side2 >out && sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual && # Expected results: @@ -109,7 +110,7 @@ test_expect_success 'test conflict notices and such' ' ' test_expect_success 'Just the conflicted files without the messages' ' - test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out && + test_expect_code 1 git merge-tree --write-tree --no-messages --exclude-modes-oids-stages side1 side2 >out && sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual && test_write_lines HASH greeting whatever~side1 >expect && @@ -117,4 +118,25 @@ test_expect_success 'Just the conflicted files without the messages' ' test_cmp expect actual ' +test_expect_success 'Check conflicted oids and modes without messages' ' + test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out && + sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual && + + # Compare the basic output format + q_to_tab >expect <<-\EOF && + HASH + 100644 HASH 1Qgreeting + 100644 HASH 2Qgreeting + 100644 HASH 3Qgreeting + 100644 HASH 1Qwhatever~side1 + 100644 HASH 2Qwhatever~side1 + EOF + + test_cmp expect actual && + + # Check the actual hashes against the `ls-files -u` output too + tail -n +2 out | sed -e s/side1/HEAD/ >actual && + test_cmp conflicted-file-info actual +' + test_done From patchwork Sat Jan 29 18:07:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 922F7C433EF for ; Sat, 29 Jan 2022 18:09:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353046AbiA2SHj (ORCPT ); Sat, 29 Jan 2022 13:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353001AbiA2SH1 (ORCPT ); Sat, 29 Jan 2022 13:07:27 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18575C061751 for ; Sat, 29 Jan 2022 10:07:26 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id d138-20020a1c1d90000000b0034e043aaac7so8013713wmd.5 for ; Sat, 29 Jan 2022 10:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=WUyLCxHvSgoMpE4PVsbUd0YaOkpPQy/P5/Q9dNOZFJs=; b=mkzSoj2dBA3QggdXawFMdXC5j6g7QTN20gnCnqvWgbiJV1Phus+ocPArrhZBT+jios Y4uY3LYOYtBt5l4/+8QLTL2mbDcfd9KgZFqBs9eLKmgpQyk+6sARxcIzZDjm0P18FuZ1 vzvVPCRr0JGd7M8TJu0EQcCez4k7ukSQKIrql4AsEPvpzeHv31lyN2gW74erMBLbFnu2 166bhndAtO0WFgt/GsFSgN5ZEvGqMxjF3kZi2Z6sh2HBVF+9k/ARpGTQb8u8aMJ8Qp8i 0LkhU9ttmOM2Kh8oH9p+tWSn2D7K1zTFx/zvodxAEv6lchv+EiD6v1FoujvD6KGROX0c uMkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=WUyLCxHvSgoMpE4PVsbUd0YaOkpPQy/P5/Q9dNOZFJs=; b=TdRPf2/EC1Zra/Gf7FEfROHBz7MvmpWo0bbfQFxB6PB0VLQfxDr9rRYU5lcXuhR3bs Qn65tfZmztUEv0uZzgBv3kIZVMFH6dNVzmOAUDMYTrlf5xhnUiTAzdqCyiTSTfJF7aPB a0m8sCiaBdFkXVGEzKEuRz97aMRlbY48Yo/d/JdkTkdIAOfWqOk1V/1mA00Mm68c6HK9 /UR1G0AZjImKSz6KY1AgXuWlXg0rIGk6nRKr5Y2yk8CMKRTA6IlUyVzKBy6olqrfqvUx SUVpLC+lUdilmnyAkgyzbc/Qi+C9ucXiq6pqBR4uwQKl+fBmxbSY05ypVBeEmOACvjk4 Gcrw== X-Gm-Message-State: AOAM531an0Hf0jDpBzh33QfXtK6QiFjQH30T5rxq/ybWhE+ST7RNzqfG HW7TXoxu4sFHbD+dRRqYmjdP2vX4o/U= X-Google-Smtp-Source: ABdhPJxiTwZtppfZAZ3pS+Hja5gWJpyx2lmRxZBqFbFgQr3zrVfKRXdNQolR+MmGrjqpuIHXtys2PA== X-Received: by 2002:a1c:f006:: with SMTP id a6mr20636504wmb.71.1643479644542; Sat, 29 Jan 2022 10:07:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g15sm2709702wri.82.2022.01.29.10.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:24 -0800 (PST) Message-Id: <25677d5038cab591774eaa1349365871b23aa2fc.1643479633.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:12 +0000 Subject: [PATCH v2 12/13] merge-tree: add a --allow-unrelated-histories flag Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Folks may want to merge histories that have no common ancestry; provide a flag with the same name as used by `git merge` to allow this. Signed-off-by: Elijah Newren --- Documentation/git-merge-tree.txt | 5 +++++ builtin/merge-tree.c | 7 ++++++- t/t4301-merge-tree-write-tree.sh | 24 +++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index 55bb7bc61c1..d35710c81d5 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -49,6 +49,11 @@ OPTIONS default is to include these messages if there are merge conflicts, and to omit them otherwise. +--allow-unrelated-histories:: + merge-tree will by default error out if the two branches specified + share no common history. This flag can be given to override that + check and make the merge proceed anyway. + OUTPUT ------ diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index dc52cd02dce..cca5075d521 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -393,6 +393,7 @@ static int trivial_merge(const char *base, struct merge_tree_options { int mode; + int allow_unrelated_histories; int show_messages; int exclude_modes_oids_stages; }; @@ -430,7 +431,7 @@ static int real_merge(struct merge_tree_options *o, * merge_incore_recursive in merge-ort.h */ common = get_merge_bases(parent1, parent2); - if (!common) + if (!common && !o->allow_unrelated_histories) die(_("refusing to merge unrelated histories")); for (j = common; j; j = j->next) commit_list_insert(j->item, &merge_bases); @@ -494,6 +495,10 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) &o.exclude_modes_oids_stages, N_("list conflicted files without modes/oids/stages"), PARSE_OPT_NONEG), + OPT_BOOL_F(0, "allow-unrelated-histories", + &o.allow_unrelated_histories, + N_("allow merging unrelated histories"), + PARSE_OPT_NONEG), OPT_END() }; diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 1572f460da0..996bdfaab7d 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -38,7 +38,13 @@ test_expect_success setup ' >whatever/empty && git add numbers greeting whatever/empty && test_tick && - git commit -m other-modifications + git commit -m other-modifications && + + git switch --orphan unrelated && + >something-else && + git add something-else && + test_tick && + git commit -m first-commit ' test_expect_success 'Content merge and a few conflicts' ' @@ -139,4 +145,20 @@ test_expect_success 'Check conflicted oids and modes without messages' ' test_cmp conflicted-file-info actual ' +test_expect_success 'error out by default for unrelated histories' ' + test_expect_code 128 git merge-tree --write-tree side1 unrelated 2>error && + + grep "refusing to merge unrelated histories" error +' + +test_expect_success 'can override merge of unrelated histories' ' + git merge-tree --write-tree --allow-unrelated-histories side1 unrelated >tree && + TREE=$(cat tree) && + + git rev-parse side1:numbers side1:greeting side1:whatever unrelated:something-else >expect && + git rev-parse $TREE:numbers $TREE:greeting $TREE:whatever $TREE:something-else >actual && + + test_cmp expect actual +' + test_done From patchwork Sat Jan 29 18:07:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12729603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A290C433F5 for ; Sat, 29 Jan 2022 18:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353093AbiA2SHn (ORCPT ); Sat, 29 Jan 2022 13:07:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353013AbiA2SH1 (ORCPT ); Sat, 29 Jan 2022 13:07:27 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D930CC061757 for ; Sat, 29 Jan 2022 10:07:26 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id j5-20020a05600c1c0500b0034d2e956aadso6391039wms.4 for ; Sat, 29 Jan 2022 10:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=lLW1tnVjrI8ldV8t2Ig6LB0ohAIWgVUqYCgU8u6eHps=; b=qMx8aUz9OSLKalXt80m8bmfRqhcdC2zJCmDonL8Z/PgKK6ciMlQg4Fgzz7TncgYJax fuWEyjYAewOTP/3phkIMbOOL+SgRxSVIV75bTIYqJLCqVqIhuAGGbunf5heEufimfqfE jN/ckp0K2BrwgBuGB6/52ZTatZ3fwNPyrboEhPMVVnKd0Zv0tJA3ehYTYCOEsz9ToTlE pjrB2OKKH9qVgEHYbJGEPq9Ffwz3t9mkC7lrNikkdBdXCImbFcV37D373aJs+VexAB27 nLHOxghLKfecSA3WW0WkAeER3ODuut26EF/df/iHSD7rqDd5CkpmfbXfXFIEoPnYobhe gMRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=lLW1tnVjrI8ldV8t2Ig6LB0ohAIWgVUqYCgU8u6eHps=; b=7ZHe0btFjrNkbwsDL0jAN4pnHmu/VIjof2nNj0wMss2PEi8GYTS56zfQDOOqrnirmB fbhelDCdo/XAt/Uxx9BYbqX689niv1pv4GM1L5WsW8qhELBxhInFb24UEuszxpPVdyWi p0W3ZAz4eOZkSJF4fhphiwYTpTX2X0SJuNqFzGrTIhUAD3cjXZArKlhx9U2nOT+AiuoB QQEVX384Pd15skfy/CmI+K0qG9lFD3O0GplqCjXinmPCAH007e9KHcOiw+GnUcijT+fP l93ed+mXDWDVfXnndcoGeauEi3pR1eANtsueHkmiwhcVY6YYYh9eDyRE1sSItSrhfH6s XRQw== X-Gm-Message-State: AOAM531fA6LBZGEm5j5LC4+RcpWJxM3D3RikrBjKV2N0PkuzyQXWAREA ibJt0EY0efuAwE4z3vGV91SJf5eyNgk= X-Google-Smtp-Source: ABdhPJy6JluEPoTDMpGm6Qvvnq1vFgHIq8PTYCTUGc3S59/H+NtkTpmQlPjaTEvMRkhhKklUJish9A== X-Received: by 2002:a05:600c:35c8:: with SMTP id r8mr8844398wmq.142.1643479645265; Sat, 29 Jan 2022 10:07:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o3sm7409535wrq.70.2022.01.29.10.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 10:07:24 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 29 Jan 2022 18:07:13 +0000 Subject: [PATCH v2 13/13] git-merge-tree.txt: add a section on potentional usage mistakes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Christian Couder , Taylor Blau , Johannes Altmanninger , Ramsay Jones , Johannes Schindelin , Christian Couder , =?utf-8?b?UmVuw6k=?= Scharfe , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Elijah Newren , Johannes Sixt , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Signed-off-by: Elijah Newren --- Documentation/git-merge-tree.txt | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index d35710c81d5..b97ddc58a7a 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -133,6 +133,52 @@ that they'd have access to if using `git merge`: * any messages that would have been printed to stdout (the ) +MISTAKES TO AVOID +----------------- + +Do NOT look through the resulting toplevel tree to try to find which +files conflict; parse the section instead. Not +only would parsing an entire tree be horrendously slow in large +repositories, there are numerous types of conflicts not representable by +conflict markers (modify/delete, mode conflict, binary file changed on +both sides, file/directory conflicts, various rename conflict +permutations, etc.) + +Do NOT interpret an empty list as a clean merge; +check the exit status. A merge can have conflicts without having +individual files conflict (there are a few types of directory rename +conflicts that fall into this category, and others might also be added +in the future). + +Do NOT attempt to guess or make the user guess the conflict types from +the list. The information there is insufficient +to do so. For example: Rename/rename(1to2) conflicts (both sides +renamed the same file differently) will result in three different file +having higher order stages (but each only has one higher order stage), +with no way (short of the section) to determine +which three files are related. File/directory conflicts also result in +a file with exactly one higher order stage. +Possibly-involved-in-directory-rename conflicts (when +"merge.directoryRenames" is unset or set to "conflicts") also result in +a file with exactly one higher order stage. In all cases, the + section has the necessary info, though it is +not designed to be machine parseable. + +Do NOT assume all filenames listed in the +section had conflicts. Messages can be included for files that have no +conflicts, such as "Auto-merging ". + +AVOID taking the OIDS from the and re-merging +them to present the conflicts to the user. This will lose information. +Instead, look up the version of the file found within the and show that instead. In particular, the latter will +have conflict markers annotated with the original branch/commit being +merged and, if renames were involved, the original filename. While you +could include the original branch/commit in the conflict marker +annotations when re-merging, the original filename is not available from +the and thus you would be losing information that +might help the user resolve the conflict. + GIT --- Part of the linkgit:git[1] suite