Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl State {
.map(|_| {
let mut prefix: PathBuf = subdir.components().map(|_| "..").collect();
prefix.push(&patches_name);
format!("{}/", prefix.display())
format!("{}/", with_slashes(prefix).display())
});

Ok(Self {
Expand Down Expand Up @@ -318,12 +318,14 @@ impl State {
} else {
self.subdir.join(path)
};
rel.components()
.filter_map(|component| match component {
Component::CurDir => None,
other => Some(other.as_os_str().to_owned()),
})
.collect()
with_slashes(
rel.components()
.filter_map(|component| match component {
Component::CurDir => None,
other => Some(other.as_os_str().to_owned()),
})
.collect(),
)
}

pub fn tracked_files(&self, patch: &str) -> Result<Vec<PathBuf>> {
Expand Down Expand Up @@ -354,14 +356,30 @@ impl State {
}
};
if entry.file_type().is_file() && entry.file_name() != ".timestamp" {
files.push(entry.path().strip_prefix(&dir)?.to_path_buf());
files.push(with_slashes(entry.path().strip_prefix(&dir)?.to_path_buf()));
}
}
sort_tracked(&mut files);
Ok(files)
}
}

/// A path relative to the quilt root as quilt writes it in patches and
/// listings, with `/` even on Windows, where `Path` joins components with `\`
/// but accepts `/` as well.
#[cfg(windows)]
pub(crate) fn with_slashes(path: PathBuf) -> PathBuf {
match path.to_str() {
Some(text) if !path.is_absolute() => PathBuf::from(text.replace('\\', "/")),
_ => path,
}
}

#[cfg(not(windows))]
pub(crate) fn with_slashes(path: PathBuf) -> PathBuf {
path
}

/// quilt's order for a patch's files: shallower paths first, then by name.
pub(crate) fn sort_tracked(files: &mut [PathBuf]) {
files.sort_by(|a, b| {
Expand Down Expand Up @@ -417,6 +435,10 @@ fn write_if_missing(path: PathBuf, value: &str) -> Result<()> {
#[cfg(test)]
mod tests {
use super::parse_series_line;
#[cfg(windows)]
use super::with_slashes;
#[cfg(windows)]
use std::path::PathBuf;

#[test]
fn parses_series_lines_with_options_and_comments() {
Expand All @@ -430,4 +452,13 @@ mod tests {
assert!(parse_series_line("# patch.diff").is_none());
assert!(parse_series_line(" ").is_none());
}

#[cfg(windows)]
#[test]
fn writes_relative_paths_with_slashes() {
let path = with_slashes(PathBuf::from(r"chrome\app\main.cc"));
assert_eq!(path.to_str(), Some("chrome/app/main.cc"));
let absolute = with_slashes(PathBuf::from(r"C:\src\main.cc"));
assert_eq!(absolute.to_str(), Some(r"C:\src\main.cc"));
}
}
Loading