Commit f8c35ae
committed
Add a way to elide diffs
When looking at a large diff for which many of the lines are unchanged
it can be difficult to locate the lines which are changed. Text-oriented
diffs such as those you get from a conventional version control system
solve this problem by collapsing parts of the diff to show you only the
most important lines (and also including some unimportant lines, aka
context, so that you know where they fit within the bigger picture):
```
diff --git a/README.md b/README.md
index 56b046c..b38f4ca 100644
--- a/README.md
+++ b/README.md
@@ -169,7 +169,6 @@ SuperDiff.configure do |config|
config.add_extra_differ_class(YourDiffer)
config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
config.add_extra_operation_tree_class(YourOperationTree)
- config.add_extra_diff_formatter_class(YourDiffFormatter)
end
```
This commit implements a similar feature for data-oriented diffs. It
adds three new configuration options to allow you to control the elision
logic:
* `diff_elision_enabled` — The elision logic is disabled by default so
as not to surprise people, so setting this to `true` will turn it on.
* `diff_elision_threshold` — This controls the maximum number of
unchanged lines in between changed lines that you want to keep.
The gem will collapse the data structures in this space as much as
possible until the limit is reached.
* `diff_elision_padding` — This is the option that's similar to the
"context" in text-based diffs and controls how many unchanged lines
you want to keep around before and after changed lines. The gem will
guarantee that no lines in this padding will ever be collapsed.
Here is a simple example. If you add this to your test helper:
``` ruby
SuperDiff.configure do |config|
config.diff_elision_enabled = true
config.diff_elision_threshold = 5
end
```
And you have this test:
``` ruby
expected = [
"Afghanistan",
"Aland Islands",
"Albania",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua And Barbuda",
"Argentina",
"Aruba",
"Australia"
]
actual = [
"Afghanistan",
"Aland Islands",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua And Barbuda",
"Armenia",
"Aruba",
"Australia"
]
expect(actual).to eq(expected)
```
Then you will get a diff that looks like:
```
[
"Afghanistan",
"Aland Islands",
- "Albania",
+ "Algeria",
"American Samoa",
"Andorra",
# ...
"Antarctica",
"Antigua And Barbuda",
- "Argentina",
+ "Armenia",
"Aruba",
"Australia"
]
```
Now let's consider this example:
``` ruby
expected = {
foo: {
bar: [
"one",
"two",
"three"
],
baz: "qux",
fizz: "buzz",
zing: "bing"
}
}
actual = [
foo: {
bar: [
"one",
"two",
"tree"
],
baz: "qux",
fizz: "buzz",
zing: "bing"
}
]
expect(actual).to eq(expected)
```
With the following configuration:
``` ruby
SuperDiff.configure do |config|
config.diff_elision_enabled = true
config.diff_elision_threshold = 0
end
```
you would get:
```
{
foo: {
bar: [
# ...
- "three"
+ "tree"
],
# ...
}
}
```
whereas with a configuration of:
``` ruby
SuperDiff.configure do |config|
config.diff_elision_enabled = true
config.diff_elision_threshold = 0
config.diff_elision_padding = 2
end
```
you would get:
```
{
foo: {
bar: [
"one",
"two",
- "three"
+ "tree"
],
baz: "qux",
# ...
}
}
```1 parent dcdf05e commit f8c35ae
File tree
170 files changed
+11089
-2545
lines changed- config
- lib
- super_diff
- active_record
- diff_formatters
- differs
- object_inspection
- inspection_tree_builders
- operation_tree_flatteners
- operation_trees
- active_support
- diff_formatters
- differs
- object_inspection
- inspection_tree_builders
- inspectors
- operation_tree_builders
- operation_tree_flatteners
- operation_trees
- csi
- diff_formatters
- differs
- equality_matchers
- object_inspection
- inspection_tree_builders
- inspectors
- nodes
- operation_tree_builders
- operation_tree_flatteners
- operation_trees
- operations
- rspec
- object_inspection
- inspection_tree_builders
- inspectors
- operation_tree_builders
- spec
- integration
- rails
- rspec
- support
- integration
- matchers
- test_programs
- unit
- matchers
- unit
- active_record
- equality_matchers
- operation_tree_flatteners
- rspec
- support
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
170 files changed
+11089
-2545
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
3 | 57 | | |
4 | 58 | | |
5 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | 172 | | |
174 | 173 | | |
175 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| 39 | + | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| |||
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
45 | 61 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
This file was deleted.
Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 3 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 10 | + | |
18 | 11 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 12 | + | |
| 13 | + | |
24 | 14 | | |
25 | 15 | | |
26 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 5 | + | |
| 6 | + | |
11 | 7 | | |
12 | 8 | | |
13 | 9 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
0 commit comments