Skip to content

Commit 4448913

Browse files
Make compose and subtract single traversal
Previously those filters where first creating the filtered histories of their inputs to populate the cache. It has shown in profiling though that in practice it is faster to apply those nested filters directly without pre building history. Change: direct-next
1 parent e58076d commit 4448913

26 files changed

+12
-321
lines changed

josh-core/src/filter/mod.rs

-74
Original file line numberDiff line numberDiff line change
@@ -564,41 +564,6 @@ fn apply_to_commit2(
564564
))
565565
.transpose();
566566
}
567-
Op::Compose(filters) => {
568-
let filtered = filters
569-
.iter()
570-
.map(|f| apply_to_commit2(&to_op(*f), commit, transaction))
571-
.collect::<Vec<_>>()
572-
.into_iter()
573-
.collect::<JoshResult<Option<Vec<_>>>>()?;
574-
575-
let filtered = some_or!(filtered, { return Ok(None) });
576-
577-
let inverted = invert(filter)?;
578-
579-
if filter == inverted {
580-
// If the filter is symetric it does not change any paths and uniqueness of
581-
// mappings is already guaranteed.
582-
let filtered = filtered
583-
.into_iter()
584-
.filter(|id| *id != git2::Oid::zero())
585-
.into_iter()
586-
.map(|id| Ok(repo.find_commit(id)?.tree_id()))
587-
.collect::<JoshResult<Vec<_>>>()?;
588-
589-
tree::compose_fast(transaction, filtered)?
590-
} else {
591-
let filtered = filters
592-
.iter()
593-
.zip(filtered.into_iter())
594-
.filter(|(_, id)| *id != git2::Oid::zero())
595-
.into_iter()
596-
.map(|(f, id)| Ok((f, repo.find_commit(id)?.tree()?)))
597-
.collect::<JoshResult<Vec<_>>>()?;
598-
599-
tree::compose(transaction, filtered)?
600-
}
601-
}
602567
Op::Workspace(ws_path) => {
603568
let normal_parents = commit
604569
.parent_ids()
@@ -673,45 +638,6 @@ fn apply_to_commit2(
673638

674639
repo.find_tree(filtered_tree)?
675640
}
676-
Op::Subtract(a, b) => {
677-
let af = {
678-
transaction
679-
.repo()
680-
.find_commit(some_or!(
681-
apply_to_commit2(&to_op(*a), commit, transaction)?,
682-
{ return Ok(None) }
683-
))
684-
.map(|x| x.tree_id())
685-
.unwrap_or_else(|_| tree::empty_id())
686-
};
687-
let bf = {
688-
transaction
689-
.repo()
690-
.find_commit(some_or!(
691-
apply_to_commit2(&to_op(*b), commit, transaction)?,
692-
{ return Ok(None) }
693-
))
694-
.map(|x| x.tree_id())
695-
.unwrap_or_else(|_| tree::empty_id())
696-
};
697-
let bf = repo.find_tree(bf)?;
698-
let bu = apply(transaction, invert(*b)?, bf)?;
699-
let ba = apply(transaction, *a, bu)?.id();
700-
repo.find_tree(tree::subtract(transaction, af, ba)?)?
701-
}
702-
Op::Exclude(b) => {
703-
let bf = {
704-
transaction
705-
.repo()
706-
.find_commit(some_or!(
707-
apply_to_commit2(&to_op(*b), commit, transaction)?,
708-
{ return Ok(None) }
709-
))
710-
.map(|x| x.tree_id())
711-
.unwrap_or_else(|_| tree::empty_id())
712-
};
713-
repo.find_tree(tree::subtract(transaction, commit.tree_id(), bf)?)?
714-
}
715641
_ => apply(transaction, filter, commit.tree()?)?,
716642
};
717643

tests/filter/compose_shadow_dir_same_name.t

-8
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,12 @@
8686
+contents1
8787

8888
$ josh-filter -s ":[:/sub/xx::file3,:/sub1,:/xx,:/sub/xx]"
89-
[1] :/sub1
90-
[1] ::file3
91-
[2] :/sub
92-
[3] :/xx
9389
[3] :[
9490
:/sub/xx::file3
9591
:/sub1
9692
:/xx
9793
:/sub/xx
9894
]
99-
[3] :[
100-
:/xx
101-
:/sub/xx
102-
]
10395
$ git diff ${EMPTY_TREE}..FILTERED_HEAD
10496
diff --git a/file1 b/file1
10597
new file mode 100644

tests/filter/empty_orphan.t

-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Empty root commits from unrelated parts of the tree should not be included
9595
c/file3
9696

9797
$ josh-filter -s c=:exclude[::sub1/] master
98-
[4] :prefix=sub1
9998
[5] :/sub1
10099
[5] :exclude[::sub1/]
101100
[6] :prefix=c
@@ -111,7 +110,6 @@ Empty root commits from unrelated parts of the tree should not be included
111110

112111
$ josh-filter -s :prefix=x FILTERED_HEAD
113112
[3] :prefix=x
114-
[4] :prefix=sub1
115113
[5] :/sub1
116114
[5] :exclude[::sub1/]
117115
[6] :prefix=c

tests/filter/exclude_compose.t

-19
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
$ git commit -m "add file3" 1> /dev/null
2121

2222
$ josh-filter -s :exclude[::sub2/] master --update refs/heads/hidden
23-
[1] :prefix=sub2
24-
[2] :/sub2
2523
[2] :exclude[::sub2/]
2624
$ git checkout -q hidden 1> /dev/null
2725
$ tree
@@ -41,14 +39,6 @@
4139
$ git commit -m "add sub1/file3" 1> /dev/null
4240

4341
$ josh-filter -s :exclude[::sub1/,::sub2/] master --update refs/josh/filtered
44-
[1] :/sub1
45-
[1] :prefix=sub1
46-
[1] :prefix=sub2
47-
[2] :/sub2
48-
[2] :[
49-
::sub1/
50-
::sub2/
51-
]
5242
[2] :exclude[
5343
::sub1/
5444
::sub2/
@@ -64,20 +54,11 @@
6454
2 directories, 1 file
6555

6656
$ josh-filter -s :exclude[sub1=:/sub3] master --update refs/josh/filtered
67-
[1] :/sub1
68-
[1] :prefix=sub2
69-
[2] :/sub2
70-
[2] :/sub3
71-
[2] :[
72-
::sub1/
73-
::sub2/
74-
]
7557
[2] :exclude[
7658
::sub1/
7759
::sub2/
7860
]
7961
[2] :exclude[::sub2/]
80-
[2] :prefix=sub1
8162
[3] :exclude[:/sub3:prefix=sub1]
8263

8364
$ git checkout -q refs/josh/filtered

tests/filter/file.t

-10
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
$ git commit -m "initial" 1> /dev/null
3030

3131
$ josh-filter -s --file file.josh
32-
[1] :prefix=a
33-
[1] :prefix=b
34-
[2] :/sub1
35-
[2] :/sub2
36-
[2] :prefix=c
3732
[3] :[
3833
c = :/sub1
3934
a/b = :/sub2
@@ -44,11 +39,6 @@
4439
* add file1
4540

4641
$ josh-filter -s --single --file file.josh
47-
[2] :prefix=a
48-
[2] :prefix=b
49-
[3] :/sub1
50-
[3] :/sub2
51-
[3] :prefix=c
5242
[4] :[
5343
c = :/sub1
5444
a/b = :/sub2

tests/filter/hide_view.t

-9
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535

3636
$ josh-filter -s c=:exclude[::sub1/] master --update refs/josh/filter/master
3737
[1] :prefix=c
38-
[2] :/sub1
3938
[2] :exclude[::sub1/]
40-
[2] :prefix=sub1
4139
$ git checkout josh/filter/master 2> /dev/null
4240
$ git log --graph --pretty=%s
4341
* add file3
@@ -50,11 +48,8 @@
5048
3 directories, 1 file
5149

5250
$ josh-filter -s c=:exclude[::sub1/file2] master --update refs/josh/filter/master
53-
[2] :/sub1
54-
[2] ::sub1/file2
5551
[2] :exclude[::sub1/]
5652
[2] :exclude[::sub1/file2]
57-
[2] :prefix=sub1
5853
[3] :prefix=c
5954
$ git checkout josh/filter/master 2> /dev/null
6055
$ git log --graph --pretty=%s
@@ -71,13 +66,9 @@
7166
4 directories, 2 files
7267

7368
$ josh-filter -s c=:exclude[::sub2/file3] master --update refs/josh/filter/master
74-
[2] :/sub1
75-
[2] ::sub1/file2
76-
[2] ::sub2/file3
7769
[2] :exclude[::sub1/]
7870
[2] :exclude[::sub1/file2]
7971
[2] :exclude[::sub2/file3]
80-
[2] :prefix=sub1
8172
[4] :prefix=c
8273
$ git checkout josh/filter/master 2> /dev/null
8374
$ git log --graph --pretty=%s

tests/filter/reverse_hide.t

-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
$ josh-filter -s :exclude[::sub2/] master --update refs/heads/hidden
1818
[1] :exclude[::sub2/]
19-
[1] :prefix=sub2
20-
[2] :/sub2
2119
$ git checkout hidden 1> /dev/null
2220
Switched to branch 'hidden'
2321
$ tree
@@ -35,8 +33,6 @@
3533

3634
$ josh-filter -s :exclude[::sub2/] --reverse master --update refs/heads/hidden
3735
[1] :exclude[::sub2/]
38-
[1] :prefix=sub2
39-
[2] :/sub2
4036

4137
$ git checkout master
4238
Switched to branch 'master'
@@ -70,8 +66,6 @@
7066
$ git commit -m "empty commit" --allow-empty 1> /dev/null
7167

7268
$ josh-filter -s :exclude[::sub2/] --reverse master --update refs/heads/hidden
73-
[1] :prefix=sub2
74-
[2] :/sub2
7569
[2] :exclude[::sub2/]
7670
$ git log --graph --pretty=%s refs/heads/master
7771
* empty commit

tests/filter/reverse_hide_edit.t

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
$ josh-filter -s :exclude[::sub2/] master --update refs/heads/hidden
1818
[1] :exclude[::sub2/]
19-
[1] :prefix=sub2
20-
[2] :/sub2
2119
$ git checkout hidden 1> /dev/null
2220
Switched to branch 'hidden'
2321
$ tree
@@ -35,8 +33,6 @@
3533

3634
$ josh-filter -s :exclude[::sub2/] --reverse master --update refs/heads/hidden
3735
[1] :exclude[::sub2/]
38-
[1] :prefix=sub2
39-
[2] :/sub2
4036

4137
$ git checkout master
4238
Switched to branch 'master'

tests/filter/reverse_hide_edit_missing_change.t

-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
$ josh-filter -s :exclude[::sub2/] master --update refs/heads/hidden
3131
[1] :exclude[::sub2/]
32-
[2] :/sub2
33-
[2] :prefix=sub2
3432
$ git checkout hidden 1> /dev/null
3533
Switched to branch 'hidden'
3634
$ tree
@@ -50,8 +48,6 @@
5048

5149
$ josh-filter -s :exclude[::sub2/] --reverse master --update refs/heads/hidden
5250
[1] :exclude[::sub2/]
53-
[2] :/sub2
54-
[2] :prefix=sub2
5551

5652
$ git checkout master
5753
Switched to branch 'master'

tests/filter/reverse_merge.t

-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
* add sub2
2626

2727
$ josh-filter -s :exclude[::sub2/] branch1 --update refs/heads/hidden_branch1
28-
[1] :/sub2
29-
[1] :prefix=sub2
3028
[2] :exclude[::sub2/]
3129
$ git checkout hidden_branch1
3230
Switched to branch 'hidden_branch1'
@@ -41,8 +39,6 @@
4139
$ git commit -m "add file3" 1> /dev/null
4240

4341
$ josh-filter -s :exclude[::sub2/] master --update refs/heads/hidden_master
44-
[1] :/sub2
45-
[1] :prefix=sub2
4642
[3] :exclude[::sub2/]
4743
$ git checkout hidden_master
4844
Switched to branch 'hidden_master'
@@ -76,8 +72,6 @@
7672
* add file1
7773

7874
$ josh-filter -s :exclude[::sub2/] --reverse master --update refs/heads/hidden_master
79-
[1] :/sub2
80-
[1] :prefix=sub2
8175
[3] :exclude[::sub2/]
8276

8377
$ git checkout master

tests/filter/reverse_split.t

-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
$ git commit -m "add file2.b" 1> /dev/null
1515

1616
$ josh-filter -s $FILTER master --update refs/heads/filtered
17-
[1] ::*.a
18-
[1] :prefix=a
1917
[2] :[
2018
a = ::*.a
2119
:prefix=rest
2220
]
23-
[2] :prefix=rest
2421
$ git checkout filtered 1> /dev/null
2522
Switched to branch 'filtered'
2623
$ tree
@@ -41,13 +38,10 @@
4138
$ git commit -m "add files" 1> /dev/null
4239

4340
$ josh-filter -s $FILTER --reverse master --update refs/heads/filtered
44-
[1] ::*.a
45-
[1] :prefix=a
4641
[2] :[
4742
a = ::*.a
4843
:prefix=rest
4944
]
50-
[2] :prefix=rest
5145

5246
$ git checkout master
5347
Switched to branch 'master'

tests/filter/workspace_combine_filter.t

-20
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@
5050
7 directories, 5 files
5151

5252
$ josh-filter -s :workspace=ws
53-
[1] :/sub1
54-
[1] :/subsub
55-
[1] :prefix=sub1
56-
[1] :prefix=sub2
57-
[1] :prefix=subsub
58-
[2] :/sub2
5953
[2] :[
6054
::sub1/
6155
::sub2/subsub/
@@ -83,27 +77,13 @@
8377

8478
$ git checkout master 2> /dev/null
8579
$ josh-filter -s :workspace=ws2
86-
[1] :/sub1
87-
[1] :/subsub
88-
[1] :prefix=blub
89-
[1] :prefix=sub1
90-
[1] :prefix=sub2
91-
[1] :prefix=sub3
92-
[1] :prefix=subsub
93-
[2] :/sub2
94-
[2] :/sub3
9580
[2] :[
9681
::sub1/
9782
::sub2/subsub/
9883
]
99-
[2] :prefix=a
10084
[2] :prefix=x
10185
[2] :workspace=ws
10286
[2] :workspace=ws2
103-
[3] :[
104-
::sub2/subsub/
105-
::sub3/
106-
]
10787
[3] :[
10888
a = :[
10989
::sub2/subsub/

0 commit comments

Comments
 (0)