Consolidate create/clone with Repo/Worktree #57

Open
opened 2026-05-05 04:21:53 +00:00 by mih · 0 comments
Owner

These two pieces are from two different waves of the development, the latter being the older.

There is no some overlap in functionality and also some duplication of costs that prevent them from being used together efficiently.

Looking at the present implementation, I think:

  • Repo.init_at should be a frontend to create_repo() (it could also be removed, but Worktree.init_at is meaninful and removal would taint the symmetry. Not sure yet)
  • Repo|Worktree.init() should perform no checks. Otherwise these would be pointless when these objects are used from within functions like clone() or create(). All checks should migrate to a respective from_path class method.
  • There is no immediate reason for Worktree.init_annex() to exist. This is not as feature rich as create() and placement is a bit odd

Overall, continued development needs a decision on the desired design.

  • should the main parameter/return value be a Path or a more specific object. The latter would avoid repeated type/validity checking
  • should the Repo|Worktree objects have any "manipulator" (like init_at), or should they at most have "interogators"

Right now I am leaning towards the following model

  • functions that operate on worktrees or repositories require these parameter types, rather than excepting Path directly and then do validation of that internally
  • functions like create|clone return Repo|Worktree rather than nothing (status quo)
  • Repo|Worktree can be created (__init__()) cheaply, in particular without filesystem interaction, and assume "valid". Dedicated methods like from_path() are provided for safer operation, for when such costs are ok.
  • Repo looses its init_at(). It would need to be frontend for create_repo(). But then it would still not provide the functionality of create(), and it would also introduce circularity when Repo requires create*() and create() requires Repo as a return value also.
  • create() should become create_dataset() to make room for a create_worktree()
  • Worktree looses its init_at() in favor of a create_worktree(), which takes a Repo instance as a parameter
These two pieces are from two different waves of the development, the latter being the older. There is no some overlap in functionality and also some duplication of costs that prevent them from being used together efficiently. Looking at the present implementation, I think: - `Repo.init_at` should be a frontend to `create_repo()` (it could also be removed, but `Worktree.init_at` is meaninful and removal would taint the symmetry. Not sure yet) - `Repo|Worktree.init()` should perform no checks. Otherwise these would be pointless when these objects are used from within functions like `clone()` or `create()`. All checks should migrate to a respective `from_path` class method. - There is no immediate reason for `Worktree.init_annex()` to exist. This is not as feature rich as `create()` and placement is a bit odd Overall, continued development needs a decision on the desired design. - should the main parameter/return value be a Path or a more specific object. The latter would avoid repeated type/validity checking - should the `Repo|Worktree` objects have any "manipulator" (like `init_at`), or should they at most have "interogators" Right now I am leaning towards the following model - functions that operate on worktrees or repositories require these parameter types, rather than excepting `Path` directly and then do validation of that internally - functions like `create|clone` return `Repo|Worktree` rather than nothing (status quo) - `Repo|Worktree` can be created (`__init__()`) cheaply, in particular without filesystem interaction, and assume "valid". Dedicated methods like `from_path()` are provided for safer operation, for when such costs are ok. - `Repo` looses its `init_at()`. It would need to be frontend for `create_repo()`. But then it would still not provide the functionality of `create()`, and it would also introduce circularity when `Repo` requires `create*()` and `create()` requires `Repo` as a return value also. - `create()` should become `create_dataset()` to make room for a `create_worktree()` - `Worktree` looses its `init_at()` in favor of a `create_worktree()`, which takes a `Repo` instance as a parameter
Sign in to join this conversation.
No description provided.