From a9042acbc412cf04f14f7556b710dfe864671012 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Thu, 29 Apr 2021 20:47:55 -0400
Subject: [PATCH 1/6] gitlab-ci: make junit reports

This enhances the GitLab pipeline to know more about specific tests.
---
 .gitlab-ci.yml            | 11 +++++++++--
 .gitlab/ci/cargo2junit.sh | 16 ++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100755 .gitlab/ci/cargo2junit.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 727f47e..bf3f21d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -37,10 +37,11 @@ before_script:
     - ".gitlab/sccache --show-stats || :"
 
 .cargo_test: &cargo_test
+    - .gitlab/ci/cargo2junit.sh
     - apt-get install -yqq --no-install-recommends git
     - git config --global user.name "Ghostflow Testing"
     - git config --global user.email "ghostflow@example.invalid"
-    - cargo test --frozen --all --verbose
+    - cargo test --frozen --all --verbose -- -Z unstable-options --format json --report-time | ./.gitlab/cargo2junit | tee junit.xml
 
 .cargo_tarpaulin_build: &cargo_tarpaulin_build
     - .gitlab/ci/sccache.sh && export RUSTC_WRAPPER=$PWD/.gitlab/sccache
@@ -140,6 +141,11 @@ before_script:
         - linux
     script: *cargo_test
     interruptible: true
+    artifacts:
+        when: always
+        reports:
+            junit:
+                - junit.xml
 
 .cargo_tarpaulin_build_job: &cargo_tarpaulin_build_job
     stage: build
@@ -323,9 +329,10 @@ test:git-master:
         - *cargo_test_job
         - *rust_stable
     script:
+        - .gitlab/ci/cargo2junit.sh
         - git config --global user.name "Ghostflow Testing"
         - git config --global user.email "ghostflow@example.invalid"
-        - PATH=$PWD/git/root/bin:$PATH cargo test --frozen --all --verbose
+        - PATH=$PWD/git/root/bin:$PATH cargo test --frozen --all --verbose -- -Z unstable-options --format json --report-time | ./.gitlab/cargo2junit | tee junit.xml
     dependencies:
         - prepare:git
         - build:cargo-stable
diff --git a/.gitlab/ci/cargo2junit.sh b/.gitlab/ci/cargo2junit.sh
new file mode 100755
index 0000000..e3c48ec
--- /dev/null
+++ b/.gitlab/ci/cargo2junit.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -e
+
+readonly version="master"
+readonly version_full="$version-01041853b-20210429.0"
+readonly sha256sum="b7b97e95d03c035020fdb23c3f0a86434c6e5025189e60cecc0f06c9919eba16"
+readonly filename="cargo2junit-v$version-x86_64-unknown-linux-gnu"
+
+cd .gitlab
+
+echo "$sha256sum  $filename" > cargo2junit.sha256sum
+curl -OL "https://gitlab.kitware.com/api/v4/projects/6955/packages/generic/cargo2junit/v$version_full/cargo2junit-v$version-x86_64-unknown-linux-gnu"
+sha256sum --check cargo2junit.sha256sum
+mv "$filename" cargo2junit
+chmod +x cargo2junit
-- 
GitLab


From 153fc48c2c3eb25cadce0c90301c8a0030de8c28 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Thu, 29 Apr 2021 21:00:02 -0400
Subject: [PATCH 2/6] gitlab-ci: update the minimum to 1.45

It just simplifies things with CI and it allows us to use newer clippy
suggestions.
---
 .gitlab-ci.yml | 20 ++------------------
 CHANGELOG.md   |  5 +++++
 2 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bf3f21d..2544545 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,11 +10,6 @@ before_script:
     - tags@utils/rust-git-workarea
 
 .cargo_update: &cargo_update
-    # XXX(minver<1.41.0): No backwards compatibility is provided. Instead, it
-    # uses the format of the existing `Cargo.lock` file to determine the format
-    # of the to-be-written file. See
-    # https://github.com/rust-lang/cargo/pull/7579#pullrequestreview-323640264
-    - touch Cargo.lock
     - cargo update $GENERATE_LOCKFILE_ARGS
     - cargo fetch --locked
     - mkdir .cargo
@@ -32,7 +27,7 @@ before_script:
     # Only use it if it's available; no need to fail the build due to something
     # gone wrong here.
     - .gitlab/ci/sccache.sh && export RUSTC_WRAPPER=$PWD/.gitlab/sccache
-    - cargo build $CARGO_BUILD_FROZEN --all --verbose
+    - cargo build --frozen --all --verbose
     - cargo test --frozen --all --no-run --verbose
     - ".gitlab/sccache --show-stats || :"
 
@@ -59,15 +54,9 @@ before_script:
     - cargo tarpaulin --frozen --exclude-files vendor --ignore-panics --all --verbose --out Html
 
 .rust_minimum: &rust_minimum
-    # XXX(mindeps): Once this is 1.38.0 or higher, remove the conditionals in
-    # the `.cargo_update` object. Until the, update the minimum version in
-    # lockstep with this.
-    image: "rust:1.32.0"
+    image: "rust:1.45.2"
 
     variables:
-        # Not supported yet here? If updating to a version where this works,
-        # remove this variable.
-        #CARGO_BUILD_FROZEN: --frozen
         CARGO_UPDATE_POLICY: newest
         GIT_CLONE_PATH: $CI_BUILDS_DIR/rust
 
@@ -75,7 +64,6 @@ before_script:
     image: "rust:latest"
 
     variables:
-        CARGO_BUILD_FROZEN: --frozen
         CARGO_UPDATE_POLICY: newest
         GIT_CLONE_PATH: $CI_BUILDS_DIR/rust
 
@@ -274,8 +262,6 @@ build:cargo-mindeps:
     <<:
         - *cargo_build_job
         - *rust_minimum
-    # https://github.com/rust-lang/cargo/issues/8696
-    allow_failure: true
     dependencies:
         - prepare:cargo-cache-mindeps
     needs:
@@ -285,8 +271,6 @@ test:cargo-mindeps:
     <<:
         - *cargo_test_job
         - *rust_minimum
-    # https://github.com/rust-lang/cargo/issues/8696
-    allow_failure: true
     dependencies:
         - build:cargo-mindeps
     needs:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5fb8dc8..b5d7ffc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# v4.2.0 (unreleased)
+
+  * MSRV bumped to 1.45. While the code update is just for a small code
+    simplification, in order to simplify CI, updating makes sense.
+
 # v4.1.0
 
   * Arguments taking `AsRef<Path>` are now `Into<PathBuf>` if the
-- 
GitLab


From 4f9ebba5c619f9af6c6eac48aca2d502c0d05aeb Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Thu, 29 Apr 2021 21:00:50 -0400
Subject: [PATCH 3/6] clippy: use `str::strip_prefix` to simplify some code

---
 src/git.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/git.rs b/src/git.rs
index d82cf18..f841835 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -312,8 +312,8 @@ impl GitContext {
             const ORIGIN_PREFIX: &str = "origin/";
             let full_refname = String::from_utf8_lossy(&origin_head.stdout);
             let refname = full_refname.trim();
-            if refname.starts_with(ORIGIN_PREFIX) {
-                return Ok(Some(refname[ORIGIN_PREFIX.len()..].into()));
+            if let Some(on_origin) = refname.strip_prefix(ORIGIN_PREFIX) {
+                return Ok(Some(on_origin.into()));
             }
         }
 
-- 
GitLab


From 4c1ff3fdb1c47fa5c23e60eef02473cc50850b50 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Thu, 29 Apr 2021 21:35:54 -0400
Subject: [PATCH 4/6] non_exhaustive: remove unnecessary bits

1.40 is now a tautology.
---
 Cargo.toml     |  3 ---
 build.rs       | 11 -----------
 src/git.rs     | 12 +-----------
 src/prepare.rs | 17 ++---------------
 4 files changed, 3 insertions(+), 40 deletions(-)
 delete mode 100644 build.rs

diff --git a/Cargo.toml b/Cargo.toml
index 493cfab..68ac4c3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,9 +12,6 @@ documentation = "https://docs.rs/git-workarea/~4.1"
 readme = "README.md"
 keywords = ["git", "utility"]
 
-[build-dependencies]
-rustversion = "^1.0"
-
 [dev-dependencies]
 itertools = "~0.8"
 
diff --git a/build.rs b/build.rs
deleted file mode 100644
index 524d439..0000000
--- a/build.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-#[rustversion::before(1.40.0)]
-fn do_check() {
-    println!("cargo:rustc-cfg=artificial_nonexhaustive");
-}
-
-#[rustversion::since(1.40.0)]
-fn do_check() {}
-
-fn main() {
-    do_check()
-}
diff --git a/src/git.rs b/src/git.rs
index f841835..1078b34 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -20,11 +20,8 @@ use prepare::{GitWorkArea, WorkAreaResult};
 pub struct CommitId(String);
 
 /// Errors which may occur when working with workareas.
-///
-/// This enum is `non_exhaustive`, but cannot be marked as such until it is stable. In the
-/// meantime, there is a hidden variant.
-#[cfg_attr(not(artificial_nonexhaustive), non_exhaustive)]
 #[derive(Debug, Error)]
+#[non_exhaustive]
 pub enum GitError {
     /// Command preparation failure.
     #[error("failed to construct 'git {}' command", subcommand)]
@@ -50,13 +47,6 @@ pub enum GitError {
         /// The invalid ref (or description of what was wrong).
         ref_: Cow<'static, str>,
     },
-    /// This is here to force `_` matching right now.
-    ///
-    /// **DO NOT USE**
-    #[cfg(artificial_nonexhaustive)]
-    #[doc(hidden)]
-    #[error("unreachable...")]
-    _NonExhaustive,
 }
 
 impl GitError {
diff --git a/src/prepare.rs b/src/prepare.rs
index 70f4ae3..cd85da8 100644
--- a/src/prepare.rs
+++ b/src/prepare.rs
@@ -23,8 +23,8 @@ use crates::thiserror::Error;
 use git::{CommitId, GitContext, GitError, GitResult, Identity};
 
 /// Steps which are involved in the submodule preparation process.
-#[cfg_attr(not(artificial_nonexhaustive), non_exhaustive)]
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[non_exhaustive]
 pub enum SubmoduleIntent {
     /// Creating the directory for the submodule.
     CreateDirectory,
@@ -32,12 +32,6 @@ pub enum SubmoduleIntent {
     CreateGitFile,
     /// Writing a `.git` file for the submodule.
     WriteGitFile,
-    /// This is here to force `_` matching right now.
-    ///
-    /// **DO NOT USE**
-    #[cfg(artificial_nonexhaustive)]
-    #[doc(hidden)]
-    _NonExhaustive,
 }
 
 impl fmt::Display for SubmoduleIntent {
@@ -55,7 +49,7 @@ impl fmt::Display for SubmoduleIntent {
 }
 
 /// Errors which may occur when using a workarea.
-#[cfg_attr(not(artificial_nonexhaustive), non_exhaustive)]
+#[non_exhaustive]
 #[derive(Debug, Error)]
 pub enum WorkAreaError {
     /// Failed to create a temporary directory for the workarea.
@@ -90,13 +84,6 @@ pub enum WorkAreaError {
         #[from]
         source: GitError,
     },
-    /// This is here to force `_` matching right now.
-    ///
-    /// **DO NOT USE**
-    #[cfg(artificial_nonexhaustive)]
-    #[doc(hidden)]
-    #[error("unreachable...")]
-    _NonExhaustive,
 }
 
 impl WorkAreaError {
-- 
GitLab


From f90d9917f3a7ea6888f8efeda3b031629da414f3 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Fri, 30 Apr 2021 06:23:05 -0400
Subject: [PATCH 5/6] cargo: update to the 2018 edition

---
 Cargo.toml     |  3 ++-
 src/git.rs     |  5 +++--
 src/lib.rs     | 20 --------------------
 src/prepare.rs | 14 ++++++++------
 src/test.rs    |  8 ++++----
 5 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 68ac4c3..84baa65 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,13 +11,14 @@ repository = "https://gitlab.kitware.com/utils/rust-git-workarea"
 documentation = "https://docs.rs/git-workarea/~4.1"
 readme = "README.md"
 keywords = ["git", "utility"]
+edition = "2018"
 
 [dev-dependencies]
 itertools = "~0.8"
 
 [dependencies]
 lazy_static = "^1.1"
-log = "~0.4"
+log = "~0.4.4"
 regex = "^1.0"
 tempdir = "~0.3.6"
 thiserror = "^1.0.2"
diff --git a/src/git.rs b/src/git.rs
index 1078b34..b076631 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -11,9 +11,10 @@ use std::io;
 use std::path::{Path, PathBuf};
 use std::process::{Command, Stdio};
 
-use crates::thiserror::Error;
+use log::debug;
+use thiserror::Error;
 
-use prepare::{GitWorkArea, WorkAreaResult};
+use crate::prepare::{GitWorkArea, WorkAreaResult};
 
 /// The Git object id of a commit.
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/src/lib.rs b/src/lib.rs
index 3291aec..3b23f27 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,26 +12,6 @@
 //! except that its on-disk representation is minimal so that operations are not constrained by
 //! disk speed.
 
-#[macro_use]
-extern crate lazy_static;
-
-#[macro_use]
-extern crate log;
-
-mod crates {
-    // public
-    pub extern crate chrono;
-
-    // private
-    pub extern crate log;
-    pub extern crate regex;
-    pub extern crate tempdir;
-    pub extern crate thiserror;
-
-    #[cfg(test)]
-    pub extern crate itertools;
-}
-
 mod git;
 mod prepare;
 
diff --git a/src/prepare.rs b/src/prepare.rs
index cd85da8..ef09275 100644
--- a/src/prepare.rs
+++ b/src/prepare.rs
@@ -15,12 +15,14 @@ use std::marker::PhantomData;
 use std::path::{Path, PathBuf};
 use std::process::{Command, Stdio};
 
-use crates::chrono::{DateTime, Utc};
-use crates::regex::Regex;
-use crates::tempdir::TempDir;
-use crates::thiserror::Error;
-
-use git::{CommitId, GitContext, GitError, GitResult, Identity};
+use chrono::{DateTime, Utc};
+use lazy_static::lazy_static;
+use log::{debug, error};
+use regex::Regex;
+use tempdir::TempDir;
+use thiserror::Error;
+
+use crate::git::{CommitId, GitContext, GitError, GitResult, Identity};
 
 /// Steps which are involved in the submodule preparation process.
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
diff --git a/src/test.rs b/src/test.rs
index 221d5a4..2da816e 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -10,11 +10,11 @@ use std::iter;
 use std::path::Path;
 use std::process::{Command, Stdio};
 
-use crates::itertools::Itertools;
-use crates::log::{self, Level, LevelFilter, Log, Metadata, Record};
-use crates::tempdir::TempDir;
+use itertools::Itertools;
+use log::{Level, LevelFilter, Log, Metadata, Record};
+use tempdir::TempDir;
 
-use {CommitId, Conflict, GitContext, GitWorkArea, MergeResult, MergeStatus};
+use crate::{CommitId, Conflict, GitContext, GitWorkArea, MergeResult, MergeStatus};
 
 fn setup_logging() {
     struct SimpleLogger;
-- 
GitLab


From 5471b5f3a1d71d5217cb3076e722c28e39b20da3 Mon Sep 17 00:00:00 2001
From: Ben Boeckel <ben.boeckel@kitware.com>
Date: Fri, 30 Apr 2021 06:23:19 -0400
Subject: [PATCH 6/6] itertools: update to 0.10

---
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index 84baa65..f5c4335 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,7 @@ keywords = ["git", "utility"]
 edition = "2018"
 
 [dev-dependencies]
-itertools = "~0.8"
+itertools = "~0.10"
 
 [dependencies]
 lazy_static = "^1.1"
-- 
GitLab