History

git-commitgraph with a more convenient public interface with AsRef(#63)

Sebastian Thiel committed 5 years ago

Commit ba04e4e1 parent 0b729662 files · +6 −5Browse files

Showing the changes to git-commitgraph/src (2 of 2 files). Show all

Unified · Split

2 files
  1. git-commitgraph/src/file/access.rs +2 −1
  2. git-commitgraph/src/graph/access.rs +4 −4
git-commitgraph/src/file/access.rs+2−1
@@ -70,7 +70,8 @@ impl File { · 69 unmodified lines
70 70
71 /// Translate the given object hash to its position within this file, if present.71 /// Translate the given object hash to its position within this file, if present.
72 // copied from git-odb/src/pack/index/access.rs72 // copied from git-odb/src/pack/index/access.rs
73 pub fn lookup(&self, id: &git_hash::oid) -> Option<file::Position> {73 pub fn lookup(&self, id: impl AsRef<git_hash::oid>) -> Option<file::Position> {
74 let id = id.as_ref();
74 let first_byte = usize::from(id.first_byte());75 let first_byte = usize::from(id.first_byte());
75 let mut upper_bound = self.fan[first_byte];76 let mut upper_bound = self.fan[first_byte];
76 let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 };77 let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 };
git-commitgraph/src/graph/access.rs+4−4
@@ -15,8 +15,8 @@ impl Graph { · 14 unmodified lines
15 }15 }
16 16
17 /// Returns the commit matching the given `id`.17 /// Returns the commit matching the given `id`.
18 pub fn commit_by_id(&self, id: &git_hash::oid) -> Option<Commit<'_>> {18 pub fn commit_by_id(&self, id: impl AsRef<git_hash::oid>) -> Option<Commit<'_>> {
19 let r = self.lookup_by_id(id)?;19 let r = self.lookup_by_id(id.as_ref())?;
20 Some(r.file.commit_at(r.file_pos))20 Some(r.file.commit_at(r.file_pos))
21 }21 }
22 22
@@ -40,8 +40,8 @@ impl Graph { · 17 unmodified lines
40 }40 }
41 41
42 /// Translate the given `id` to its position in the file.42 /// Translate the given `id` to its position in the file.
43 pub fn lookup(&self, id: &git_hash::oid) -> Option<graph::Position> {43 pub fn lookup(&self, id: impl AsRef<git_hash::oid>) -> Option<graph::Position> {
44 Some(self.lookup_by_id(id)?.graph_pos)44 Some(self.lookup_by_id(id.as_ref())?.graph_pos)
45 }45 }
46 46
47 /// Returns the number of commits stored in this file.47 /// Returns the number of commits stored in this file.