Skip to content

Commit 1909852

Browse files
committed
window: Introduce start_point when traversing graph
1 parent bcaaa54 commit 1909852

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎src/graph.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl GitGraph {
4343
pub fn new(
4444
mut repository: Repository,
4545
settings: &Settings,
46+
start_point: Option<String>,
4647
max_count: Option<usize>,
4748
) -> Result<Self, String> {
4849
#![doc = include_str!("../docs/branch_assignment.md")]
@@ -61,8 +62,17 @@ impl GitGraph {
6162
walk.set_sorting(git2::Sort::TOPOLOGICAL | git2::Sort::TIME)
6263
.map_err(|err| err.message().to_string())?;
6364

64-
walk.push_glob("*")
65-
.map_err(|err| err.message().to_string())?;
65+
// Use starting point if specified
66+
if let Some(start) = start_point {
67+
let object = repository
68+
.revparse_single(&start)
69+
.map_err(|err| format!("Failed to resolve start point '{}': {}", start, err))?;
70+
walk.push(object.id())
71+
.map_err(|err| err.message().to_string())?;
72+
} else {
73+
walk.push_glob("*")
74+
.map_err(|err| err.message().to_string())?;
75+
}
6676

6777
if repository.is_shallow() {
6878
return Err("ERROR: git-graph does not support shallow clones due to a missing feature in the underlying libgit2 library.".to_string());

‎src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fn run(
422422
pager: bool,
423423
) -> Result<(), String> {
424424
let now = Instant::now();
425-
let graph = GitGraph::new(repository, settings, max_commits)?;
425+
let graph = GitGraph::new(repository, settings, None, max_commits)?;
426426

427427
let duration_graph = now.elapsed().as_micros();
428428

0 commit comments

Comments
 (0)