History

refactor (#301)

Sebastian Thiel committed 4 years ago

Commit e22e2dd1 parent 92a67a62 files · +28 −24Browse files

Unified · Split

2 files
  1. git-revision/src/describe.rs +27 −0
  2. git-revision/src/lib.rs +1 −24
git-revision/src/describe.rs+27−0
@@ -48,3 +48,30 @@ impl<'a> Display for Outcome<'a> { · 47 unmodified lines
48}48}
49 49
50pub type Error = ();50pub type Error = ();
51
52pub(crate) mod function {
53 use super::{Error, Outcome};
54 use git_hash::{oid, ObjectId};
55 use git_object::bstr::BStr;
56 use std::borrow::Cow;
57 use std::collections::HashMap;
58
59 #[allow(clippy::result_unit_err)]
60 pub fn describe<'a>(
61 commit: &oid,
62 hex_len: usize,
63 name_set: &HashMap<ObjectId, Cow<'a, BStr>>,
64 ) -> Result<Option<Outcome<'a>>, Error> {
65 if let Some(name) = name_set.get(commit) {
66 return Ok(Some(Outcome {
67 name: name.to_owned(),
68 id: commit.to_owned(),
69 hex_len,
70 depth: 0,
71 long: false,
72 dirty_suffix: None,
73 }));
74 }
75 todo!("actually search for it")
76 }
77}
git-revision/src/lib.rs+1−24
@@ -1,27 +1,4 @@
1#![forbid(unsafe_code, rust_2018_idioms)]1#![forbid(unsafe_code, rust_2018_idioms)]
2 2
3use git_hash::{oid, ObjectId};
4use git_object::bstr::BStr;
5use std::borrow::Cow;
6use std::collections::HashMap;
7
8pub mod describe;3pub mod describe;
9 4pub use describe::function::describe;
10#[allow(clippy::result_unit_err)]
11pub fn describe<'a>(
12 commit: &oid,
13 hex_len: usize,
14 name_set: &HashMap<ObjectId, Cow<'a, BStr>>,
15) -> Result<Option<describe::Outcome<'a>>, describe::Error> {
16 if let Some(name) = name_set.get(commit) {
17 return Ok(Some(describe::Outcome {
18 name: name.to_owned(),
19 id: commit.to_owned(),
20 hex_len,
21 depth: 0,
22 long: false,
23 dirty_suffix: None,
24 }));
25 }
26 todo!("actually search for it")
27}