Skip to content

Make refdb_fs (hopefully) fully aware of per worktree refs #6387

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

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

csware
Copy link
Contributor

@csware csware commented Aug 18, 2022

This makes refdb_fs fully aware of per worktree refs (fixes issue #5492).

The code has some duplication but does the trick.

Signed-off-by: Sven Strickroth <[email protected]>
@csware csware changed the title Make refdb_fs fully aware of per worktree refs Make refdb_fs (hopefully) fully aware of per worktree refs Aug 18, 2022
@csware csware force-pushed the issue-5492 branch 2 times, most recently from 59b4385 to 21e5903 Compare August 18, 2022 12:53
Fixes issue isse libgit2#5492.

Signed-off-by: Sven Strickroth <[email protected]>
@csware
Copy link
Contributor Author

csware commented Jul 17, 2023

@ethomson Any chance to get a review?

@ethomson ethomson added the v1.8 label Feb 20, 2024
@@ -863,6 +867,49 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
error = git_vector_insert(&iter->loose, ref_dup);
}

if (!error && git_repository_is_worktree(backend->repo) == 1) {
git_iterator_free(fsit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think from a layering perspective, the filesystem refdb is not the right place for this — that would mean that every reference db would have to handle the per-corktree references themselves. I think that we should hoist the worktree logic into refs.c instead. In theory, the reference database should be able to operate without any knowledge of a repository (indeed, should be able to operate without a repository instance at all).

Reference databases should just handle the storage of references, and the git_reference family of functions should handle the business logic, including understanding whether there's a worktree or not.

Let me know if this makes sense — I can take a stab at an implementation on the references if you'd like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

However, here, both parts are within the filesystem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that I understand? Are you saying that since worktrees are in the filesystem and the default git-compatible ref database is also on the filesystem, that this is a reasonable separation of concerns?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, no, you're saying that the worktree reference storage living in the commondir is actually an implementation detail of the git-compatible ref database implementation itself. 🤔

That's a bit disappointing, but I think that you may be correct given our current database architecture.

@ethomson ethomson merged commit 4b289c1 into libgit2:main Mar 8, 2024
@ethomson
Copy link
Member

ethomson commented Mar 8, 2024

Thanks for the fix! I hope to come back and maybe re-think the abstraction around worktree refs databases, so that each refdb backend doesn't need to think about worktrees. In the meantime, this is great. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants