git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Ayush Chandekar <ayu.chandekar@gmail.com>,
	 git@vger.kernel.org, shejialuo@gmail.com
Subject: Re: [PATCH] environment: move access to "core.attributesfile" into repo settings
Date: Mon, 10 Mar 2025 09:16:33 -0700	[thread overview]
Message-ID: <xmqqwmcw97z2.fsf@gitster.g> (raw)
In-Reply-To: <Z86PUkJ1sbSH2VTU@pks.im> (Patrick Steinhardt's message of "Mon, 10 Mar 2025 08:05:54 +0100")

Patrick Steinhardt <ps@pks.im> writes:

> On Sun, Mar 09, 2025 at 09:03:21PM +0530, Ayush Chandekar wrote:
>> Stop relying on global state to access the "core.attributesfile"
>> configuration. Instead, store the value in `struct repo_settings` and
>> retrieve it via `repo_settings_get_attributes_file_path()`.
>> 
>> This prevents incorrect values from being used when a user or tool is
>> handling multiple repositories in the same process, each with different
>> attribute configurations. It also improves repository isolation and helps
>> progress towards libification by avoiding unnecessary global state.
>
> We typically switch the order around a bit in our commit messages: we
> first explain what the actual problem is, and then we say how we fix it.

A good suggestion.

>>  int git_attr_system_is_enabled(void)
>
> Hm. I wonder what the actual merit of this function is after the
> refactoring. Right now there isn't really any as it is a direct wrapper
> of `repo_settings_get_attributesfile_path()`.

Another thing that felt awkward about this change is actually
larger.  The current attributes globals are built around the notion
that the functions involved work on a single set of attributes at a
time.  Even in a single repository, when you are checking new contents
into the object database and when you are checking objects out of
the object database, you'd need to switch the direction manually,
which means you always have two sets of attributes active that you
can switch between (one is from the working tree and the other one
is from the index, if I am recalling correctly).

But step back and think.  What does it mean to make them belong to a
repository instance?  Whose index and working tree does the attribute
set that belongs to a repository that is not the_repository come from?

So it seems to me that removing the reliance on globals is a good
thing, and introducing some abstraction is a good step forward, but
it is dubious if the abstracted "set of attributes" should be part
of a repository instance.  This is a bit similar to the_index
situation, where we can have more than one in-core index instance
for a given repository we are working with, an index_state knows its
repository, but a repository instance only has a pointer to its
primary index_state instance and does not know other index_state
objects.  The right way to deal with in-core index is to pass
index_state, not repository, through the call chain for this reason,
and I suspect that we are better off to make sure that we do the
same for the attributes, i.e. pass pointer to an attribute set
instance through the callchain, not a repository.




  parent reply	other threads:[~2025-03-10 16:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-09 15:33 [PATCH] environment: move access to "core.attributesfile" into repo settings Ayush Chandekar
2025-03-10  7:05 ` Patrick Steinhardt
2025-03-10  9:07   ` Ayush Chandekar
2025-03-10 16:16   ` Junio C Hamano [this message]
2025-03-10 17:21     ` Ayush Chandekar
2025-03-10 19:25       ` Junio C Hamano
2025-03-10 15:10 ` [GSOC PATCH v2 0/2] Stop depending on `the_repository` for core.attributesfile Ayush Chandekar
2025-03-10 15:10   ` [GSOC PATCH v2 1/2] environment: move access to "core.attributesfile" into repo settings Ayush Chandekar
2025-03-10 21:11     ` Karthik Nayak
2025-03-10 15:10   ` [GSOC PATCH v2 2/2] attr: use `repo_settings_get_attributesfile_path()` and update callers Ayush Chandekar
2025-03-10 21:17     ` Karthik Nayak
2025-03-10 23:08       ` Junio C Hamano
2025-03-11 17:41       ` Ayush Chandekar
2025-03-11 14:39     ` shejialuo
2025-03-11 17:03       ` Junio C Hamano
2025-03-11 17:20       ` Ayush Chandekar

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=xmqqwmcw97z2.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=ayu.chandekar@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=shejialuo@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).