Skip to content

Commit a3f2816

Browse files
committed
Remove re-export of git_object::borrowed::Id (#63)
1 parent fdbe704 commit a3f2816

File tree

22 files changed

+64
-69
lines changed

22 files changed

+64
-69
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* **this is optional but desirable if…**
5252
* …there is no leakage otherwise to support user interfaces. They background long-running operations and need them to be cancellable.
5353

54-
* **prepare for SHA256 support by using `owned::Id` and `borrowed::Id`**
54+
* **prepare for SHA256 support by using `owned::Id` and `git_hash::borrowed::Id`**
5555
* eventually there will be the need to support both Sha1 and Sha256. We anticipate it by using the `Id` type instead
5656
of slices or arrays of 20 bytes. This way, eventually we can support multiple hash digest sizes.
5757
* Right now it's unclear how Sha256 is going to work in git, so we only support Sha1 for now. It might be an avenue to proactively

git-commitgraph/src/file/access.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::file::{self, commit::Commit, File, COMMIT_DATA_ENTRY_SIZE};
22
use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
3-
use git_object::{borrowed, HashKind};
3+
use git_object::HashKind;
44
use std::{
55
convert::{TryFrom, TryInto},
66
fmt::{Debug, Formatter},
@@ -35,7 +35,7 @@ impl File {
3535
/// Returns 20 bytes sha1 at the given index in our list of (sorted) sha1 hashes.
3636
/// The position ranges from 0 to self.num_commits()
3737
// copied from git-odb/src/pack/index/access.rs
38-
pub fn id_at(&self, pos: file::Position) -> borrowed::Id<'_> {
38+
pub fn id_at(&self, pos: file::Position) -> git_hash::borrowed::Id<'_> {
3939
assert!(
4040
pos.0 < self.num_commits(),
4141
"expected lexigraphical position less than {}, got {}",
@@ -47,16 +47,16 @@ impl File {
4747
.try_into()
4848
.expect("an architecture able to hold 32 bits of integer");
4949
let start = self.oid_lookup_offset + (pos * SHA1_SIZE);
50-
borrowed::Id::try_from(&self.data[start..start + SHA1_SIZE]).expect("20 bytes SHA1 to be alright")
50+
git_hash::borrowed::Id::try_from(&self.data[start..start + SHA1_SIZE]).expect("20 bytes SHA1 to be alright")
5151
}
5252

5353
/// Return an iterator over all object hashes stored in the base graph.
54-
pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> {
54+
pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = git_hash::borrowed::Id<'_>> {
5555
let start = self.base_graphs_list_offset.unwrap_or(0);
5656
let base_graphs_list = &self.data[start..start + (SHA1_SIZE * usize::from(self.base_graph_count))];
5757
base_graphs_list
5858
.chunks(SHA1_SIZE)
59-
.map(|bytes| borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright"))
59+
.map(|bytes| git_hash::borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright"))
6060
}
6161

6262
/// return an iterator over all commits in this file.
@@ -65,13 +65,13 @@ impl File {
6565
}
6666

6767
/// Return an iterator over all object hashes stored in this file.
68-
pub fn iter_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> {
68+
pub fn iter_ids(&self) -> impl Iterator<Item = git_hash::borrowed::Id<'_>> {
6969
(0..self.num_commits()).map(move |i| self.id_at(file::Position(i)))
7070
}
7171

7272
/// Translate the given object hash to its position within this file, if present.
7373
// copied from git-odb/src/pack/index/access.rs
74-
pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<file::Position> {
74+
pub fn lookup(&self, id: git_hash::borrowed::Id<'_>) -> Option<file::Position> {
7575
let first_byte = usize::from(id.first_byte());
7676
let mut upper_bound = self.fan[first_byte];
7777
let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 };

git-commitgraph/src/file/commit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
};
66
use byteorder::{BigEndian, ByteOrder};
77
use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
8-
use git_object::{borrowed, owned};
8+
use git_object::owned;
99
use std::{
1010
convert::{TryFrom, TryInto},
1111
fmt::{Debug, Formatter},
@@ -40,7 +40,7 @@ pub struct Commit<'a> {
4040
generation: u32,
4141
parent1: ParentEdge,
4242
parent2: ParentEdge,
43-
root_tree_id: borrowed::Id<'a>,
43+
root_tree_id: git_hash::borrowed::Id<'a>,
4444
}
4545

4646
impl<'a> Commit<'a> {
@@ -49,7 +49,7 @@ impl<'a> Commit<'a> {
4949
Commit {
5050
file,
5151
pos,
52-
root_tree_id: borrowed::Id::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"),
52+
root_tree_id: git_hash::borrowed::Id::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"),
5353
parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE..SHA1_SIZE + 4])),
5454
parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE + 4..SHA1_SIZE + 8])),
5555
generation: BigEndian::read_u32(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 12]) >> 2,
@@ -84,7 +84,7 @@ impl<'a> Commit<'a> {
8484
}
8585

8686
/// Returns the hash of this commit.
87-
pub fn id(&self) -> borrowed::Id<'a> {
87+
pub fn id(&self) -> git_hash::borrowed::Id<'a> {
8888
self.file.id_at(self.pos)
8989
}
9090

@@ -99,7 +99,7 @@ impl<'a> Commit<'a> {
9999
}
100100

101101
/// Return the hash of the tree this commit points to.
102-
pub fn root_tree_id(&self) -> borrowed::Id<'a> {
102+
pub fn root_tree_id(&self) -> git_hash::borrowed::Id<'a> {
103103
self.root_tree_id
104104
}
105105
}

git-commitgraph/src/file/verify.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
};
66
use bstr::ByteSlice;
77
use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
8-
use git_object::{borrowed, owned};
8+
use git_object::owned;
99
use std::{
1010
cmp::{max, min},
1111
collections::HashMap,
@@ -58,8 +58,9 @@ pub struct Outcome {
5858
/// Verification
5959
impl File {
6060
/// Returns the trailing checksum over the entire content of this file.
61-
pub fn checksum(&self) -> borrowed::Id<'_> {
62-
borrowed::Id::try_from(&self.data[self.data.len() - SHA1_SIZE..]).expect("file to be large enough for a hash")
61+
pub fn checksum(&self) -> git_hash::borrowed::Id<'_> {
62+
git_hash::borrowed::Id::try_from(&self.data[self.data.len() - SHA1_SIZE..])
63+
.expect("file to be large enough for a hash")
6364
}
6465

6566
/// Traverse all [commits][file::Commit] stored in this file and call `processor(commit) -> Result<(), Error>` on it.
@@ -74,7 +75,7 @@ impl File {
7475
.map_err(|(actual, expected)| Error::Mismatch { actual, expected })?;
7576
verify_split_chain_filename_hash(&self.path, self.checksum()).map_err(Error::Filename)?;
7677

77-
let null_id = borrowed::Id::null_sha1();
78+
let null_id = git_hash::borrowed::Id::null_sha1();
7879

7980
let mut stats = Outcome {
8081
max_generation: 0,
@@ -85,7 +86,7 @@ impl File {
8586
};
8687

8788
// TODO: Verify self.fan values as we go.
88-
let mut prev_id: borrowed::Id<'a> = null_id;
89+
let mut prev_id: git_hash::borrowed::Id<'a> = null_id;
8990
for commit in self.iter_commits() {
9091
if commit.id() <= prev_id {
9192
if commit.id() == null_id {
@@ -157,7 +158,10 @@ impl File {
157158

158159
/// If the given path's filename matches "graph-{hash}.graph", check that `hash` matches the
159160
/// expected hash.
160-
fn verify_split_chain_filename_hash(path: impl AsRef<Path>, expected: borrowed::Id<'_>) -> Result<(), String> {
161+
fn verify_split_chain_filename_hash(
162+
path: impl AsRef<Path>,
163+
expected: git_hash::borrowed::Id<'_>,
164+
) -> Result<(), String> {
161165
let path = path.as_ref();
162166
path.file_name()
163167
.and_then(|filename| filename.to_str())

git-commitgraph/src/graph/access.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{
22
file::{self, Commit, File},
33
graph::{self, Graph},
44
};
5-
use git_object::borrowed;
65

76
/// Access
87
impl Graph {
@@ -16,7 +15,7 @@ impl Graph {
1615
}
1716

1817
/// Returns the commit matching the given `id`.
19-
pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<Commit<'_>> {
18+
pub fn commit_by_id(&self, id: git_hash::borrowed::Id<'_>) -> Option<Commit<'_>> {
2019
let r = self.lookup_by_id(id)?;
2120
Some(r.file.commit_at(r.file_pos))
2221
}
@@ -25,7 +24,7 @@ impl Graph {
2524
///
2625
/// # Panics
2726
/// If `pos` is greater or equal to [`num_commits()`][Graph::num_commits()].
28-
pub fn id_at(&self, pos: graph::Position) -> borrowed::Id<'_> {
27+
pub fn id_at(&self, pos: graph::Position) -> git_hash::borrowed::Id<'_> {
2928
let r = self.lookup_by_pos(pos);
3029
r.file.id_at(r.pos)
3130
}
@@ -36,12 +35,12 @@ impl Graph {
3635
}
3736

3837
/// Iterate over commit IDs in unsorted order.
39-
pub fn iter_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> {
38+
pub fn iter_ids(&self) -> impl Iterator<Item = git_hash::borrowed::Id<'_>> {
4039
self.files.iter().flat_map(|file| file.iter_ids())
4140
}
4241

4342
/// Translate the given `id` to its position in the file.
44-
pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<graph::Position> {
43+
pub fn lookup(&self, id: git_hash::borrowed::Id<'_>) -> Option<graph::Position> {
4544
Some(self.lookup_by_id(id)?.graph_pos)
4645
}
4746

@@ -53,7 +52,7 @@ impl Graph {
5352

5453
/// Access fundamentals
5554
impl Graph {
56-
pub(crate) fn lookup_by_id(&self, id: borrowed::Id<'_>) -> Option<LookupByIdResult<'_>> {
55+
pub(crate) fn lookup_by_id(&self, id: git_hash::borrowed::Id<'_>) -> Option<LookupByIdResult<'_>> {
5756
let mut current_file_start = 0;
5857
for file in &self.files {
5958
if let Some(lex_pos) = file.lookup(id) {

git-commitgraph/tests/commitgraph.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ pub struct RefInfo {
8888
}
8989

9090
impl RefInfo {
91-
pub fn id(&self) -> borrowed::Id {
91+
pub fn id(&self) -> git_hash::borrowed::Id {
9292
self.id.to_borrowed()
9393
}
9494

9595
pub fn pos(&self) -> GraphPosition {
9696
self.pos
9797
}
9898

99-
pub fn parent_ids(&self) -> impl IntoIterator<Item = borrowed::Id> {
99+
pub fn parent_ids(&self) -> impl IntoIterator<Item = git_hash::borrowed::Id> {
100100
self.parent_ids.iter().map(|x| x.to_borrowed())
101101
}
102102

103-
pub fn root_tree_id(&self) -> borrowed::Id {
103+
pub fn root_tree_id(&self) -> git_hash::borrowed::Id {
104104
self.root_tree_id.to_borrowed()
105105
}
106106
}
@@ -136,7 +136,7 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa
136136
.collect();
137137
infos.sort_by_key(|x| x.1);
138138

139-
let get_pos = |id: borrowed::Id| -> GraphPosition {
139+
let get_pos = |id: git_hash::borrowed::Id| -> GraphPosition {
140140
let pos: u32 = infos
141141
.binary_search_by_key(&id, |x| x.1.to_borrowed())
142142
.expect("sorted_ids to contain id")

git-object/src/borrowed/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
mod commit;
77
pub use commit::Commit;
88

9-
pub use git_hash::borrowed::Id;
10-
119
mod tag;
1210
pub use tag::Tag;
1311

git-object/src/borrowed/tree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{borrowed, borrowed::parse::SPACE, borrowed::Error, tree};
1+
use crate::{borrowed::parse::SPACE, borrowed::Error, tree};
22
use bstr::{BStr, ByteSlice};
33
use nom::{
44
bytes::complete::{tag, take, take_while1, take_while_m_n},
@@ -29,7 +29,7 @@ pub struct Entry<'a> {
2929
pub filename: &'a BStr,
3030
/// The id of the object representing the entry.
3131
#[cfg_attr(feature = "serde1", serde(borrow))]
32-
pub oid: borrowed::Id<'a>,
32+
pub oid: git_hash::borrowed::Id<'a>,
3333
}
3434

3535
impl<'a> Tree<'a> {
@@ -68,7 +68,7 @@ fn parse_entry(i: &[u8]) -> IResult<&[u8], Entry<'_>, Error> {
6868
Entry {
6969
mode,
7070
filename: filename.as_bstr(),
71-
oid: borrowed::Id::try_from(oid).expect("we counted exactly 20 bytes"),
71+
oid: git_hash::borrowed::Id::try_from(oid).expect("we counted exactly 20 bytes"),
7272
},
7373
))
7474
}

git-object/tests/borrowed/tree.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod from_bytes {
22
use crate::borrowed::fixture_bytes;
33
use git_object::{
4-
borrowed,
54
borrowed::{tree::Entry, Tree},
65
bstr::ByteSlice,
76
tree,
@@ -12,7 +11,7 @@ mod from_bytes {
1211
<[u8; 20]>::from_hex(hex).expect("40 bytes hex sha")
1312
}
1413

15-
pub fn as_id(id: &[u8; 20]) -> borrowed::Id {
14+
pub fn as_id(id: &[u8; 20]) -> git_hash::borrowed::Id {
1615
id.into()
1716
}
1817

git-odb/src/borrowed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod verify {
4444
/// Compute the checksum of `self` and compare it with the `desired` hash.
4545
/// If the hashes do not match, an [`Error`] is returned, containing the actual
4646
/// hash of `self`.
47-
pub fn verify_checksum(&self, desired: borrowed::Id<'_>) -> Result<(), Error> {
47+
pub fn verify_checksum(&self, desired: git_hash::borrowed::Id<'_>) -> Result<(), Error> {
4848
let mut sink = hash::Write::new(io::sink(), desired.kind());
4949

5050
loose::object::header::encode(self.kind, self.data.len() as u64, &mut sink).expect("hash to always work");

0 commit comments

Comments
 (0)