Commit 087dcfc2 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'misc-cleanups'

0caeb4c0 logging: use Path::display instead of the file_name helper
1e8fcb26 git: document that `gitdir` needs to be a `.git` directory
9c5ef6c6 git: prefer Into<X> for generics passing ownership
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Brad King's avatarBrad King <brad.king@kitware.com>
Merge-request: !75
parents 770d3b96 0caeb4c0
# v4.1.0 (unreleased)
* Arguments taking `AsRef<Path>` are now `Into<PathBuf>` if the
implementation ends up owning the parameter anyays.
# v4.0.0
* The `MergeCommand::author_date` method now takes a `DateTime<Utc>` rather
......
......@@ -101,7 +101,10 @@ pub(crate) type GitResult<T> = Result<T, GitError>;
impl CommitId {
/// Create a new `CommitId`.
pub fn new<I: Into<String>>(id: I) -> Self {
pub fn new<I>(id: I) -> Self
where
I: Into<String>,
{
CommitId(id.into())
}
......@@ -121,6 +124,8 @@ impl Display for CommitId {
#[derive(Debug, Clone)]
pub struct GitContext {
/// The path to the `.git` directory.
///
/// Note that this must not be the path to a checkout. It is treated as a bare repository.
gitdir: PathBuf,
/// The path to the configuration file.
config: Option<PathBuf>,
......@@ -191,10 +196,10 @@ impl GitContext {
/// Create a new context for the given directory.
pub fn new<P>(gitdir: P) -> Self
where
P: AsRef<Path>,
P: Into<PathBuf>,
{
Self {
gitdir: gitdir.as_ref().to_path_buf(),
gitdir: gitdir.into(),
config: None,
}
}
......@@ -202,12 +207,12 @@ 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>,
P: Into<PathBuf>,
C: Into<PathBuf>,
{
Self {
gitdir: gitdir.as_ref().to_path_buf(),
config: Some(config.as_ref().to_path_buf()),
gitdir: gitdir.into(),
config: Some(config.into()),
}
}
......@@ -274,9 +279,9 @@ impl GitContext {
T: AsRef<str>,
{
self.fetch_into(
remote.as_ref(),
remote,
format!("+{}", refname.as_ref()),
target.as_ref(),
target,
)
}
......
......@@ -4,7 +4,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::borrow::Cow;
use std::collections::hash_map::HashMap;
use std::ffi::OsStr;
use std::fmt::{self, Debug};
......@@ -392,14 +391,6 @@ fn checkout_files(ctx: &dyn WorkAreaGitContext, files: &[u8]) -> GitResult<()> {
Ok(())
}
/// Get the file name of a path.
///
/// Used to simplify printing a filename.
fn file_name(path: &Path) -> Cow<str> {
path.file_name()
.map_or_else(|| Cow::Borrowed("<unknown>"), OsStr::to_string_lossy)
}
impl PreparingGitWorkArea {
/// Create an area for performing actions which require a work tree.
fn new(context: GitContext, rev: &CommitId) -> Result<Self, WorkAreaError> {
......@@ -411,16 +402,20 @@ impl PreparingGitWorkArea {
dir: tempdir,
};
debug!(target: "git.workarea",
"creating prepared workarea under {}",
workarea.dir.path().display());
debug!(
target: "git.workarea",
"creating prepared workarea under {}",
workarea.dir.path().display(),
);
fs::create_dir_all(workarea.work_tree()).map_err(WorkAreaError::work_tree)?;
workarea.prepare(rev)?;
debug!(target: "git.workarea",
"created prepared workarea under {}",
file_name(workarea.dir.path()));
debug!(
target: "git.workarea",
"created prepared workarea under {}",
workarea.dir.path().display(),
);
Ok(workarea)
}
......@@ -558,15 +553,19 @@ impl GitWorkArea {
dir: intermediate.dir,
};
debug!(target: "git.workarea",
"creating prepared workarea with submodules under {}",
workarea.dir.path().display());
debug!(
target: "git.workarea",
"creating prepared workarea with submodules under {}",
workarea.dir.path().display(),
);
workarea.prepare_submodules()?;
debug!(target: "git.workarea",
"created prepared workarea with submodules under {}",
file_name(workarea.dir.path()));
debug!(
target: "git.workarea",
"created prepared workarea with submodules under {}",
workarea.dir.path().display(),
);
Ok(workarea)
}
......@@ -577,19 +576,23 @@ impl GitWorkArea {
return Ok(());
}
debug!(target: "git.workarea",
"preparing submodules for {}",
file_name(self.dir.path()));
debug!(
target: "git.workarea",
"preparing submodules for {}",
self.dir.path().display(),
);
for (name, config) in &self.submodule_config {
let gitdir = self.context.gitdir().join("modules").join(name);
if !gitdir.exists() {
error!(target: "git.workarea",
"{}: submodule configuration for {} does not exist: {}",
file_name(self.dir.path()),
name,
gitdir.display());
error!(
target: "git.workarea",
"{}: submodule configuration for {} does not exist: {}",
self.dir.path().display(),
name,
gitdir.display(),
);
continue;
}
......@@ -597,11 +600,13 @@ impl GitWorkArea {
let path = match config.get("path") {
Some(path) => path,
None => {
error!(target: "git.workarea",
"{}: submodule configuration for {}.path does not exist (skipping): {}",
file_name(self.dir.path()),
name,
gitdir.display());
error!(
target: "git.workarea",
"{}: submodule configuration for {}.path does not exist (skipping): {}",
self.dir.path().display(),
name,
gitdir.display(),
);
continue;
},
};
......@@ -643,10 +648,12 @@ impl GitWorkArea {
{
let path = path.as_ref().to_path_buf();
debug!(target: "git.workarea",
"{} checking for a submodule conflict for {}",
file_name(self.dir.path()),
path.display());
debug!(
target: "git.workarea",
"{} checking for a submodule conflict for {}",
self.dir.path().display(),
path.display(),
);
let branch_info = self
.submodule_config
......@@ -661,18 +668,22 @@ impl GitWorkArea {
let (name, branch) = if let Some((name, branch_name)) = branch_info {
if branch_name == "." {
// TODO(#6): Pass the branch name we are working on down to here.
debug!(target: "git.workarea",
"the `.` branch specifier for submodules is not supported for conflict \
resolution");
debug!(
target: "git.workarea",
"the `.` branch specifier for submodules is not supported for conflict \
resolution",
);
return Ok(Conflict::Path(path));
}
(name, branch_name)
} else {
debug!(target: "git.workarea",
"no submodule configured for {}; cannot attempt smarter resolution",
path.display());
debug!(
target: "git.workarea",
"no submodule configured for {}; cannot attempt smarter resolution",
path.display(),
);
return Ok(Conflict::Path(path));
};
......@@ -841,10 +852,12 @@ impl GitWorkArea {
base: &CommitId,
topic: &CommitId,
) -> GitResult<MergeResult<'a>> {
debug!(target: "git.workarea",
"merging {} into {}",
topic,
base);
debug!(
target: "git.workarea",
"merging {} into {}",
topic,
base,
);
let write_tree = self
.git()
......
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