Skip to content

Commit fbb9f98

Browse files
committed
fix naming change, which was introduced accidentally
…auto-refactoring gone wrong :D
1 parent 8ea05de commit fbb9f98

File tree

11 files changed

+105
-104
lines changed

11 files changed

+105
-104
lines changed

Diff for: git-odb/src/loose/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ const HEADER_READ_COMPRESSED_BYTES: usize = 256;
22
const HEADER_READ_UNCOMPRESSED_BYTES: usize = 512;
33

44
pub(crate) mod db;
5-
mod object;
5+
6+
pub mod object;
7+
pub use object::*;
68

79
pub mod stream;
810

9-
pub use db::{Db, Error as DbError};
10-
pub use object::*;
11+
pub use db::{Db, Error};

Diff for: git-odb/src/loose/object.rs

+77-77
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
use crate::{
2-
loose::stream::ObjectReader,
3-
loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES},
4-
zlib,
5-
};
1+
use crate::loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES};
62
use git_object as object;
7-
use miniz_oxide::inflate::decompress_to_vec_zlib;
8-
use object::borrowed;
9-
use quick_error::quick_error;
103
use smallvec::SmallVec;
11-
use std::{io::Read, path::PathBuf};
12-
13-
quick_error! {
14-
#[derive(Debug)]
15-
pub enum Error {
16-
Decompress(err: zlib::Error) {
17-
display("decompression of object data failed")
18-
from()
19-
cause(err)
20-
}
21-
ParseTag(err: borrowed::Error) {
22-
display("Could not parse tag object")
23-
from()
24-
cause(err)
25-
}
26-
Io(err: std::io::Error, action: &'static str, path: PathBuf) {
27-
display("Could not {} data at '{}'", action, path.display())
28-
cause(err)
29-
}
30-
}
31-
}
4+
use std::path::PathBuf;
325

336
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
347
pub struct Object {
@@ -41,59 +14,86 @@ pub struct Object {
4114
pub(crate) decompression_complete: bool,
4215
}
4316

44-
impl Object {
45-
// Note: Blobs are loaded or mapped into memory and are made available that way.
46-
// Consider the streaming API if large Blobs are expected.
47-
pub fn decode(&mut self) -> Result<borrowed::Object, Error> {
48-
self.decompress_all()?;
49-
let bytes = &self.decompressed_data[self.header_size..];
50-
Ok(match self.kind {
51-
object::Kind::Tag => borrowed::Object::Tag(borrowed::Tag::from_bytes(bytes)?),
52-
object::Kind::Tree => borrowed::Object::Tree(borrowed::Tree::from_bytes(bytes)?),
53-
object::Kind::Commit => borrowed::Object::Commit(borrowed::Commit::from_bytes(bytes)?),
54-
object::Kind::Blob => borrowed::Object::Blob(borrowed::Blob { data: bytes }),
55-
})
56-
}
17+
pub mod decode {
18+
use crate::{loose, loose::stream::Reader, zlib};
19+
use git_object as object;
20+
use miniz_oxide::inflate::decompress_to_vec_zlib;
21+
use object::borrowed;
22+
use quick_error::quick_error;
23+
use smallvec::SmallVec;
24+
use std::{io::Read, path::PathBuf};
5725

58-
pub fn stream(&self) -> Result<ObjectReader, Error> {
59-
match &self.path {
60-
Some(path) => Ok(ObjectReader::from_read(
61-
self.header_size,
62-
std::fs::File::open(path).map_err(|e| Error::Io(e, "open", path.to_owned()))?,
63-
)),
64-
None => Ok(ObjectReader::from_data(
65-
self.header_size,
66-
&self.decompressed_data.as_slice(),
67-
)),
26+
quick_error! {
27+
#[derive(Debug)]
28+
pub enum Error {
29+
Decompress(err: zlib::Error) {
30+
display("decompression of object data failed")
31+
from()
32+
cause(err)
33+
}
34+
ParseTag(err: borrowed::Error) {
35+
display("Could not parse tag object")
36+
from()
37+
cause(err)
38+
}
39+
Io(err: std::io::Error, action: &'static str, path: PathBuf) {
40+
display("Could not {} data at '{}'", action, path.display())
41+
cause(err)
42+
}
6843
}
6944
}
7045

71-
fn decompress_all(&mut self) -> Result<(), Error> {
72-
if self.decompression_complete {
73-
debug_assert!(
74-
self.size + self.header_size == self.decompressed_data.len(),
75-
"when decompression is done, we have stored everything in memory"
76-
);
77-
return Ok(());
46+
impl loose::Object {
47+
// Note: Blobs are loaded or mapped into memory and are made available that way.
48+
// Consider the streaming API if large Blobs are expected.
49+
pub fn decode(&mut self) -> Result<borrowed::Object, Error> {
50+
self.decompress_all()?;
51+
let bytes = &self.decompressed_data[self.header_size..];
52+
Ok(match self.kind {
53+
object::Kind::Tag => borrowed::Object::Tag(borrowed::Tag::from_bytes(bytes)?),
54+
object::Kind::Tree => borrowed::Object::Tree(borrowed::Tree::from_bytes(bytes)?),
55+
object::Kind::Commit => borrowed::Object::Commit(borrowed::Commit::from_bytes(bytes)?),
56+
object::Kind::Blob => borrowed::Object::Blob(borrowed::Blob { data: bytes }),
57+
})
7858
}
79-
let total_size = self.header_size + self.size;
80-
if let Some(path) = self.path.take() {
81-
// NOTE: For now we just re-read everything from the beginning without seeking, as our buffer
82-
// is small so the seek might be more expensive than just reading everything.
83-
let mut file = std::fs::File::open(&path).map_err(|e| Error::Io(e, "open", path.clone()))?;
84-
let file_size = file
85-
.metadata()
86-
.map_err(|e| Error::Io(e, "read metadata", path.clone()))?
87-
.len() as usize;
88-
let mut buf = Vec::with_capacity(file_size);
89-
file.read_to_end(&mut buf).map_err(|e| Error::Io(e, "read", path))?;
90-
self.compressed_data = SmallVec::from(buf);
59+
60+
pub fn stream(&self) -> Result<Reader, Error> {
61+
match &self.path {
62+
Some(path) => Ok(Reader::from_read(
63+
self.header_size,
64+
std::fs::File::open(path).map_err(|e| Error::Io(e, "open", path.to_owned()))?,
65+
)),
66+
None => Ok(Reader::from_data(self.header_size, &self.decompressed_data.as_slice())),
67+
}
68+
}
69+
70+
fn decompress_all(&mut self) -> Result<(), Error> {
71+
if self.decompression_complete {
72+
debug_assert!(
73+
self.size + self.header_size == self.decompressed_data.len(),
74+
"when decompression is done, we have stored everything in memory"
75+
);
76+
return Ok(());
77+
}
78+
let total_size = self.header_size + self.size;
79+
if let Some(path) = self.path.take() {
80+
// NOTE: For now we just re-read everything from the beginning without seeking, as our buffer
81+
// is small so the seek might be more expensive than just reading everything.
82+
let mut file = std::fs::File::open(&path).map_err(|e| Error::Io(e, "open", path.clone()))?;
83+
let file_size = file
84+
.metadata()
85+
.map_err(|e| Error::Io(e, "read metadata", path.clone()))?
86+
.len() as usize;
87+
let mut buf = Vec::with_capacity(file_size);
88+
file.read_to_end(&mut buf).map_err(|e| Error::Io(e, "read", path))?;
89+
self.compressed_data = SmallVec::from(buf);
90+
}
91+
self.decompressed_data = SmallVec::from(decompress_to_vec_zlib(&self.compressed_data[..]).unwrap());
92+
self.decompressed_data.shrink_to_fit();
93+
assert!(self.decompressed_data.len() == total_size);
94+
self.decompression_complete = true;
95+
self.compressed_data = Default::default();
96+
Ok(())
9197
}
92-
self.decompressed_data = SmallVec::from(decompress_to_vec_zlib(&self.compressed_data[..]).unwrap());
93-
self.decompressed_data.shrink_to_fit();
94-
assert!(self.decompressed_data.len() == total_size);
95-
self.decompression_complete = true;
96-
self.compressed_data = Default::default();
97-
Ok(())
9898
}
9999
}

Diff for: git-odb/src/loose/stream.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
use crate::zlib::stream::InflateReader;
22
use std::io::BufReader;
33

4-
pub enum ObjectReader<'data> {
4+
pub enum Reader<'data> {
55
File(usize, InflateReader<BufReader<std::fs::File>>),
66
Buffer(&'data [u8]),
77
}
88

9-
impl<'data> ObjectReader<'data> {
10-
pub fn from_read(header_size: usize, file: std::fs::File) -> ObjectReader<'data> {
11-
ObjectReader::File(header_size, InflateReader::new(file))
9+
impl<'data> Reader<'data> {
10+
pub fn from_read(header_size: usize, file: std::fs::File) -> Reader<'data> {
11+
Reader::File(header_size, InflateReader::new(file))
1212
}
13-
pub fn from_data(header_size: usize, data: &'data [u8]) -> ObjectReader<'data> {
14-
ObjectReader::Buffer(&data[header_size..])
13+
pub fn from_data(header_size: usize, data: &'data [u8]) -> Reader<'data> {
14+
Reader::Buffer(&data[header_size..])
1515
}
1616
}
1717

18-
impl<'data> std::io::Read for ObjectReader<'data> {
18+
impl<'data> std::io::Read for Reader<'data> {
1919
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
2020
match self {
21-
ObjectReader::Buffer(data) => data.read(buf),
22-
ObjectReader::File(header_size_left, r) => {
21+
Reader::Buffer(data) => data.read(buf),
22+
Reader::File(header_size_left, r) => {
2323
if *header_size_left == 0 {
2424
r.read(buf)
2525
} else {

Diff for: git-odb/src/pack/bundle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ quick_error! {
1111
#[derive(Debug)]
1212
pub enum Error {
1313
InvalidPath(path: PathBuf) {
14-
display("An 'idx' extension is expected of an index data: '{}'", path.display())
14+
display("An 'idx' extension is expected of an index file: '{}'", path.display())
1515
}
1616
Pack(err: pack::data::init::Error) {
1717
display("Could not instantiate pack")
@@ -36,7 +36,7 @@ pub struct Bundle {
3636
}
3737

3838
impl Bundle {
39-
/// `path` is either a pack data or an index data
39+
/// `path` is either a pack file or an index file
4040
pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> {
4141
Self::try_from(path.as_ref())
4242
}

Diff for: git-odb/src/pack/data/decode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl File {
8585
}
8686

8787
/// Currently only done during pack verification - finding the right size is only possible by decompressing
88-
/// the pack entry beforehand, or by using the (to be sorted) offsets stored in an index data.
88+
/// the pack entry beforehand, or by using the (to be sorted) offsets stored in an index file.
8989
pub fn entry_crc32(&self, pack_offset: u64, size: usize) -> u32 {
9090
let pack_offset: usize = pack_offset.try_into().expect("pack_size fits into usize");
9191
git_features::hash::crc32(&self.data[pack_offset..pack_offset + size])

Diff for: git-odb/src/pack/data/init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ quick_error! {
99
#[derive(Debug)]
1010
pub enum Error {
1111
Io(err: std::io::Error, path: std::path::PathBuf) {
12-
display("Could not open pack data at '{}'", path.display())
12+
display("Could not open pack file at '{}'", path.display())
1313
cause(err)
1414
}
1515
Corrupt(msg: String) {

Diff for: git-odb/src/pack/data/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ quick_error! {
99
display("pack checksum mismatch: expected {}, got {}", expected, actual)
1010
}
1111
Io(err: std::io::Error) {
12-
display("could not read pack data")
12+
display("could not read pack file")
1313
from()
1414
cause(err)
1515
}

Diff for: git-odb/src/pack/index/init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ quick_error! {
99
#[derive(Debug)]
1010
pub enum Error {
1111
Io(err: std::io::Error, path: std::path::PathBuf) {
12-
display("Could not open pack index data at '{}'", path.display())
12+
display("Could not open pack index file at '{}'", path.display())
1313
cause(err)
1414
}
1515
Corrupt(msg: String) {

Diff for: git-odb/src/pack/index/verify.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ quick_error! {
1616
display("index checksum mismatch: expected {}, got {}", expected, actual)
1717
}
1818
PackChecksum(err: pack::data::verify::Error) {
19-
display("The pack of this index data failed to verify its checksums")
19+
display("The pack of this index file failed to verify its checksums")
2020
from()
2121
cause(err)
2222
}
@@ -25,13 +25,13 @@ quick_error! {
2525
cause(err)
2626
}
2727
PackMismatch { expected: git_object::Id, actual: git_object::Id } {
28-
display("The packfiles checksum didn't match the index data checksum: expected {}, got {}", expected, actual)
28+
display("The packfiles checksum didn't match the index file checksum: expected {}, got {}", expected, actual)
2929
}
3030
PackObjectMismatch { expected: git_object::Id, actual: git_object::Id, offset: u64, kind: git_object::Kind} {
31-
display("The SHA1 of {} object at offset {} didn't match the checksum in the index data: expected {}, got {}", kind, offset, expected, actual)
31+
display("The SHA1 of {} object at offset {} didn't match the checksum in the index file: expected {}, got {}", kind, offset, expected, actual)
3232
}
3333
Crc32Mismatch { expected: u32, actual: u32, offset: u64, kind: git_object::Kind} {
34-
display("The CRC32 of {} object at offset {} didn't match the checksum in the index data: expected {}, got {}", kind, offset, expected, actual)
34+
display("The CRC32 of {} object at offset {} didn't match the checksum in the index file: expected {}, got {}", kind, offset, expected, actual)
3535
}
3636
}
3737
}
@@ -76,7 +76,7 @@ pub struct Outcome {
7676
pub pack_size: u64,
7777
}
7878

79-
/// Verify and validate the content of the index data
79+
/// Verify and validate the content of the index file
8080
impl index::File {
8181
pub fn checksum_of_index(&self) -> git_object::Id {
8282
git_object::Id::from_20_bytes(&self.data[self.data.len() - SHA1_SIZE..])

Diff for: gitoxide-core/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ where
114114
})?;
115115
let res = match ext {
116116
"pack" => {
117-
let pack = git_odb::pack::data::File::at(path).with_context(|| "Could not open pack data")?;
117+
let pack = git_odb::pack::data::File::at(path).with_context(|| "Could not open pack file")?;
118118
pack.verify_checksum().map(|id| (id, None))?
119119
}
120120
"idx" => {
121-
let idx = git_odb::pack::index::File::at(path).with_context(|| "Could not open pack index data")?;
121+
let idx = git_odb::pack::index::File::at(path).with_context(|| "Could not open pack index file")?;
122122
let packfile_path = path.with_extension("pack");
123123
let pack = git_odb::pack::data::File::at(&packfile_path)
124124
.or_else(|e| {
125125
writeln!(
126126
err,
127-
"Could not find matching pack data at '{}' - only index data will be verified, error was: {}",
127+
"Could not find matching pack file at '{}' - only index file will be verified, error was: {}",
128128
packfile_path.display(),
129129
e
130130
)

Diff for: src/plumbing/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod options {
2626

2727
#[derive(Debug, StructOpt)]
2828
pub enum Subcommands {
29-
/// Verify the integrity of a pack or index data
29+
/// Verify the integrity of a pack or index file
3030
#[structopt(setting = AppSettings::ColoredHelp)]
3131
VerifyPack {
3232
/// output statistical information about the pack

0 commit comments

Comments
 (0)