diff --git a/libimagref/src/reference.rs b/libimagref/src/reference.rs index 5c83e35c..465ca105 100644 --- a/libimagref/src/reference.rs +++ b/libimagref/src/reference.rs @@ -6,8 +6,10 @@ use std::ops::Deref; use std::ops::DerefMut; use std::collections::BTreeMap; use std::fs::File; -use std::io::Read; +use std::io::{Read, Write}; +use std::fmt::{Display, Error as FmtError, Formatter}; use std::fs::Permissions; +use std::result::Result as RResult; use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreId; @@ -495,6 +497,20 @@ impl<'a> DerefMut for Ref<'a> { } +impl<'a> Display for Ref<'a> { + + fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FmtError> { + let path = self.fs_file() + .map(|pb| String::from(pb.to_str().unwrap_or(""))) + .unwrap_or(String::from("Could not read Path from reference object")); + + let hash = self.get_stored_hash().unwrap_or(String::from("")); + + write!(fmt, "Ref({} -> {})", hash, path) + } + +} + fn hash_file_contents(f: &mut File) -> String { let mut hasher = Sha1::new(); let mut s = String::new();