Last active
August 10, 2021 21:04
-
-
Save medwards/b42df0f7c5904c1849079d54f25c4219 to your computer and use it in GitHub Desktop.
Example lifetime problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RepositoryHolder { | |
repository: std::rc::Rc<git2::Repository>, | |
} | |
impl RepositoryHolder { | |
fn commits(&self) -> impl Iterator<Item = git2::Commit> { | |
let repo = self.repository.clone(); | |
self.walker() | |
.flat_map(move |oid| repo.find_commit(oid.expect("Revwalk didn't get oid"))) | |
// maybe I want to filter the commits by whether they touched a path: | |
/* | |
.filter(|commit| { | |
let parent_tree = commit.parent(0).ok().map(|p| p.tree().ok()).flatten(); | |
let diff = self | |
.repository | |
.diff_tree_to_tree(parent_tree.as_ref(), commit.tree().ok().as_ref(), None) | |
.expect("Unable to create diff"); | |
diff.deltas().any(|delta| { | |
delta.old_file().path().map(|p| p.to_str()).flatten() == Some("src/main.rs") | |
|| delta.new_file().path().map(|p| p.to_str()).flatten() | |
== Some("src/main.rs") | |
}) | |
}) | |
*/ | |
} | |
fn walker(&self) -> git2::Revwalk { | |
let mut walker = self | |
.repository | |
.revwalk() | |
.expect("Unable to initialie revwalk"); | |
// could do other things here, like pushing a revision specifier instead | |
walker.push_head().expect("Unable to push head"); | |
walker | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment