Skip to content

Commit 28f94b4

Browse files
committed
[commitgraph] Replace T as U with U::from(T) or t.try_into().
1 parent 5b06780 commit 28f94b4

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

git-commitgraph/src/file/access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl File {
5959

6060
// copied from git-odb/src/pack/index/access.rs
6161
pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<file::Position> {
62-
let first_byte = id.first_byte() as usize;
62+
let first_byte = usize::from(id.first_byte());
6363
let mut upper_bound = self.fan[first_byte];
6464
let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 };
6565

git-commitgraph/src/file/init.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl TryFrom<&Path> for File {
115115
let base_graph_count = data[ofs];
116116
ofs += 1;
117117

118-
let chunk_lookup_end = ofs + ((chunk_count as usize + 1) * CHUNK_LOOKUP_SIZE);
118+
let chunk_lookup_end = ofs + ((usize::from(chunk_count) + 1) * CHUNK_LOOKUP_SIZE);
119119
if chunk_lookup_end > data_size {
120120
return Err(Error::Corrupt(format!(
121121
"Commit-graph file is too small to hold {} chunks",
@@ -179,8 +179,10 @@ impl TryFrom<&Path> for File {
179179
msg: format!("chunk size {} is not a multiple of {}", chunk_size, SHA1_SIZE),
180180
});
181181
}
182-
let chunk_base_graph_count = (chunk_size / SHA1_SIZE) as u32;
183-
if chunk_base_graph_count != base_graph_count as u32 {
182+
let chunk_base_graph_count: u32 = (chunk_size / SHA1_SIZE)
183+
.try_into()
184+
.expect("base graph count to fit in 32-bits");
185+
if chunk_base_graph_count != u32::from(base_graph_count) {
184186
return Err(Error::BaseGraphMismatch {
185187
from_chunk: chunk_base_graph_count,
186188
from_header: base_graph_count,
@@ -202,7 +204,9 @@ impl TryFrom<&Path> for File {
202204
});
203205
}
204206
commit_data_offset = Some(chunk_offset);
205-
commit_data_count = (chunk_size / COMMIT_DATA_ENTRY_SIZE) as u32;
207+
commit_data_count = (chunk_size / COMMIT_DATA_ENTRY_SIZE)
208+
.try_into()
209+
.expect("number of commits in CDAT chunk to fit in 32 bits");
206210
}
207211
EXTENDED_EDGES_LIST_CHUNK_ID => {
208212
if extra_edges_list_range.is_some() {
@@ -241,7 +245,9 @@ impl TryFrom<&Path> for File {
241245
});
242246
}
243247
oid_lookup_offset = Some(chunk_offset);
244-
oid_lookup_count = (chunk_size / OID_LOOKUP_ENTRY_SIZE) as u32;
248+
oid_lookup_count = (chunk_size / OID_LOOKUP_ENTRY_SIZE)
249+
.try_into()
250+
.expect("number of commits in OIDL chunk to fit in 32 bits");
245251
// TODO(ST): Figure out how to handle this. Don't know what to do with the commented code.
246252
// git allows extra garbage in the extra edges list chunk?
247253
// if oid_lookup_count > 0 {

git-commitgraph/src/graph/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl Graph {
8282
}
8383

8484
pub fn new(files: Vec<File>) -> Result<Self, Error> {
85-
let num_commits: u64 = files.iter().map(|f| f.num_commits() as u64).sum();
86-
if num_commits > MAX_COMMITS as u64 {
85+
let num_commits: u64 = files.iter().map(|f| u64::from(f.num_commits())).sum();
86+
if num_commits > u64::from(MAX_COMMITS) {
8787
return Err(Error::TooManyCommits(num_commits));
8888
}
8989

0 commit comments

Comments
 (0)