Skip to content

Commit 1a16413

Browse files
Fix prefix/subdir optimisation bug
The optimiser rule was wrong in case the subdir filter path was a prefix of the prefix filter. It resulted in :empty in this case, which is wrong. Change: fix-prefix-subdir
1 parent a973f60 commit 1a16413

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+59
-50
lines changed

src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use std::collections::HashMap;
33

4-
const CACHE_VERSION: u64 = 13;
4+
const CACHE_VERSION: u64 = 14;
55

66
lazy_static! {
77
static ref DB: std::sync::Mutex<Option<sled::Db>> = std::sync::Mutex::new(None);

src/filter/opt.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,14 @@ fn step(filter: Filter) -> Filter {
353353
Op::Chain(a, b) => match (to_op(a), to_op(b)) {
354354
(Op::Chain(x, y), b) => Op::Chain(x, to_filter(Op::Chain(y, to_filter(b)))),
355355
(Op::Prefix(a), Op::Subdir(b)) if a == b => Op::Nop,
356-
(Op::Prefix(a), Op::Subdir(b)) if a != b => Op::Empty,
356+
(Op::Prefix(a), Op::Subdir(b))
357+
if a != b && a.components().count() == b.components().count() =>
358+
{
359+
Op::Empty
360+
}
361+
(Op::Prefix(a), Op::Subdir(b)) if a != b => {
362+
Op::Prefix(a.strip_prefix(&b).unwrap_or(&a).to_owned())
363+
}
357364
(Op::Nop, b) => b,
358365
(a, Op::Nop) => a,
359366
(Op::Empty, _) => Op::Empty,

tests/filter/pretty_print.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
:/"a%\"$"
1313
$ josh-filter -p :/a:/b
1414
:/a/b
15+
$ josh-filter -p :prefix=x/y:/x
16+
:prefix=y
1517
$ josh-filter -p :[:/a:/b,:/a/b]
1618
:/a/b
1719
$ josh-filter -p :[:empty,:/a]

tests/proxy/amend_patchset.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"real_repo.git" = [':/sub3']
122122
.
123123
|-- josh
124-
| `-- 13
124+
| `-- 14
125125
| `-- sled
126126
| |-- blobs
127127
| |-- conf

tests/proxy/authentication.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"real_repo.git" = [':/sub1']
125125
.
126126
|-- josh
127-
| `-- 13
127+
| `-- 14
128128
| `-- sled
129129
| |-- blobs
130130
| |-- conf

tests/proxy/caching.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"real_repo.git" = [':/sub1']
4949
.
5050
|-- josh
51-
| `-- 13
51+
| `-- 14
5252
| `-- sled
5353
| |-- blobs
5454
| |-- conf
@@ -156,7 +156,7 @@
156156
"real_repo.git" = [':/sub1']
157157
.
158158
|-- josh
159-
| `-- 13
159+
| `-- 14
160160
| `-- sled
161161
| |-- blobs
162162
| |-- conf

tests/proxy/clone_absent_head.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
$ bash ${TESTDIR}/destroy_test_env.sh
8888
.
8989
|-- josh
90-
| `-- 13
90+
| `-- 14
9191
| `-- sled
9292
| |-- blobs
9393
| |-- conf

tests/proxy/clone_all.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"real_repo.git" = [':/sub1']
5454
.
5555
|-- josh
56-
| `-- 13
56+
| `-- 14
5757
| `-- sled
5858
| |-- blobs
5959
| |-- conf

tests/proxy/clone_blocked.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$ bash ${TESTDIR}/destroy_test_env.sh
1010
.
1111
|-- josh
12-
| `-- 13
12+
| `-- 14
1313
| `-- sled
1414
| |-- blobs
1515
| |-- conf

tests/proxy/clone_invalid_url.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$ bash ${TESTDIR}/destroy_test_env.sh
3333
.
3434
|-- josh
35-
| `-- 13
35+
| `-- 14
3636
| `-- sled
3737
| |-- blobs
3838
| |-- conf

0 commit comments

Comments
 (0)