Skip to content

Commit c0a170a

Browse files
authored
Fix bug in alternates usage in template rendering (#1229)
When the template rendering was used, the mirror and overlay were switched, leading the objects to end-up in the wrong store. Change: template-render-alternate
1 parent 5709a59 commit c0a170a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

josh-core/src/query.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl GraphQLHelper {
5454
variables.insert(k.to_string(), juniper::InputValue::scalar(v.render()));
5555
}
5656

57-
let (transaction, transaction_overlay) =
57+
let (transaction, transaction_mirror) =
5858
if let Ok(to) = cache::Transaction::open(&self.repo_path.join("overlay"), None) {
5959
to.repo().odb()?.add_disk_alternate(
6060
self.repo_path
@@ -64,8 +64,8 @@ impl GraphQLHelper {
6464
.unwrap(),
6565
)?;
6666
(
67-
cache::Transaction::open(&self.repo_path.join("mirror"), None)?,
6867
to,
68+
cache::Transaction::open(&self.repo_path.join("mirror"), None)?,
6969
)
7070
} else {
7171
(
@@ -79,7 +79,7 @@ impl GraphQLHelper {
7979
None,
8080
&graphql::commit_schema(self.commit_id),
8181
&variables,
82-
&graphql::context(transaction, transaction_overlay),
82+
&graphql::context(transaction, transaction_mirror),
8383
)?;
8484

8585
let j = serde_json::to_string(&res)?;

tests/proxy/query.t

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
$ mkdir sub1
1010
$ echo contents1 > sub1/file1
11+
$ echo contents > sub1/test
1112
$ git add sub1
1213
$ git commit -m "add file1" 1> /dev/null
1314

@@ -19,13 +20,18 @@
1920
$ cat > x.graphql <<EOF
2021
> query {
2122
> hash
23+
> rev(filter: "::**/file*")
24+
> {
25+
> hash
26+
> }
2227
> }
2328
> EOF
2429

2530
$ cat > tmpl_file <<EOF
2631
> param: {{ param_val }}
2732
> {{ #with (graphql file="x.graphql") as |gql| }}
2833
> sha: {{ gql.hash }}
34+
> filter_sha: {{gql.rev.hash}}
2935
> {{ /with }}
3036
> EOF
3137

@@ -46,18 +52,31 @@
4652
* [new reference] HEAD -> refs/changes/123/2
4753

4854
$ cd ${TESTTMP}
49-
55+
Get works
5056
$ curl -s http://localhost:8002/real_repo.git:/sub1.git?get=file1
5157
contents1
58+
59+
Filter once before calling render
60+
$ git clone http://localhost:8002/real_repo.git::**/file*.git
61+
Cloning into 'file*'...
62+
63+
Now render still works (used to fail if filtered previously)
64+
$ curl -s http://localhost:8002/real_repo.git?render=tmpl_file\&param_val=12345
65+
param: 12345
66+
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
67+
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e
68+
69+
70+
Failing render for lack of variable
5271
$ curl -i -s http://localhost:8002/real_repo.git?render=tmpl_file
5372
HTTP/1.1 422 Unprocessable Entity\r (esc)
5473
content-length: 100\r (esc)
5574
date: *\r (esc) (glob)
5675
\r (esc)
5776
JoshError(Error rendering "tmpl_file" line 1, col 8: Variable "param_val" not found in strict mode.) (no-eol)
58-
$ curl -s http://localhost:8002/real_repo.git?render=tmpl_file\&param_val=12345
59-
param: 12345
60-
sha: 002d20d28aab1ebe3892b01ec1dfc60d43fc598f
77+
78+
79+
6180
$ curl -s http://localhost:8002/real_repo.git?get=sub1/file1
6281
contents1
6382
$ curl -s http://localhost:8002/real_repo.git@refs/changes/123/2:nop.git?get=sub2/on_change

0 commit comments

Comments
 (0)