Skip to content

Instantly share code, notes, and snippets.

@samrat
Created October 24, 2019 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samrat/bd5e7896a7d9e83bbe78ed6839efb3f3 to your computer and use it in GitHub Desktop.
Save samrat/bd5e7896a7d9e83bbe78ed6839efb3f3 to your computer and use it in GitHub Desktop.
use std::path::{Path, PathBuf};
// The proper modeling of the domain would be for a Repository to own
// Status. But because some Status methods call Repository methods, I
// have had to make Repository a field in Status instead.(which I've
// marked HACKY in the code below)
// This means that the struct that owns Repository now owns a Status
// and methods in the parent struct call Repository methods look like
// `self.status.repo.some_repository_method()`
// This is my attempt at creating a minimal example(compiling but
// non-functional) of the problem I'm trying to solve. The codebase
// I'm actually working on is here:
// https://github.com/samrat/rug/blob/master/src/repository/status.rs
// )
struct Index {
// ...
}
impl Index {
fn is_tracked(&self, path: &Path) -> bool {
// ...
false
}
}
struct Repository {
index: Index,
// status: Status, // HACKY
}
struct Stat {
// ...
}
impl Repository {
fn list_dir(&self, prefix: PathBuf) -> Vec<(PathBuf, Stat)> {
// ...
vec![]
}
}
struct Status {
repo: Repository, // HACKY
workspace_changes: Vec<String>,
index_changes: Vec<String>,
}
impl Status {
fn new(repo: Repository) -> Status {
// ...
Status {
repo,
workspace_changes: vec![],
index_changes: vec![],
}
}
fn scan_workspace(&mut self) {
let prefix = Path::new("");
for (mut path, stat) in self.repo.list_dir(prefix.to_path_buf()) {
if self.repo.index.is_tracked(&path) {
// Figure out workspace_changes and index_changes
}
}
}
}
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment