git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Jonathan Nieder <jrnieder@gmail.com>,
	Derrick Stolee <dstolee@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 03/11] merge-ort: add a function for initializing our special attr_index
Date: Mon, 08 Mar 2021 13:46:57 +0100	[thread overview]
Message-ID: <87czw9ke2m.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <815af5d30ebd5e7f80aa42e4a54808af2e3781e0.1614905738.git.gitgitgadget@gmail.com>


On Fri, Mar 05 2021, Elijah Newren via GitGitGadget wrote:

> From: Elijah Newren <newren@gmail.com>
>
> Add a function which can be called to populate the attr_index with the
> appropriate .gitattributes contents when necessary.  Make it return
> early if the attr_index is already initialized or if we are not
> renormalizing files.
>
> NOTE 1: Even if the user has a working copy or a real index (which is
> not a given as merge-ort can be used in bare repositories), we
> explicitly ignore any .gitattributes file from either of these
> locations.  merge-ort can be used to merge two branches that are
> unrelated to HEAD, so .gitattributes from the working copy and current
> index should not be considered relevant.
>
> NOTE 2: Since we are in the middle of merging, there is a risk that
> .gitattributes itself is conflicted...leaving us with an ill-defined
> situation about how to perform the rest of the merge.  It could be that
> the .gitattributes file does not even exist on one of the sides of the
> merge, or that it has been modified on both sides.  If it's been
> modified on both sides, it's possible that it could itself be merged
> cleanly, though it's also possible that it only merges cleanly if you
> use the right version of the .gitattributes file to drive the merge.  It
> gets kind of complicated.  The only test we ever had that attempted to
> test behavior in this area was seemingly unaware of the undefined
> behavior, but knew the test wouldn't work for lack of attribute handling
> support, marked it as test_expect_failure from the beginning, but
> managed to fail for several reasons unrelated to attribute handling.
> See commit 6f6e7cfb52 ("t6038: remove problematic test", 2020-08-03) for
> details.  So there are probably various ways to improve what
> initialize_attr_index() picks in the case of a conflicted .gitattributes
> but for now I just implemented something simple -- look for whatever
> .gitattributes file we can find in any of the higher order stages and
> use it.
>
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>  merge-ort.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
>
> diff --git a/merge-ort.c b/merge-ort.c
> index d91b66a052b6..028d1adcd2c9 100644
> --- a/merge-ort.c
> +++ b/merge-ort.c
> @@ -988,6 +988,67 @@ static int merge_submodule(struct merge_options *opt,
>  	return 0;
>  }
>  
> +MAYBE_UNUSED

As with the lst series you had I also think this is better squashed with
04/11.

> +static void initialize_attr_index(struct merge_options *opt)
> +{
> +	/*
> +	 * The renormalize_buffer() functions require attributes, and
> +	 * annoyingly those can only be read from the working tree or from
> +	 * an index_state.  merge-ort doesn't have an index_state, so we
> +	 * generate a fake one containing only attribute information.
> +	 */
> +	struct merged_info *mi;
> +	struct index_state *attr_index = &opt->priv->attr_index;
> +	struct cache_entry *ce;
> +
> +	if (!opt->renormalize)
> +		return;
> +
> +	if (attr_index->initialized)
> +		return;

Will comment on this in 04/11.

> +	attr_index->initialized = 1;
> +
> +	mi = strmap_get(&opt->priv->paths, GITATTRIBUTES_FILE);
> +	if (!mi)
> +		return;
> +
> +	if (mi->clean) {
> +		int len = strlen(GITATTRIBUTES_FILE);
> +		ce = make_empty_cache_entry(attr_index, len);
> +		ce->ce_mode = create_ce_mode(mi->result.mode);
> +		ce->ce_flags = create_ce_flags(0);
> +		ce->ce_namelen = len;
> +		oidcpy(&ce->oid, &mi->result.oid);
> +		memcpy(ce->name, GITATTRIBUTES_FILE, len);
> +		add_index_entry(attr_index, ce,
> +				ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
> +		get_stream_filter(attr_index, GITATTRIBUTES_FILE, &ce->oid);
> +	}
> +	else {

Style nit: } else {

> +		int stage, len;
> +		struct conflict_info *ci;
> +
> +		ASSIGN_AND_VERIFY_CI(ci, mi);
> +		for (stage=0; stage<3; ++stage) {

Style nit: stage < 3

Style nit: I find just stage++ to be more readable in for-loops, makes
no difference to the compiler, just more idiomatic.

> +			unsigned stage_mask = (1 << stage);
> +
> +			if (!(ci->filemask & stage_mask))
> +				continue;
> +			len = strlen(GITATTRIBUTES_FILE);
> +			ce = make_empty_cache_entry(attr_index, len);
> +			ce->ce_mode = create_ce_mode(ci->stages[stage].mode);
> +			ce->ce_flags = create_ce_flags(stage);
> +			ce->ce_namelen = len;
> +			oidcpy(&ce->oid, &ci->stages[stage].oid);
> +			memcpy(ce->name, GITATTRIBUTES_FILE, len);
> +			add_index_entry(attr_index, ce,
> +					ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
> +			get_stream_filter(attr_index, GITATTRIBUTES_FILE,
> +					  &ce->oid);
> +		}
> +	}
> +}
> +


  reply	other threads:[~2021-03-08 12:47 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05  0:55 [PATCH 00/11] Complete merge-ort implementation...almost Elijah Newren via GitGitGadget
2021-03-05  0:55 ` [PATCH 01/11] merge-ort: use STABLE_QSORT instead of QSORT where required Elijah Newren via GitGitGadget
2021-03-05  0:55 ` [PATCH 02/11] merge-ort: add a special minimal index just for renormalization Elijah Newren via GitGitGadget
2021-03-05  0:55 ` [PATCH 03/11] merge-ort: add a function for initializing our special attr_index Elijah Newren via GitGitGadget
2021-03-08 12:46   ` Ævar Arnfjörð Bjarmason [this message]
2021-03-05  0:55 ` [PATCH 04/11] merge-ort: have ll_merge() calls use the attr_index for renormalization Elijah Newren via GitGitGadget
2021-03-08 12:49   ` Ævar Arnfjörð Bjarmason
2021-03-09  4:27     ` Elijah Newren
2021-03-05  0:55 ` [PATCH 05/11] merge-ort: let renormalization change modify/delete into clean delete Elijah Newren via GitGitGadget
2021-03-08 12:55   ` Ævar Arnfjörð Bjarmason
2021-03-05  0:55 ` [PATCH 06/11] merge-ort: support subtree shifting Elijah Newren via GitGitGadget
2021-03-05  0:55 ` [PATCH 07/11] t6428: new test for SKIP_WORKTREE handling and conflicts Elijah Newren via GitGitGadget
2021-03-08 13:03   ` Ævar Arnfjörð Bjarmason
2021-03-08 20:52     ` Elijah Newren
2021-03-05  0:55 ` [PATCH 08/11] merge-ort: implement CE_SKIP_WORKTREE handling with conflicted entries Elijah Newren via GitGitGadget
2021-03-08 13:06   ` Ævar Arnfjörð Bjarmason
2021-03-08 20:54     ` Elijah Newren
2021-03-05  0:55 ` [PATCH 09/11] t: mark several submodule merging tests as fixed under merge-ort Elijah Newren via GitGitGadget
2021-03-08 13:07   ` Ævar Arnfjörð Bjarmason
2021-03-05  0:55 ` [PATCH 10/11] merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a conflict Elijah Newren via GitGitGadget
2021-03-08 13:11   ` Ævar Arnfjörð Bjarmason
2021-03-08 21:51     ` Elijah Newren
2021-03-05  0:55 ` [PATCH 11/11] merge-recursive: add a bunch of FIXME comments documenting known bugs Elijah Newren via GitGitGadget
2021-03-08 13:12   ` Ævar Arnfjörð Bjarmason
2021-03-08 14:43 ` [PATCH 00/11] Complete merge-ort implementation...almost Ævar Arnfjörð Bjarmason
2021-03-08 22:13   ` Elijah Newren
2021-03-09  6:24 ` [PATCH v2 00/10] " Elijah Newren via GitGitGadget
2021-03-09  6:24   ` [PATCH v2 01/10] merge-ort: use STABLE_QSORT instead of QSORT where required Elijah Newren via GitGitGadget
2021-03-09  6:24   ` [PATCH v2 02/10] merge-ort: add a special minimal index just for renormalization Elijah Newren via GitGitGadget
2021-03-11 14:48     ` Derrick Stolee
2021-03-09  6:24   ` [PATCH v2 03/10] merge-ort: have ll_merge() use a special attr_index " Elijah Newren via GitGitGadget
2021-03-11 14:52     ` Derrick Stolee
2021-03-09  6:24   ` [PATCH v2 04/10] merge-ort: let renormalization change modify/delete into clean delete Elijah Newren via GitGitGadget
2021-03-09  6:24   ` [PATCH v2 05/10] merge-ort: support subtree shifting Elijah Newren via GitGitGadget
2021-03-09  6:24   ` [PATCH v2 06/10] t6428: new test for SKIP_WORKTREE handling and conflicts Elijah Newren via GitGitGadget
2021-03-11 14:55     ` Derrick Stolee
2021-03-09  6:24   ` [PATCH v2 07/10] merge-ort: implement CE_SKIP_WORKTREE handling with conflicted entries Elijah Newren via GitGitGadget
2021-03-09  6:24   ` [PATCH v2 08/10] t: mark several submodule merging tests as fixed under merge-ort Elijah Newren via GitGitGadget
2021-03-11 15:15     ` Derrick Stolee
2021-03-09  6:24   ` [PATCH v2 09/10] merge-ort: write $GIT_DIR/AUTO_MERGE whenever we hit a conflict Elijah Newren via GitGitGadget
2021-03-09  6:24   ` [PATCH v2 10/10] merge-recursive: add a bunch of FIXME comments documenting known bugs Elijah Newren via GitGitGadget
2021-03-11 15:20   ` [PATCH v2 00/10] Complete merge-ort implementation...almost Derrick Stolee
2021-03-11 16:42     ` Elijah Newren
2021-03-17 21:42   ` Elijah Newren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czw9ke2m.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).