Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 12, 2020
1 parent db3c343 commit 2aa0857
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 64 deletions.
3 changes: 1 addition & 2 deletions git-core/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const TPL_HOOKS_PREPARE_COMMIT_MSG: &'static [u8] =
include_bytes!("../../tests/snapshots/cli/baseline-init/hooks/prepare-commit-msg.sample");
const TPL_HOOKS_UPDATE: &'static [u8] =
include_bytes!("../../tests/snapshots/cli/baseline-init/hooks/update.sample");
const TPL_CONFIG: &'static [u8] =
include_bytes!("../../tests/snapshots/cli/baseline-init/config");
const TPL_CONFIG: &'static [u8] = include_bytes!("../../tests/snapshots/cli/baseline-init/config");
const TPL_DESCRIPTION: &'static [u8] =
include_bytes!("../../tests/snapshots/cli/baseline-init/description");
const TPL_HEAD: &'static [u8] = include_bytes!("../../tests/snapshots/cli/baseline-init/HEAD");
Expand Down
8 changes: 6 additions & 2 deletions git-odb/examples/git-count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ extern crate failure;
extern crate git_odb as odb;

use failure::{Error, ResultExt};
use std::{env, io::{stdout, Write}};
use std::{
env,
io::{stdout, Write},
};

fn run() -> Result<(), Error> {
let mut args = env::args().skip(1);
Expand Down Expand Up @@ -37,7 +40,8 @@ fn run() -> Result<(), Error> {
blobs,
tags,
deltas,
).map_err(Into::into)
)
.map_err(Into::into)
}

fn main() -> Result<(), Error> {
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ extern crate walkdir;
#[macro_use]
extern crate itertools;

mod zlib;
mod types;
mod zlib;

pub mod object;
pub mod loose;
pub mod object;
pub mod pack;

pub use types::*;
5 changes: 3 additions & 2 deletions git-odb/src/loose/db.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::object::Id;

use walkdir::WalkDir;
use failure::Error;
use hex::FromHex;
use std::path::PathBuf;
use walkdir::WalkDir;

pub struct Db {
pub path: PathBuf,
Expand All @@ -21,7 +21,8 @@ impl Db {
let mut is_valid_path = false;
let e = e.map_err(Error::from).map(|e| {
let p = e.path();
let (c1, c2) = p.components()
let (c1, c2) = p
.components()
.fold((None, None), |(_c1, c2), cn| (c2, Some(cn)));
if let (Some(Normal(c1)), Some(Normal(c2))) = (c1, c2) {
if c1.len() == 2 && c2.len() == 38 {
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/loose/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const HEADER_READ_COMPRESSED_BYTES: usize = 512;
const HEADER_READ_UNCOMPRESSED_BYTES: usize = 1024;

mod object;
mod db;
mod object;

pub use self::db::*;
pub use self::object::*;
23 changes: 6 additions & 17 deletions git-odb/src/loose/object.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
use crate::{
zlib,
object::{parsed, Kind},
loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES},
loose::Db,
object::Id
};
use failure::{
err_msg,
ResultExt,
Error
loose::{HEADER_READ_COMPRESSED_BYTES, HEADER_READ_UNCOMPRESSED_BYTES},
object::Id,
object::{parsed, Kind},
zlib,
};
use failure::{err_msg, Error, ResultExt};
use hex::ToHex;
use smallvec::SmallVec;
use std::{
io::Cursor,
path::PathBuf,
str,
fs::File,
io::Read,
os::unix::fs::MetadataExt
};
use std::{fs::File, io::Cursor, io::Read, os::unix::fs::MetadataExt, path::PathBuf, str};

pub struct Object {
pub kind: Kind,
Expand Down
10 changes: 5 additions & 5 deletions git-odb/src/object/parsed.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use failure::{err_msg, Error, ResultExt};
use crate::{
object::{Id, Kind},
Sign,
Time
Sign, Time,
};
use std::str;
use failure::{err_msg, Error, ResultExt};
use hex::FromHex;
use std::str;

const PGP_SIGNATURE_BEGIN: &'static [u8] = b"-----BEGIN PGP SIGNATURE-----";
const PGP_SIGNATURE_END: &'static [u8] = b"-----END PGP SIGNATURE-----";
Expand Down Expand Up @@ -80,7 +79,8 @@ fn parse_timezone_offset(d: &str) -> Result<(i32, Sign), Error> {

fn parse_signature(d: &[u8]) -> Result<Signature, Error> {
const ONE_SPACE: usize = 1;
let email_begin = d.iter()
let email_begin = d
.iter()
.position(|&b| b == b'<')
.ok_or_else(|| err_msg("Could not find beginning of email marked by '<'"))
.and_then(|pos| {
Expand Down
35 changes: 18 additions & 17 deletions git-odb/src/pack/index.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::object::{self, SHA1_SIZE};
use byteorder::{BigEndian, ByteOrder};
use failure::{Error, ResultExt};
use std::path::Path;
use filebuffer::FileBuffer;
use byteorder::{BigEndian, ByteOrder};
use crate::object::{self, SHA1_SIZE};
use std::mem::size_of;
use std::path::Path;

const V2_SIGNATURE: &'static [u8] = b"\xfftOc";
const FOOTER_SIZE: usize = SHA1_SIZE * 2;
Expand Down Expand Up @@ -95,20 +95,21 @@ impl File {
self.data[V2_SHA1_OFFSET..].chunks(SHA1_SIZE),
self.data[self.offset_crc32_v2()..].chunks(N32_SIZE),
self.data[self.offset_pack_offset_v2()..].chunks(N32_SIZE)
).take(self.size as usize)
.map(move |(oid, crc32, ofs32)| Entry {
oid: object::id_from_20_bytes(oid),
offset: {
let ofs32 = BigEndian::read_u32(ofs32);
if ofs32 > MAX_N31 {
let from = pack64_offset + (ofs32 as usize >> 1) * N64_SIZE;
BigEndian::read_u64(&self.data[from..from + N64_SIZE])
} else {
ofs32 as u64
}
},
crc32: Some(BigEndian::read_u32(crc32)),
}),
)
.take(self.size as usize)
.map(move |(oid, crc32, ofs32)| Entry {
oid: object::id_from_20_bytes(oid),
offset: {
let ofs32 = BigEndian::read_u32(ofs32);
if ofs32 > MAX_N31 {
let from = pack64_offset + (ofs32 as usize >> 1) * N64_SIZE;
BigEndian::read_u64(&self.data[from..from + N64_SIZE])
} else {
ofs32 as u64
}
},
crc32: Some(BigEndian::read_u32(crc32)),
}),
_ => bail!("Cannot use iter_v2() on index of type {:?}", self.kind),
})
}
Expand Down
9 changes: 5 additions & 4 deletions git-odb/src/pack/pack.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use failure::{Error, ResultExt};

use byteorder::{BigEndian, ByteOrder};
use std::{mem::size_of, path::Path};
use filebuffer::FileBuffer;
use std::{mem::size_of, path::Path};

use crate::object::SHA1_SIZE;

Expand Down Expand Up @@ -62,8 +62,9 @@ impl File {
}

pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> {
let data = FileBuffer::open(path.as_ref())
.with_context(|_| format!("Could not map pack file at '{}'", path.as_ref().display()))?;
let data = FileBuffer::open(path.as_ref()).with_context(|_| {
format!("Could not map pack file at '{}'", path.as_ref().display())
})?;
let pack_len = data.len();
if pack_len < N32_SIZE * 3 + SHA1_SIZE {
bail!(
Expand Down Expand Up @@ -91,8 +92,8 @@ impl File {
pub mod parsed {
use crate::object;

use std::mem;
use crate::object::SHA1_SIZE;
use std::mem;

const _TYPE_EXT1: u8 = 0;
const COMMIT: u8 = 1;
Expand Down
18 changes: 12 additions & 6 deletions git-odb/src/zlib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use failure::Error;
use miniz_oxide::inflate::core::DecompressorOxide;
use miniz_oxide::inflate::{
core::{
decompress,
inflate_flags::{
TINFL_FLAG_HAS_MORE_INPUT, TINFL_FLAG_PARSE_ZLIB_HEADER,
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF,
},
},
TINFLStatus,
};
use std::io::{self, Cursor};
use miniz_oxide::inflate::{TINFLStatus,
core::{decompress,
inflate_flags::{TINFL_FLAG_HAS_MORE_INPUT,
TINFL_FLAG_PARSE_ZLIB_HEADER,
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF}}};

pub struct Inflate {
inner: DecompressorOxide,
Expand Down Expand Up @@ -64,7 +69,8 @@ impl Inflate {
&mut self.inner,
input,
out,
TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_HAS_MORE_INPUT
TINFL_FLAG_PARSE_ZLIB_HEADER
| TINFL_FLAG_HAS_MORE_INPUT
| TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF,
);

Expand Down
9 changes: 6 additions & 3 deletions git-odb/tests/loose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ mod utils;

use utils::*;

use std::{fs::File, io::Read};
use odb::{loose::Db, object::{parsed, Kind}};
use odb::Time;
use odb::Sign;
use odb::Time;
use odb::{
loose::Db,
object::{parsed, Kind},
};
use std::{fs::File, io::Read};

pub fn fixture_bytes(path: &str) -> Vec<u8> {
let mut buf = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion git-odb/tests/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate hex;
mod utils;

use odb::pack::{self, index};
use utils::fixture;
use utils::bin;
use utils::fixture;

const INDEX_V1: &'static str = "packs/pack-c0438c19fb16422b6bbcce24387b3264416d485b.idx";
const PACK_FOR_INDEX_V1: &'static str = "packs/pack-c0438c19fb16422b6bbcce24387b3264416d485b.pack";
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate failure_tools;
extern crate clap;
extern crate git_core as git;

use failure_tools::ok_or_exit;
use failure::{Error, ResultExt};
use failure_tools::ok_or_exit;

mod app {
use clap::{App, AppSettings, SubCommand};
Expand All @@ -26,7 +26,8 @@ fn run() -> Result<(), Error> {
match matches.subcommand() {
("init", Some(_args)) => git::init().with_context(|_| "Repository initialization failed"),
_ => unreachable!(),
}.map_err(Into::into)
}
.map_err(Into::into)
}

fn main() {
Expand Down

0 comments on commit 2aa0857

Please sign in to comment.