Enable the indent heuristic feature unconditionally, since it provides nice
visual improvements. See the added test, and [1].
[1]: https://github.com/git/git/commit/433860f3d0beb0c6f205290bd16cda413148f098
| ryanmce |
| hg-reviewers |
Enable the indent heuristic feature unconditionally, since it provides nice
visual improvements. See the added test, and [1].
[1]: https://github.com/git/git/commit/433860f3d0beb0c6f205290bd16cda413148f098
Added a test case.
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/thirdparty/xdiff.c (6 lines) | |||
| A | M | tests/test-diff-indent-heuristic.t (227 lines) |
| mmfile_t a = {sa, na}, b = {sb, nb}; | mmfile_t a = {sa, na}, b = {sb, nb}; | ||||
| PyObject *rl = PyList_New(0); | PyObject *rl = PyList_New(0); | ||||
| if (!rl) | if (!rl) | ||||
| return PyErr_NoMemory(); | return PyErr_NoMemory(); | ||||
| xpparam_t xpp = { | xpparam_t xpp = { | ||||
| 0, /* flags */ | XDF_INDENT_HEURISTIC, /* flags */ | ||||
| NULL, /* anchors */ | NULL, /* anchors */ | ||||
| 0, /* anchors_nr */ | 0, /* anchors_nr */ | ||||
| }; | }; | ||||
| xdemitconf_t xecfg = { | xdemitconf_t xecfg = { | ||||
| 0, /* ctxlen */ | 0, /* ctxlen */ | ||||
| 0, /* interhunkctxlen */ | 0, /* interhunkctxlen */ | ||||
| XDL_EMIT_BDIFFHUNK, /* flags */ | XDL_EMIT_BDIFFHUNK, /* flags */ | ||||
| NULL, /* find_func */ | NULL, /* find_func */ | ||||
| NULL, /* find_func_priv */ | NULL, /* find_func_priv */ | ||||
| hunk_consumer, /* hunk_consume_func */ | hunk_consumer, /* hunk_consume_func */ | ||||
| #require xdiff | |||||
| Test cases are most from git t/t4061-diff-indent.sh, and commit messages. | |||||
| $ hg init | |||||
| $ cat > a.c <<'EOF' | |||||
| > int a() | |||||
| > { | |||||
| > return 1; | |||||
| > } | |||||
| > | |||||
| > int c() | |||||
| > { | |||||
| > return 3; | |||||
| > } | |||||
| > EOF | |||||
| $ cat > partial.pl <<'EOF' | |||||
| > } | |||||
| > | |||||
| > if (!$smtp_server) { | |||||
| > foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) { | |||||
| > if (-x $_) { | |||||
| > $smtp_server = $_; | |||||
| > EOF | |||||
| $ cat > c.rb <<'EOF' | |||||
| > ["foo", "bar", "baz"].map do |i| | |||||
| > i.upcase | |||||
| > end | |||||
| > EOF | |||||
| $ cat > d.rb <<'EOF' | |||||
| > def foo | |||||
| > do_foo_stuff() | |||||
| > | |||||
| > common_ending() | |||||
| > end | |||||
| > EOF | |||||
| $ cat > spaces.txt <<'EOF' | |||||
| > 1 | |||||
| > 2 | |||||
| > a | |||||
| > | |||||
| > b | |||||
| > 3 | |||||
| > 4 | |||||
| > EOF | |||||
| $ cat > functions.c <<'EOF' | |||||
| > 1 | |||||
| > 2 | |||||
| > /* function */ | |||||
| > foo() { | |||||
| > foo | |||||
| > } | |||||
| > | |||||
| > 3 | |||||
| > 4 | |||||
| > EOF | |||||
| $ hg commit -m 1 -A . -q | |||||
| $ cat > a.c <<'EOF' | |||||
| > int a() | |||||
| > { | |||||
| > return 1; | |||||
| > } | |||||
| > | |||||
| > int b() | |||||
| > { | |||||
| > return 2; | |||||
| > } | |||||
| > | |||||
| > int c() | |||||
| > { | |||||
| > return 3; | |||||
| > } | |||||
| > EOF | |||||
| $ cat > partial.pl <<'EOF' | |||||
| > } | |||||
| > | |||||
| > if (!$smtp_server) { | |||||
| > $smtp_server = $repo->config('sendemail.smtpserver'); | |||||
| > } | |||||
| > if (!$smtp_server) { | |||||
| > foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) { | |||||
| > if (-x $_) { | |||||
| > $smtp_server = $_; | |||||
| > EOF | |||||
| $ cat > c.rb <<'EOF' | |||||
| > ["foo", "bar", "baz"].map do |i| | |||||
| > i | |||||
| > end | |||||
| > | |||||
| > ["foo", "bar", "baz"].map do |i| | |||||
| > i.upcase | |||||
| > end | |||||
| > EOF | |||||
| $ cat > d.rb <<'EOF' | |||||
| > def foo | |||||
| > do_foo_stuff() | |||||
| > | |||||
| > common_ending() | |||||
| > end | |||||
| > | |||||
| > def bar | |||||
| > do_bar_stuff() | |||||
| > | |||||
| > common_ending() | |||||
| > end | |||||
| > EOF | |||||
| $ cat > spaces.txt <<'EOF' | |||||
| > 1 | |||||
| > 2 | |||||
| > a | |||||
| > | |||||
| > b | |||||
| > a | |||||
| > | |||||
| > b | |||||
| > 3 | |||||
| > 4 | |||||
| > EOF | |||||
| $ cat > functions.c <<'EOF' | |||||
| > 1 | |||||
| > 2 | |||||
| > /* function */ | |||||
| > bar() { | |||||
| > foo | |||||
| > } | |||||
| > | |||||
| > /* function */ | |||||
| > foo() { | |||||
| > foo | |||||
| > } | |||||
| > | |||||
| > 3 | |||||
| > 4 | |||||
| > EOF | |||||
| $ hg diff --git | |||||
| diff --git a/a.c b/a.c | |||||
| --- a/a.c | |||||
| +++ b/a.c | |||||
| @@ -3,6 +3,11 @@ | |||||
| return 1; | |||||
| } | |||||
| +int b() | |||||
| +{ | |||||
| + return 2; | |||||
| +} | |||||
| + | |||||
| int c() | |||||
| { | |||||
| return 3; | |||||
| diff --git a/c.rb b/c.rb | |||||
| --- a/c.rb | |||||
| +++ b/c.rb | |||||
| @@ -1,3 +1,7 @@ | |||||
| +["foo", "bar", "baz"].map do |i| | |||||
| + i | |||||
| +end | |||||
| + | |||||
| ["foo", "bar", "baz"].map do |i| | |||||
| i.upcase | |||||
| end | |||||
| diff --git a/d.rb b/d.rb | |||||
| --- a/d.rb | |||||
| +++ b/d.rb | |||||
| @@ -3,3 +3,9 @@ | |||||
| common_ending() | |||||
| end | |||||
| + | |||||
| +def bar | |||||
| + do_bar_stuff() | |||||
| + | |||||
| + common_ending() | |||||
| +end | |||||
| diff --git a/functions.c b/functions.c | |||||
| --- a/functions.c | |||||
| +++ b/functions.c | |||||
| @@ -1,5 +1,10 @@ | |||||
| 1 | |||||
| 2 | |||||
| +/* function */ | |||||
| +bar() { | |||||
| + foo | |||||
| +} | |||||
| + | |||||
| /* function */ | |||||
| foo() { | |||||
| foo | |||||
| diff --git a/partial.pl b/partial.pl | |||||
| --- a/partial.pl | |||||
| +++ b/partial.pl | |||||
| @@ -1,5 +1,8 @@ | |||||
| } | |||||
| +if (!$smtp_server) { | |||||
| + $smtp_server = $repo->config('sendemail.smtpserver'); | |||||
| +} | |||||
| if (!$smtp_server) { | |||||
| foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) { | |||||
| if (-x $_) { | |||||
| diff --git a/spaces.txt b/spaces.txt | |||||
| --- a/spaces.txt | |||||
| +++ b/spaces.txt | |||||
| @@ -2,6 +2,9 @@ | |||||
| 2 | |||||
| a | |||||
| +b | |||||
| +a | |||||
| + | |||||
| b | |||||
| 3 | |||||
| 4 | |||||