Skip to content

Commit

Permalink
Prevent re-mapping of workspace file
Browse files Browse the repository at this point in the history
For workspace reversal to work, the mapped location of the
workspace.josh file must always be the root of the workspace.
Previously it was possible to change this by adding a mapping to
the file itself, breaking push.

Change-Id: no-workspace-remap
  • Loading branch information
christian-schilling authored and LMG committed Aug 25, 2022
1 parent e907cfd commit a287bc6
Show file tree
Hide file tree
Showing 47 changed files with 197 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use std::collections::HashMap;

const CACHE_VERSION: u64 = 11;
const CACHE_VERSION: u64 = 12;

lazy_static! {
static ref DB: std::sync::Mutex<Option<sled::Db>> = std::sync::Mutex::new(None);
Expand Down
10 changes: 7 additions & 3 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,12 @@ fn apply2<'a>(
Op::Invert => tree::invert_paths(transaction, "", tree),

Op::Workspace(path) => {
let wsj_file = to_filter(Op::File(Path::new("workspace.josh").to_owned()));
let base = to_filter(Op::Subdir(path.to_owned()));
let wsj_file = chain(base, wsj_file);
apply(
transaction,
compose(get_workspace(repo, &tree, path), base),
compose(wsj_file, compose(get_workspace(repo, &tree, path), base)),
tree,
)
}
Expand Down Expand Up @@ -661,8 +663,10 @@ fn unapply_workspace<'a>(
let original_workspace = get_workspace(transaction.repo(), &parent_tree, path);

let root = to_filter(Op::Subdir(path.to_owned()));
let filter = compose(workspace, root);
let original_filter = compose(original_workspace, root);
let wsj_file = to_filter(Op::File(Path::new("workspace.josh").to_owned()));
let wsj_file = chain(root, wsj_file);
let filter = compose(wsj_file, compose(workspace, root));
let original_filter = compose(wsj_file, compose(original_workspace, root));
let matching = apply(
transaction,
chain(original_filter, invert(original_filter)?),
Expand Down
6 changes: 6 additions & 0 deletions tests/filter/workspace_unique.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
$ git commit -m "add file2" 1> /dev/null

$ mkdir ws

Note that we are trying to relocate the workspace.josh file, which is not possible
so the workspace.josh will still appear in the root of the workspace
$ cat > ws/workspace.josh <<EOF
> :/sub1::file1
> ::sub2/subsub/
> a = :/sub1
> b = ::ws/workspace.josh
> EOF
$ git add ws
$ git commit -m "add ws" 1> /dev/null
Expand All @@ -28,6 +32,7 @@
[1] :/sub1
[1] :/subsub
[1] ::file1
[1] ::ws/workspace.josh
[1] :[
::file1
:prefix=a
Expand All @@ -42,6 +47,7 @@
:prefix=a
]
::sub2/subsub/
b = ::ws/workspace.josh
]
[2] :workspace=ws

Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/amend_patchset.t
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"real_repo.git" = [':/sub3']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/authentication.t
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
4 changes: 2 additions & 2 deletions tests/proxy/caching.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down Expand Up @@ -156,7 +156,7 @@
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_absent_head.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_all.t
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_blocked.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_invalid_url.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_prefix.t
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_sha.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subsubtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subtree_no_master.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/clone_subtree_tags.t
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/empty_commit.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ should still be included.
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/get_version.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/import_export.t
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ Flushed credential cache
"repo2.git" = [':prefix=repo2']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/join_with_merge.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"real_repo.git" = [':prefix=sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/markers.t
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/no_proxy.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$ bash ${TESTDIR}/destroy_test_env.sh
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_new_branch.t
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Check the branch again
"real_repo.git" = [':/sub']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_prefix.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_review.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Make sure all temporary namespace got removed
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_review_already_in.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test for that.
"real_repo.git" = []
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_review_nop_behind.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This is a regression test for that problem.
"real_repo.git" = []
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_review_old.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Flushed credential cache
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_review_topic.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Make sure all temporary namespace got removed
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_stacked.t
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Make sure all temporary namespace got removed
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_stacked_sub.t
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Make sure all temporary namespace got removed
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_subdir_prefix.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_subtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Make sure all temporary namespace got removed
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/push_subtree_two_repos.t
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Put a double slash in the URL to see that it also works
"real_repo.git" = [':/sub1']
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/unrelated_leak.t
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Flushed credential cache
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/workspace.t
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
]
.
|-- josh
| `-- 11
| `-- 12
| `-- sled
| |-- blobs
| |-- conf
Expand Down
Loading

0 comments on commit a287bc6

Please sign in to comment.