step thirty one: implement symbolic refs idea

This commit is contained in:
Gonçalo Valério 2020-11-07 23:01:19 +00:00
parent 29e6a60de8
commit da2967c736
1 changed files with 8 additions and 2 deletions

View File

@ -55,8 +55,14 @@ pub fn update_ref(reference: String, oid: String) {
} }
pub fn get_ref(reference: String) -> Result<String, Box<dyn std::error::Error + 'static>> { pub fn get_ref(reference: String) -> Result<String, Box<dyn std::error::Error + 'static>> {
let oid = fs::read_to_string(format!("{}/{}", RGIT_DIR, reference))?; let ref_path = format!("{}/{}", RGIT_DIR, reference);
return Ok(oid); let value = fs::read_to_string(ref_path)?;
if !value.is_empty() && value.starts_with("ref:") {
let new_ref: Vec<&str> = value.splitn(2, ":").collect();
return get_ref(new_ref[1].to_owned());
}
return Ok(value);
} }
pub fn iter_refs() -> Vec<(String, String)> { pub fn iter_refs() -> Vec<(String, String)> {