History

change!: Change accessors named `hash_kind()` to `object_hash()` for consistency (#279)

Sebastian Thiel committed 4 years ago

Commit 2ef9a841 parent 1b7554124 files · +75 −58Browse files

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

Unified · Split

5 files
  1. git-commitgraph/src/file/access.rs +2 −2
  2. git-commitgraph/src/file/init.rs +12 −11
  3. git-commitgraph/src/file/mod.rs +1 −0
  4. git-commitgraph/src/file/verify.rs +2 −2
  5. git-commitgraph/src/graph/init.rs +3 −3
git-commitgraph/src/file/access.rs+2−2
@@ -27,8 +27,8 @@ impl File { · 26 unmodified lines
2727 /// The kind of hash used in this File.
2828 ///
2929 /// Note that it is always conforming to the hash used in the owning repository.
30− pub fn hash_kind(&self) -> git_hash::Kind {
31− git_hash::Kind::from_len_in_bytes(self.hash_len)
30+ pub fn object_hash(&self) -> git_hash::Kind {
31+ self.object_hash
3232 }
3333
3434 /// Returns an object id at the given index in our list of (sorted) hashes.
git-commitgraph/src/file/init.rs+12−11
@@ -92,7 +92,7 @@ impl TryFrom<&Path> for File { · 91 unmodified lines
9292 };
9393 ofs += 1;
9494
95− let hash_kind = match data[ofs] {
95+ let object_hash = match data[ofs] {
9696 1 => git_hash::Kind::Sha1,
9797 x => {
9898 return Err(Error::UnsupportedHashVersion(x));
@@ -113,17 +113,17 @@ impl TryFrom<&Path> for File { · 14 unmodified lines
113113 let base_graphs_list_offset = chunks
114114 .validated_usize_offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID, |chunk_range| {
115115 let chunk_size = chunk_range.len();
116− if chunk_size % hash_kind.len_in_bytes() != 0 {
116+ if chunk_size % object_hash.len_in_bytes() != 0 {
117117 return Err(Error::InvalidChunkSize {
118118 id: BASE_GRAPHS_LIST_CHUNK_ID,
119119 msg: format!(
120120 "chunk size {} is not a multiple of {}",
121121 chunk_size,
122− hash_kind.len_in_bytes()
122+ object_hash.len_in_bytes()
123123 ),
124124 });
125125 }
126− let chunk_base_graph_count: u32 = (chunk_size / hash_kind.len_in_bytes())
126+ let chunk_base_graph_count: u32 = (chunk_size / object_hash.len_in_bytes())
127127 .try_into()
128128 .expect("base graph count to fit in 32-bits");
129129 if chunk_base_graph_count != u32::from(base_graph_count) {
@@ -141,7 +141,7 @@ impl TryFrom<&Path> for File { · 11 unmodified lines
141141 chunks.validated_usize_offset_by_id(COMMIT_DATA_CHUNK_ID, |chunk_range| {
142142 let chunk_size = chunk_range.len();
143143
144− let entry_size = hash_kind.len_in_bytes() + COMMIT_DATA_ENTRY_SIZE_SANS_HASH;
144+ let entry_size = object_hash.len_in_bytes() + COMMIT_DATA_ENTRY_SIZE_SANS_HASH;
145145 if chunk_size % entry_size != 0 {
146146 return Err(Error::InvalidChunkSize {
147147 id: COMMIT_DATA_CHUNK_ID,
@@ -173,19 +173,19 @@ impl TryFrom<&Path> for File { · 25 unmodified lines
173173 chunks.validated_usize_offset_by_id(OID_LOOKUP_CHUNK_ID, |chunk_range| {
174174 let chunk_size = chunk_range.len();
175175
176− if chunk_size % hash_kind.len_in_bytes() != 0 {
176+ if chunk_size % object_hash.len_in_bytes() != 0 {
177177 return Err(Error::InvalidChunkSize {
178178 id: OID_LOOKUP_CHUNK_ID,
179179 msg: format!(
180180 "chunk size {} is not a multiple of {}",
181181 chunk_size,
182− hash_kind.len_in_bytes()
182+ object_hash.len_in_bytes()
183183 ),
184184 });
185185 }
186186 Ok((
187187 chunk_range.start,
188− (chunk_size / hash_kind.len_in_bytes())
188+ (chunk_size / object_hash.len_in_bytes())
189189 .try_into()
190190 .expect("number of commits in OIDL chunk to fit in 32 bits"),
191191 ))
@@ -194,10 +194,10 @@ impl TryFrom<&Path> for File { · 2 unmodified lines
194194 let extra_edges_list_range = chunks.usize_offset_by_id(EXTENDED_EDGES_LIST_CHUNK_ID).ok();
195195
196196 let trailer = &data[chunks.highest_offset() as usize..];
197− if trailer.len() != hash_kind.len_in_bytes() {
197+ if trailer.len() != object_hash.len_in_bytes() {
198198 return Err(Error::Trailer(format!(
199199 "Expected commit-graph trailer to contain {} bytes, got {}",
200− hash_kind.len_in_bytes(),
200+ object_hash.len_in_bytes(),
201201 trailer.len()
202202 )));
203203 }
@@ -235,7 +235,8 @@ impl TryFrom<&Path> for File { · 31 unmodified lines
235235 fan,
236236 oid_lookup_offset,
237237 path: path.to_owned(),
238− hash_len: hash_kind.len_in_bytes(),
238+ hash_len: object_hash.len_in_bytes(),
239+ object_hash,
239240 })
240241 }
241242 }
git-commitgraph/src/file/mod.rs+1−0
@@ -48,6 +48,7 @@ pub struct File { · 47 unmodified lines
4848 oid_lookup_offset: usize,
4949 path: PathBuf,
5050 hash_len: usize,
51+ object_hash: git_hash::Kind,
5152 }
5253
5354 /// The position of a given commit within a graph file, starting at 0.
git-commitgraph/src/file/verify.rs+2−2
@@ -81,7 +81,7 @@ impl File { · 80 unmodified lines
8181 .map_err(|(actual, expected)| Error::Mismatch { actual, expected })?;
8282 verify_split_chain_filename_hash(&self.path, self.checksum()).map_err(Error::Filename)?;
8383
84− let null_id = self.hash_kind().null_ref();
84+ let null_id = self.object_hash().null_ref();
8585
8686 let mut stats = Outcome {
8787 max_generation: 0,
@@ -149,7 +149,7 @@ impl File { · 61 unmodified lines
149149 // as these files are usually small enough to process them in less than a second, even for the large ones.
150150 // But it's possible, once a progress instance is passed.
151151 let data_len_without_trailer = self.data.len() - self.hash_len;
152− let mut hasher = git_features::hash::hasher(self.hash_kind());
152+ let mut hasher = git_features::hash::hasher(self.object_hash());
153153 hasher.update(&self.data[..data_len_without_trailer]);
154154 let actual = git_hash::ObjectId::from(hasher.digest().as_ref());
155155
git-commitgraph/src/graph/init.rs+3−3
@@ -98,12 +98,12 @@ impl Graph { · 97 unmodified lines
9898 for window in files.windows(2) {
9999 let f1 = &window[0];
100100 let f2 = &window[1];
101− if f1.hash_kind() != f2.hash_kind() {
101+ if f1.object_hash() != f2.object_hash() {
102102 return Err(Error::HashVersionMismatch {
103103 path1: f1.path().to_owned(),
104− hash1: f1.hash_kind(),
104+ hash1: f1.object_hash(),
105105 path2: f2.path().to_owned(),
106− hash2: f2.hash_kind(),
106+ hash2: f2.object_hash(),
107107 });
108108 }
109109 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t