Skip to content

Commit 6d7a538

Browse files
LMGchristian-schilling
authored andcommitted
Fix exclude of compose
Bump cache version as it changes behaviour if this is used
1 parent f2453b3 commit 6d7a538

File tree

9 files changed

+170
-65
lines changed

9 files changed

+170
-65
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 VERSION: u64 = 6;
4+
const VERSION: u64 = 7;
55

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

src/filter/mod.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,23 @@ fn apply_to_commit2(
377377
.map(|x| x.tree_id())
378378
.unwrap_or(tree::empty_id())
379379
};
380-
let bf = {
380+
let bu = {
381381
transaction
382382
.repo()
383383
.find_commit(some_or!(
384-
apply_to_commit2(&to_op(*b), commit, transaction)?,
384+
apply_to_commit2(
385+
&Op::Chain(
386+
to_filter(Op::Paths),
387+
to_filter(Op::Chain(*b, to_filter(Op::Invert))),
388+
),
389+
commit,
390+
transaction,
391+
)?,
385392
{ return Ok(None) }
386393
))
387-
.map(|x| x.tree_id())
388-
.unwrap_or(tree::empty_id())
389-
};
390-
let bf = repo.find_tree(bf)?;
391-
let bu = unapply(transaction, *b, bf, tree::empty(repo))?;
394+
.map(|x| x.tree())
395+
.unwrap_or(Ok(tree::empty(repo)))
396+
}?;
392397
let ba = apply(transaction, *a, bu)?;
393398

394399
repo.find_tree(tree::subtract(repo, af, ba.id())?)?
@@ -474,8 +479,14 @@ fn apply2<'a>(
474479

475480
Op::Subtract(a, b) => {
476481
let af = apply(transaction, *a, tree.clone())?;
477-
let bf = apply(transaction, *b, tree.clone())?;
478-
let bu = unapply(transaction, *b, bf, tree::empty(repo))?;
482+
let bu = apply(
483+
transaction,
484+
to_filter(Op::Chain(
485+
to_filter(Op::Paths),
486+
to_filter(Op::Chain(*b, to_filter(Op::Invert))),
487+
)),
488+
tree.clone(),
489+
)?;
479490
let ba = apply(transaction, *a, bu)?;
480491
Ok(repo.find_tree(tree::subtract(repo, af.id(), ba.id())?)?)
481492
}

tests/filter/empty_orphan.t

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ Empty root commits from unrelated parts of the tree should not be included
101101
c/file3
102102

103103
$ josh-filter -s c=:exclude[:/sub1] master
104-
[5] :/sub1
104+
[4] :INVERT
105+
[4] _invert
105106
[5] :exclude[:/sub1]
106107
[6] :prefix=c
108+
[7] :PATHS
109+
[9] :/sub1
110+
[10] _paths
107111

108112
$ git log FILTERED_HEAD --graph --pretty=%s
109113
* add some_other_file
@@ -116,9 +120,13 @@ Empty root commits from unrelated parts of the tree should not be included
116120

117121
$ josh-filter -s :prefix=x FILTERED_HEAD
118122
[3] :prefix=x
119-
[5] :/sub1
123+
[4] :INVERT
124+
[4] _invert
120125
[5] :exclude[:/sub1]
121126
[6] :prefix=c
127+
[7] :PATHS
128+
[9] :/sub1
129+
[10] _paths
122130

123131
$ git ls-tree --name-only -r FILTERED_HEAD
124132
x/c/some_file

tests/filter/exclude_compose.t

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,53 @@
1414
$ git add sub2
1515
$ git commit -m "add file2" 1> /dev/null
1616

17+
$ mkdir sub3
18+
$ echo contents1 > sub3/file3
19+
$ git add sub3
20+
$ git commit -m "add file3" 1> /dev/null
21+
22+
$ echo contents1 > file4
23+
$ git add file4
24+
$ git commit -m "add file4" 1> /dev/null
25+
1726
$ josh-filter -s :exclude[:/sub2] master --update refs/heads/hidden
18-
[1] :exclude[:/sub2]
27+
[1] :INVERT
28+
[1] _invert
1929
[2] :/sub2
30+
[3] :exclude[:/sub2]
31+
[4] :PATHS
32+
[7] _paths
2033
$ git checkout hidden 1> /dev/null
2134
Switched to branch 'hidden'
2235
$ tree
2336
.
24-
`-- sub1
25-
`-- file1
37+
|-- file4
38+
|-- sub1
39+
| `-- file1
40+
`-- sub3
41+
`-- file3
2642

27-
1 directory, 1 file
43+
2 directories, 3 files
2844
$ git log --graph --pretty=%s
45+
* add file4
46+
* add file3
2947
* add file1
3048

3149
$ echo contents3 > sub1/file3
3250
$ git add sub1/file3
3351
$ git commit -m "add sub1/file3" 1> /dev/null
3452

35-
$ josh-filter -s :exclude[:/sub1,:/sub2] master --update refs/josh/filtered
53+
$ josh-filter -s :exclude[:/sub1]:exclude[:/sub2]:exclude[:/sub3] master --update refs/josh/filtered
3654
[1] :/sub1
37-
[1] :exclude[
38-
:/sub1
39-
:/sub2
40-
]
41-
[1] :exclude[:/sub2]
42-
[2] :/sub2
43-
[2] :[
44-
:/sub1
45-
:/sub2
46-
]
47-
55+
[1] :/sub3
56+
[2] :exclude[:/sub3]
57+
[3] :/sub2
58+
[3] :INVERT
59+
[3] _invert
60+
[4] :exclude[:/sub1]
61+
[6] :exclude[:/sub2]
62+
[9] :PATHS
63+
[12] _paths
4864
$ git checkout refs/josh/filtered
4965
Note: switching to 'refs/josh/filtered'.
5066

@@ -63,10 +79,38 @@
6379

6480
Turn off this advice by setting config variable advice.detachedHead to false
6581

66-
HEAD is now at bb282e9 add file1
82+
HEAD is now at e96b01b add file4
83+
$ tree
84+
.
85+
`-- file4
86+
87+
0 directories, 1 file
88+
$ josh-filter -s :exclude[:/sub1,:/sub2,:/sub3] master --update refs/josh/filtered
89+
[1] :/sub1
90+
[2] :exclude[
91+
:/sub1
92+
:/sub2
93+
:/sub3
94+
]
95+
[2] :exclude[:/sub3]
96+
[3] :/sub2
97+
[3] :/sub3
98+
[3] :[
99+
:/sub1
100+
:/sub2
101+
:/sub3
102+
]
103+
[4] :exclude[:/sub1]
104+
[5] :INVERT
105+
[5] _invert
106+
[6] :exclude[:/sub2]
107+
[9] :PATHS
108+
[12] _paths
109+
110+
$ git checkout refs/josh/filtered
111+
HEAD is now at e96b01b add file4
67112
$ tree
68113
.
69-
`-- sub1
70-
`-- file1
114+
`-- file4
71115

72-
1 directory, 1 file
116+
0 directories, 1 file

tests/filter/hide_view.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
$ josh-filter -s c=:exclude[:/sub1] master --update refs/josh/filter/master
3737
[1] :prefix=c
3838
[2] :/sub1
39+
[2] :INVERT
3940
[2] :exclude[:/sub1]
41+
[2] _invert
42+
[3] :PATHS
43+
[6] _paths
4044
$ git checkout josh/filter/master 2> /dev/null
4145
$ git log --graph --pretty=%s
4246
* add file3
@@ -53,7 +57,11 @@
5357
[2] ::sub1/file2
5458
[2] :exclude[:/sub1]
5559
[2] :exclude[::sub1/file2]
60+
[3] :INVERT
61+
[3] :PATHS
5662
[3] :prefix=c
63+
[4] _invert
64+
[6] _paths
5765
$ git checkout josh/filter/master 2> /dev/null
5866
$ git log --graph --pretty=%s
5967
* add file3
@@ -75,7 +83,11 @@
7583
[2] :exclude[:/sub1]
7684
[2] :exclude[::sub1/file2]
7785
[2] :exclude[::sub2/file3]
86+
[3] :PATHS
87+
[4] :INVERT
7888
[4] :prefix=c
89+
[6] _invert
90+
[6] _paths
7991
$ git checkout josh/filter/master 2> /dev/null
8092
$ git log --graph --pretty=%s
8193
* add file2

tests/filter/permissions.t

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@
185185
[1] :/a
186186
[1] :exclude[:/c]
187187
[1] :prefix=x
188-
[3] :/c
189-
[3] :PATHS
190-
[16] _paths
188+
[3] :INVERT
189+
[6] :/c
190+
[6] :PATHS
191+
[7] _invert
192+
[28] _paths
191193

192194
$ git log --graph --pretty=%s refs/josh/filtered
193195
* add dirs
@@ -235,11 +237,11 @@
235237
[1] :/a
236238
[1] :exclude[:/c]
237239
[1] :prefix=x
238-
[3] :/c
239-
[3] :INVERT
240-
[3] :PATHS
241-
[12] _invert
242-
[16] _paths
240+
[6] :/c
241+
[6] :INVERT
242+
[6] :PATHS
243+
[19] _invert
244+
[28] _paths
243245

244246
$ git checkout refs/josh/filtered 2> /dev/null
245247
$ tree
@@ -313,12 +315,12 @@
313315
[1] :/a
314316
[1] :exclude[:/c]
315317
[1] :prefix=x
316-
[3] :/c
317-
[3] :PATHS
318318
[3] :workspace=a
319-
[6] :INVERT
320-
[16] _paths
321-
[22] _invert
319+
[6] :/c
320+
[6] :PATHS
321+
[9] :INVERT
322+
[28] _paths
323+
[29] _invert
322324

323325
$ git checkout refs/josh/filtered 2> /dev/null
324326
$ tree
@@ -381,13 +383,13 @@
381383
[1] :/a
382384
[1] :exclude[:/c]
383385
[1] :prefix=x
384-
[3] :/c
385386
[3] :FOLD
386-
[3] :PATHS
387387
[3] :workspace=a
388-
[6] :INVERT
389-
[16] _paths
390-
[22] _invert
388+
[6] :/c
389+
[6] :PATHS
390+
[9] :INVERT
391+
[28] _paths
392+
[29] _invert
391393

392394

393395

@@ -406,13 +408,13 @@
406408
[1] :/a
407409
[1] :exclude[:/c]
408410
[1] :prefix=x
409-
[3] :/c
410411
[3] :FOLD
411412
[3] :workspace=a
412-
[5] :PATHS
413-
[6] :INVERT
414-
[19] _paths
415-
[22] _invert
413+
[6] :/c
414+
[8] :PATHS
415+
[9] :INVERT
416+
[29] _invert
417+
[31] _paths
416418

417419
$ git log --graph --pretty=%s master
418420
* add newfile
@@ -536,12 +538,12 @@
536538
[1] :exclude[:/c]
537539
[1] :prefix=x
538540
[3] :workspace=a
539-
[4] :/c
540-
[5] :PATHS
541541
[6] :FOLD
542-
[6] :INVERT
543-
[19] _paths
544-
[22] _invert
542+
[7] :/c
543+
[8] :PATHS
544+
[9] :INVERT
545+
[29] _invert
546+
[31] _paths
545547

546548
$ git log --graph --pretty=%s refs/josh/filtered
547549
* add file_cd3
@@ -591,13 +593,13 @@
591593
[1] :/a
592594
[1] :exclude[:/c]
593595
[1] :prefix=x
594-
[4] :/c
595-
[5] :PATHS
596596
[5] :workspace=a
597-
[6] :INVERT
597+
[7] :/c
598+
[8] :PATHS
599+
[9] :INVERT
598600
[10] :FOLD
599-
[19] _paths
600-
[22] _invert
601+
[29] _invert
602+
[31] _paths
601603

602604
$ git log --graph --pretty=%s refs/josh/filtered
603605
* add newfile

tests/filter/reverse_hide.t

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
$ git commit -m "add file2" 1> /dev/null
1616

1717
$ josh-filter -s :exclude[:/sub2] master --update refs/heads/hidden
18+
[1] :INVERT
1819
[1] :exclude[:/sub2]
20+
[1] _invert
1921
[2] :/sub2
22+
[2] :PATHS
23+
[4] _paths
2024
$ git checkout hidden 1> /dev/null
2125
Switched to branch 'hidden'
2226
$ tree
@@ -33,8 +37,12 @@
3337
$ git commit -m "add sub1/file3" 1> /dev/null
3438

3539
$ josh-filter -s :exclude[:/sub2] --reverse master --update refs/heads/hidden
40+
[1] :INVERT
3641
[1] :exclude[:/sub2]
42+
[1] _invert
3743
[2] :/sub2
44+
[2] :PATHS
45+
[4] _paths
3846

3947
$ git checkout master
4048
Switched to branch 'master'

0 commit comments

Comments
 (0)