History

git-core: get rid of failure crate in favor of quick-error

Sebastian Thiel committed 6 years ago

Commit 91c8fc11 parent f037c4d3 files · +26 −18Browse files

Unified · Split

3 files
  1. git-core/src/init.rs +24 −13
  2. git-core/src/lib.rs +1 −4
  3. git-odb/src/object/parsed.rs +1 −1
git-core/src/init.rs+24−13
@@ -1,6 +1,5 @@
1use failure::{Error, ResultExt};
2use std::{1use std::{
3 fs::{create_dir, OpenOptions},2 fs::{self, OpenOptions},
4 io::Write,3 io::Write,
5 path::Path,4 path::Path,
6 path::PathBuf,5 path::PathBuf,
@@ -10,7 +9,18 @@ quick_error! { · 3 unmodified lines
10 #[derive(Debug)]9 #[derive(Debug)]
11 pub enum InitError {10 pub enum InitError {
12 IoOpen(err: std::io::Error, path: PathBuf) {11 IoOpen(err: std::io::Error, path: PathBuf) {
13 display("Could not open file at {:#?}", path.display())12 display("Could not open file at '{}'", path.display())
13 cause(err)
14 }
15 IoWrite(err: std::io::Error, path: PathBuf) {
16 display("Could not write file at '{}'", path.display())
17 cause(err)
18 }
19 DirectoryExists(path: PathBuf) {
20 display("Refusing to initialize the existing '{}' directory", path.display())
21 }
22 CreateDirectory(err: std::io::Error, path: PathBuf) {
23 display("Cold not create directory at '{}'", path.display())
14 cause(err)24 cause(err)
15 }25 }
16 }26 }
@@ -59,7 +69,7 @@ impl<'a> PathCursor<'a> { · 42 unmodified lines
59}69}
60 70
61impl<'a> NewDir<'a> {71impl<'a> NewDir<'a> {
62 fn at(self, component: &str) -> Result<Self, Error> {72 fn at(self, component: &str) -> Result<Self, InitError> {
63 self.0.push(component);73 self.0.push(component);
64 create_dir(&self.0)?;74 create_dir(&self.0)?;
65 Ok(self)75 Ok(self)
@@ -81,24 +91,25 @@ impl<'a> Drop for PathCursor<'a> { · 15 unmodified lines
81 }91 }
82}92}
83 93
84fn write_file(data: &[u8], path: &Path) -> Result<(), Error> {94fn write_file(data: &[u8], path: &Path) -> Result<(), InitError> {
85 let mut file = OpenOptions::new()95 let mut file = OpenOptions::new()
86 .write(true)96 .write(true)
87 .create(true)97 .create(true)
88 .append(false)98 .append(false)
89 .open(path)?;99 .open(path)
100 .map_err(|e| InitError::IoOpen(e, path.to_owned()))?;
90 file.write_all(data)101 file.write_all(data)
91 .with_context(|_| format!("Could not initialize file at '{}'", path.display()))102 .map_err(|e| InitError::IoWrite(e, path.to_owned()))
92 .map_err(Into::into)103}
104
105fn create_dir(p: &Path) -> Result<(), InitError> {
106 fs::create_dir(p).map_err(|e| InitError::CreateDirectory(e, p.to_owned()))
93}107}
94 108
95pub fn init() -> Result<(), Error> {109pub fn init() -> Result<(), InitError> {
96 let mut cursor = PathBuf::from(GIT_DIR_NAME);110 let mut cursor = PathBuf::from(GIT_DIR_NAME);
97 if cursor.is_dir() {111 if cursor.is_dir() {
98 bail!(112 return Err(InitError::DirectoryExists(cursor));
99 "Refusing to initialize the existing '{}' directory",
100 cursor.display()
101 )
102 }113 }
103 create_dir(&cursor)?;114 create_dir(&cursor)?;
104 115
git-core/src/lib.rs+1−4
@@ -1,9 +1,6 @@
1#[macro_use]
2extern crate failure;
3
4#[macro_use]1#[macro_use]
5extern crate quick_error;2extern crate quick_error;
6 3
7mod init;4mod init;
8 5
9pub use init::init;6pub use init::{init, InitError};
git-odb/src/object/parsed.rs+1−1
@@ -137,7 +137,7 @@ fn parse_message<'data>( · 136 unmodified lines
137 }137 }
138 let mut msg_end = d.len();138 let mut msg_end = d.len();
139 let mut pgp_signature = None;139 let mut pgp_signature = None;
140 if let Some(pgp_begin_line) = lines.find(|l| l.starts_with(PGP_SIGNATURE_BEGIN)) {140 if let Some(_pgp_begin_line) = lines.find(|l| l.starts_with(PGP_SIGNATURE_BEGIN)) {
141 match lines.find(|l| l.starts_with(PGP_SIGNATURE_END)) {141 match lines.find(|l| l.starts_with(PGP_SIGNATURE_END)) {
142 None => bail!("Didn't find end of signature marker"),142 None => bail!("Didn't find end of signature marker"),
143 Some(_) => {143 Some(_) => {