-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ext_common_ancestor feature to Cargo.toml
Add ext_common_ancestor feature to Cargo.toml so that we could experiment with using the external common ancestor functionality rather than the built in one to see if it is more performant when dealing with larger numbers of branches. <!-- ps-id: c1e664d4-101e-4817-9ea9-e5dc7a1df114 -->
- Loading branch information
1 parent
109f265
commit a3fd36d
Showing
4 changed files
with
64 additions
and
3 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 |
---|---|---|
|
@@ -41,3 +41,4 @@ clap_mangen = "0.2.14" | |
|
||
[features] | ||
backup_cmd = [] | ||
ext_common_ancestor = [] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use super::super::utils; | ||
use git2; | ||
use std::result::Result; | ||
|
||
#[derive(Debug)] | ||
pub enum ExtCommonAncestorError { | ||
Unhandled(Box<dyn std::error::Error>), | ||
} | ||
|
||
impl std::fmt::Display for ExtCommonAncestorError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Unhandled(e) => write!(f, "{}", e), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for ExtCommonAncestorError { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
Self::Unhandled(e) => Some(e.as_ref()), | ||
} | ||
} | ||
} | ||
|
||
impl From<utils::ExecuteWithOutputError> for ExtCommonAncestorError { | ||
fn from(value: utils::ExecuteWithOutputError) -> Self { | ||
Self::Unhandled(value.into()) | ||
} | ||
} | ||
|
||
impl From<std::string::FromUtf8Error> for ExtCommonAncestorError { | ||
fn from(value: std::string::FromUtf8Error) -> Self { | ||
Self::Unhandled(value.into()) | ||
} | ||
} | ||
|
||
impl From<git2::Error> for ExtCommonAncestorError { | ||
fn from(value: git2::Error) -> Self { | ||
Self::Unhandled(value.into()) | ||
} | ||
} | ||
|
||
pub fn ext_common_ancestor( | ||
one: git2::Oid, | ||
two: git2::Oid, | ||
) -> Result<git2::Oid, ExtCommonAncestorError> { | ||
let output = | ||
utils::execute_with_output("git", &["merge-base", &one.to_string(), &two.to_string()])?; | ||
let sha = String::from_utf8(output.stdout)?; | ||
let common_ancestor_oid = git2::Oid::from_str(sha.trim())?; | ||
Ok(common_ancestor_oid) | ||
} |
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