Closed jorio closed 7 months ago
Merged, thanks.
My only concern is the API consistency of the Repository
class:
add_submodule
init_submodules
listall_submodules
lookup_submodule
update_submodules
submodule_status (NEW)
submodule_cache_all (NEW)
submodule_cache_clear (NEW)
I think it would be best to do like the remotes and have:
.submodules.add
.submodules.init
.submodules.__iter__
.submodules.__getitem__
.submodules.update
.submodules.status
.submodules.cache_all
.submodules.cache_clear
With the old function names kept for backwards compatibility, as deprecated.
What do you think? Do you mind to make a new PR in that direction?
I agree, this looks better. I'll submit a new PR this week!
This PR fleshes out submodules a bit.
Repository.init_submodules
andupdate_submodules
(which would do a redundant submodule lookup). Those two functions still exist in Repository, but they are now convenience wrappers around the new init/update functions in all the submodules in the repo.Notes about API design: The PR brings in new enums (GIT_SUBMODULESTATUS...) that I encapsulated as enum classes (IntFlag, IntEnum) in
enums.py
.This allows for friendlier development – function signatures can say they return a
SubmoduleStatus
instead of just anint
, and callingrepr
on aSubmoduleStatus
returns more descriptive text than just a number, such as:<SubmoduleStatus.IN_HEAD|IN_INDEX|IN_CONFIG|WD_UNINITIALIZED: 135>
This isn't how pygit2 currently exposes enums to Python code – but if you think it'd improve pygit2, we could progressively convert the existing enums to IntFlag/IntEnum classes. (The raw GIT_* values would still be available for legacy code.)
If you'd rather not have
enums.py
for consistency with the existing API, let me know and I'll edit this PR accordingly.