summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2023-11-28 16:14:22 -0500
committerAndrew Gallant <jamslam@gmail.com>2023-11-28 16:17:14 -0500
commitdaa157b5f99c064eac7cd4593e4ec07bb8fd9bef (patch)
treef805306b2b6aaafd1c02fc37aebbf29f2cafca8a
parentca5e294ad6b64b03c1d2fb4d9ed8c32b73e656ae (diff)
core: actually implement --sortr=path
This is an embarrassing oversight. A `todo!()` actually made its way into a release! Oof. This was working in ripgrep 13, but I had redone some aspects of sorting and this just got left undone. Fixes #2664
-rw-r--r--CHANGELOG.md10
-rw-r--r--crates/core/flags/hiargs.rs8
-rw-r--r--tests/feature.rs11
3 files changed, 28 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b8ef0e67..366f904e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+14.0.3 (2023-11-28)
+===================
+This is a patch release with a bug fix for the `--sortr` flag.
+
+Bug fixes:
+
+* [BUG #2664](https://github.com/BurntSushi/ripgrep/issues/2664):
+ Fix `--sortr=path`. I left a `todo!()` in the source. Oof.
+
+
14.0.2 (2023-11-27)
===================
This is a patch release with a few small bug fixes.
diff --git a/crates/core/flags/hiargs.rs b/crates/core/flags/hiargs.rs
index 59a178e4..e027a2c9 100644
--- a/crates/core/flags/hiargs.rs
+++ b/crates/core/flags/hiargs.rs
@@ -771,7 +771,13 @@ impl HiArgs {
let Some(ref sort) = self.sort else { return Box::new(haystacks) };
let mut with_timestamps: Vec<_> = match sort.kind {
SortModeKind::Path if !sort.reverse => return Box::new(haystacks),
- SortModeKind::Path => todo!(),
+ SortModeKind::Path => {
+ let mut haystacks = haystacks.collect::<Vec<Haystack>>();
+ haystacks.sort_by(|ref h1, ref h2| {
+ h1.path().cmp(h2.path()).reverse()
+ });
+ return Box::new(haystacks.into_iter());
+ }
SortModeKind::LastModified => {
attach_timestamps(haystacks, |md| md.modified()).collect()
}
diff --git a/tests/feature.rs b/tests/feature.rs
index e2786854..b0a70acc 100644
--- a/tests/feature.rs
+++ b/tests/feature.rs
@@ -356,6 +356,17 @@ rgtest!(f263_sort_files, |dir: Dir, mut cmd: TestCommand| {
eqnice!(expected, cmd.arg("--sort-files").arg("test").stdout());
});
+// See: https://github.com/BurntSushi/ripgrep/issues/263
+rgtest!(f263_sort_files_reverse, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("foo", "test");
+ dir.create("abc", "test");
+ dir.create("zoo", "test");
+ dir.create("bar", "test");
+
+ let expected = "zoo:test\nfoo:test\nbar:test\nabc:test\n";
+ eqnice!(expected, cmd.arg("--sortr=path").arg("test").stdout());
+});
+
// See: https://github.com/BurntSushi/ripgrep/issues/275
rgtest!(f275_pathsep, |dir: Dir, mut cmd: TestCommand| {
dir.create_dir("foo");