Skip to content

Commit

Permalink
Walk all commits reachable from a refspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Notgnoshi committed Mar 10, 2024
1 parent d98db51 commit 4c14ba3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ pub fn fetch_or_find(repo: &str) -> eyre::Result<gix::Repository> {
Ok(repo)
}
}

pub fn walk_reference<'w>(
reference: &str,
repo: &'w gix::Repository,
) -> eyre::Result<gix::revision::Walk<'w>> {
let reference = repo.find_reference(reference)?;
let revision = reference.id();
let platform = repo.rev_walk([revision]);
let walk = platform.all()?;
Ok(walk)
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ struct CliArgs {
/// A path to a work tree or bare repository, or a clone URL
repository: String,

/// The branch to search for achievements
///
/// Technically, this argument is allowed to be any refspec, remote or local.
branch: String,

/// Set the application log level
///
/// You can also set the value of the HEROSTRATUS_LOG environment variable like so
Expand All @@ -30,7 +35,11 @@ fn main() -> eyre::Result<()> {
.from_env_lossy();
tracing_subscriber::fmt().with_env_filter(filter).init();

let _repo = git::fetch_or_find(&args.repository)?;
let repo = git::fetch_or_find(&args.repository)?;
let _walk = match git::walk_reference(&args.branch, &repo) {
Ok(w) => w,
Err(e) => return Err(e.wrap_err(format!("Could not walk reference '{}'", args.branch))),
};

Ok(())
}

0 comments on commit 4c14ba3

Please sign in to comment.