Skip to content

Commit 7e2474f

Browse files
Fix chain(prefix(a/b),subdir(a)) (#1529)
The implementation here was wrong in that it assumed subdir would be deeper than prefix. Strangely the bug never manifested except now in a scenario of building filters programatically. I could not get the bug to reproduce by writing a filter spec, so the regression test needs to be a rust test. Change: fix-chain-bug
1 parent 673489f commit 7e2474f

Some content is hidden

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

53 files changed

+74
-54
lines changed

josh-core/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 = 23;
4+
const CACHE_VERSION: u64 = 24;
55

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

josh-core/src/filter/opt.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ fn step(filter: Filter) -> Filter {
427427
Op::Empty
428428
}
429429
(Op::Prefix(a), Op::Subdir(b)) if a != b => {
430-
Op::Prefix(a.strip_prefix(&b).unwrap_or(&a).to_owned())
430+
if let Ok(stripped) = a.strip_prefix(&b) {
431+
Op::Prefix(stripped.to_owned())
432+
} else {
433+
to_op(filter)
434+
}
431435
}
432436
(Op::Nop, b) => b,
433437
(a, Op::Nop) => a,
@@ -528,3 +532,19 @@ pub fn invert(filter: Filter) -> JoshResult<Filter> {
528532
INVERTED.lock().unwrap().insert(original, result);
529533
Ok(result)
530534
}
535+
536+
#[cfg(test)]
537+
mod tests {
538+
use super::*;
539+
540+
#[test]
541+
fn regression_chain_prefix_subdir() {
542+
// When prefix is chained with subdir, and the subdir is deeper than
543+
// the prefix, the errornous code optimized this to just Prefix("a")
544+
let filter = to_filter(Op::Chain(
545+
to_filter(Op::Prefix(std::path::PathBuf::from("a"))),
546+
to_filter(Op::Subdir(std::path::PathBuf::from("a/b"))),
547+
));
548+
assert_eq!(filter, optimize(filter));
549+
}
550+
}

tests/proxy/amend_patchset.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
]
125125
.
126126
|-- josh
127-
| `-- 23
127+
| `-- 24
128128
| `-- sled
129129
| |-- blobs
130130
| |-- 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-
| `-- 23
127+
| `-- 24
128128
| `-- sled
129129
| |-- blobs
130130
| |-- conf

tests/proxy/caching.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
]
5252
.
5353
|-- josh
54-
| `-- 23
54+
| `-- 24
5555
| `-- sled
5656
| |-- blobs
5757
| |-- conf
@@ -162,7 +162,7 @@
162162
]
163163
.
164164
|-- josh
165-
| `-- 23
165+
| `-- 24
166166
| `-- sled
167167
| |-- blobs
168168
| |-- conf

tests/proxy/clone_absent_head.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
$ bash ${TESTDIR}/destroy_test_env.sh
8686
.
8787
|-- josh
88-
| `-- 23
88+
| `-- 24
8989
| `-- sled
9090
| |-- blobs
9191
| |-- 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-
| `-- 23
56+
| `-- 24
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-
| `-- 23
12+
| `-- 24
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-
| `-- 23
35+
| `-- 24
3636
| `-- sled
3737
| |-- blobs
3838
| |-- conf

tests/proxy/clone_locked_refs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
]
112112
.
113113
|-- josh
114-
| `-- 23
114+
| `-- 24
115115
| `-- sled
116116
| |-- blobs
117117
| |-- conf

0 commit comments

Comments
 (0)