summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Grunert <Sascha.Grunert@rohde-schwarz.com>2016-11-11 10:59:21 +0100
committerSascha Grunert <Sascha.Grunert@rohde-schwarz.com>2016-11-11 10:59:21 +0100
commitd3f81d281e944baf640308ecf7c77248e257ddce (patch)
tree5602cdfc2256b883821d86e39b9f0c2feb2d7b3d
parentd86f7de27ed055023dc019511efd611acda63c43 (diff)
Changed try! to ?
-rw-r--r--Cargo.lock84
-rw-r--r--src/config.rs23
-rw-r--r--src/lib.rs99
-rw-r--r--src/logger.rs32
-rw-r--r--src/main.rs26
-rw-r--r--src/parser.rs239
6 files changed, 236 insertions, 267 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 648feff..09d586a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,14 +3,14 @@ name = "git-journal"
version = "1.1.0"
dependencies = [
"chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
- "clap 2.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "git2 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clap 2.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "git2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -44,7 +44,7 @@ dependencies = [
[[package]]
name = "clap"
-version = "2.17.1"
+version = "2.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -68,13 +68,13 @@ dependencies = [
[[package]]
name = "curl-sys"
-version = "0.2.4"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -103,12 +103,14 @@ dependencies = [
[[package]]
name = "git2"
-version = "0.5.0"
+version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-probe 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -143,36 +145,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libgit2-sys"
-version = "0.5.1"
+version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cmake 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
- "curl-sys 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "libssh2-sys 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libssh2-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
-name = "libressl-pnacl-sys"
-version = "2.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "libssh2-sys"
-version = "0.1.39"
+version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cmake 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -254,13 +248,17 @@ dependencies = [
]
[[package]]
+name = "openssl-probe"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "openssl-sys"
-version = "0.7.17"
+version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
- "libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -271,14 +269,6 @@ version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "pnacl-build-helper"
-version = "1.4.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "rand"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -316,7 +306,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
-version = "0.3.19"
+version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -325,14 +315,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "tempdir"
-version = "0.3.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "term"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -383,7 +365,7 @@ name = "toml"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -457,20 +439,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00"
-"checksum clap 2.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27dac76762fb56019b04aed3ccb43a770a18f80f9c2eb62ee1a18d9fb4ea2430"
+"checksum clap 2.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "40046b8a004bf3ba43b9078bf4b9b6d1708406a234848f925dbd7160a374c8a8"
"checksum cmake 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0e5bcf27e097a184c1df4437654ed98df3d7a516e8508a6ba45d8b092bbdf283"
-"checksum curl-sys 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4f198d10378a3bc1f1b0e3bc3a2de5c9bb9e08938460dec57ba6667d9a65fbc3"
+"checksum curl-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "55800e1d1ebc1361fc4eda26fbc1bf3779c09b017bc9ab2ce8f0b0441b722946"
"checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf"
"checksum gcc 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)" = "553f11439bdefe755bf366b264820f1da70f3aaf3924e594b886beb9c831bcf5"
"checksum gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0912515a8ff24ba900422ecda800b52f4016a56251922d397c576bf92c690518"
-"checksum git2 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f6419fd6f609a1a2fbbee5dffdb2c26e8e5cd0c06d558d17d3381187e03bbe18"
+"checksum git2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae93eae026f17b013912629d243444e52ee5d6b1339e71d5212099d1d1b73fc2"
"checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f"
"checksum libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "044d1360593a78f5c8e5e710beccdc24ab71d1f01bc19a29bcacdba22e8475d8"
-"checksum libgit2-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd65176b163aa0667afe8e0bac790d353ff64160f8289a4b7197878a3f336a1"
-"checksum libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "cbc058951ab6a3ef35ca16462d7642c4867e6403520811f28537a4e2f2db3e71"
-"checksum libssh2-sys 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1debd7e56d19655eb786f827675dc55f6d530de6d7b81e76d13d1afc635d6c07"
+"checksum libgit2-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ac5f3385d84817fd20f9c2c61f1ed598af9d2be68aaafb106c5e96365fe7aee4"
+"checksum libssh2-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "538844618f14e5e919332beaf718cf22b63b18cb9b37370560cd1bc55b2734f8"
"checksum libz-sys 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "40f2df7730b5d29426c3e44ce4d088d8c5def6471c2c93ba98585b89fb201ce6"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1"
@@ -481,16 +462,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c"
"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
"checksum num_cpus 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8890e6084723d57d0df8d2720b0d60c6ee67d6c93e7169630e4371e88765dcad"
-"checksum openssl-sys 0.7.17 (registry+https://github.com/rust-lang/crates.io-index)" = "89c47ee94c352eea9ddaf8e364be7f978a3bb6d66d73176572484238dd5a5c3f"
+"checksum openssl-probe 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "756d49c8424483a3df3b5d735112b4da22109ced9a8294f1f5cdf80fb3810919"
+"checksum openssl-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "48b25c7337949b0e04625444efbff87bef5251e1a4d19aeac6d317d49c8a8df3"
"checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa"
-"checksum pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "61c9231d31aea845007443d62fcbb58bb6949ab9c18081ee1e09920e0cf1118b"
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
"checksum rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b6a6e05e0e6b703e9f2ad266eb63f3712e693a17a2702b95a23de14ce8defa9"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
-"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
+"checksum rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)" = "bff9fc1c79f2dec76b253273d07682e94a978bd8f132ded071188122b2af9818"
"checksum strsim 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "50c069df92e4b01425a8bf3576d5d417943a6a7272fbabaf5bd80b1aaa76442e"
-"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
"checksum term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3deff8a2b3b6607d6d7cc32ac25c0b33709453ca9cceac006caac51e963cf94a"
"checksum term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7f5f3f71b0040cecc71af239414c23fd3c73570f5ff54cf50e03cef637f2a0"
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
diff --git a/src/config.rs b/src/config.rs
index fbb39b9..fd7b95b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -124,15 +124,15 @@ impl Config {
///
pub fn save_default_config(&self, path: &str) -> Result<String, Error> {
let mut encoder = Encoder::new();
- try!(self.encode(&mut encoder));
+ self.encode(&mut encoder)?;
let toml_string = encode_str(&Value::Table(encoder.toml));
let path_buf = self.get_path_with_filename(path);
- let path_string = try!(path_buf.to_str()
- .ok_or(io::Error::new(io::ErrorKind::Other, "Cannot convert path to string")));
+ let path_string = path_buf.to_str()
+ .ok_or(io::Error::new(io::ErrorKind::Other, "Cannot convert path to string"))?;
- let mut file = try!(File::create(&path_buf));
- try!(file.write_all(toml_string.as_bytes()));
+ let mut file = File::create(&path_buf)?;
+ file.write_all(toml_string.as_bytes())?;
Ok(path_string.to_owned())
}
@@ -150,15 +150,14 @@ impl Config {
///
pub fn load(&mut self, path: &str) -> Result<(), Error> {
let path_buf = self.get_path_with_filename(path);
- let mut file = try!(File::open(path_buf));
+ let mut file = File::open(path_buf)?;
let mut toml_string = String::new();
- try!(file.read_to_string(&mut toml_string));
+ file.read_to_string(&mut toml_string)?;
- let toml = try!(Parser::new(&toml_string)
- .parse()
- .ok_or(toml::Error::Custom("Could not parse toml configuration.".to_owned())));
- *self = try!(decode(Value::Table(toml))
- .ok_or(toml::Error::Custom("Could not decode toml configuration.".to_owned())));
+ let toml = Parser::new(&toml_string).parse()
+ .ok_or(toml::Error::Custom("Could not parse toml configuration.".to_owned()))?;
+ *self =
+ decode(Value::Table(toml)).ok_or(toml::Error::Custom("Could not decode toml configuration.".to_owned()))?;
// If the categories are not found within the toml it will return an empty array
// which will break the parser. So use the default ones instead.
diff --git a/src/lib.rs b/src/lib.rs
index 3a6aaab..8784988 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -144,11 +144,11 @@ impl GitJournal {
let mut path_buf = if path != "." {
PathBuf::from(path)
} else {
- try!(std::env::current_dir())
+ std::env::current_dir()?
};
'git_search: loop {
- for dir in try!(fs::read_dir(&path_buf)) {
- let dir_path = try!(dir).path();
+ for dir in fs::read_dir(&path_buf)? {
+ let dir_path = dir?.path();
if dir_path.ends_with(".git") {
break 'git_search;
}
@@ -159,15 +159,15 @@ impl GitJournal {
}
// Open the repository
- let repo = try!(Repository::open(&path_buf));
+ let repo = Repository::open(&path_buf)?;
// Get all available tags in some vector of tuples
let mut new_tags = vec![];
- for name in try!(repo.tag_names(None)).iter() {
- let name = try!(name.ok_or(git2::Error::from_str("Could not receive tag name")));
- let obj = try!(repo.revparse_single(name));
+ for name in repo.tag_names(None)?.iter() {
+ let name = name.ok_or(git2::Error::from_str("Could not receive tag name"))?;
+ let obj = repo.revparse_single(name)?;
if let Ok(tag) = obj.into_tag() {
- let tag_name = try!(tag.name().ok_or(git2::Error::from_str("Could not parse tag name"))).to_owned();
+ let tag_name = tag.name().ok_or(git2::Error::from_str("Could not parse tag name"))?.to_owned();
new_tags.push((tag.target_id(), tag_name));
}
}
@@ -263,14 +263,14 @@ impl GitJournal {
///
pub fn setup(&self) -> Result<(), Error> {
// Save the default config
- let output_file = try!(Config::new().save_default_config(&self.path));
+ let output_file = Config::new().save_default_config(&self.path)?;
info!("Defaults written to '{}' file.", output_file);
// Install commit message hook
- try!(self.install_git_hook("commit-msg", "git journal v $1\n"));
+ self.install_git_hook("commit-msg", "git journal v $1\n")?;
// Install the prepare commit message hook
- try!(self.install_git_hook("prepare-commit-msg", "git journal p $1 $2\n"));
+ self.install_git_hook("prepare-commit-msg", "git journal p $1 $2\n")?;
Ok(())
}
@@ -284,19 +284,19 @@ impl GitJournal {
warn!("There is already a hook available in '{}'. Please verifiy \
the hook by hand after the installation.",
hook_path.display());
- hook_file = try!(OpenOptions::new().read(true).append(true).open(&hook_path));
+ hook_file = OpenOptions::new().read(true).append(true).open(&hook_path)?;
let mut hook_content = String::new();
- try!(hook_file.read_to_string(&mut hook_content));
+ hook_file.read_to_string(&mut hook_content)?;
if hook_content.contains(content) {
info!("Hook already installed, nothing changed in existing hook.");
return Ok(());
}
} else {
- hook_file = try!(File::create(&hook_path));
- try!(hook_file.write_all("#!/usr/bin/env sh\n".as_bytes()));
+ hook_file = File::create(&hook_path)?;
+ hook_file.write_all("#!/usr/bin/env sh\n".as_bytes())?;
}
- try!(hook_file.write_all(content.as_bytes()));
- try!(self.chmod(&hook_path, 0o755));
+ hook_file.write_all(content.as_bytes())?;
+ self.chmod(&hook_path, 0o755)?;
info!("Git hook installed to '{}'.", hook_path.display());
Ok(())
@@ -305,7 +305,7 @@ impl GitJournal {
#[cfg(unix)]
fn chmod(&self, path: &Path, perms: u32) -> Result<(), Error> {
use std::os::unix::prelude::PermissionsExt;
- try!(fs::set_permissions(path, fs::Permissions::from_mode(perms)));
+ fs::set_permissions(path, fs::Permissions::from_mode(perms))?;
Ok(())
}
@@ -342,12 +342,12 @@ impl GitJournal {
}
// Read the file contents to get the actual commit message string
- let mut read_file = try!(File::open(path));
+ let mut read_file = File::open(path)?;
let mut commit_message = String::new();
- try!(read_file.read_to_string(&mut commit_message));
+ read_file.read_to_string(&mut commit_message)?;
// Write the new generated content to the file
- let mut file = try!(OpenOptions::new().write(true).open(path));
+ let mut file = OpenOptions::new().write(true).open(path)?;
let mut old_msg_vec = commit_message.lines()
.filter_map(|line| {
if !line.is_empty() {
@@ -372,7 +372,7 @@ impl GitJournal {
let new_content =
prefix + &self.config.categories[0] + " ...\n\n# Add a more detailed description if needed\n\n# - " +
&self.config.categories.join("\n# - ") + "\n\n" + &old_msg_vec.join("\n");
- try!(file.write_all(&new_content.as_bytes()));
+ file.write_all(&new_content.as_bytes())?;
}
Ok(())
}
@@ -394,25 +394,24 @@ impl GitJournal {
///
pub fn verify(&self, path: &str) -> Result<(), Error> {
// Open the file and read to string
- let mut file = try!(File::open(path));
+ let mut file = File::open(path)?;
let mut commit_message = String::new();
- try!(file.read_to_string(&mut commit_message));
+ file.read_to_string(&mut commit_message)?;
// Parse the commit and extract the tags
- let parsed_commit = try!(self.parser.parse_commit_message(&commit_message, None));
+ let parsed_commit = self.parser.parse_commit_message(&commit_message, None)?;
let tags = parsed_commit.get_tags_unique(vec![]);
// Check if the tags within the commit also occur in the default template and error if not.
if let Some(ref template) = self.config.default_template {
let mut path_buf = PathBuf::from(&self.path);
path_buf.push(template);
- let mut file = try!(File::open(path_buf));
+ let mut file = File::open(path_buf)?;
let mut toml_string = String::new();
- try!(file.read_to_string(&mut toml_string));
+ file.read_to_string(&mut toml_string)?;
- let toml = try!(toml::Parser::new(&toml_string)
- .parse()
- .ok_or(Error::Verify("Could not parse default toml template.".to_owned())));
+ let toml = toml::Parser::new(&toml_string).parse()
+ .ok_or(Error::Verify("Could not parse default toml template.".to_owned()))?;
let toml_tags = self.parser.get_tags_from_toml(&toml, vec![]);
let invalid_tags = tags.into_iter().filter(|tag| !toml_tags.contains(tag)).collect::<Vec<String>>();
@@ -447,27 +446,27 @@ impl GitJournal {
skip_unreleased: &bool)
-> Result<(), Error> {
- let repo = try!(Repository::open(&self.path));
- let mut revwalk = try!(repo.revwalk());
+ let repo = Repository::open(&self.path)?;
+ let mut revwalk = repo.revwalk()?;
revwalk.set_sorting(git2::SORT_TIME);
// Fill the revwalk with the selected revisions.
- let revspec = try!(repo.revparse(&revision_range));
+ let revspec = repo.revparse(&revision_range)?;
if revspec.mode().contains(git2::REVPARSE_SINGLE) {
// A single commit was given
- let from = try!(revspec.from().ok_or(git2::Error::from_str("Could not set revision range start")));
- try!(revwalk.push(from.id()));
+ let from = revspec.from().ok_or(git2::Error::from_str("Could not set revision range start"))?;
+ revwalk.push(from.id())?;
} else {
// A specific commit range was given
- let from = try!(revspec.from().ok_or(git2::Error::from_str("Could not set revision range start")));
- let to = try!(revspec.to().ok_or(git2::Error::from_str("Could not set revision range end")));
- try!(revwalk.push(to.id()));
+ let from = revspec.from().ok_or(git2::Error::from_str("Could not set revision range start"))?;
+ let to = revspec.to().ok_or(git2::Error::from_str("Could not set revision range end"))?;
+ revwalk.push(to.id())?;
if revspec.mode().contains(git2::REVPARSE_MERGE_BASE) {
- let base = try!(repo.merge_base(from.id(), to.id()));
- let o = try!(repo.find_object(base, Some(ObjectType::Commit)));
- try!(revwalk.push(o.id()));
+ let base = repo.merge_base(from.id(), to.id())?;
+ let o = repo.find_object(base, Some(ObjectType::Commit))?;
+ revwalk.push(o.id())?;
}
- try!(revwalk.hide(from.id()));
+ revwalk.hide(from.id())?;
}
// Iterate over the git objects and collect them in a vector of tuples
@@ -481,8 +480,8 @@ impl GitJournal {
};
let mut worker_vec = vec![];
'revloop: for (index, id) in revwalk.enumerate() {
- let oid = try!(id);
- let commit = try!(repo.find_commit(oid));
+ let oid = id?;
+ let commit = repo.find_commit(oid)?;
for tag in self.tags
.iter()
.filter(|tag| tag.0.as_bytes() == oid.as_bytes() && !tag.1.contains(tag_skip_pattern)) {
@@ -515,7 +514,7 @@ impl GitJournal {
// Add the commit message to the parser work to be done, the `id` represents the index
// within the worker vector
- let message = try!(commit.message().ok_or(git2::Error::from_str("Commit message error.")));
+ let message = commit.message().ok_or(git2::Error::from_str("Commit message error."))?;
let id = worker_vec.len();
// The worker_vec contains the commit message and the parsed commit (currently none)
@@ -623,8 +622,8 @@ impl GitJournal {
let mut path_buf = PathBuf::from(&self.path);
path_buf.push("template.toml");
let toml_string = toml::encode_str(&toml);
- let mut toml_file = try!(File::create(&path_buf));
- try!(toml_file.write_all(toml_string.as_bytes()));
+ let mut toml_file = File::create(&path_buf)?;
+ toml_file.write_all(toml_string.as_bytes())?;
info!("Template written to '{}'", path_buf.display());
Ok(())
@@ -673,12 +672,12 @@ impl GitJournal {
};
// Print the log
- let output_vec = try!(self.parser.print(&compact, used_template));
+ let output_vec = self.parser.print(&compact, used_template)?;
// Print the log to the file if necessary
if let Some(output) = output {
- let mut output_file = try!(OpenOptions::new().create(true).append(true).open(output));
- try!(output_file.write_all(&output_vec));
+ let mut output_file = OpenOptions::new().create(true).append(true).open(output)?;
+ output_file.write_all(&output_vec)?;
info!("Output written to '{}'.", output);
}
diff --git a/src/logger.rs b/src/logger.rs
index 4abb35c..eed0a04 100644
--- a/src/logger.rs
+++ b/src/logger.rs
@@ -24,30 +24,30 @@ impl Logger {
// We have to create a new terminal on each log because
// `term::Terminal<Output=std::io::Stderr> + Send + 'static` cannot be shared between
// threads safely'
- let mut t = try!(term::stderr().ok_or(term::Error::NotSupported));
- try!(t.fg(term::color::BRIGHT_BLUE));
- try!(write!(t, "[git-journal] "));
+ let mut t = term::stderr().ok_or(term::Error::NotSupported)?;
+ t.fg(term::color::BRIGHT_BLUE)?;
+ write!(t, "[git-journal] ")?;
match record.level() {
LogLevel::Info => {
- try!(t.fg(term::color::GREEN));
- try!(write!(t, "[OKAY] "));
- try!(t.reset());
- try!(writeln!(t, "{}", record.args()));
+ t.fg(term::color::GREEN)?;
+ write!(t, "[OKAY] ")?;
+ t.reset()?;
+ writeln!(t, "{}", record.args())?;
}
LogLevel::Warn => {
- try!(t.fg(term::color::BRIGHT_YELLOW));
- try!(write!(t, "[WARN] "));
- try!(t.reset());
- try!(writeln!(t, "{}", record.args()));
+ t.fg(term::color::BRIGHT_YELLOW)?;
+ write!(t, "[WARN] ")?;
+ t.reset()?;
+ writeln!(t, "{}", record.args())?;
}
LogLevel::Error => {
- try!(t.fg(term::color::RED));
- try!(write!(t, "[ERROR] "));
- try!(t.reset());
- try!(writeln!(t, "{}", record.args()));
+ t.fg(term::color::RED)?;
+ write!(t, "[ERROR] ")?;
+ t.reset()?;
+ writeln!(t, "{}", record.args())?;
}
_ => {
- try!(writeln!(t, "[{}] {}", record.level(), record.args()));
+ writeln!(t, "[{}] {}", record.level(), record.args())?;
}
}
Ok(())
diff --git a/src/main.rs b/src/main.rs
index 67a33cc..23e37df 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -68,17 +68,17 @@ fn run() -> Result<(), Error> {
let yaml = load_yaml!("cli.yaml");
let mut app = App::from_yaml(yaml).version(crate_version!());
let matches = app.clone().get_matches();
- let path = try!(matches.value_of("path").ok_or(Error::Cli));
+ let path = matches.value_of("path").ok_or(Error::Cli)?;
// Create the journal
- let mut journal = try!(GitJournal::new(path));
+ let mut journal = GitJournal::new(path)?;
// Check for the subcommand
match matches.subcommand_name() {
Some("prepare") => {
// Prepare a commit message before editing by the user
if let Some(sub_matches) = matches.subcommand_matches("prepare") {
- match journal.prepare(try!(sub_matches.value_of("message").ok_or(Error::Cli)),
+ match journal.prepare(sub_matches.value_of("message").ok_or(Error::Cli)?,
sub_matches.value_of("type")) {
Ok(()) => info!("Commit message prepared."),
Err(error) => {
@@ -90,7 +90,7 @@ fn run() -> Result<(), Error> {
}
Some("setup") => {
// Do the setup procedure
- try!(journal.setup());
+ journal.setup()?;
// Generate completions if necessary
if is_program_in_path("bash") {
@@ -109,7 +109,7 @@ fn run() -> Result<(), Error> {
Some("verify") => {
// Verify a commit message
if let Some(sub_matches) = matches.subcommand_matches("verify") {
- match journal.verify(try!(sub_matches.value_of("message").ok_or(Error::Cli))) {
+ match journal.verify(sub_matches.value_of("message").ok_or(Error::Cli)?) {
Ok(()) => info!("Commit message valid."),
Err(error) => error_and_exit("Commit message invalid", Error::GitJournal(error)),
}
@@ -117,10 +117,10 @@ fn run() -> Result<(), Error> {
}
_ => {
// Get all values of the given CLI parameters with default values
- let revision_range = try!(matches.value_of("revision_range").ok_or(Error::Cli));
- let tag_skip_pattern = try!(matches.value_of("tag_skip_pattern").ok_or(Error::Cli));
- let tags_count = try!(matches.value_of("tags_count").ok_or(Error::Cli));
- let max_tags = try!(tags_count.parse::<u32>());
+ let revision_range = matches.value_of("revision_range").ok_or(Error::Cli)?;
+ let tag_skip_pattern = matches.value_of("tag_skip_pattern").ok_or(Error::Cli)?;
+ let tags_count = matches.value_of("tags_count").ok_or(Error::Cli)?;
+ let max_tags = tags_count.parse::<u32>()?;
// Parse the log
if let Err(error) = journal.parse_log(revision_range,
@@ -133,11 +133,11 @@ fn run() -> Result<(), Error> {
// Generate the template or print the log
if matches.is_present("generate") {
- try!(journal.generate_template());
+ journal.generate_template()?;
} else {
- try!(journal.print_log(matches.is_present("short"),
- matches.value_of("template"),
- matches.value_of("output")));
+ journal.print_log(matches.is_present("short"),
+ matches.value_of("template"),
+ matches.value_of("output"))?;
}
}
};
diff --git a/src/parser.rs b/src/parser.rs
index 1ab940b..719f7e6 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -26,18 +26,6 @@ pub static TOML_ONCE_KEY: &'static str = "once";
pub static TOML_HEADER_KEY: &'static str = "header";
pub static TOML_FOOTER_KEY: &'static str = "footer";
-macro_rules! trywln(
- ($($arg:tt)*) => {{
- try!(writeln!($($arg)*));
- }}
-);
-
-macro_rules! tryw(
- ($($arg:tt)*) => {{
- try!(write!($($arg)*));
- }}
-);
-
#[derive(Debug)]
pub enum Error {
CommitMessageLength,
@@ -101,7 +89,7 @@ pub trait Print {
H: Fn(&mut T) -> Result<(), Error>;
fn print_default<T: Write>(&self, t: &mut T, config: &Config, tag: Option<&str>) -> Result<(), Error> {
- try!(self.print(t, config, tag, &|_| Ok(()), &|_| Ok(()), &|_| Ok(())));
+ self.print(t, config, tag, &|_| Ok(()), &|_| Ok(()), &|_| Ok(()))?;
Ok(())
}
@@ -110,21 +98,21 @@ pub trait Print {
config: &Config,
tag: Option<&str>)
-> Result<(), Error> {
- try!(self.print(&mut t,
- config,
- tag,
- &|t| {
- try!(t.fg(term::color::BRIGHT_BLUE));
- Ok(())
- },
- &|t| {
- try!(t.fg(term::color::WHITE));
- Ok(())
- },
- &|t| {
- try!(t.reset());
- Ok(())
- }));
+ self.print(&mut t,
+ config,
+ tag,
+ &|t| {
+ t.fg(term::color::BRIGHT_BLUE)?;
+ Ok(())
+ },
+ &|t| {
+ t.fg(term::color::WHITE)?;
+ Ok(())
+ },
+ &|t| {
+ t.reset()?;
+ Ok(())
+ })?;
Ok(())
}
@@ -149,8 +137,8 @@ pub trait Print {
config: &Config,
tag: Option<&str>)
-> Result<(), Error> {
- try!(self.print_default_term(&mut term, config, tag));
- try!(self.print_default(&mut vec, config, tag));
+ self.print_default_term(&mut term, config, tag)?;
+ self.print_default(&mut vec, config, tag)?;
Ok(())
}
}
@@ -185,43 +173,43 @@ impl ParsedTag {
H: Fn(&mut T) -> Result<(), Error>
{
if config.colored_output {
- try!(c1(t));
+ c1(t)?;
}
- tryw!(t, "\n# {} ", self.name);
+ write!(t, "\n# {} ", self.name)?;
if config.colored_output {
- try!(c2(t));
+ c2(t)?;
}
- tryw!(t,
- "({}-{:02}-{:02}):",
- self.date.year(),
- self.date.month(),
- self.date.day());
+ write!(t,
+ "({}-{:02}-{:02}):",
+ self.date.year(),
+ self.date.month(),
+ self.date.day())?;
if config.colored_output {
- try!(c3(t));
+ c3(t)?;
}
Ok(Printed::Something)
}
fn print_default<T: Write>(&self, t: &mut T, config: &Config) -> Result<(), Error> {
- try!(self.print(t, config, &|_| Ok(()), &|_| Ok(()), &|_| Ok(())));
+ self.print(t, config, &|_| Ok(()), &|_| Ok(()), &|_| Ok(()))?;
Ok(())
}
fn print_default_term(&self, mut t: &mut Box<term::St