Replies: 2 comments
-
So over at this fork I rewrote a few things /// A remote which represents a way to interact with hosts for remote clones of the parent repository.
#[derive(Debug, Clone, PartialEq)]
pub struct Remote<T> {
/*…*/
pub(crate) repo: T,
}
/// A remote with a reference to a given repository.
pub type RemoteRef<'a> = Remote<&'a Repository>;
/// A remote with a mutable reference to a given repository.
pub type RemoteRefMut<'a> = Remote<&'a mut Repository>; And then I pretty much just replaced all occurrences of What I like about this is that instead of impl RemoteRef<'_> {
pub fn save_to(&self, config: &mut git_config::File<'static>) -> Result<(), Error> {/*…*/}
} we could e.g. have impl RemoteRefMut<'_> {
pub fn save(&self) -> Result<(), Error> {/*…*/}
} Which will save VIA the given repository. |
Beta Was this translation helpful? Give feedback.
-
Saving remotes is currently a bit cumbersome as all changes remain in memory. Here is a function where that is done though as part of a clone. It's planned to improve this once there is a mechanism to easily write back changes to
There was a time when this was the case. It was complicated and ultimately not what would work for a high-level crate like |
Beta Was this translation helpful? Give feedback.
-
I'm trying to figure out how to add new remotes to a git repo.
Anyway regarding,
Thereafter I'm completely prevented from doing any mutable operations on a
Repository
. What if, instead of using a lifetime, we just used a generic in place of a specific repository type, like so:So we can have methods that return mutable and immutable references
Although I haven't demoed/tested this idea so perhaps there are nuances I haven't considered...
Personally I'd rather have a types that don't require references to their parent, it just complicates things to no end, if methods need access to such I'd rather pass it in as an argument....
Beta Was this translation helpful? Give feedback.
All reactions