- A new design document. - Uses examples/diff.rs to test out some ideas. - Removes the type Browser. - Removes the type Snapshot.
2.2 KiB
An updated design for radicle-surf
Now we have ported the radicle-surf crate from its own github repo to be part of the radicle-git repo. We are taking this opportunity to refactor its design as well. Intuitively, radicle-surf provides an API so that one can use it to create a github-like UI for a git repo:
- Given a commit (or other types of ref), list the content: i.e. files and directories.
- Generate a diff between two commits.
- List the history of the commits.
- List refs: Branches, Tags.
The main goals of the changes are:
- make API simpler whenever possible.
- address open issues in the original
radicle-surfrepo as much as possible. - not to shy away from being
gitspecific. (i.e. not to consider supporting other VCS systems)
Make API simpler
The current API has quite a bit accidental complexity that is not inherent with the requirements, especially when we can be git specific and don't care about other VCS systems.
Remove the Browser
The type Browser is awkward as of today:
- it is not a source of truth of any information. For example,
list_branchesmethod is just a wrapper ofRepository::list_branches. - it takes in
History, but really works at theSnapshotlevel. - it is mutable but its state does not help much.
Can we just remove Browser and implement its functionalities using other types?
- For iteratoring the history, use
History. - For generating
Directory, useRepositorydirectly given aRev. - For accessing
Branch,TagorCommit, useRepository.
Remove the Snapshot
A Snapshot should be really just a tree (or Directory) of a Commit in git. Currently it is a function that returns a Directory. Because it is OK to be git specific, we don't need to have this generic function to create a snapshot across different VCS systems.
The only snapshot function defined currently:
let snapshot = Box::new(|repository: &RepositoryRef<'a>, history: &History| {
let tree = Self::get_tree(repository.repo_ref, history.0.first())?;
Ok(directory::Directory::from_hash_map(tree))
});
The above function can be easily implement as a method of Repository.