summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Jung <tummychow511@gmail.com>2020-10-08 13:02:17 -0700
committerGitHub <noreply@github.com>2020-10-08 13:02:17 -0700
commitad130ae7933f4236d8801f25645ec982ca488817 (patch)
tree2a5663ff91ac8db6b5d3a597021bceb5809df4ee
parente96f00e302a9a3b7fadbdeff0bca51608d293695 (diff)
parentddf567e066e7325b5108010a34b1698319374be9 (diff)
Merge pull request #33 from alexmaco/lib
Switch to anyhow for error handling, and upgrade rest of deps
-rw-r--r--Cargo.lock265
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs9
-rw-r--r--src/owned.rs49
-rw-r--r--src/stack.rs6
5 files changed, 123 insertions, 208 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7bf5a7a..6babadd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,6 +10,12 @@ dependencies = [
]
[[package]]
+name = "anyhow"
+version = "1.0.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c"
+
+[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -23,59 +29,32 @@ checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]]
name = "atty"
-version = "0.2.12"
+version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ecaaea69f52b3b18633611ec0007d188517d0366f47ff703d400fa6879d6f8d5"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
+ "hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
-
-[[package]]
-name = "autocfg"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
-
-[[package]]
-name = "backtrace"
-version = "0.3.32"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "18b50f5258d1a9ad8396d2d345827875de4261b158124d4c819d9b351454fae5"
-dependencies = [
- "backtrace-sys",
- "cfg-if",
- "libc",
- "rustc-demangle",
-]
-
-[[package]]
-name = "backtrace-sys"
-version = "0.1.30"
+version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b3a000b9c543553af61bc01cbfc403b04b5caa9e421033866f2e98061eb3e61"
-dependencies = [
- "cc",
- "libc",
-]
+checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "base64"
-version = "0.11.0"
+version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
+checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "bitflags"
-version = "1.1.0"
+version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
+checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blake2b_simd"
@@ -99,20 +78,21 @@ dependencies = [
[[package]]
name = "cfg-if"
-version = "0.1.9"
+version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
+checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
-version = "0.4.7"
+version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "77d81f58b7301084de3b958691458a53c3f7e0b1d702f77e550b6a88e3a88abe"
+checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
+ "winapi",
]
[[package]]
@@ -138,9 +118,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "crossbeam-channel"
-version = "0.4.2"
+version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061"
+checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
dependencies = [
"crossbeam-utils",
"maybe-uninit",
@@ -152,7 +132,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
- "autocfg 1.0.0",
+ "autocfg",
"cfg-if",
"lazy_static",
]
@@ -169,54 +149,32 @@ dependencies = [
[[package]]
name = "dirs-sys"
-version = "0.3.4"
+version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
+checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a"
dependencies = [
- "cfg-if",
"libc",
"redox_users",
"winapi",
]
[[package]]
-name = "failure"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
-dependencies = [
- "backtrace",
- "failure_derive",
-]
-
-[[package]]
-name = "failure_derive"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "synstructure",
-]
-
-[[package]]
name = "getrandom"
-version = "0.1.6"
+version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e65cce4e5084b14874c4e7097f38cab54f47ee554f9194673456ea379dcc4c55"
+checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [
- "lazy_static",
+ "cfg-if",
"libc",
+ "wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "git-absorb"
version = "0.6.4"
dependencies = [
+ "anyhow",
"clap",
- "failure",
"git2",
"memchr",
"slog",
@@ -239,6 +197,15 @@ dependencies = [
]
[[package]]
+name = "hermit-abi"
+version = "0.1.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "idna"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -260,18 +227,15 @@ dependencies = [
[[package]]
name = "lazy_static"
-version = "1.3.0"
+version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
-dependencies = [
- "spin",
-]
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.59"
+version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3262021842bf00fe07dbd6cf34ff25c99d7a7ebef8deea84db72be3ea3bb0aff"
+checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
[[package]]
name = "libgit2-sys"
@@ -326,21 +290,21 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "num-integer"
-version = "0.1.41"
+version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
+checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
dependencies = [
- "autocfg 0.1.4",
+ "autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
-version = "0.2.8"
+version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
+checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [
- "autocfg 0.1.4",
+ "autocfg",
]
[[package]]
@@ -351,9 +315,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pkg-config"
-version = "0.3.14"
+version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
+checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "ppv-lite86"
@@ -362,24 +326,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
[[package]]
-name = "proc-macro2"
-version = "0.4.30"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
-dependencies = [
- "unicode-xid",
-]
-
-[[package]]
-name = "quote"
-version = "0.6.13"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
-dependencies = [
- "proc-macro2",
-]
-
-[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -422,15 +368,15 @@ dependencies = [
[[package]]
name = "redox_syscall"
-version = "0.1.56"
+version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
+checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_users"
-version = "0.3.4"
+version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431"
+checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
dependencies = [
"getrandom",
"redox_syscall",
@@ -439,18 +385,18 @@ dependencies = [
[[package]]
name = "remove_dir_all"
-version = "0.5.2"
+version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
+checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]]
name = "rust-argon2"
-version = "0.7.0"
+version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017"
+checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
dependencies = [
"base64",
"blake2b_simd",
@@ -459,12 +405,6 @@ dependencies = [
]
[[package]]
-name = "rustc-demangle"
-version = "0.1.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af"
-
-[[package]]
name = "slog"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -496,47 +436,12 @@ dependencies = [
]
[[package]]
-name = "smallvec"
-version = "0.6.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
-
-[[package]]
-name = "spin"
-version = "0.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
-
-[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
-name = "syn"
-version = "0.15.39"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-xid",
-]
-
-[[package]]
-name = "synstructure"
-version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "unicode-xid",
-]
-
-[[package]]
name = "take_mut"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -586,16 +491,22 @@ dependencies = [
[[package]]
name = "time"
-version = "0.1.42"
+version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
+checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
- "redox_syscall",
+ "wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
+name = "tinyvec"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117"
+
+[[package]]
name = "unicode-bidi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -606,24 +517,18 @@ dependencies = [
[[package]]
name = "unicode-normalization"
-version = "0.1.8"
+version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426"
+checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977"
dependencies = [
- "smallvec",
+ "tinyvec",
]
[[package]]
name = "unicode-width"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
-
-[[package]]
-name = "unicode-xid"
-version = "0.1.0"
+version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
+checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "url"
@@ -638,21 +543,33 @@ dependencies = [
[[package]]
name = "vcpkg"
-version = "0.2.7"
+version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95"
+checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
[[package]]
name = "vec_map"
-version = "0.8.1"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
+name = "wasi"
+version = "0.9.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
+
+[[package]]
+name = "wasi"
+version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
+checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
-version = "0.3.7"
+version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
diff --git a/Cargo.toml b/Cargo.toml
index aa37ef5..1d72fae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,8 +29,8 @@ clap = "~2.33"
slog = "~2.5"
slog-term = "~2.6"
slog-async = "~2.5"
-failure = "~0.1"
memchr = "~2.3"
+anyhow = "~1.0"
[dev-dependencies]
tempfile = "~3.1"
diff --git a/src/lib.rs b/src/lib.rs
index 9ef9fcd..49a4380 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,6 @@
#[macro_use]
extern crate slog;
+use anyhow::{anyhow, Result};
mod commute;
mod owned;
@@ -15,7 +16,7 @@ pub struct Config<'a> {
pub logger: &'a slog::Logger,
}
-pub fn run(config: &Config) -> Result<(), failure::Error> {
+pub fn run(config: &Config) -> Result<()> {
let repo = git2::Repository::open_from_env()?;
debug!(config.logger, "repository found"; "path" => repo.path().to_str());
@@ -282,7 +283,7 @@ fn apply_hunk_to_tree<'repo>(
base: &git2::Tree,
hunk: &owned::Hunk,
path: &[u8],
-) -> Result<git2::Tree<'repo>, failure::Error> {
+) -> Result<git2::Tree<'repo>> {
let mut treebuilder = repo.treebuilder(Some(base))?;
// recurse into nested tree if applicable
@@ -293,7 +294,7 @@ fn apply_hunk_to_tree<'repo>(
let (subtree, submode) = {
let entry = treebuilder
.get(first)?
- .ok_or_else(|| failure::err_msg("couldn't find tree entry in tree for path"))?;
+ .ok_or_else(|| anyhow!("couldn't find tree entry in tree for path"))?;
(repo.find_tree(entry.id())?, entry.filemode())
};
// TODO: loop instead of recursing to avoid potential stack overflow
@@ -306,7 +307,7 @@ fn apply_hunk_to_tree<'repo>(
let (blob, mode) = {
let entry = treebuilder
.get(path)?
- .ok_or_else(|| failure::err_msg("couldn't find blob entry in tree for path"))?;
+ .ok_or_else(|| anyhow!("couldn't find blob entry in tree for path"))?;
(repo.find_blob(entry.id())?, entry.filemode())
};
diff --git a/src/owned.rs b/src/owned.rs
index d9994d0..ff7ec8b 100644
--- a/src/owned.rs
+++ b/src/owned.rs
@@ -1,3 +1,5 @@
+use anyhow::{anyhow, Result};
+
use std::collections::hash_map::HashMap;
use std::rc::Rc;
@@ -14,7 +16,7 @@ impl ::std::ops::Deref for Diff {
}
}
impl Diff {
- pub fn new(diff: &git2::Diff) -> Result<Self, failure::Error> {
+ pub fn new(diff: &git2::Diff) -> Result<Self> {
let mut ret = Diff {
patches: Vec::new(),
by_old: HashMap::new(),
@@ -24,15 +26,15 @@ impl Diff {
for (delta_idx, _delta) in diff.deltas().enumerate() {
let patch = Patch::new(
&mut git2::Patch::from_diff(diff, delta_idx)?
- .ok_or_else(|| failure::err_msg("got empty delta"))?,
+ .ok_or_else(|| anyhow!("got empty delta"))?,
)?;
if ret.by_old.contains_key(&patch.old_path) {
// TODO: would this case be hit if the diff was put through copy detection?
- return Err(failure::err_msg("old path already occupied"));
+ return Err(anyhow!("old path already occupied"));
}
ret.by_old.insert(patch.old_path.clone(), ret.patches.len());
if ret.by_new.contains_key(&patch.new_path) {
- return Err(failure::err_msg("new path already occupied"));
+ return Err(anyhow!("new path already occupied"));
}
ret.by_new.insert(patch.new_path.clone(), ret.patches.len());
ret.patches.push(patch);
@@ -60,7 +62,7 @@ pub struct Hunk {
pub removed: Block,
}
impl Hunk {
- pub fn new(patch: &mut git2::Patch, idx: usize) -> Result<Self, failure::Error> {
+ pub fn new(patch: &mut git2::Patch, idx: usize) -> Result<Self> {
let (added_start, removed_start, mut added_lines, mut removed_lines) = {
let (hunk, _size) = patch.hunk(idx)?;
(
@@ -78,62 +80,55 @@ impl Hunk {
match line.origin() {
'+' => {
if line.num_lines() > 1 {
- return Err(failure::err_msg("wrong number of lines in hunk"));
+ return Err(anyhow!("wrong number of lines in hunk"));
}
if line
.new_lineno()
- .ok_or_else(|| failure::err_msg("added line did not have lineno"))?
+ .ok_or_else(|| anyhow!("added line did not have lineno"))?
as usize
!= added_start + added_lines.len()
{
- return Err(failure::err_msg("added line did not reach expected lineno"));
+ return Err(anyhow!("added line did not reach expected lineno"));
}
added_lines.push(Vec::from(line.content()))
}
'-' => {
if line.num_lines() > 1 {
- return Err(failure::err_msg("wrong number of lines in hunk"));
+ return Err(anyhow!("wrong number of lines in hunk"));
}
if line
.old_lineno()
- .ok_or_else(|| failure::err_msg("removed line did not have lineno"))?
+ .ok_or_else(|| anyhow!("removed line did not have lineno"))?
as usize
!= removed_start + removed_lines.len()
{
- return Err(failure::err_msg(
- "removed line did not reach expected lineno",
- ));
+ return Err(anyhow!("removed line did not reach expected lineno",));
}
removed_lines.push(Vec::from(line.content()))
}
'>' => {
if !removed_trailing_newline {
- return Err(failure::err_msg("removed nneof was already detected"));
+ return Err(anyhow!("removed nneof was already detected"));
};
removed_trailing_newline = false
}
'<' => {
if !added_trailing_newline {
- return Err(failure::err_msg("added nneof was already detected"));
+ return Err(anyhow!("added nneof was already detected"));
};
added_trailing_newline = false
}
- _ => {
- return Err(failure::err_msg(format!(
- "unknown line type {:?}",
- line.origin()
- )))
- }
+ _ => return Err(anyhow!("unknown line type {:?}", line.origin())),
};
}
{
let (hunk, _size) = patch.hunk(idx)?;
if added_lines.len() != hunk.new_lines() as usize {
- return Err(failure::err_msg("hunk added block size mismatch"));
+ return Err(anyhow!("hunk added block size mismatch"));
}
if removed_lines.len() != hunk.old_lines() as usize {
- return Err(failure::err_msg("hunk removed block size mismatch"));
+ return Err(anyhow!("hunk removed block size mismatch"));
}
}
@@ -221,27 +216,27 @@ pub struct Patch {
pub hunks: Vec<Hunk>,
}
impl Patch {
- pub fn new(patch: &mut git2::Patch) -> Result<Self, failure::Error> {
+ pub fn new(patch: &mut git2::Patch) -> Result<Self> {
let mut ret = Patch {
old_path: patch
.delta()
.old_file()
.path_bytes()
.map(Vec::from)
- .ok_or_else(|| failure::err_msg("delta with empty old path"))?,
+ .ok_or_else(|| anyhow!("delta with empty old path"))?,
old_id: patch.delta().old_file().id(),
new_path: patch
.delta()
.new_file()
.path_bytes()
.map(Vec::from)
- .ok_or_else(|| failure::err_msg("delta with empty new path"))?,
+ .ok_or_else(|| anyhow!("delta with empty new path"))?,
new_id: patch.delta().new_file().id(),
status: patch.delta().status(),
hunks: Vec::with_capacity(patch.num_hunks()),
};
if patch.delta().nfiles() < 1 || patch.delta().nfiles() > 2 {
- return Err(failure::err_msg("delta with multiple files"));
+ return Err(anyhow!("delta with multiple files"));
}
for idx in 0..patch.num_hunks() {
diff --git a/src/stack.rs b/src/stack.rs
index 2d72b41..ff7015c 100644
--- a/src/stack.rs
+++ b/src/stack.rs
@@ -1,3 +1,5 @@
+use anyhow::{anyhow, Result};
+
use std::collections::HashMap;
pub const MAX_STACK_CONFIG_NAME: &str = "absorb.maxStack";
@@ -18,12 +20,12 @@ pub fn working_stack<'repo>(
user_provided_base: Option<&str>,
force: bool,
logger: &slog::Logger,
-) -> Result<Vec<git2::Commit<'repo>>, failure::Error> {
+) -> Result<Vec<git2::Commit<'repo>>> {
let head = repo.head()?;
debug!(logger, "head found"; "head" => head.name());
if !head.is_branch() {
- return Err(failure::err_msg("HEAD is not a branch"));
+ return Err(anyhow!("HEAD is not a branch"));
}
let mut revwalk = repo.revwalk()?;