-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now it only supports the standard merge-base, but more derivatives can be added easily on demand.
- Loading branch information
Showing
5 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::OutputFormat; | ||
use anyhow::bail; | ||
|
||
pub fn merge_base( | ||
mut repo: gix::Repository, | ||
first: String, | ||
others: Vec<String>, | ||
mut out: impl std::io::Write, | ||
format: OutputFormat, | ||
) -> anyhow::Result<()> { | ||
if format != OutputFormat::Human { | ||
bail!("Only 'human' format is currently supported"); | ||
} | ||
repo.object_cache_size_if_unset(50 * 1024 * 1024); | ||
let first_id = repo.rev_parse_single(first.as_str())?; | ||
let other_ids: Vec<_> = others | ||
.iter() | ||
.cloned() | ||
.map(|other| repo.rev_parse_single(other.as_str()).map(gix::Id::detach)) | ||
.collect::<Result<_, _>>()?; | ||
|
||
let cache = repo.commit_graph_if_enabled()?; | ||
let bases = repo.merge_bases_many_with_cache(first_id, &other_ids, cache.as_ref())?; | ||
if bases.is_empty() { | ||
bail!("No base found for {first} and {others}", others = others.join(", ")) | ||
} | ||
for id in bases { | ||
writeln!(&mut out, "{id}")?; | ||
} | ||
Ok(()) | ||
} |
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
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
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
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