From 60291b83e2fa2f8500446a457c88b565c5e2ead7 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 12 Aug 2020 10:47:13 +0200 Subject: [PATCH 1/2] Fix finding latest tags --- Cargo.lock | 7 ++++ Cargo.toml | 1 + src/git.rs | 100 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 67 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c3aa0b..56b45ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,7 @@ dependencies = [ "erreur", "futures", "git2", + "human-sort", "humansize", "log", "md5", @@ -833,6 +834,12 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +[[package]] +name = "human-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "140a09c9305e6d5e557e2ed7cbc68e05765a7d4213975b87cb04920689cc6219" + [[package]] name = "humansize" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 53207eb..5b05d56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ futures = "0.3.4" git2 = { version = "0.13.6", default-features = false } chrono = "0.4.11" +human-sort = "0.2.2" [dev-dependencies] rand = "0.7.3" diff --git a/src/git.rs b/src/git.rs index 5b0c1df..2a93967 100644 --- a/src/git.rs +++ b/src/git.rs @@ -44,55 +44,44 @@ pub fn find_tags_to_patch(current: &str, tags: &[String]) -> Result> Some(SmolStr::from(prev.to_string())) } + let tags = { + let mut tags = tags.to_vec(); + tags.sort_by(|a, b| human_sort::compare(a, b)); + tags + }; let parsed_tags = tags.iter().map(|tag| tag_to_slice(tag)).collect::>(); let current = tag_to_slice(current); - - let mut to_patch = vec![]; - - if let Some(x) = current.iter().last().and_then(dec) { - let pos = current.len() - 1; - let prev = { - let mut prev = current.clone(); - prev[pos] = x; - prev - }; - - if let Some((idx, _)) = parsed_tags - .iter() - .enumerate() - .find(|(_idx, tag)| tag == &&prev) - { - to_patch.push(tags[idx].clone()); - } else { - log::debug!("no matching tag for {:?}", prev); - } - } - - if let Some(x) = current.iter().rev().nth(1).and_then(dec) { - let pos = current.len() - 2; - let prev = { - let mut prev = current.clone(); - prev[pos] = x; - prev - }; - - if let Some((idx, _)) = parsed_tags - .iter() - .enumerate() - .filter(|(_idx, tag)| tag.starts_with(&prev[..=pos])) - .last() - { - to_patch.push(tags[idx].clone()); - } else { - log::debug!("no matching tag for {:?}", prev); - } - } + let to_patch: Vec = (0..current.len()) + .filter_map(|pos_from_end| { + if let Some(x) = current.iter().rev().nth(pos_from_end).and_then(dec) { + let pos = current.len() - pos_from_end - 1; + let prev = { + let mut prev = current.to_vec(); + prev[pos] = x; + prev + }; + + if let Some((idx, _)) = parsed_tags + .iter() + .enumerate() + .filter(|(_idx, tag)| tag.starts_with(&prev[..=pos])) + .last() + { + return Some(tags[idx].clone()); + } else { + log::debug!("no matching tag for {:?}", prev); + } + } + None + }) + .collect(); Ok(to_patch) } #[test] fn tags_to_patch_from_works() { + crate::test_helpers::logger(); let tags = vec![ "IL40.0.0".to_string(), "IL40.0.1".to_string(), @@ -110,6 +99,7 @@ fn tags_to_patch_from_works() { #[test] fn tags_to_patch_from_1() { + crate::test_helpers::logger(); let tags = vec![]; let current_tag = "IL40.2.19"; let patch_these = find_tags_to_patch(current_tag, &tags).unwrap(); @@ -118,6 +108,7 @@ fn tags_to_patch_from_1() { #[test] fn tags_to_patch_from_2() { + crate::test_helpers::logger(); let tags = vec!["garbage".to_string(), "v1.5-1.beta.1".to_string()]; let current_tag = "v2.0.0"; let patch_these = find_tags_to_patch(current_tag, &tags).unwrap(); @@ -126,6 +117,7 @@ fn tags_to_patch_from_2() { #[test] fn tags_to_patch_from_3() { + crate::test_helpers::logger(); let tags = vec![ "IL40.0.0".to_string(), "IL40.0.1".to_string(), @@ -174,3 +166,29 @@ fn tags_to_patch_from_fuzzy() { vec!["IL40.2.18".to_string(), "IL40.1.0".to_string()] ); } + +#[test] +fn tags_to_patch_from_5() { + let tags = vec![ + "il60-0-8".to_string(), + "il60-0-9".to_string(), + "il60-0-10".to_string(), + "il60-0-11".to_string(), + ]; + let current_tag = "il60-1-0"; + let patch_these = find_tags_to_patch(current_tag, &tags).unwrap(); + assert_eq!(patch_these, vec!["il60-0-11".to_string()]); +} + +#[test] +fn tags_to_patch_from_5_sorted() { + let tags = vec![ + "il60-0-10".to_string(), + "il60-0-11".to_string(), + "il60-0-8".to_string(), + "il60-0-9".to_string(), + ]; + let current_tag = "il60-1-0"; + let patch_these = find_tags_to_patch(current_tag, &tags).unwrap(); + assert_eq!(patch_these, vec!["il60-0-11".to_string()]); +} From 23662cd94c8bdca63a46225448e45dbdf9a0d0d4 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 12 Aug 2020 10:48:04 +0200 Subject: [PATCH 2/2] Update dependencies --- Cargo.lock | 126 ++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56b45ad..4e86be1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,6 +33,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "arc-swap" version = "0.4.7" @@ -308,11 +317,11 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.1" +version = "2.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" +checksum = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim", @@ -323,11 +332,11 @@ dependencies = [ [[package]] name = "color-eyre" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c72672243200c10efdf22867bc2e156ac4f27852572a99f5fbbe18f0c417d76" +checksum = "028eb0f4472a78c8f7b82751eedb5326dcb2a00c8ba89454e2d0df819d856e2c" dependencies = [ - "ansi_term", + "ansi_term 0.12.1", "backtrace", "eyre", "indenter", @@ -497,9 +506,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "env_logger" @@ -534,9 +543,9 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "affc17579b132fc2461adf7c575cc6e8b134ebca52c51f5411388965227dc695" +checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" dependencies = [ "cfg-if", "libc", @@ -678,9 +687,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.3" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -766,9 +775,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" dependencies = [ "autocfg", ] @@ -934,9 +943,9 @@ checksum = "e0bd112d44d9d870a6819eb505d04dd92b5e4d94bb8c304924a0872ae7016fb5" [[package]] name = "indexmap" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" +checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9" dependencies = [ "autocfg", "hashbrown", @@ -983,9 +992,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.42" +version = "0.3.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2" +checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73" dependencies = [ "wasm-bindgen", ] @@ -1008,9 +1017,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.73" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" +checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" [[package]] name = "libgit2-sys" @@ -1322,9 +1331,9 @@ dependencies = [ [[package]] name = "proc-macro-error" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", @@ -1335,14 +1344,12 @@ dependencies = [ [[package]] name = "proc-macro-error-attr" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "syn", - "syn-mid", "version_check", ] @@ -1787,18 +1794,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2", "quote", @@ -1843,9 +1850,9 @@ checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" [[package]] name = "signal-hook-registry" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" +checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" dependencies = [ "arc-swap", "libc", @@ -1947,9 +1954,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de2f5e239ee807089b62adce73e48c625e0ed80df02c7ab3f068f5db5281065c" +checksum = "de5472fb24d7e80ae84a7801b7978f95a19ec32cb1876faea59ab711eb901976" dependencies = [ "clap", "lazy_static", @@ -1958,9 +1965,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510413f9de616762a4fbeab62509bf15c729603b72d7cd71280fbca431b1c118" +checksum = "1e0eb37335aeeebe51be42e2dc07f031163fbabfa6ac67d7ea68b5c2f68d5f99" dependencies = [ "heck", "proc-macro-error", @@ -1977,26 +1984,15 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tar" version = "0.4.29" @@ -2173,9 +2169,9 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" +checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" dependencies = [ "cfg-if", "log", @@ -2184,9 +2180,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +checksum = "db63662723c316b43ca36d833707cc93dff82a02ba3d7e354f342682cc8b3545" dependencies = [ "lazy_static", ] @@ -2318,9 +2314,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.65" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d" +checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2328,9 +2324,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.65" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d" +checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0" dependencies = [ "bumpalo", "lazy_static", @@ -2343,9 +2339,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.65" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e" +checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2353,9 +2349,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.65" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" +checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" dependencies = [ "proc-macro2", "quote", @@ -2366,15 +2362,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.65" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87" +checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092" [[package]] name = "web-sys" -version = "0.3.42" +version = "0.3.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2" +checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47" dependencies = [ "js-sys", "wasm-bindgen",