Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ConfigManager, Repo, and Worktree #19

Merged
merged 6 commits into from
Oct 14, 2024
Merged

New ConfigManager, Repo, and Worktree #19

merged 6 commits into from
Oct 14, 2024

Conversation

mih
Copy link
Member

@mih mih commented Oct 2, 2024

No description provided.

@mih mih marked this pull request as draft October 2, 2024 12:49
@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ab85e20) to head (1cbb796).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main       #19    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            6        27    +21     
  Lines           72       882   +810     
  Branches         2        54    +52     
==========================================
+ Hits            72       882   +810     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

datalad_core/config/git.py Outdated Show resolved Hide resolved
datalad_core/config/git.py Outdated Show resolved Hide resolved
datalad_core/config/git.py Outdated Show resolved Hide resolved
datalad_core/config/git.py Outdated Show resolved Hide resolved
@mih mih force-pushed the config branch 6 times, most recently from a7f287d to 73f9aac Compare October 7, 2024 11:17
@mih mih force-pushed the config branch 8 times, most recently from ac96ef0 to 3a897f9 Compare October 14, 2024 05:33
@mih mih changed the title feat: new configuration manager New ConfigManager, Repo, and Worktree Oct 14, 2024
@mih mih marked this pull request as ready for review October 14, 2024 05:34
mih added 3 commits October 14, 2024 07:35
Clarity can benefit from having base classes with common implementation
that we nevertheless do not expose directly in a (sub)package.

This change ensures that appropriate documentation for class members
inherited from such private classes is rendered.
The initial content is taken from legacy DataLad and is largely focused
on the composition of a dataset.
This new implementation represents a substantial departure from the
relatively thin wrapper around `git-config` that is used in
legacy DataLad.

It is based on the `Settings` class from `datasalad`, and extends it
with additional features, for example a context manager to
temporarily amend or override configuration items
(see datalad/datalad#5155).

Unlike legacy DataLad, no global config manager instance is created
on import. Instead, a `get_manager()` function is provided that can
be called by any code that requires access to a global manager
instance.

A number of additional implementations of setting sources are provided,
most notably individual sources for all of Git's configuration scopes.
This now also includes a `git-worktree` scope, not supported by legacy
DataLad.

All sources use a dedicated `ConfigItem` class for individual settings.
At present, this is identical to a `datasalad` `Setting`. However,
this item class will be extended to support UI-based query for
configuration values in the future. This is not implemented yet.

A dedicated `ImplementationDefaults` source (singleton) is included in any
`ConfigManager` instance. It can be populated with application specific
defaults (on import). This commit also introduced type-coercion for
few standard Git configuration items using this feature.
@mih mih force-pushed the config branch 3 times, most recently from 411ebfd to 5290c72 Compare October 14, 2024 10:19
There are no direct equivalents in legacy DataLad for the classes
`Repo` and `Worktree`. The closest would be `GitRepo`, but this
is a compound representation of a Git repository with an associated
checkout.

In comparison, `Repo` and `Worktree` is more focused, simpler
models with leaner implementations.

A `Repo` is a Git repository (location). It is conceptually identical
to what is called GIT-DIR in the Git documentation. It refers to
just the "bare" components of a repository, not to any potential
checkout. A `Repo` features a dedicated `ConfigManager` that is derived
from a global instances, sharing all common sources (actually
using the exact same source instances). It adds a `git-local` and
a `datalad-branch` configuration scope. The latter is added for
semantic compatibility with legacy DataLad, which reads the
committed configuration from the configured HEAD branch of a bare repo
also.

A `Worktree` is a primary checkout (of a non-bare) Git repository, or
any (linked) additional Git worktree. A `Worktree` always has an
associated `Repo`, accessible via its `.repo` property.
With `extensions.worktreeConfig` enabled in Git, `Worktree` provides
a tailored `ConfigManager` with an additional `git-worktree` scope.
Otherwise is uses the manager of the underlying `Repo`.

Both classes implement the "flyweight" pattern, like it is done
in legacy DataLad. This means that, within the same process, creating
instances of `Repo` and `Worktree` always yields the same instance
for the same path location. This enables a straightforward
implementation of cleanup routines, locking, but also sharing
`ConfigManager` instances and their sources. In comparison to
legacy DataLad, the flyweight pattern implementation is simplified.
Only classes with a single `path` parameter are supported.

Importantly, neither `Repo` nor `Worktree` class constructors support
the actual creation of a repository or worktree "on disk".
Both `Repo` and `Worktree` have received `init_at()` class methods.
The present implementation is focused on bare necessities:
(re)initialization in an existing directory.

The `Worktree.init_at()` implementation supports the git-init feature
for repository relocation, and it takes care of suitable instance
invalidation. This is a prelimary implementation. The criticial test
will be whether `git-init` can relocate a repository with an annex.
A corresponding tests needs to be added when an `init_annex()` method
becomes available.
@mih mih mentioned this pull request Oct 14, 2024
@mih mih merged commit e432e31 into main Oct 14, 2024
9 checks passed
@mih mih deleted the config branch October 14, 2024 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants