Harness the power of signify(1) to sign arbitrary git objects
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

impl revparse_single_ok_or_else

+26 -5
+26 -5
src/utils.rs
··· 153 153 pub signature: Blob<'repo>, 154 154 } 155 155 156 + /// Parse a revision `rev`, and dispatch between `ok_` or `else_`, in case it is 157 + /// found (or not). 158 + pub fn revparse_single_ok_or_else<'repo, OK, ELSE, T>( 159 + repo: &'repo Repository, 160 + rev: &str, 161 + ok_: OK, 162 + else_: ELSE, 163 + ) -> Result<T> 164 + where 165 + OK: FnOnce(Object<'repo>) -> Result<T>, 166 + ELSE: FnOnce() -> Result<T>, 167 + { 168 + match repo.revparse_single(rev) { 169 + Ok(obj) => ok_(obj), 170 + Err(e) if e.code() == ErrorCode::NotFound => else_(), 171 + Err(e) => Err(e).context("Failed to look-up revision"), 172 + } 173 + } 174 + 156 175 impl<'repo> TreeSignature<'repo> { 157 176 /// Load a [`TreeSignature`] at the given `tree_rev` from the 158 177 /// provided git repository. The value of `tree_rev` is expected 159 178 /// to follow the refspec [`ALL_SIGNIFY_SIGNATURE_REFS`]. 160 179 #[inline] 161 180 pub fn load(repo: &'repo Repository, tree_rev: &str) -> Result<Option<Self>> { 162 - match repo.revparse_single(tree_rev) { 163 - Ok(obj) => Self::load_oid(repo, obj.id()).map(Some), 164 - Err(e) if e.code() == ErrorCode::NotFound => Ok(None), 165 - Err(e) => Err(e).context("Failed to look-up tree signature"), 166 - } 181 + revparse_single_ok_or_else( 182 + repo, 183 + tree_rev, 184 + |obj| Self::load_oid(repo, obj.id()).map(Some), 185 + || Ok(None), 186 + ) 187 + .context("Failed to look-up tree signature") 167 188 } 168 189 169 190 /// Like [`TreeSignature::load`], but uses a concrete revision pointing