-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache branchname lookup (closes #159)
- Loading branch information
Stephan Dilly
committed
Jul 4, 2020
1 parent
715c179
commit a33db8d
Showing
8 changed files
with
61 additions
and
5 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
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,41 @@ | ||
use crate::{ | ||
error::Result, | ||
sync::{self, CommitId}, | ||
}; | ||
|
||
/// | ||
pub struct BranchName { | ||
last_result: Option<(CommitId, String)>, | ||
repo_path: String, | ||
} | ||
|
||
impl BranchName { | ||
/// | ||
pub fn new(path: &str) -> Self { | ||
Self { | ||
repo_path: path.to_string(), | ||
last_result: None, | ||
} | ||
} | ||
|
||
/// | ||
pub fn lookup(&mut self) -> Result<String> { | ||
let current_head = sync::get_head(self.repo_path.as_str())?; | ||
|
||
if let Some((last_head, branch_name)) = | ||
self.last_result.as_ref() | ||
{ | ||
if *last_head == current_head { | ||
return Ok(branch_name.clone()); | ||
} | ||
} | ||
|
||
self.fetch(current_head) | ||
} | ||
|
||
fn fetch(&mut self, head: CommitId) -> Result<String> { | ||
let name = sync::get_branch_name(self.repo_path.as_str())?; | ||
self.last_result = Some((head, name.clone())); | ||
Ok(name) | ||
} | ||
} |
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,7 @@ | ||
//! cached lookups: | ||
//! parts of the sync api that might take longer | ||
//! to compute but change seldom so doing them async might be overkill | ||
|
||
mod branchname; | ||
|
||
pub use branchname::BranchName; |
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
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