-
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 ps::private::cherry_picking module
Add ps::private::cherry_picking module so that we have a place to house Patch Stack specific cherry picking concerns. To start we have added the map_range_for_cherry_pick() function that translates patch indexs to struct ready to be used with the git modules cherry pick functions. <!-- ps-id: c0921e7b-2d0c-429a-86fa-bac397a665c3 -->
- Loading branch information
1 parent
d63ad32
commit f42e67b
Showing
2 changed files
with
52 additions
and
0 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,51 @@ | ||
use super::super::super::ps; | ||
use std::result::Result; | ||
|
||
pub struct CherryPickRange { | ||
pub root_oid: git2::Oid, | ||
pub leaf_oid: Option<git2::Oid>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum MapRangeForCherryPickError { | ||
StartIndexNotFound, | ||
EndIndexNotFound, | ||
} | ||
|
||
pub fn map_range_for_cherry_pick( | ||
patches_vec: &Vec<ps::ListPatch>, | ||
start_patch_index: usize, | ||
end_patch_index: Option<usize>, | ||
) -> Result<CherryPickRange, MapRangeForCherryPickError> { | ||
let start_patch_oid = patches_vec | ||
.get(start_patch_index) | ||
.ok_or(MapRangeForCherryPickError::StartIndexNotFound)? | ||
.oid; | ||
|
||
Ok(match (start_patch_index, end_patch_index) { | ||
(si, Some(ei)) if (si < ei) => { | ||
let end_patch_oid = patches_vec | ||
.get(ei) | ||
.ok_or(MapRangeForCherryPickError::EndIndexNotFound)? | ||
.oid; | ||
CherryPickRange { | ||
root_oid: start_patch_oid, | ||
leaf_oid: Some(end_patch_oid), | ||
} | ||
} | ||
(si, Some(ei)) if (si > ei) => { | ||
let end_patch_oid = patches_vec | ||
.get(ei) | ||
.ok_or(MapRangeForCherryPickError::EndIndexNotFound)? | ||
.oid; | ||
CherryPickRange { | ||
root_oid: end_patch_oid, | ||
leaf_oid: Some(start_patch_oid), | ||
} | ||
} | ||
_ => CherryPickRange { | ||
root_oid: start_patch_oid, | ||
leaf_oid: None, | ||
}, | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod checkout; | ||
pub mod cherry_picking; | ||
pub mod commit_is_behind; | ||
pub mod config; | ||
pub mod git; | ||
|