From patchwork Wed Feb 2 02:37:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732509 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 996FFC433EF for ; Wed, 2 Feb 2022 02:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243817AbiBBChm (ORCPT ); Tue, 1 Feb 2022 21:37:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243812AbiBBChm (ORCPT ); Tue, 1 Feb 2022 21:37:42 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4C75C06173B for ; Tue, 1 Feb 2022 18:37:41 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id h21so35570807wrb.8 for ; Tue, 01 Feb 2022 18:37:41 -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=YA/t2RR9P00m9Cz8VLtmYxgeduPrOT5/iFTuToguFVc=; b=aE1y4yIlE5YPN3RiqgO5wOJmBxVZ9X1ggV+K2EhupDxXmdodD6Z/U024RZeC4eFQ3j EnAbckAIoMjS8rf3HLHS93foeovd8zlWVjWpW9JO8/iK/DOwErUNm1I/EA2FbnohenOl PGfccW37BQ0teWosLvhFeeIgXQKcl4Iclo1TBej1So/Hpu5uj8LsRuLRV/3/QKZraHgO 7AiWw/u7hRS4UiQmspqVhJrgORAvYBnbYxagmFfDn7mSKuJ4Z2BLNbPqfp3IiUv7thUb scf5WO23M+NxkILFbgqfuxkGuHj7/4D4CbOmIIaZu4JmXuYsnmzoLUz7uj4oD1AIoaKF DT+A== 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=YA/t2RR9P00m9Cz8VLtmYxgeduPrOT5/iFTuToguFVc=; b=Mm8DO63NH98G/aRy1n5tscVcXwB94glPzb8MOV4eFS5GRYo3Mar+aeT+ZkOiD/baEY 5M3zXqjQCN1UJRZVUMlSDiAyKUqs7MGiGZUKRw/NwH1WapVUZjFCzkIrVTQIV6bcZT6c ZxrcvLCSThmXOfEoWTUdPxd4FFlIrvY57wAoKIduIGCfZahjbovpHcCql1YZPqqvhDAL d9tfAbCni0MFQYwoXLQr2lLYcuEgr0RMyX4r8cJy8F8EGjcvO23+TZT9bXCsAeYY76QU jUru8RIK/icD2W3w7VmvkT/uWrxJr7SkjNhyntWgcmSUNmoNhMu3rjPsPfgZP5qM7DfA oveg== X-Gm-Message-State: AOAM530XfY55WtUDgVqLLtxZ+6tbE7oFCVvCIzlGc9nWSyzrmAQS5MVK FU0xy0erbci5gpJgqjQk7+nAlbpUDQY= X-Google-Smtp-Source: ABdhPJz8tNeXLPoWi1DP+4olR4IYhNg5mxf0DK7+3xdL2QPNaMnmmsBoMN7PG7jL9y7kWlphN0ne3Q== X-Received: by 2002:a5d:64ac:: with SMTP id m12mr23557779wrp.361.1643769460034; Tue, 01 Feb 2022 18:37:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a15sm15969626wrp.41.2022.02.01.18.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:39 -0800 (PST) Message-Id: <0a260125266e3482558089f9bca4f17623df3e11.1643769457.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:28 +0000 Subject: [PATCH v5 01/10] show, log: provide a --remerge-diff capability Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren When this option is specified, we remerge all (two parent) merge commits and diff the actual merge commit to the automatically created version, in order to show how users removed conflict markers, resolved the different conflict versions, and potentially added new changes outside of conflict regions in order to resolve semantic merge problems (or, possibly, just to hide other random changes). This capability works by creating a temporary object directory and marking it as the primary object store. This makes it so that any blobs or trees created during the automatic merge are easily removable afterwards by just deleting all objects from the temporary object directory. There are a few ways that this implementation is suboptimal: * `log --remerge-diff` becomes slow, because the temporary object directory can fill with many loose objects while running * the log output can be muddied with misplaced "warning: cannot merge binary files" messages, since ll-merge.c unconditionally writes those messages to stderr while running instead of allowing callers to manage them. * important conflict and warning messages are simply dropped; thus for conflicts like modify/delete or rename/rename or file/directory which are not representable with content conflict markers, there may be no way for a user of --remerge-diff to know that there had been a conflict which was resolved (and which possibly motivated other changes in the merge commit). * when fixing the previous issue, note that some unimportant conflict and warning messages might start being included. We should instead make sure these remain dropped. Subsequent commits will address these issues. Signed-off-by: Elijah Newren --- Documentation/diff-options.txt | 14 +++++- builtin/log.c | 14 ++++++ diff-merges.c | 12 +++++ log-tree.c | 59 ++++++++++++++++++++++ revision.h | 3 +- t/t4069-remerge-diff.sh | 91 ++++++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 2 deletions(-) create mode 100755 t/t4069-remerge-diff.sh diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index c89d530d3d1..7e27841a95b 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -34,7 +34,7 @@ endif::git-diff[] endif::git-format-patch[] ifdef::git-log[] ---diff-merges=(off|none|on|first-parent|1|separate|m|combined|c|dense-combined|cc):: +--diff-merges=(off|none|on|first-parent|1|separate|m|combined|c|dense-combined|cc|remerge|r):: --no-diff-merges:: Specify diff format to be used for merge commits. Default is {diff-merges-default} unless `--first-parent` is in use, in which case @@ -64,6 +64,18 @@ ifdef::git-log[] each of the parents. Separate log entry and diff is generated for each parent. + +--diff-merges=remerge::: +--diff-merges=r::: +--remerge-diff::: + With this option, two-parent merge commits are remerged to + create a temporary tree object -- potentially containing files + with conflict markers and such. A diff is then shown between + that temporary tree and the actual merge commit. ++ +The output emitted when this option is used is subject to change, and +so is its interaction with other options (unless explicitly +documented). ++ --diff-merges=combined::: --diff-merges=c::: -c::: diff --git a/builtin/log.c b/builtin/log.c index f75d87e8d7f..846ba0f995a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -35,6 +35,7 @@ #include "repository.h" #include "commit-reach.h" #include "range-diff.h" +#include "tmp-objdir.h" #define MAIL_DEFAULT_WRAP 72 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100 @@ -406,6 +407,14 @@ static int cmd_log_walk(struct rev_info *rev) struct commit *commit; int saved_nrl = 0; int saved_dcctc = 0; + struct tmp_objdir *remerge_objdir = NULL; + + if (rev->remerge_diff) { + remerge_objdir = tmp_objdir_create("remerge-diff"); + if (!remerge_objdir) + die(_("unable to create temporary object directory")); + tmp_objdir_replace_primary_odb(remerge_objdir, 1); + } if (rev->early_output) setup_early_output(); @@ -449,6 +458,9 @@ static int cmd_log_walk(struct rev_info *rev) rev->diffopt.no_free = 0; diff_free(&rev->diffopt); + if (rev->remerge_diff) + tmp_objdir_destroy(remerge_objdir); + if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF && rev->diffopt.flags.check_failed) { return 02; @@ -1943,6 +1955,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) die(_("--name-status does not make sense")); if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF) die(_("--check does not make sense")); + if (rev.remerge_diff) + die(_("--remerge-diff does not make sense")); if (!use_patch_format && (!rev.diffopt.output_format || diff --git a/diff-merges.c b/diff-merges.c index 5060ccd890b..0af4b3f9191 100644 --- a/diff-merges.c +++ b/diff-merges.c @@ -17,6 +17,7 @@ static void suppress(struct rev_info *revs) revs->combined_all_paths = 0; revs->merges_imply_patch = 0; revs->merges_need_diff = 0; + revs->remerge_diff = 0; } static void set_separate(struct rev_info *revs) @@ -45,6 +46,12 @@ static void set_dense_combined(struct rev_info *revs) revs->dense_combined_merges = 1; } +static void set_remerge_diff(struct rev_info *revs) +{ + suppress(revs); + revs->remerge_diff = 1; +} + static diff_merges_setup_func_t func_by_opt(const char *optarg) { if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) @@ -57,6 +64,8 @@ static diff_merges_setup_func_t func_by_opt(const char *optarg) return set_combined; else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined")) return set_dense_combined; + else if (!strcmp(optarg, "r") || !strcmp(optarg, "remerge")) + return set_remerge_diff; else if (!strcmp(optarg, "m") || !strcmp(optarg, "on")) return set_to_default; return NULL; @@ -110,6 +119,9 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv) } else if (!strcmp(arg, "--cc")) { set_dense_combined(revs); revs->merges_imply_patch = 1; + } else if (!strcmp(arg, "--remerge-diff")) { + set_remerge_diff(revs); + revs->merges_imply_patch = 1; } else if (!strcmp(arg, "--no-diff-merges")) { suppress(revs); } else if (!strcmp(arg, "--combined-all-paths")) { diff --git a/log-tree.c b/log-tree.c index 644893fd8cf..84ed864fc81 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "commit-reach.h" #include "config.h" #include "diff.h" #include "object-store.h" @@ -7,6 +8,7 @@ #include "tag.h" #include "graph.h" #include "log-tree.h" +#include "merge-ort.h" #include "reflog-walk.h" #include "refs.h" #include "string-list.h" @@ -902,6 +904,51 @@ static int do_diff_combined(struct rev_info *opt, struct commit *commit) return !opt->loginfo; } +static int do_remerge_diff(struct rev_info *opt, + struct commit_list *parents, + struct object_id *oid, + struct commit *commit) +{ + struct merge_options o; + struct commit_list *bases; + struct merge_result res = {0}; + struct pretty_print_context ctx = {0}; + struct commit *parent1 = parents->item; + struct commit *parent2 = parents->next->item; + struct strbuf parent1_desc = STRBUF_INIT; + struct strbuf parent2_desc = STRBUF_INIT; + + /* Setup merge options */ + init_merge_options(&o, the_repository); + o.show_rename_progress = 0; + + ctx.abbrev = DEFAULT_ABBREV; + format_commit_message(parent1, "%h (%s)", &parent1_desc, &ctx); + format_commit_message(parent2, "%h (%s)", &parent2_desc, &ctx); + o.branch1 = parent1_desc.buf; + o.branch2 = parent2_desc.buf; + + /* Parse the relevant commits and get the merge bases */ + parse_commit_or_die(parent1); + parse_commit_or_die(parent2); + bases = get_merge_bases(parent1, parent2); + + /* Re-merge the parents */ + merge_incore_recursive(&o, bases, parent1, parent2, &res); + + /* Show the diff */ + diff_tree_oid(&res.tree->object.oid, oid, "", &opt->diffopt); + log_tree_diff_flush(opt); + + /* Cleanup */ + strbuf_release(&parent1_desc); + strbuf_release(&parent2_desc); + merge_finalize(&o, &res); + /* TODO: clean up the temporary object directory */ + + return !opt->loginfo; +} + /* * Show the diff of a commit. * @@ -936,6 +983,18 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log } if (is_merge) { + int octopus = (parents->next->next != NULL); + + if (opt->remerge_diff) { + if (octopus) { + show_log(opt); + fprintf(opt->diffopt.file, + "diff: warning: Skipping remerge-diff " + "for octopus merges.\n"); + return 1; + } + return do_remerge_diff(opt, parents, oid, commit); + } if (opt->combine_merges) return do_diff_combined(opt, commit); if (opt->separate_merges) { diff --git a/revision.h b/revision.h index 5578bb4720a..13178e6b8f3 100644 --- a/revision.h +++ b/revision.h @@ -195,7 +195,8 @@ struct rev_info { combine_merges:1, combined_all_paths:1, dense_combined_merges:1, - first_parent_merges:1; + first_parent_merges:1, + remerge_diff:1; /* Format info */ int show_notes; diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh new file mode 100755 index 00000000000..d7ab0f50066 --- /dev/null +++ b/t/t4069-remerge-diff.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +test_description='remerge-diff handling' + +. ./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 basic merges' ' + test_write_lines 1 2 3 4 5 6 7 8 9 >numbers && + git add numbers && + git commit -m base && + + git branch feature_a && + git branch feature_b && + git branch feature_c && + + git branch ab_resolution && + git branch bc_resolution && + + git checkout feature_a && + test_write_lines 1 2 three 4 5 6 7 eight 9 >numbers && + git commit -a -m change_a && + + git checkout feature_b && + test_write_lines 1 2 tres 4 5 6 7 8 9 >numbers && + git commit -a -m change_b && + + git checkout feature_c && + test_write_lines 1 2 3 4 5 6 7 8 9 10 >numbers && + git commit -a -m change_c && + + git checkout bc_resolution && + git merge --ff-only feature_b && + # no conflict + git merge feature_c && + + git checkout ab_resolution && + git merge --ff-only feature_a && + # conflicts! + test_must_fail git merge feature_b && + # Resolve conflict...and make another change elsewhere + test_write_lines 1 2 drei 4 5 6 7 acht 9 >numbers && + git add numbers && + git merge --continue +' + +test_expect_success 'remerge-diff on a clean merge' ' + git log -1 --oneline bc_resolution >expect && + git show --oneline --remerge-diff bc_resolution >actual && + test_cmp expect actual +' + +test_expect_success 'remerge-diff with both a resolved conflict and an unrelated change' ' + git log -1 --oneline ab_resolution >tmp && + cat <<-EOF >>tmp && + diff --git a/numbers b/numbers + index a1fb731..6875544 100644 + --- a/numbers + +++ b/numbers + @@ -1,13 +1,9 @@ + 1 + 2 + -<<<<<<< b0ed5cb (change_a) + -three + -======= + -tres + ->>>>>>> 6cd3f82 (change_b) + +drei + 4 + 5 + 6 + 7 + -eight + +acht + 9 + EOF + # Hashes above are sha1; rip them out so test works with sha256 + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && + + git show --oneline --remerge-diff ab_resolution >tmp && + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && + test_cmp expect actual +' + +test_done From patchwork Wed Feb 2 02:37:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732510 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 56217C433F5 for ; Wed, 2 Feb 2022 02:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243826AbiBBChp (ORCPT ); Tue, 1 Feb 2022 21:37:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243815AbiBBChm (ORCPT ); Tue, 1 Feb 2022 21:37:42 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E9A7C061714 for ; Tue, 1 Feb 2022 18:37:42 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id v13so35473228wrv.10 for ; Tue, 01 Feb 2022 18:37:42 -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=d9k6H4wsEoq0GmByUI0p7NXqXRYaCSz94mZMecym4D0=; b=WSNw1iGT04MycFc8GqZOkC67qzRMnbwNav5BJOpyvPdF3RPB+6NDpfuwVeitvpFyot Q+6OQWv5AUMC4Jcmc75+9UUtXUaBtkt5mo9Pp/NF7TCb2h8POcD6YBFUSEuHwriGh0Ji XhuScyIuXHkDcUN5ysAEmtxGmP/7oTmOt3Zl7bmY4+7EiCwkSJ6lOUCP77bJFSRk2dch dmyxR3thUzupOhjqZn0hY5xuyR+Mcgn9mBZ+zxyHlnFq08T4LVEyBISeUBfpzYENF4u7 BexB7CXU4z/ksohOk1AmOW6PC7jPSiTWpD1mu07FyBy3gz1NsO5gDEa+8jCf72pjFmTJ sfMg== 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=d9k6H4wsEoq0GmByUI0p7NXqXRYaCSz94mZMecym4D0=; b=lsCwRbGa4Wq0YRtC5rYn05VEpEtPzWu+tGdRmZeqiqkqgI+lbu2p6ClewayFxQQXxZ Mrz4+jt5rskU/kkee2gypJZ4aSot0JJnoO/Kt8RVvxUw4Nt0YZw6VkHiXpvoLP3AcovS nbT/IRM60NKbKuPjSDYcbY30JbZbMiC8zZGKlEHAQHWV0Fz/iwFElsnZkpiyedJvIkVZ bSI1zT5dR5kqdJO7iqH1jKcfOeKenVXKiMCT7F5Xo2zWYcMj3JSoW+HJ646PWXZWi1Z0 C/lrSPy/xHXIO/0v3AaG7j7ubTvgUEEKS/d12kYNjB0jXSYwNPGWti5ejL4x+lmQ03Au aRVg== X-Gm-Message-State: AOAM531WQ7WAYUpZ8xZa1XhXpngqf35SO/EwThzVqGza45ZbUikan1me 46Ugv1oErQt1sg+XaNAWI/PVO8CXRto= X-Google-Smtp-Source: ABdhPJz01LiMOPHCqJ0j53+r+zmiOKM44w/EFGfecY7LUVayqZjPZQluvr5QLG+2GNuqb7ieHMb2/Q== X-Received: by 2002:adf:dc44:: with SMTP id m4mr23868707wrj.355.1643769460867; Tue, 01 Feb 2022 18:37:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s17sm15715939wrm.62.2022.02.01.18.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:40 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:29 +0000 Subject: [PATCH v5 02/10] log: clean unneeded objects during `log --remerge-diff` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren The --remerge-diff option will need to create new blobs and trees representing the "automatic merge" state. If one is traversing a long project history, one can easily get hundreds of thousands of loose objects generated during `log --remerge-diff`. However, none of those loose objects are needed after we have completed our diff operation; they can be summarily deleted. Add a new helper function to tmp_objdir to discard all the contained objects, and call it after each merge is handled. Signed-off-by: Elijah Newren --- builtin/log.c | 13 +++++++------ log-tree.c | 8 +++++++- revision.h | 3 +++ tmp-objdir.c | 5 +++++ tmp-objdir.h | 6 ++++++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 846ba0f995a..ac550e1ae62 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -407,13 +407,12 @@ static int cmd_log_walk(struct rev_info *rev) struct commit *commit; int saved_nrl = 0; int saved_dcctc = 0; - struct tmp_objdir *remerge_objdir = NULL; if (rev->remerge_diff) { - remerge_objdir = tmp_objdir_create("remerge-diff"); - if (!remerge_objdir) + rev->remerge_objdir = tmp_objdir_create("remerge-diff"); + if (!rev->remerge_objdir) die(_("unable to create temporary object directory")); - tmp_objdir_replace_primary_odb(remerge_objdir, 1); + tmp_objdir_replace_primary_odb(rev->remerge_objdir, 1); } if (rev->early_output) @@ -458,8 +457,10 @@ static int cmd_log_walk(struct rev_info *rev) rev->diffopt.no_free = 0; diff_free(&rev->diffopt); - if (rev->remerge_diff) - tmp_objdir_destroy(remerge_objdir); + if (rev->remerge_diff) { + tmp_objdir_destroy(rev->remerge_objdir); + rev->remerge_objdir = NULL; + } if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF && rev->diffopt.flags.check_failed) { diff --git a/log-tree.c b/log-tree.c index 84ed864fc81..89da7de5dbf 100644 --- a/log-tree.c +++ b/log-tree.c @@ -4,6 +4,7 @@ #include "diff.h" #include "object-store.h" #include "repository.h" +#include "tmp-objdir.h" #include "commit.h" #include "tag.h" #include "graph.h" @@ -944,7 +945,12 @@ static int do_remerge_diff(struct rev_info *opt, strbuf_release(&parent1_desc); strbuf_release(&parent2_desc); merge_finalize(&o, &res); - /* TODO: clean up the temporary object directory */ + + /* Clean up the contents of the temporary object directory */ + if (opt->remerge_objdir) + tmp_objdir_discard_objects(opt->remerge_objdir); + else + BUG("did a remerge diff without remerge_objdir?!?"); return !opt->loginfo; } diff --git a/revision.h b/revision.h index 13178e6b8f3..44efce3f410 100644 --- a/revision.h +++ b/revision.h @@ -318,6 +318,9 @@ struct rev_info { /* misc. flags related to '--no-kept-objects' */ unsigned keep_pack_cache_flags; + + /* Location where temporary objects for remerge-diff are written. */ + struct tmp_objdir *remerge_objdir; }; int ref_excluded(struct string_list *, const char *path); diff --git a/tmp-objdir.c b/tmp-objdir.c index 3d38eeab66b..adf6033549e 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -79,6 +79,11 @@ static void remove_tmp_objdir_on_signal(int signo) raise(signo); } +void tmp_objdir_discard_objects(struct tmp_objdir *t) +{ + remove_dir_recursively(&t->path, REMOVE_DIR_KEEP_TOPLEVEL); +} + /* * These env_* functions are for setting up the child environment; the * "replace" variant overrides the value of any existing variable with that diff --git a/tmp-objdir.h b/tmp-objdir.h index cda5ec76778..76efc7edee5 100644 --- a/tmp-objdir.h +++ b/tmp-objdir.h @@ -46,6 +46,12 @@ int tmp_objdir_migrate(struct tmp_objdir *); */ int tmp_objdir_destroy(struct tmp_objdir *); +/* + * Remove all objects from the temporary object directory, while leaving it + * around so more objects can be added. + */ +void tmp_objdir_discard_objects(struct tmp_objdir *); + /* * Add the temporary object directory as an alternate object store in the * current process. From patchwork Wed Feb 2 02:37:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732511 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 E2B80C433EF for ; Wed, 2 Feb 2022 02:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243854AbiBBChz (ORCPT ); Tue, 1 Feb 2022 21:37:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243818AbiBBChn (ORCPT ); Tue, 1 Feb 2022 21:37:43 -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 71229C061714 for ; Tue, 1 Feb 2022 18:37:43 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id m26so7887704wms.0 for ; Tue, 01 Feb 2022 18:37:43 -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=yNaezyHCbZfihrt2P4wjEMui/03iDIuquSCOMU1Tw38=; b=GvzU50ydAWsMM6B47GD1kfQhRbCtOCWoLM16HMZEOiK9rbbQ9JNCuVDF90CDL0GVgB NP7Z8CTnmlXsngbvZw2vUxk+UxmGhHqAfehlOIP4LnJwo0VnvHa6llxKSfzU0t7b8Fz3 2U/pUEhDMHByqRZm14snvtrQbV974kVxrfMAruiaO/cSL5z5DtRYWAs/VjMdjmk/6QqS Z1dQmLIbDCGOSC8kEoAAOmAGRCKpkOE58gBaGOxIH+DACJKR5f59c99h3CNjymclt2of 0DU+KembMJ6RayLpjXTEtAd/8yg6GBwencUzMTQm2LxNXdlr4aiosR1KFYRKcneMqHET 0Xgw== 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=yNaezyHCbZfihrt2P4wjEMui/03iDIuquSCOMU1Tw38=; b=L9GOaz1RTFe40XhHbalxB4yhxCAa6gOWeoFV85yrJVWFdrzmRXbaQL4YSHkqFYVfpB rZuAAigl1PaeyQm5p5cHrtT1NwSaNupCpeDTdY7UAQVAEFk8/0BVMeQjzZEAiPnyakP9 AjmeEzcggmrW8VIIUJtboTN35097Z+0ogvn1A11JQ5ePsKIISluruyJltSW0v70RVd2s /IMPsNl+1DX9N+asNR7GV5e88aNJEg2QcNhAEwY2gkgQu6Dvq5e61GUWLx2AesK3q2Xo mLk7OqcrF0Ksu9RRtH1x93n/EK89KNFE3vkThp3j4X0c/z8jPAnuRbFG2xeTmf5SnT1A 4SxA== X-Gm-Message-State: AOAM532BoVbNzqoxZK52PEHMqLC/ZdxQzZM7UzIxz1o8z0ezoaEeMhH0 ylgj1ibA4AM2YON8T+lK/eU8mOVUNog= X-Google-Smtp-Source: ABdhPJz9fDD8fPjNa92DxwlCtkkq+YZ3GVA7q2NKzzYYCSC/N4lY+1aJak95p7Gl1SaowZGDgPPjAw== X-Received: by 2002:a1c:a5d0:: with SMTP id o199mr4220681wme.65.1643769461649; Tue, 01 Feb 2022 18:37:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o27sm3634254wms.4.2022.02.01.18.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:41 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:30 +0000 Subject: [PATCH v5 03/10] ll-merge: make callers responsible for showing warnings Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Since some callers may want to send warning messages to somewhere other than stdout/stderr, stop printing "warning: Cannot merge binary files" from ll-merge and instead modify the return status of ll_merge() to indicate when a merge of binary files has occurred. Message printing probably does not belong in a "low-level merge" anyway. This commit continues printing the message as-is, just from the callers instead of within ll_merge(). Future changes will start handling the message differently in the merge-ort codepath. There was one special case here: the callers in rerere.c do NOT check for and print such a message; since those code paths explicitly skip over binary files, there is no reason to check for a return status of LL_MERGE_BINARY_CONFLICT or print the related message. Note that my methodology included first modifying ll_merge() to return a struct, so that the compiler would catch all the callers for me and ensure I had modified all of them. After modifying all of them, I then changed the struct to an enum. Signed-off-by: Elijah Newren --- apply.c | 5 ++++- builtin/checkout.c | 12 ++++++++---- ll-merge.c | 40 ++++++++++++++++++++++------------------ ll-merge.h | 9 ++++++++- merge-blobs.c | 5 ++++- merge-ort.c | 5 ++++- merge-recursive.c | 5 ++++- notes-merge.c | 5 ++++- rerere.c | 9 +++++---- 9 files changed, 63 insertions(+), 32 deletions(-) diff --git a/apply.c b/apply.c index 43a0aebf4ee..8079395755f 100644 --- a/apply.c +++ b/apply.c @@ -3492,7 +3492,7 @@ static int three_way_merge(struct apply_state *state, { mmfile_t base_file, our_file, their_file; mmbuffer_t result = { NULL }; - int status; + enum ll_merge_result status; /* resolve trivial cases first */ if (oideq(base, ours)) @@ -3509,6 +3509,9 @@ static int three_way_merge(struct apply_state *state, &their_file, "theirs", state->repo->index, NULL); + if (status == LL_MERGE_BINARY_CONFLICT) + warning("Cannot merge binary files: %s (%s vs. %s)", + path, "ours", "theirs"); free(base_file.ptr); free(our_file.ptr); free(their_file.ptr); diff --git a/builtin/checkout.c b/builtin/checkout.c index cbf73b8c9f6..3a559d69303 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -237,6 +237,7 @@ static int checkout_merged(int pos, const struct checkout *state, struct cache_entry *ce = active_cache[pos]; const char *path = ce->name; mmfile_t ancestor, ours, theirs; + enum ll_merge_result merge_status; int status; struct object_id oid; mmbuffer_t result_buf; @@ -267,13 +268,16 @@ static int checkout_merged(int pos, const struct checkout *state, memset(&ll_opts, 0, sizeof(ll_opts)); git_config_get_bool("merge.renormalize", &renormalize); ll_opts.renormalize = renormalize; - status = ll_merge(&result_buf, path, &ancestor, "base", - &ours, "ours", &theirs, "theirs", - state->istate, &ll_opts); + merge_status = ll_merge(&result_buf, path, &ancestor, "base", + &ours, "ours", &theirs, "theirs", + state->istate, &ll_opts); free(ancestor.ptr); free(ours.ptr); free(theirs.ptr); - if (status < 0 || !result_buf.ptr) { + if (merge_status == LL_MERGE_BINARY_CONFLICT) + warning("Cannot merge binary files: %s (%s vs. %s)", + path, "ours", "theirs"); + if (merge_status < 0 || !result_buf.ptr) { free(result_buf.ptr); return error(_("path '%s': cannot merge"), path); } diff --git a/ll-merge.c b/ll-merge.c index 261657578c7..a937cec59a6 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -14,7 +14,7 @@ struct ll_merge_driver; -typedef int (*ll_merge_fn)(const struct ll_merge_driver *, +typedef enum ll_merge_result (*ll_merge_fn)(const struct ll_merge_driver *, mmbuffer_t *result, const char *path, mmfile_t *orig, const char *orig_name, @@ -49,7 +49,7 @@ void reset_merge_attributes(void) /* * Built-in low-levels */ -static int ll_binary_merge(const struct ll_merge_driver *drv_unused, +static enum ll_merge_result ll_binary_merge(const struct ll_merge_driver *drv_unused, mmbuffer_t *result, const char *path, mmfile_t *orig, const char *orig_name, @@ -58,6 +58,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused, const struct ll_merge_options *opts, int marker_size) { + enum ll_merge_result ret; mmfile_t *stolen; assert(opts); @@ -68,16 +69,19 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused, */ if (opts->virtual_ancestor) { stolen = orig; + ret = LL_MERGE_OK; } else { switch (opts->variant) { default: - warning("Cannot merge binary files: %s (%s vs. %s)", - path, name1, name2); - /* fallthru */ + ret = LL_MERGE_BINARY_CONFLICT; + stolen = src1; + break; case XDL_MERGE_FAVOR_OURS: + ret = LL_MERGE_OK; stolen = src1; break; case XDL_MERGE_FAVOR_THEIRS: + ret = LL_MERGE_OK; stolen = src2; break; } @@ -87,16 +91,10 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused, result->size = stolen->size; stolen->ptr = NULL; - /* - * With -Xtheirs or -Xours, we have cleanly merged; - * otherwise we got a conflict. - */ - return opts->variant == XDL_MERGE_FAVOR_OURS || - opts->variant == XDL_MERGE_FAVOR_THEIRS ? - 0 : 1; + return ret; } -static int ll_xdl_merge(const struct ll_merge_driver *drv_unused, +static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unused, mmbuffer_t *result, const char *path, mmfile_t *orig, const char *orig_name, @@ -105,7 +103,9 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused, const struct ll_merge_options *opts, int marker_size) { + enum ll_merge_result ret; xmparam_t xmp; + int status; assert(opts); if (orig->size > MAX_XDIFF_SIZE || @@ -133,10 +133,12 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused, xmp.ancestor = orig_name; xmp.file1 = name1; xmp.file2 = name2; - return xdl_merge(orig, src1, src2, &xmp, result); + status = xdl_merge(orig, src1, src2, &xmp, result); + ret = (status > 0) ? LL_MERGE_CONFLICT : status; + return ret; } -static int ll_union_merge(const struct ll_merge_driver *drv_unused, +static enum ll_merge_result ll_union_merge(const struct ll_merge_driver *drv_unused, mmbuffer_t *result, const char *path, mmfile_t *orig, const char *orig_name, @@ -178,7 +180,7 @@ static void create_temp(mmfile_t *src, char *path, size_t len) /* * User defined low-level merge driver support. */ -static int ll_ext_merge(const struct ll_merge_driver *fn, +static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn, mmbuffer_t *result, const char *path, mmfile_t *orig, const char *orig_name, @@ -194,6 +196,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn, const char *args[] = { NULL, NULL }; int status, fd, i; struct stat st; + enum ll_merge_result ret; assert(opts); sq_quote_buf(&path_sq, path); @@ -236,7 +239,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn, unlink_or_warn(temp[i]); strbuf_release(&cmd); strbuf_release(&path_sq); - return status; + ret = (status > 0) ? LL_MERGE_CONFLICT : status; + return ret; } /* @@ -362,7 +366,7 @@ static void normalize_file(mmfile_t *mm, const char *path, struct index_state *i } } -int ll_merge(mmbuffer_t *result_buf, +enum ll_merge_result ll_merge(mmbuffer_t *result_buf, const char *path, mmfile_t *ancestor, const char *ancestor_label, mmfile_t *ours, const char *our_label, diff --git a/ll-merge.h b/ll-merge.h index aceb1b24132..e4a20e81a3a 100644 --- a/ll-merge.h +++ b/ll-merge.h @@ -82,13 +82,20 @@ struct ll_merge_options { long xdl_opts; }; +enum ll_merge_result { + LL_MERGE_ERROR = -1, + LL_MERGE_OK = 0, + LL_MERGE_CONFLICT, + LL_MERGE_BINARY_CONFLICT, +}; + /** * Perform a three-way single-file merge in core. This is a thin wrapper * around `xdl_merge` that takes the path and any merge backend specified in * `.gitattributes` or `.git/info/attributes` into account. * Returns 0 for a clean merge. */ -int ll_merge(mmbuffer_t *result_buf, +enum ll_merge_result ll_merge(mmbuffer_t *result_buf, const char *path, mmfile_t *ancestor, const char *ancestor_label, mmfile_t *ours, const char *our_label, diff --git a/merge-blobs.c b/merge-blobs.c index ee0a0e90c94..8138090f81c 100644 --- a/merge-blobs.c +++ b/merge-blobs.c @@ -36,7 +36,7 @@ static void *three_way_filemerge(struct index_state *istate, mmfile_t *their, unsigned long *size) { - int merge_status; + enum ll_merge_result merge_status; mmbuffer_t res; /* @@ -50,6 +50,9 @@ static void *three_way_filemerge(struct index_state *istate, istate, NULL); if (merge_status < 0) return NULL; + if (merge_status == LL_MERGE_BINARY_CONFLICT) + warning("Cannot merge binary files: %s (%s vs. %s)", + path, ".our", ".their"); *size = res.size; return res.ptr; diff --git a/merge-ort.c b/merge-ort.c index 0342f104836..c24da2ba3cb 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -1743,7 +1743,7 @@ static int merge_3way(struct merge_options *opt, mmfile_t orig, src1, src2; struct ll_merge_options ll_opts = {0}; char *base, *name1, *name2; - int merge_status; + enum ll_merge_result merge_status; if (!opt->priv->attr_index.initialized) initialize_attr_index(opt); @@ -1787,6 +1787,9 @@ static int merge_3way(struct merge_options *opt, merge_status = ll_merge(result_buf, path, &orig, base, &src1, name1, &src2, name2, &opt->priv->attr_index, &ll_opts); + if (merge_status == LL_MERGE_BINARY_CONFLICT) + warning("Cannot merge binary files: %s (%s vs. %s)", + path, name1, name2); free(base); free(name1); diff --git a/merge-recursive.c b/merge-recursive.c index d9457797dbb..bc73c52dd84 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1044,7 +1044,7 @@ static int merge_3way(struct merge_options *opt, mmfile_t orig, src1, src2; struct ll_merge_options ll_opts = {0}; char *base, *name1, *name2; - int merge_status; + enum ll_merge_result merge_status; ll_opts.renormalize = opt->renormalize; ll_opts.extra_marker_size = extra_marker_size; @@ -1090,6 +1090,9 @@ static int merge_3way(struct merge_options *opt, merge_status = ll_merge(result_buf, a->path, &orig, base, &src1, name1, &src2, name2, opt->repo->index, &ll_opts); + if (merge_status == LL_MERGE_BINARY_CONFLICT) + warning("Cannot merge binary files: %s (%s vs. %s)", + a->path, name1, name2); free(base); free(name1); diff --git a/notes-merge.c b/notes-merge.c index b4a3a903e86..01d596920ea 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -344,7 +344,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o, { mmbuffer_t result_buf; mmfile_t base, local, remote; - int status; + enum ll_merge_result status; read_mmblob(&base, &p->base); read_mmblob(&local, &p->local); @@ -358,6 +358,9 @@ static int ll_merge_in_worktree(struct notes_merge_options *o, free(local.ptr); free(remote.ptr); + if (status == LL_MERGE_BINARY_CONFLICT) + warning("Cannot merge binary files: %s (%s vs. %s)", + oid_to_hex(&p->obj), o->local_ref, o->remote_ref); if ((status < 0) || !result_buf.ptr) die("Failed to execute internal merge"); diff --git a/rerere.c b/rerere.c index d83d58df4fb..d26627c5932 100644 --- a/rerere.c +++ b/rerere.c @@ -609,19 +609,20 @@ static int try_merge(struct index_state *istate, const struct rerere_id *id, const char *path, mmfile_t *cur, mmbuffer_t *result) { - int ret; + enum ll_merge_result ret; mmfile_t base = {NULL, 0}, other = {NULL, 0}; if (read_mmfile(&base, rerere_path(id, "preimage")) || - read_mmfile(&other, rerere_path(id, "postimage"))) - ret = 1; - else + read_mmfile(&other, rerere_path(id, "postimage"))) { + ret = LL_MERGE_CONFLICT; + } else { /* * A three-way merge. Note that this honors user-customizable * low-level merge driver settings. */ ret = ll_merge(result, path, &base, NULL, cur, "", &other, "", istate, NULL); + } free(base.ptr); free(other.ptr); From patchwork Wed Feb 2 02:37:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732512 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 B25DEC433F5 for ; Wed, 2 Feb 2022 02:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243815AbiBBChz (ORCPT ); Tue, 1 Feb 2022 21:37:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243820AbiBBCho (ORCPT ); Tue, 1 Feb 2022 21:37:44 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E42C06173B for ; Tue, 1 Feb 2022 18:37:44 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id s18so35514943wrv.7 for ; Tue, 01 Feb 2022 18:37:43 -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=obkKWvubyxcsBWBqodq9GjqtIG2fyoJpZDBmj1ztp44=; b=cA1LwmUfxi8kiqA04k9tdctMjYIzf7ZFHEQyuTNZY98HdOYUtU27RVrx83R86cupaX Molf11TbbPFGzKKT7ZM6cy7eZN/Syrwg/Lt+W5j3t5xP/KX5SxUabEiXi9eIkxVk1jCy N2rZlTHMJlJAtJum1jhg2dL1yTdW7E8G1fQqUQnsiSoD3QXGhdwo2srKou3m+OkJM8hR k/oaNSWoEA1e8yczBHVOaJOYvoDMmIwqmvbOyEtjb8Vtrn4Z9QmGPPjx3tsMCtXHo3G9 ZKomYTt8taNMcpjx0nA7l0E17N1O0GyD8b5CsWebHKA5wIaxlRCOWZ8qJkFYgNRTJvHE brxw== 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=obkKWvubyxcsBWBqodq9GjqtIG2fyoJpZDBmj1ztp44=; b=o0TNTTA80C3hILZ/Jx20KUWGZnCYNs1xbfmN6cgzyXsIcEhpCWNuXU4d8lPMsAe/au ZWV2lAxetW8nhu3/w2Bdki+teOtdoZfKUL2WZ+zyadAVkkAeKZYIbKTm3OVHjAO4T/94 qvVe1YOXU1MaGKsFscGvgmvEKP1L4pe6Sx5gkRoUU3/V3Zgo0AuZxKyfIsIYL+IIhUY/ gWsPtYIrJLmvXirglOgANeJfMmKQxiU2NMq16u137mBDYEFZ4IMvdUw5Nkdp/nRMYATK Z1N5O5/8gBFXV3qgN6GJ/GKzTX3UKV23VPY3H2eSK30ExtJZc12oUQ1U5FJ8aQk/Gs37 saZw== X-Gm-Message-State: AOAM530E3ZLVazciVIO8HZzu2JnPoRi7Pzn3GKKoVHu4FV/oWGb6JG+A Jk/z2S+5JxQxBUFb1SVQTDs2otUvpMQ= X-Google-Smtp-Source: ABdhPJzTi51Joi6gtFwb7/k++98Es8UVXe7MT22k3gNFDAh0Y6l9hbyHADcfKfJll/oFgnxU3rM8wg== X-Received: by 2002:adf:fa48:: with SMTP id y8mr23884626wrr.646.1643769462424; Tue, 01 Feb 2022 18:37:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j4sm18878802wrq.81.2022.02.01.18.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:42 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:31 +0000 Subject: [PATCH v5 04/10] merge-ort: capture and print ll-merge warnings in our preferred fashion Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Instead of immediately printing ll-merge warnings to stderr, we save them in our output strbuf. Besides allowing us to move these warnings to a special file for --remerge-diff, this has two other benefits for regular merges done by merge-ort: * The deferral of messages ensures we can print all messages about any given path together (merge-recursive was known to sometimes intersperse messages about other paths, particularly when renames were involved). * The deferral of messages means we can avoid printing spurious conflict messages when we just end up aborting due to local user modifications in the way. (In contrast to merge-recursive.c which prematurely checks for local modifications in the way via unpack_trees() and gets the check wrong both in terms of false positives and false negatives relative to renames, merge-ort does not perform the local modifications in the way check until the checkout() step after the full merge has been computed.) Signed-off-by: Elijah Newren --- merge-ort.c | 5 +++-- t/t6404-recursive-merge.sh | 9 +++++++-- t/t6406-merge-attr.sh | 9 +++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index c24da2ba3cb..a18f47e23c5 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -1788,8 +1788,9 @@ static int merge_3way(struct merge_options *opt, &src1, name1, &src2, name2, &opt->priv->attr_index, &ll_opts); if (merge_status == LL_MERGE_BINARY_CONFLICT) - warning("Cannot merge binary files: %s (%s vs. %s)", - path, name1, name2); + path_msg(opt, path, 0, + "warning: Cannot merge binary files: %s (%s vs. %s)", + path, name1, name2); free(base); free(name1); diff --git a/t/t6404-recursive-merge.sh b/t/t6404-recursive-merge.sh index eaf48e941e2..b8735c6db4d 100755 --- a/t/t6404-recursive-merge.sh +++ b/t/t6404-recursive-merge.sh @@ -108,8 +108,13 @@ test_expect_success 'refuse to merge binary files' ' printf "\0\0" >binary-file && git add binary-file && git commit -m binary2 && - test_must_fail git merge F >merge.out 2>merge.err && - grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err + if test "$GIT_TEST_MERGE_ALGORITHM" = ort + then + test_must_fail git merge F >merge_output + else + test_must_fail git merge F 2>merge_output + fi && + grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge_output ' test_expect_success 'mark rename/delete as unmerged' ' diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 84946458371..c41584eb33e 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -221,8 +221,13 @@ test_expect_success 'binary files with union attribute' ' printf "two\0" >bin.txt && git commit -am two && - test_must_fail git merge bin-main 2>stderr && - grep -i "warning.*cannot merge.*HEAD vs. bin-main" stderr + if test "$GIT_TEST_MERGE_ALGORITHM" = ort + then + test_must_fail git merge bin-main >output + else + test_must_fail git merge bin-main 2>output + fi && + grep -i "warning.*cannot merge.*HEAD vs. bin-main" output ' test_done From patchwork Wed Feb 2 02:37:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732513 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 96880C433EF for ; Wed, 2 Feb 2022 02:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243822AbiBBCh5 (ORCPT ); Tue, 1 Feb 2022 21:37:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243825AbiBBChp (ORCPT ); Tue, 1 Feb 2022 21:37:45 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD5CC061401 for ; Tue, 1 Feb 2022 18:37:45 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m13-20020a05600c3b0d00b00353951c3f62so2813933wms.5 for ; Tue, 01 Feb 2022 18:37:45 -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=3DjTSuxoeCeG9xk74b8MP4D3yFu5DTvO02bZbX9rQ60=; b=C+WKaIpPGtY7s6NZ+PRwjTAKfd0dQSLJ3rDmcIf0jhx3gVPiBerMFy/eSvAp6yoYMT 9G2faSS/tIQhLSo6s4arQuu9G04WxnrHYlRBIcPCXMzBIoxjUjpryLxL+/lxNbIpxj+1 iwET8NpglOPR3WmYrSPrAC1EHwPC6B7HJNDFQq5QT4yq7lfRHhhGMILh3g4OaWkLeBmq bLuR6OIPe2YlfKA4PnTQEchHmIsiaOKc4T+nJq17QISLZG/e13r6xQCRIw6Cpq2uPxMs Fd5L351jB/EAvYzZ8bs1OfREdHnB3JkdmzOsXTvLPDtYDrfaau+lqajwsC785JvpV+vV H8iQ== 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=3DjTSuxoeCeG9xk74b8MP4D3yFu5DTvO02bZbX9rQ60=; b=xZTiNE/3JtPb9VmAff/uSBJ382EC+cZ8XjTUY9UxKkUHv/92xGx7t3jNrKptYYCrN5 av6ujFbu0jXhzRNdRXtKE3GgTdfT2rClg50MjY3DAaAYqN0c52+FJ2YxBsPMDIQ+j0ep S3LIiOhb54WPDCCnwRrh8ubUHTrX8mZxQ9tfblWJaJkfLs35e10B2oiiJy2Sebyg2y84 LBHi1G5qdMocGXuPELq1bK8eS3l2KXLeL7x9beEc2MxcbvzYwmJCDOwXeGWkwSCgIgIb 6KNCQQADLAGDOsizFPd53RNtvT4nGGbJRLNHM289eATfNjooM0BvVDET4aHUnilu6RaX AUjg== X-Gm-Message-State: AOAM530TUjH/E3R5jz9oCip6+D/oEfuO/ezvJ11g1MqOXuAiEPH/GKZn /Z1MOgOIpb0X4pyABXDENtOOpUdKObM= X-Google-Smtp-Source: ABdhPJwDTA1HIuaDMTp0tcJW5/MZKp4CFXqnEmw7Conww+TItNy23m9KaO1zp4ZIzj6TtOxhVbAgFA== X-Received: by 2002:a05:600c:288:: with SMTP id 8mr4158586wmk.25.1643769463402; Tue, 01 Feb 2022 18:37:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b11sm3355876wmq.46.2022.02.01.18.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:43 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:32 +0000 Subject: [PATCH v5 05/10] merge-ort: mark a few more conflict messages as omittable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren path_msg() has the ability to mark messages as omittable, designed for remerge-diff where we'll instead be showing conflict messages as diff headers for a subsequent diff. While all these messages are very useful when trying to create a merge initially, early use with the --remerge-diff feature (the only user of this omittable conflict message capability), suggests that the particular messages marked in this commit are just noise when trying to see what changes users made to create a merge commit. Mark them as omittable. Note that there were already a few messages marked as omittable in merge-ort when doing a remerge-diff, because the development of --remerge-diff preceded the upstreaming of merge-ort and I was trying to ensure merge-ort could handle all the necessary requirements. See commit c5a6f65527 ("merge-ort: add modify/delete handling and delayed output processing", 2020-12-03) for the initial details. For some examples of already-marked-as-omittable messages, see either "Auto-merging " or some of the submodule update hints. This commit just adds two more messages that should also be omittable. Signed-off-by: Elijah Newren --- merge-ort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index a18f47e23c5..998e92ec593 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2420,7 +2420,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt, */ ci->path_conflict = 1; if (pair->status == 'A') - path_msg(opt, new_path, 0, + path_msg(opt, new_path, 1, _("CONFLICT (file location): %s added in %s " "inside a directory that was renamed in %s, " "suggesting it should perhaps be moved to " @@ -2428,7 +2428,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt, old_path, branch_with_new_path, branch_with_dir_rename, new_path); else - path_msg(opt, new_path, 0, + path_msg(opt, new_path, 1, _("CONFLICT (file location): %s renamed to %s " "in %s, inside a directory that was renamed " "in %s, suggesting it should perhaps be " From patchwork Wed Feb 2 02:37:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732556 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 9B8A3C433FE for ; Wed, 2 Feb 2022 02:40:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243883AbiBBCiF (ORCPT ); Tue, 1 Feb 2022 21:38:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243834AbiBBChy (ORCPT ); Tue, 1 Feb 2022 21:37:54 -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 D11C4C061748 for ; Tue, 1 Feb 2022 18:37:45 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id a13so35568543wrh.9 for ; Tue, 01 Feb 2022 18:37:45 -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=Jt+pEdaNvy6+eLb7fLZGKq6uyZ8j2uRNVRhVEtft+jI=; b=b8KIDNp0UWlsNMdm8Kr26A0O71QY7UvntiBVCRWSwfc48qRAeQ53wTx9CP9o0WAD/k 8t6ypd/gY01enI1ek1Hq+5eucHEy1TKpqf/Jyiah2albpiiHM5kkyuXJiPxgXm2njV3g F/rw/ncYFlyQJmDFan7ALUQt2afFe6K7cEeO7EuK8NleFrHz3qNTIgZ1qqpMQiIBc2yY WofvcVendkd5a/QDx9zzsAbpFgTRMGxPaglxlx921fQg1PUNkypBTTCiS5MAFiDzaF6B +lIHRL/vyCOSCKuZs2r9gnWJ4k3/1+lGHj5cy4TSNuTSUtDS0KkGL+rSK/oaHmriS2B6 Wlsw== 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=Jt+pEdaNvy6+eLb7fLZGKq6uyZ8j2uRNVRhVEtft+jI=; b=wmQxo6zqcUgqGa+wha2jOF9/qu9ObWfAXzm/KgBS1mNMLkP4qgSaPqIvbvhkKKeip6 kKcLoLf1NfFHh04lBJ8HgZs0/TJXhoX8iwmHcHH/Bb8FCHvq30QKLrCwKsDOMzL/ZfmU JjI5WkHldxD0INPytzEoZ5AjMfePY1XFSMsxP/e40uEzpZqIQIfXX9tEjKu5NII4ZVd/ TL3OAIhtvIk8D3GknTllEHhdfab9jDULf3CIeSejr+RD0DokJ5GDQtzMArdzNoDagGF+ NYPgOvUB/tbBedQ7Ye8iS3irKS1wfWfjqgoX8vb1bHGLQbMHt1aTcA976CvJeuGCOscQ jTjw== X-Gm-Message-State: AOAM530Xo2Yvh7BEH4Ff69ejJCwE8uttD9B+o1Y7JlV68zrkm/nv1rzE LgteWj3POS8Q8Uls6AYrPPckXSkxi0I= X-Google-Smtp-Source: ABdhPJwkWULXXd8eFqB6bENqm9k7l7gFFmd4qw8L8OH64Bzk5z82qHvoIfg8sRuUeMQVlpLBVO9hLQ== X-Received: by 2002:adf:de0b:: with SMTP id b11mr22924760wrm.608.1643769464271; Tue, 01 Feb 2022 18:37:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b2sm18383576wri.88.2022.02.01.18.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:43 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:33 +0000 Subject: [PATCH v5 06/10] merge-ort: format messages slightly different for use in headers Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren When users run git show --remerge-diff $MERGE_COMMIT or git log -p --remerge-diff ... stdout is not an appropriate location to dump conflict messages, but we do want to provide them to users. We will include them in the diff headers instead...but for that to work, we need for any multiline messages to replace newlines with both a newline and a space. Add a new flag to signal when we want these messages modified in such a fashion, and use it in path_msg() to modify these messages this way. Also, allow a special prefix to be specified for these headers. Signed-off-by: Elijah Newren --- merge-ort.c | 42 ++++++++++++++++++++++++++++++++++++++++-- merge-recursive.c | 4 ++++ merge-recursive.h | 2 ++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 998e92ec593..481305d2bcf 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -634,17 +634,49 @@ static void path_msg(struct merge_options *opt, const char *fmt, ...) { va_list ap; - struct strbuf *sb = strmap_get(&opt->priv->output, path); + struct strbuf *sb, *dest; + struct strbuf tmp = STRBUF_INIT; + + if (opt->record_conflict_msgs_as_headers && omittable_hint) + return; /* Do not record mere hints in tree */ + sb = strmap_get(&opt->priv->output, path); if (!sb) { sb = xmalloc(sizeof(*sb)); strbuf_init(sb, 0); strmap_put(&opt->priv->output, path, sb); } + dest = (opt->record_conflict_msgs_as_headers ? &tmp : sb); + va_start(ap, fmt); - strbuf_vaddf(sb, fmt, ap); + strbuf_vaddf(dest, fmt, ap); va_end(ap); + if (opt->record_conflict_msgs_as_headers) { + int i_sb = 0, i_tmp = 0; + + /* Start with the specified prefix */ + if (opt->msg_header_prefix) + strbuf_addf(sb, "%s ", opt->msg_header_prefix); + + /* Copy tmp to sb, adding spaces after newlines */ + strbuf_grow(sb, sb->len + 2*tmp.len); /* more than sufficient */ + for (; i_tmp < tmp.len; i_tmp++, i_sb++) { + /* Copy next character from tmp to sb */ + sb->buf[sb->len + i_sb] = tmp.buf[i_tmp]; + + /* If we copied a newline, add a space */ + if (tmp.buf[i_tmp] == '\n') + sb->buf[++i_sb] = ' '; + } + /* Update length and ensure it's NUL-terminated */ + sb->len += i_sb; + sb->buf[sb->len] = '\0'; + + strbuf_release(&tmp); + } + + /* Add final newline character to sb */ strbuf_addch(sb, '\n'); } @@ -4246,6 +4278,9 @@ void merge_switch_to_result(struct merge_options *opt, 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 */ @@ -4347,6 +4382,9 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) assert(opt->recursive_variant >= MERGE_VARIANT_NORMAL && opt->recursive_variant <= MERGE_VARIANT_THEIRS); + if (opt->msg_header_prefix) + assert(opt->record_conflict_msgs_as_headers); + /* * detect_renames, verbosity, buffer_output, and obuf are ignored * fields that were used by "recursive" rather than "ort" -- but diff --git a/merge-recursive.c b/merge-recursive.c index bc73c52dd84..9ec1e6d043a 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3714,6 +3714,10 @@ static int merge_start(struct merge_options *opt, struct tree *head) assert(opt->priv == NULL); + /* Not supported; option specific to merge-ort */ + assert(!opt->record_conflict_msgs_as_headers); + assert(!opt->msg_header_prefix); + /* Sanity check on repo state; index must match head */ if (repo_index_has_changes(opt->repo, head, &sb)) { err(opt, _("Your local changes to the following files would be overwritten by merge:\n %s"), diff --git a/merge-recursive.h b/merge-recursive.h index 0795a1d3ec1..b88000e3c25 100644 --- a/merge-recursive.h +++ b/merge-recursive.h @@ -46,6 +46,8 @@ struct merge_options { /* miscellaneous control options */ const char *subtree_shift; unsigned renormalize : 1; + unsigned record_conflict_msgs_as_headers : 1; + const char *msg_header_prefix; /* internal fields used by the implementation */ struct merge_options_internal *priv; From patchwork Wed Feb 2 02:37:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732514 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 1409CC4332F for ; Wed, 2 Feb 2022 02:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243841AbiBBCh7 (ORCPT ); Tue, 1 Feb 2022 21:37:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243839AbiBBChy (ORCPT ); Tue, 1 Feb 2022 21:37:54 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C61C06174E for ; Tue, 1 Feb 2022 18:37:46 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id e2so35612693wra.2 for ; Tue, 01 Feb 2022 18:37:46 -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=jCx0TQA+nM3VBIasKno5xrY9sq5xNpTB47wKzQwI3P8=; b=ESnn/k13abJiSeL6u/XxnG3gHveW0ZCJ6C/54LgCPGWpD+qmbRu9LwGDwjXzMBSlbU ODHguV3uQH4FZQ/LE+8cqL+TPqZQSYaATfpSmhTMJh3xcJ+CvOqi+pd/hS8JTVVh+14n mn1CIXEeE2OXDlCDoxIJanLxwImc4sv7EttnjI/PfX/pYh2uT4XzyrGFTNAsd/8lcl+v d0Sc6nReLVeeAh4Lfs95t6sJ9uRV8DiqV4bVm9Ao1bfpN73KPGnPeGimKIUgh3AiLQIH b3mC4CfMcXm+/a+MFM/fmGRYsd+u7/uI0CtBPenuaclHbEe+gv/IAYsx/9uzagu2RfFe GsUw== 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=jCx0TQA+nM3VBIasKno5xrY9sq5xNpTB47wKzQwI3P8=; b=gwreQLa3uVVTuyfhpByHZIfoT4+4ymzUC/BdxR/mmoxIBmc1DmzwbZJX7cr3tunSsa aE9Yl7sDeySS6W7weMrzFIDkhvztQ1CLAekz1z/IhIVugvJ8hiBxcgL9ldgunbnx/4i9 C9/YXkNyNy8aBVUmufDj1vv7vy5mFmluXi3A12RnjTrES4ehApaM5P4lMOzV2wv6JMXx Zy+gJ57A4XOjaNkJE/xV/m87q2w5T1ySqHyadTTbVGWMWJw3xV/m94FfS9zavq9tTPYM jF1dJaEPXNiFLV8tLhzpLo3eKf+23GCV0rsR21M9S5ToX1+gFI2j7JVzVrBjBdDyLJnr D1Uw== X-Gm-Message-State: AOAM531GPfIz2xfaJWUb3mhJ8uAiteP4QMImLqneHqOi14vsVTzbpx1b 9EU2Po6pLEo04QTl6O/dCJEPSFr0oaA= X-Google-Smtp-Source: ABdhPJyif6D+ElXtrT0Ttk1kEr1ERo7FxMi2s93mXAlhRZMesGTYx2X7Pw6nu9V8F2CsvlM1QYVisA== X-Received: by 2002:adf:bad4:: with SMTP id w20mr23538890wrg.457.1643769465101; Tue, 01 Feb 2022 18:37:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g9sm10918730wri.95.2022.02.01.18.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:44 -0800 (PST) Message-Id: <4d79da6e20a1ebbfac9869d7584d279d280016f0.1643769457.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:34 +0000 Subject: [PATCH v5 07/10] diff: add ability to insert additional headers for paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren When additional headers are provided, we need to * add diff_filepairs to diff_queued_diff for each paths in the additional headers map which, unless that path is part of another diff_filepair already found in diff_queued_diff * format the headers (colorization, line_prefix for --graph) * make sure the various codepaths that attempt to return early if there are "no changes" take into account the headers that need to be shown. Signed-off-by: Elijah Newren --- diff.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++-- diff.h | 3 +- log-tree.c | 2 +- 3 files changed, 123 insertions(+), 6 deletions(-) diff --git a/diff.c b/diff.c index 861282db1c3..1bfb01c18ec 100644 --- a/diff.c +++ b/diff.c @@ -27,6 +27,7 @@ #include "help.h" #include "promisor-remote.h" #include "dir.h" +#include "strmap.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 @@ -3406,6 +3407,31 @@ struct userdiff_driver *get_textconv(struct repository *r, return userdiff_get_textconv(r, one->driver); } +static struct strbuf *additional_headers(struct diff_options *o, + const char *path) +{ + if (!o->additional_path_headers) + return NULL; + return strmap_get(o->additional_path_headers, path); +} + +static void add_formatted_headers(struct strbuf *msg, + struct strbuf *more_headers, + const char *line_prefix, + const char *meta, + const char *reset) +{ + char *next, *newline; + + for (next = more_headers->buf; *next; next = newline) { + newline = strchrnul(next, '\n'); + strbuf_addf(msg, "%s%s%.*s%s\n", line_prefix, meta, + (int)(newline - next), next, reset); + if (*newline) + newline++; + } +} + static void builtin_diff(const char *name_a, const char *name_b, struct diff_filespec *one, @@ -3464,6 +3490,17 @@ static void builtin_diff(const char *name_a, b_two = quote_two(b_prefix, name_b + (*name_b == '/')); lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null"; lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null"; + if (!DIFF_FILE_VALID(one) && !DIFF_FILE_VALID(two)) { + /* + * We should only reach this point for pairs from + * create_filepairs_for_header_only_notifications(). For + * these, we should avoid the "/dev/null" special casing + * above, meaning we avoid showing such pairs as either + * "new file" or "deleted file" below. + */ + lbl[0] = a_one; + lbl[1] = b_two; + } strbuf_addf(&header, "%s%sdiff --git %s %s%s\n", line_prefix, meta, a_one, b_two, reset); if (lbl[0][0] == '/') { /* /dev/null */ @@ -4328,6 +4365,7 @@ static void fill_metainfo(struct strbuf *msg, const char *set = diff_get_color(use_color, DIFF_METAINFO); const char *reset = diff_get_color(use_color, DIFF_RESET); const char *line_prefix = diff_line_prefix(o); + struct strbuf *more_headers = NULL; *must_show_header = 1; strbuf_init(msg, PATH_MAX * 2 + 300); @@ -4364,6 +4402,11 @@ static void fill_metainfo(struct strbuf *msg, default: *must_show_header = 0; } + if ((more_headers = additional_headers(o, name))) { + add_formatted_headers(msg, more_headers, + line_prefix, set, reset); + *must_show_header = 1; + } if (one && two && !oideq(&one->oid, &two->oid)) { const unsigned hexsz = the_hash_algo->hexsz; int abbrev = o->abbrev ? o->abbrev : DEFAULT_ABBREV; @@ -5852,12 +5895,27 @@ int diff_unmodified_pair(struct diff_filepair *p) static void diff_flush_patch(struct diff_filepair *p, struct diff_options *o) { - if (diff_unmodified_pair(p)) + int include_conflict_headers = + (additional_headers(o, p->one->path) && + (!o->filter || filter_bit_tst(DIFF_STATUS_UNMERGED, o))); + + /* + * Check if we can return early without showing a diff. Note that + * diff_filepair only stores {oid, path, mode, is_valid} + * information for each path, and thus diff_unmodified_pair() only + * considers those bits of info. However, we do not want pairs + * created by create_filepairs_for_header_only_notifications() + * (which always look like unmodified pairs) to be ignored, so + * return early if both p is unmodified AND we don't want to + * include_conflict_headers. + */ + if (diff_unmodified_pair(p) && !include_conflict_headers) return; + /* Actually, we can also return early to avoid showing tree diffs */ if ((DIFF_FILE_VALID(p->one) && S_ISDIR(p->one->mode)) || (DIFF_FILE_VALID(p->two) && S_ISDIR(p->two->mode))) - return; /* no tree diffs in patch format */ + return; run_diff(p, o); } @@ -5888,10 +5946,17 @@ static void diff_flush_checkdiff(struct diff_filepair *p, run_checkdiff(p, o); } -int diff_queue_is_empty(void) +int diff_queue_is_empty(struct diff_options *o) { struct diff_queue_struct *q = &diff_queued_diff; int i; + int include_conflict_headers = + (o->additional_path_headers && + (!o->filter || filter_bit_tst(DIFF_STATUS_UNMERGED, o))); + + if (include_conflict_headers) + return 0; + for (i = 0; i < q->nr; i++) if (!diff_unmodified_pair(q->queue[i])) return 0; @@ -6325,6 +6390,54 @@ void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc) warning(_(rename_limit_advice), varname, needed); } +static void create_filepairs_for_header_only_notifications(struct diff_options *o) +{ + struct strset present; + struct diff_queue_struct *q = &diff_queued_diff; + struct hashmap_iter iter; + struct strmap_entry *e; + int i; + + strset_init_with_options(&present, /*pool*/ NULL, /*strdup*/ 0); + + /* + * Find out which paths exist in diff_queued_diff, preferring + * one->path for any pair that has multiple paths. + */ + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + char *path = p->one->path ? p->one->path : p->two->path; + + if (strmap_contains(o->additional_path_headers, path)) + strset_add(&present, path); + } + + /* + * Loop over paths in additional_path_headers; for each NOT already + * in diff_queued_diff, create a synthetic filepair and insert that + * into diff_queued_diff. + */ + strmap_for_each_entry(o->additional_path_headers, &iter, e) { + if (!strset_contains(&present, e->key)) { + struct diff_filespec *one, *two; + struct diff_filepair *p; + + one = alloc_filespec(e->key); + two = alloc_filespec(e->key); + fill_filespec(one, null_oid(), 0, 0); + fill_filespec(two, null_oid(), 0, 0); + p = diff_queue(q, one, two); + p->status = DIFF_STATUS_MODIFIED; + } + } + + /* Re-sort the filepairs */ + diffcore_fix_diff_index(); + + /* Cleanup */ + strset_clear(&present); +} + static void diff_flush_patch_all_file_pairs(struct diff_options *o) { int i; @@ -6337,6 +6450,9 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o) if (o->color_moved) o->emitted_symbols = &esm; + if (o->additional_path_headers) + create_filepairs_for_header_only_notifications(o); + for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; if (check_pair_status(p)) @@ -6413,7 +6529,7 @@ void diff_flush(struct diff_options *options) * Order: raw, stat, summary, patch * or: name/name-status/checkdiff (other bits clear) */ - if (!q->nr) + if (!q->nr && !options->additional_path_headers) goto free_queue; if (output_format & (DIFF_FORMAT_RAW | diff --git a/diff.h b/diff.h index 8ba85c5e605..ce9e2cf2e4f 100644 --- a/diff.h +++ b/diff.h @@ -395,6 +395,7 @@ struct diff_options { struct repository *repo; struct option *parseopts; + struct strmap *additional_path_headers; int no_free; }; @@ -593,7 +594,7 @@ void diffcore_fix_diff_index(void); " show all files diff when -S is used and hit is found.\n" \ " -a --text treat all files as text.\n" -int diff_queue_is_empty(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); diff --git a/log-tree.c b/log-tree.c index 89da7de5dbf..8013edcc5d4 100644 --- a/log-tree.c +++ b/log-tree.c @@ -850,7 +850,7 @@ int log_tree_diff_flush(struct rev_info *opt) opt->shown_dashes = 0; diffcore_std(&opt->diffopt); - if (diff_queue_is_empty()) { + if (diff_queue_is_empty(&opt->diffopt)) { int saved_fmt = opt->diffopt.output_format; opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT; diff_flush(&opt->diffopt); From patchwork Wed Feb 2 02:37:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732516 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 2F5FDC433EF for ; Wed, 2 Feb 2022 02:38:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbiBBCiB (ORCPT ); Tue, 1 Feb 2022 21:38:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243840AbiBBChy (ORCPT ); Tue, 1 Feb 2022 21:37:54 -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 EF7BEC061753 for ; Tue, 1 Feb 2022 18:37:47 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id f17so35571161wrx.1 for ; Tue, 01 Feb 2022 18:37:47 -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=khScJrwqGJ2l/xtXNgvFZl64D7laxCe0xrzFbvngYV4=; b=o3wVdItDNdmgPbY6basrIER1Uu4ZyjrzZvqYAxDPd2WfdwFuZeqJtWSC6L2K5VS5a5 rLqMPguQhwbCn5m9t7c1PP1eLsi0yjFpEC7ffvb/kfuSetv274nNEwYfpFHsST8cwX2L mSvqtZEKlrP3W8SINgHne8or8AOntxWXBsHD3sEsQHErVm8VS9UU02oj3spYqoxAea7k Bh9KqexPpKnOLTyqR3mwLNwmmBf4jHL7OqsuWaBYRoc6G9YOjd17yBIrQGQ8V/rAPhW8 AbRRcA4nR/7Ch5bvkS4l9kccy7ZOR6kr30MSeeVWCt8RCvKP/uklHEXfvqKCDjk7lOis +jnA== 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=khScJrwqGJ2l/xtXNgvFZl64D7laxCe0xrzFbvngYV4=; b=LkdocDf+T18ttCyTJUiOus7qo8UeGE9zEzaP9NxNw0pjO+wjOFfOiypRhijqgApvP0 CVYUfxYqmGP5DOzXpfyNg7KArE2DEq/je0FaRG3bpCVVmm1wFjGwUxYNhkZ9WhEyiLia lEuyMG6jDO3tr6rhhrFykj/ac+Fi0lbxPQAi+x/gugtSI20Fywj+coKRyUbu5D1EdAKQ D1lEeK3GQMxI25HoEjGIiVvtM2FuPACZHP5MW5P84GwpEHFv5fPoIVNEu5GGcJij24uy bd4MZBzX1TI4aw1LEM1hMQd4j2FZchooyreLiBOro+z0rm3ILmsHHqYqw86qQP4qpJSu FJ6Q== X-Gm-Message-State: AOAM53002bo2MjjKk8X3FvOntzoh3sm+d1cun8bCsrBIOpQUJokbN1sO hOA8gzX94tbCyssuK6N9IGEOMaKwmgk= X-Google-Smtp-Source: ABdhPJyyMed5YvlLAtMnjjfee5p2NPaVGnASIhZXxa6AqFALsLJVOKISY7v2bxa0ndz7RVQnB4xQIw== X-Received: by 2002:a05:6000:1cc:: with SMTP id t12mr22957965wrx.424.1643769466158; Tue, 01 Feb 2022 18:37:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j5sm374340wrq.31.2022.02.01.18.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:45 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:35 +0000 Subject: [PATCH v5 08/10] show, log: include conflict/warning messages in --remerge-diff headers Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Conflicts such as modify/delete, rename/rename, or file/directory are not representable via content conflict markers, and the normal output messages notifying users about these were dropped with --remerge-diff. While we don't want these messages randomly shown before the commit and diff headers, we do want them to still be shown; include them as part of the diff headers instead. Signed-off-by: Elijah Newren --- log-tree.c | 51 ++++++++++++++ merge-ort.c | 1 + merge-ort.h | 10 +++ t/t4069-remerge-diff.sh | 144 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) diff --git a/log-tree.c b/log-tree.c index 8013edcc5d4..d93bafa5be3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -19,6 +19,7 @@ #include "line-log.h" #include "help.h" #include "range-diff.h" +#include "strmap.h" static struct decoration name_decoration = { "object names" }; static int decoration_loaded; @@ -905,6 +906,52 @@ static int do_diff_combined(struct rev_info *opt, struct commit *commit) return !opt->loginfo; } +static void setup_additional_headers(struct diff_options *o, + struct strmap *all_headers) +{ + struct hashmap_iter iter; + struct strmap_entry *entry; + + /* + * Make o->additional_path_headers contain the subset of all_headers + * that match o->pathspec. If there aren't any that match o->pathspec, + * then make o->additional_path_headers be NULL. + */ + + if (!o->pathspec.nr) { + o->additional_path_headers = all_headers; + return; + } + + o->additional_path_headers = xmalloc(sizeof(struct strmap)); + strmap_init_with_options(o->additional_path_headers, NULL, 0); + strmap_for_each_entry(all_headers, &iter, entry) { + if (match_pathspec(the_repository->index, &o->pathspec, + entry->key, strlen(entry->key), + 0 /* prefix */, NULL /* seen */, + 0 /* is_dir */)) + strmap_put(o->additional_path_headers, + entry->key, entry->value); + } + if (!strmap_get_size(o->additional_path_headers)) { + strmap_clear(o->additional_path_headers, 0); + FREE_AND_NULL(o->additional_path_headers); + } +} + +static void cleanup_additional_headers(struct diff_options *o) +{ + if (!o->pathspec.nr) { + o->additional_path_headers = NULL; + return; + } + if (!o->additional_path_headers) + return; + + strmap_clear(o->additional_path_headers, 0); + FREE_AND_NULL(o->additional_path_headers); +} + static int do_remerge_diff(struct rev_info *opt, struct commit_list *parents, struct object_id *oid, @@ -922,6 +969,8 @@ static int do_remerge_diff(struct rev_info *opt, /* Setup merge options */ init_merge_options(&o, the_repository); o.show_rename_progress = 0; + o.record_conflict_msgs_as_headers = 1; + o.msg_header_prefix = "remerge"; ctx.abbrev = DEFAULT_ABBREV; format_commit_message(parent1, "%h (%s)", &parent1_desc, &ctx); @@ -938,10 +987,12 @@ static int do_remerge_diff(struct rev_info *opt, merge_incore_recursive(&o, bases, parent1, parent2, &res); /* Show the diff */ + setup_additional_headers(&opt->diffopt, res.path_messages); diff_tree_oid(&res.tree->object.oid, oid, "", &opt->diffopt); log_tree_diff_flush(opt); /* Cleanup */ + cleanup_additional_headers(&opt->diffopt); strbuf_release(&parent1_desc); strbuf_release(&parent2_desc); merge_finalize(&o, &res); diff --git a/merge-ort.c b/merge-ort.c index 481305d2bcf..43f980d2586 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4585,6 +4585,7 @@ redo: trace2_region_leave("merge", "process_entries", opt->repo); /* Set return values */ + result->path_messages = &opt->priv->output; result->tree = parse_tree_indirect(&working_tree_oid); /* existence of conflicted entries implies unclean */ result->clean &= strmap_empty(&opt->priv->conflicted); diff --git a/merge-ort.h b/merge-ort.h index c011864ffeb..fe599b87868 100644 --- a/merge-ort.h +++ b/merge-ort.h @@ -5,6 +5,7 @@ struct commit; struct tree; +struct strmap; struct merge_result { /* @@ -23,6 +24,15 @@ struct merge_result { */ struct tree *tree; + /* + * Special messages and conflict notices for various paths + * + * This is a map of pathnames to strbufs. It contains various + * warning/conflict/notice messages (possibly multiple per path) + * that callers may want to use. + */ + struct strmap *path_messages; + /* * Additional metadata used by merge_switch_to_result() or future calls * to merge_incore_*(). Includes data needed to update the index (if diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh index d7ab0f50066..fd6bce64781 100755 --- a/t/t4069-remerge-diff.sh +++ b/t/t4069-remerge-diff.sh @@ -60,6 +60,7 @@ test_expect_success 'remerge-diff with both a resolved conflict and an unrelated git log -1 --oneline ab_resolution >tmp && cat <<-EOF >>tmp && diff --git a/numbers b/numbers + remerge CONFLICT (content): Merge conflict in numbers index a1fb731..6875544 100644 --- a/numbers +++ b/numbers @@ -88,4 +89,147 @@ test_expect_success 'remerge-diff with both a resolved conflict and an unrelated test_cmp expect actual ' +test_expect_success 'setup non-content conflicts' ' + git switch --orphan base && + + test_write_lines 1 2 3 4 5 6 7 8 9 >numbers && + test_write_lines a b c d e f g h i >letters && + test_write_lines in the way >content && + git add numbers letters content && + git commit -m base && + + git branch side1 && + git branch side2 && + + git checkout side1 && + test_write_lines 1 2 three 4 5 6 7 8 9 >numbers && + git mv letters letters_side1 && + git mv content file_or_directory && + git add numbers && + git commit -m side1 && + + git checkout side2 && + git rm numbers && + git mv letters letters_side2 && + mkdir file_or_directory && + echo hello >file_or_directory/world && + git add file_or_directory/world && + git commit -m side2 && + + git checkout -b resolution side1 && + test_must_fail git merge side2 && + test_write_lines 1 2 three 4 5 6 7 8 9 >numbers && + git add numbers && + git add letters_side1 && + git rm letters && + git rm letters_side2 && + git add file_or_directory~HEAD && + git mv file_or_directory~HEAD wanted_content && + git commit -m resolved +' + +test_expect_success 'remerge-diff with non-content conflicts' ' + git log -1 --oneline resolution >tmp && + cat <<-EOF >>tmp && + diff --git a/file_or_directory~HASH (side1) b/wanted_content + similarity index 100% + rename from file_or_directory~HASH (side1) + rename to wanted_content + remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead. + diff --git a/letters b/letters + remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2). + diff --git a/letters_side2 b/letters_side2 + deleted file mode 100644 + index b236ae5..0000000 + --- a/letters_side2 + +++ /dev/null + @@ -1,9 +0,0 @@ + -a + -b + -c + -d + -e + -f + -g + -h + -i + diff --git a/numbers b/numbers + remerge CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1). Version HASH (side1) of numbers left in tree. + EOF + # We still have some sha1 hashes above; rip them out so test works + # with sha256 + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && + + git show --oneline --remerge-diff resolution >tmp && + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && + test_cmp expect actual +' + +test_expect_success 'remerge-diff w/ diff-filter=U: all conflict headers, no diff content' ' + git log -1 --oneline resolution >tmp && + cat <<-EOF >>tmp && + diff --git a/file_or_directory~HASH (side1) b/file_or_directory~HASH (side1) + remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead. + diff --git a/letters b/letters + remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2). + diff --git a/numbers b/numbers + remerge CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1). Version HASH (side1) of numbers left in tree. + EOF + # We still have some sha1 hashes above; rip them out so test works + # with sha256 + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && + + git show --oneline --remerge-diff --diff-filter=U resolution >tmp && + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && + test_cmp expect actual +' + +test_expect_success 'remerge-diff w/ diff-filter=R: relevant file + conflict header' ' + git log -1 --oneline resolution >tmp && + cat <<-EOF >>tmp && + diff --git a/file_or_directory~HASH (side1) b/wanted_content + similarity index 100% + rename from file_or_directory~HASH (side1) + rename to wanted_content + remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead. + EOF + # We still have some sha1 hashes above; rip them out so test works + # with sha256 + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && + + git show --oneline --remerge-diff --diff-filter=R resolution >tmp && + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && + test_cmp expect actual +' + +test_expect_success 'remerge-diff w/ pathspec: limits to relevant file including conflict header' ' + git log -1 --oneline resolution >tmp && + cat <<-EOF >>tmp && + diff --git a/letters b/letters + remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2). + diff --git a/letters_side2 b/letters_side2 + deleted file mode 100644 + index b236ae5..0000000 + --- a/letters_side2 + +++ /dev/null + @@ -1,9 +0,0 @@ + -a + -b + -c + -d + -e + -f + -g + -h + -i + EOF + # We still have some sha1 hashes above; rip them out so test works + # with sha256 + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && + + git show --oneline --remerge-diff --full-history resolution -- "letters*" >tmp && + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && + test_cmp expect actual +' + test_done From patchwork Wed Feb 2 02:37:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732557 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 82FA1C433F5 for ; Wed, 2 Feb 2022 02:40:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243858AbiBBCiD (ORCPT ); Tue, 1 Feb 2022 21:38:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243844AbiBBChy (ORCPT ); Tue, 1 Feb 2022 21:37:54 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B50DFC061755 for ; Tue, 1 Feb 2022 18:37:48 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id s9so35506556wrb.6 for ; Tue, 01 Feb 2022 18:37:48 -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=rB1GXXgaPG4nqGNrl25zZ0WJDHbu4Z/7BmEvF3+puqs=; b=OJREW0TgcQGNbGWfbXq2+rZ0rgsUyruzjx83J1yzUWQpe+dhxX/eYIRZAFJUb8GAuU FS9m0pRHjKuMhWJgJCWCaNy07rBKiplBwcWFnE1mqAUy0fSFsBSeS7lbt6b359N6Aqo7 sLJF9drANg+3bacGqTqNFhK3IwFKnz/QLtzduyNnZ8KPsgnUiMbx04RXRtyrKywvG3i+ 5W++VCWr+eHGZRYUNuwrWc/EhqyK4e6CX3q/mfR/B0dpfZXzIrNOPAQQ/hmf0E/qJ3ir JSjveLO0IBWFap/7QbRbrYqhAWs1XsxD1stBy+hwwtNgjJmN3duoje+hx1x80FWl19oa 6lmQ== 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=rB1GXXgaPG4nqGNrl25zZ0WJDHbu4Z/7BmEvF3+puqs=; b=q9bkw/0sD7RtkNpe+bGlABSPCFENnH1eOyYgL9M6oDDEBdJ5p5eF51H1oQMEixmTtY EFXMvKVnKTxaXZTS3gUfqOaUnEzt9GNWJJC/UvJ2bd8lsypMpQcngVUHr8WvvUuLDWDG 2Qo29++1r2FjkbdK9l6nsuY601o5qEDUJ4WlFADi4PNBKEnIwkEkyqfL6bEIRZOOfW5d 43f4FhI1zailsw66tRYW74tjLSOaJRwpkr0xCy5VNIs14XJq1pDN8Q9W7fRy4itqFKpA 4nsg5cmiSvJqtQRDdzN3aC9n5xhQaHc44dvZDDXqeANNEobzbCHIYXwG66dJ/KpG4LUe usXw== X-Gm-Message-State: AOAM532xX6SbmMMgDjDnBrXL8USLMQ92HuIPZOUBtwen97gs+OPCuVEY vEpyKz5gKzha1vA0uonQ5MHLAe6/tNA= X-Google-Smtp-Source: ABdhPJzGqt0+5ySinveSAX8B81OuJqddRCSDgCRAwszriQlwrF3+bjubICRlqw02NmbF3DgG1mbdEA== X-Received: by 2002:a5d:4a46:: with SMTP id v6mr13210725wrs.526.1643769467175; Tue, 01 Feb 2022 18:37:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z17sm3307859wmf.47.2022.02.01.18.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:46 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:36 +0000 Subject: [PATCH v5 09/10] merge-ort: mark conflict/warning messages from inner merges as omittable Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren A recursive merge involves merging the merge bases of the two branches being merged. Such an inner merge can itself generate conflict notices. While such notices may be useful when initially trying to create a merge, they seem to just be noise when investigating merges later with --remerge-diff. (Especially when both sides of the outer merge resolved the conflict the same way leading to no overall conflict.) Remove them. Signed-off-by: Elijah Newren --- merge-ort.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/merge-ort.c b/merge-ort.c index 43f980d2586..9bf15a01db8 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -638,7 +638,9 @@ static void path_msg(struct merge_options *opt, struct strbuf tmp = STRBUF_INIT; if (opt->record_conflict_msgs_as_headers && omittable_hint) - return; /* Do not record mere hints in tree */ + return; /* Do not record mere hints in headers */ + if (opt->record_conflict_msgs_as_headers && opt->priv->call_depth) + return; /* Do not record inner merge issues in headers */ sb = strmap_get(&opt->priv->output, path); if (!sb) { sb = xmalloc(sizeof(*sb)); From patchwork Wed Feb 2 02:37:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12732515 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 AE9D0C433F5 for ; Wed, 2 Feb 2022 02:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243846AbiBBCiB (ORCPT ); Tue, 1 Feb 2022 21:38:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243847AbiBBChy (ORCPT ); Tue, 1 Feb 2022 21:37:54 -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 87476C06175A for ; Tue, 1 Feb 2022 18:37:49 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id u15so35581471wrt.3 for ; Tue, 01 Feb 2022 18:37:49 -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=WHxDyfRSomseEUeYcK3uIIfwY7bG5/mcAOhBCCfSPqo=; b=JjOLRUAojPNea78sbRoNX9Ro4gnmGR+pGV18IHxOxYNw5Fy9gC+6N+XxMHHoSuDEQ9 vXqjCurIRoWovf7KqDjr83bWupnpykbRsENzIznYV+ulxFzRtWJl3k12pGZq74f++NM4 mXKq2LIdz0C/X4+cWLcN/q6INxmy2aWGflhS2triqwWKBHnOGZ6P0eRIzuBYJtfh5Qo5 Wt2u5uK/R5MJr3Dfa13VJi46dmpaVfM4sQwITrreKhO2KeYnpsPReYhcfK3F/kpA20ti iMiC7tLQ2f2wydJ70QF13MZ7n+Sqve7nYszW7MWI4WwrjJ5i+rrny/z3Tb4R5c7gThET zWBw== 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=WHxDyfRSomseEUeYcK3uIIfwY7bG5/mcAOhBCCfSPqo=; b=rfBm2Welio3U3tRz7tf+2HOf4P0opsfRiPSTaL5VwtpNhhT8zZVqbWgFvFIKlr0JZv dDjyUmc13TdfeupvMaH6xq4fc97OurTUN3vmg3qpLMMc2hJHbYUVJE/+r6Ug+Cm3JzjI wh8U+xjB6lsi/qb5bAT7XxfaMvqPIyoYWa9bbgqkqEaigLuJzs5waKKJNVeMAmLEuSum NtR8O/Za8hsQ+hIGyb3zvqr58Ygp2tglQrxzgNNYyWx9IvCxTTati5cZYG8S5GYLdSzv fopJ4Wzdllu/Ff4JwBFMM+sjnzERz1Dd6txnl6pbYxEuOPC3v8SjaoLuWv1J9NP+fri8 aLYQ== X-Gm-Message-State: AOAM531YlE1iXSWfsdlpz0EmLiLIkS6fhJmwZlnZDspwNM3i3EN2Ke9N 5spNUP+QFk0Iq4MSX787Mh4o1PrpJ80= X-Google-Smtp-Source: ABdhPJxxXvbpYzkFcLrmYz1IkyqGNr1c30AuAtax9jaTV3QE0k6QZmraNYC27yBQR8fs8Oufo3ZoNQ== X-Received: by 2002:a05:6000:2ad:: with SMTP id l13mr23142711wry.174.1643769467911; Tue, 01 Feb 2022 18:37:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y8sm3051066wrd.32.2022.02.01.18.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 18:37:47 -0800 (PST) Message-Id: <59d12f213b25087fc610d1151f3bb790046fe6ca.1643769457.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 02 Feb 2022 02:37:37 +0000 Subject: [PATCH v5 10/10] diff-merges: avoid history simplifications when diffing merges Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Jonathan Nieder , Sergey Organov , Bagas Sanjaya , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Neeraj Singh , Johannes Altmanninger , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Doing diffs for merges are special; they should typically avoid history simplification. For example, with git log --diff-merges=first-parent -- path the default history simplification would remove merge commits from consideration if the file "path" matched the second parent. That is counter to what the user wants when looking for first-parent diffs. Similar comments can be made for --diff-merges=separate (which diffs against both parents) and --diff-merges=remerge (which diffs against a remerge of the merge commit). However, history simplification still makes sense if not doing diffing merges, and it also makes sense for the combined and dense-combined forms of diffing merges (because both of those are defined to only show a diff when the merge result at the relevant paths differs from *both* parents). So, for separate, first-parent, and remerge styles of diff-merges, turn off history simplification. Signed-off-by: Elijah Newren --- diff-merges.c | 2 ++ t/t4069-remerge-diff.sh | 58 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/diff-merges.c b/diff-merges.c index 0af4b3f9191..a833fd747ad 100644 --- a/diff-merges.c +++ b/diff-merges.c @@ -24,6 +24,7 @@ static void set_separate(struct rev_info *revs) { suppress(revs); revs->separate_merges = 1; + revs->simplify_history = 0; } static void set_first_parent(struct rev_info *revs) @@ -50,6 +51,7 @@ static void set_remerge_diff(struct rev_info *revs) { suppress(revs); revs->remerge_diff = 1; + revs->simplify_history = 0; } static diff_merges_setup_func_t func_by_opt(const char *optarg) diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh index fd6bce64781..35f94957fce 100755 --- a/t/t4069-remerge-diff.sh +++ b/t/t4069-remerge-diff.sh @@ -227,7 +227,63 @@ test_expect_success 'remerge-diff w/ pathspec: limits to relevant file including # with sha256 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && - git show --oneline --remerge-diff --full-history resolution -- "letters*" >tmp && + git show --oneline --remerge-diff resolution -- "letters*" >tmp && + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && + test_cmp expect actual +' + +test_expect_success 'setup non-content conflicts' ' + git switch --orphan newbase && + + test_write_lines 1 2 3 4 5 6 7 8 9 >numbers && + git add numbers && + git commit -m base && + + git branch newside1 && + git branch newside2 && + + git checkout newside1 && + test_write_lines 1 2 three 4 5 6 7 8 9 >numbers && + git add numbers && + git commit -m side1 && + + git checkout newside2 && + test_write_lines 1 2 drei 4 5 6 7 8 9 >numbers && + git add numbers && + git commit -m side2 && + + git checkout -b newresolution newside1 && + test_must_fail git merge newside2 && + git checkout --theirs numbers && + git add -u numbers && + git commit -m resolved +' + +test_expect_success 'remerge-diff turns off history simplification' ' + git log -1 --oneline newresolution >tmp && + cat <<-EOF >>tmp && + diff --git a/numbers b/numbers + remerge CONFLICT (content): Merge conflict in numbers + index 070e9e7..5335e78 100644 + --- a/numbers + +++ b/numbers + @@ -1,10 +1,6 @@ + 1 + 2 + -<<<<<<< 96f1e45 (side1) + -three + -======= + drei + ->>>>>>> 4fd522f (side2) + 4 + 5 + 6 + EOF + # We still have some sha1 hashes above; rip them out so test works + # with sha256 + sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect && + + git show --oneline --remerge-diff newresolution -- numbers >tmp && sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual && test_cmp expect actual '