Commit 25b6f61d authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'rustfmt-20180904'

885c7387 MergeCommand: use debug_struct
a50cdc6b rust: avoid unnecessary Vec collecting
62f8658f rustfmt: add a space after a comment marker
b4898058 rustfmt: markup a TODO item with an issue number
458474b6 rustfmt: reformat function call arguments
b68441b1 rustfmt: reformat `where` clauses
e5d3e65b rustfmt: move operators to the front
9ae0df0a rustfmt: sort imports
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !62
parents 11acb0ac 885c7387
Pipeline #115556 passed with stage
in 0 seconds
// Copyright {\d+} Kitware, Inc.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum_trailing_comma = true
fn_args_density = "Compressed"
fn_args_layout = "Visual"
match_block_trailing_comma = true
match_wildcard_trailing_comma = true
reorder_imported_names = true
struct_lit_multiline_style = "ForceMulti"
struct_lit_trailing_comma = "Always"
struct_trailing_comma = "Always"
where_trailing_comma = true
force_multiline_blocks = true
report_todo = "Unnumbered"
report_fixme = "Unnumbered"
struct_lit_single_line = false
trailing_comma = "Always"
license_template_path = ".license.template"
......@@ -14,8 +14,8 @@ use std::fmt::{self, Display};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
/// The Git object id of a commit.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CommitId(String);
impl CommitId {
......@@ -36,8 +36,8 @@ impl Display for CommitId {
}
}
#[derive(Debug, Clone)]
/// A context for performing git commands.
#[derive(Debug, Clone)]
pub struct GitContext {
/// The path to the `.git` directory.
gitdir: PathBuf,
......@@ -45,8 +45,8 @@ pub struct GitContext {
config: Option<PathBuf>,
}
#[derive(Debug, PartialEq, Eq)]
/// An identity for creating git commits.
#[derive(Debug, PartialEq, Eq)]
pub struct Identity {
/// The name.
pub name: String,
......@@ -57,8 +57,9 @@ pub struct Identity {
impl Identity {
/// Create a new identity.
pub fn new<N, E>(name: N, email: E) -> Self
where N: ToString,
E: ToString,
where
N: ToString,
E: ToString,
{
Self {
name: name.to_string(),
......@@ -79,8 +80,8 @@ impl Display for Identity {
}
}
#[derive(Debug)]
/// Status of a merge check.
#[derive(Debug)]
pub enum MergeStatus {
/// The branches do not contain common history.
NoCommonHistory,
......@@ -92,20 +93,23 @@ pub enum MergeStatus {
impl Display for MergeStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"{}",
match *self {
MergeStatus::NoCommonHistory => "no common history",
MergeStatus::AlreadyMerged => "already merged",
MergeStatus::Mergeable(_) => "mergeable",
})
write!(
f,
"{}",
match *self {
MergeStatus::NoCommonHistory => "no common history",
MergeStatus::AlreadyMerged => "already merged",
MergeStatus::Mergeable(_) => "mergeable",
},
)
}
}
impl GitContext {
/// Create a new context for the given directory.
pub fn new<P>(gitdir: P) -> Self
where P: AsRef<Path>,
where
P: AsRef<Path>,
{
Self {
gitdir: gitdir.as_ref().to_path_buf(),
......@@ -115,8 +119,9 @@ impl GitContext {
/// Create a new context for the given directory with git configuration.
pub fn new_with_config<P, C>(gitdir: P, config: C) -> Self
where P: AsRef<Path>,
C: AsRef<Path>,
where
P: AsRef<Path>,
C: AsRef<Path>,
{
Self {
gitdir: gitdir.as_ref().to_path_buf(),
......@@ -143,21 +148,24 @@ impl GitContext {
///
/// The remote is interpreted by Git, so it can be a remote or a specific URL.
pub fn fetch<R, I, N>(&self, remote: R, refnames: I) -> Result<()>
where R: AsRef<str>,
I: IntoIterator<Item = N>,
N: AsRef<OsStr>,
where
R: AsRef<str>,
I: IntoIterator<Item = N>,
N: AsRef<OsStr>,
{
let fetch = self.git()
let fetch = self
.git()
.arg("fetch")
.arg(remote.as_ref())
.args(&refnames.into_iter()
.collect::<Vec<_>>())
.args(refnames.into_iter())
.output()
.chain_err(|| "failed to construct fetch command")?;
if !fetch.status.success() {
bail!(ErrorKind::Git(format!("fetch from {} failed: {}",
remote.as_ref(),
String::from_utf8_lossy(&fetch.stderr))));
bail!(ErrorKind::Git(format!(
"fetch from {} failed: {}",
remote.as_ref(),
String::from_utf8_lossy(&fetch.stderr)
)));
}
Ok(())
......@@ -165,23 +173,29 @@ impl GitContext {
/// Fetch a commit from the given remote into a specific local refname.
pub fn fetch_into<R, N, T>(&self, remote: R, refname: N, target: T) -> Result<()>
where R: AsRef<str>,
N: AsRef<str>,
T: AsRef<str>,
where
R: AsRef<str>,
N: AsRef<str>,
T: AsRef<str>,
{
self.fetch(remote,
&[&format!("{}:{}", refname.as_ref(), target.as_ref())])
self.fetch(
remote,
&[&format!("{}:{}", refname.as_ref(), target.as_ref())],
)
}
/// Fetch a commit from the given remote into a specific local refname, allowing rewinds.
pub fn force_fetch_into<R, N, T>(&self, remote: R, refname: N, target: T) -> Result<()>
where R: AsRef<str>,
N: AsRef<str>,
T: AsRef<str>,
where
R: AsRef<str>,
N: AsRef<str>,
T: AsRef<str>,
{
self.fetch_into(remote.as_ref(),
format!("+{}", refname.as_ref()),
target.as_ref())
self.fetch_into(
remote.as_ref(),
format!("+{}", refname.as_ref()),
target.as_ref(),
)
}
/// Create a tree where further work on the given revision can occur.
......@@ -196,14 +210,16 @@ impl GitContext {
/// The reserved reference is created as `refs/{name}/heads/{id}` where `id` is a unique
/// integer (which is also returned).
pub fn reserve_ref<N>(&self, name: N, commit: &CommitId) -> Result<(String, usize)>
where N: AsRef<str>,
where
N: AsRef<str>,
{
let ref_prefix = format!("refs/{}/heads", name.as_ref());
debug!(target: "git", "reserving ref under {}", ref_prefix);
loop {
let for_each_ref = self.git()
let for_each_ref = self
.git()
.arg("for-each-ref")
.arg("--format=%(refname)")
.arg("--")
......@@ -211,9 +227,11 @@ impl GitContext {
.output()
.chain_err(|| "failed to construct for-each-ref command")?;
if !for_each_ref.status.success() {
bail!(ErrorKind::Git(format!("listing all {} refs: {}",
ref_prefix,
String::from_utf8_lossy(&for_each_ref.stderr))));
bail!(ErrorKind::Git(format!(
"listing all {} refs: {}",
ref_prefix,
String::from_utf8_lossy(&for_each_ref.stderr)
)));
}
let refs = String::from_utf8_lossy(&for_each_ref.stdout);
......@@ -222,7 +240,8 @@ impl GitContext {
debug!(target: "git", "trying to reserve ref {}", new_ref);
let lock_ref = self.git()
let lock_ref = self
.git()
.arg("update-ref")
.arg(&new_ref)
.arg(commit.as_str())
......@@ -258,7 +277,8 @@ impl GitContext {
/// It is assumed that the `bases` refs are aligned with the `heads` references and not used
/// for other purposes.
pub fn reserve_refs<N>(&self, name: N, commit: &CommitId) -> Result<(String, String)>
where N: AsRef<str>,
where
N: AsRef<str>,
{
let (new_ref, id) = self.reserve_ref(name.as_ref(), commit)?;
let new_base = format!("refs/{}/bases/{}", name.as_ref(), id);
......@@ -281,7 +301,8 @@ impl GitContext {
return Ok(MergeStatus::NoCommonHistory);
}
let bases = String::from_utf8_lossy(&merge_base.stdout);
let bases = bases.split_whitespace()
let bases = bases
.split_whitespace()
.map(CommitId::new)
.collect::<Vec<_>>();
......
......@@ -43,8 +43,8 @@ mod prepare;
pub use error::Error;
pub use error::ErrorKind;
pub use error::ResultExt;
pub use error::Result;
pub use error::ResultExt;
pub use git::CommitId;
pub use git::GitContext;
......@@ -52,9 +52,9 @@ pub use git::Identity;
pub use git::MergeStatus;
pub use prepare::Conflict;
pub use prepare::GitWorkArea;
pub use prepare::MergeCommand;
pub use prepare::MergeResult;
pub use prepare::GitWorkArea;
pub use prepare::SubmoduleConfig;
#[cfg(test)]
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment