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
27 /// The kind of hash used in this File.27 /// The kind of hash used in this File.
28 ///28 ///
29 /// Note that it is always conforming to the hash used in the owning repository.29 /// Note that it is always conforming to the hash used in the owning repository.
30 pub fn hash_kind(&self) -> git_hash::Kind {30 pub fn object_hash(&self) -> git_hash::Kind {
31 git_hash::Kind::from_len_in_bytes(self.hash_len)31 self.object_hash
32 }32 }
33 33
34 /// Returns an object id at the given index in our list of (sorted) hashes.34 /// 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
92 };92 };
93 ofs += 1;93 ofs += 1;
94 94
95 let hash_kind = match data[ofs] {95 let object_hash = match data[ofs] {
96 1 => git_hash::Kind::Sha1,96 1 => git_hash::Kind::Sha1,
97 x => {97 x => {
98 return Err(Error::UnsupportedHashVersion(x));98 return Err(Error::UnsupportedHashVersion(x));
@@ -113,17 +113,17 @@ impl TryFrom<&Path> for File { · 14 unmodified lines
113 let base_graphs_list_offset = chunks113 let base_graphs_list_offset = chunks
114 .validated_usize_offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID, |chunk_range| {114 .validated_usize_offset_by_id(BASE_GRAPHS_LIST_CHUNK_ID, |chunk_range| {
115 let chunk_size = chunk_range.len();115 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 {
117 return Err(Error::InvalidChunkSize {117 return Err(Error::InvalidChunkSize {
118 id: BASE_GRAPHS_LIST_CHUNK_ID,118 id: BASE_GRAPHS_LIST_CHUNK_ID,
119 msg: format!(119 msg: format!(
120 "chunk size {} is not a multiple of {}",120 "chunk size {} is not a multiple of {}",
121 chunk_size,121 chunk_size,
122 hash_kind.len_in_bytes()122 object_hash.len_in_bytes()
123 ),123 ),
124 });124 });
125 }125 }
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())
127 .try_into()127 .try_into()
128 .expect("base graph count to fit in 32-bits");128 .expect("base graph count to fit in 32-bits");
129 if chunk_base_graph_count != u32::from(base_graph_count) {129 if chunk_base_graph_count != u32::from(base_graph_count) {
@@ -141,7 +141,7 @@ impl TryFrom<&Path> for File { · 11 unmodified lines
141 chunks.validated_usize_offset_by_id(COMMIT_DATA_CHUNK_ID, |chunk_range| {141 chunks.validated_usize_offset_by_id(COMMIT_DATA_CHUNK_ID, |chunk_range| {
142 let chunk_size = chunk_range.len();142 let chunk_size = chunk_range.len();
143 143
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;
145 if chunk_size % entry_size != 0 {145 if chunk_size % entry_size != 0 {
146 return Err(Error::InvalidChunkSize {146 return Err(Error::InvalidChunkSize {
147 id: COMMIT_DATA_CHUNK_ID,147 id: COMMIT_DATA_CHUNK_ID,
@@ -173,19 +173,19 @@ impl TryFrom<&Path> for File { · 25 unmodified lines
173 chunks.validated_usize_offset_by_id(OID_LOOKUP_CHUNK_ID, |chunk_range| {173 chunks.validated_usize_offset_by_id(OID_LOOKUP_CHUNK_ID, |chunk_range| {
174 let chunk_size = chunk_range.len();174 let chunk_size = chunk_range.len();
175 175
176 if chunk_size % hash_kind.len_in_bytes() != 0 {176 if chunk_size % object_hash.len_in_bytes() != 0 {
177 return Err(Error::InvalidChunkSize {177 return Err(Error::InvalidChunkSize {
178 id: OID_LOOKUP_CHUNK_ID,178 id: OID_LOOKUP_CHUNK_ID,
179 msg: format!(179 msg: format!(
180 "chunk size {} is not a multiple of {}",180 "chunk size {} is not a multiple of {}",
181 chunk_size,181 chunk_size,
182 hash_kind.len_in_bytes()182 object_hash.len_in_bytes()
183 ),183 ),
184 });184 });
185 }185 }
186 Ok((186 Ok((
187 chunk_range.start,187 chunk_range.start,
188 (chunk_size / hash_kind.len_in_bytes())188 (chunk_size / object_hash.len_in_bytes())
189 .try_into()189 .try_into()
190 .expect("number of commits in OIDL chunk to fit in 32 bits"),190 .expect("number of commits in OIDL chunk to fit in 32 bits"),
191 ))191 ))
@@ -194,10 +194,10 @@ impl TryFrom<&Path> for File { · 2 unmodified lines
194 let extra_edges_list_range = chunks.usize_offset_by_id(EXTENDED_EDGES_LIST_CHUNK_ID).ok();194 let extra_edges_list_range = chunks.usize_offset_by_id(EXTENDED_EDGES_LIST_CHUNK_ID).ok();
195 195
196 let trailer = &data[chunks.highest_offset() as usize..];196 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() {
198 return Err(Error::Trailer(format!(198 return Err(Error::Trailer(format!(
199 "Expected commit-graph trailer to contain {} bytes, got {}",199 "Expected commit-graph trailer to contain {} bytes, got {}",
200 hash_kind.len_in_bytes(),200 object_hash.len_in_bytes(),
201 trailer.len()201 trailer.len()
202 )));202 )));
203 }203 }
@@ -235,7 +235,8 @@ impl TryFrom<&Path> for File { · 31 unmodified lines
235 fan,235 fan,
236 oid_lookup_offset,236 oid_lookup_offset,
237 path: path.to_owned(),237 path: path.to_owned(),
238 hash_len: hash_kind.len_in_bytes(),238 hash_len: object_hash.len_in_bytes(),
239 object_hash,
239 })240 })
240 }241 }
241}242}
git-commitgraph/src/file/mod.rs+1−0
@@ -48,6 +48,7 @@ pub struct File { · 47 unmodified lines
48 oid_lookup_offset: usize,48 oid_lookup_offset: usize,
49 path: PathBuf,49 path: PathBuf,
50 hash_len: usize,50 hash_len: usize,
51 object_hash: git_hash::Kind,
51}52}
52 53
53/// The position of a given commit within a graph file, starting at 0.54/// 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
81 .map_err(|(actual, expected)| Error::Mismatch { actual, expected })?;81 .map_err(|(actual, expected)| Error::Mismatch { actual, expected })?;
82 verify_split_chain_filename_hash(&self.path, self.checksum()).map_err(Error::Filename)?;82 verify_split_chain_filename_hash(&self.path, self.checksum()).map_err(Error::Filename)?;
83 83
84 let null_id = self.hash_kind().null_ref();84 let null_id = self.object_hash().null_ref();
85 85
86 let mut stats = Outcome {86 let mut stats = Outcome {
87 max_generation: 0,87 max_generation: 0,
@@ -149,7 +149,7 @@ impl File { · 61 unmodified lines
149 // as these files are usually small enough to process them in less than a second, even for the large ones.149 // as these files are usually small enough to process them in less than a second, even for the large ones.
150 // But it's possible, once a progress instance is passed.150 // But it's possible, once a progress instance is passed.
151 let data_len_without_trailer = self.data.len() - self.hash_len;151 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());
153 hasher.update(&self.data[..data_len_without_trailer]);153 hasher.update(&self.data[..data_len_without_trailer]);
154 let actual = git_hash::ObjectId::from(hasher.digest().as_ref());154 let actual = git_hash::ObjectId::from(hasher.digest().as_ref());
155 155
git-commitgraph/src/graph/init.rs+3−3
@@ -98,12 +98,12 @@ impl Graph { · 97 unmodified lines
98 for window in files.windows(2) {98 for window in files.windows(2) {
99 let f1 = &window[0];99 let f1 = &window[0];
100 let f2 = &window[1];100 let f2 = &window[1];
101 if f1.hash_kind() != f2.hash_kind() {101 if f1.object_hash() != f2.object_hash() {
102 return Err(Error::HashVersionMismatch {102 return Err(Error::HashVersionMismatch {
103 path1: f1.path().to_owned(),103 path1: f1.path().to_owned(),
104 hash1: f1.hash_kind(),104 hash1: f1.object_hash(),
105 path2: f2.path().to_owned(),105 path2: f2.path().to_owned(),
106 hash2: f2.hash_kind(),106 hash2: f2.object_hash(),
107 });107 });
108 }108 }
109 }109 }

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