D2578: xdiff: enable indent heuristic unconditionally

ryanmce (Ryan McElroy) phabricator at mercurial-scm.org
Sat Mar 3 00:25:56 UTC 2018


ryanmce created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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

TEST PLAN
  Added a test case.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2578

AFFECTED FILES
  mercurial/thirdparty/xdiff.c
  tests/test-diff-indent-heuristic.t

CHANGE DETAILS

diff --git a/tests/test-diff-indent-heuristic.t b/tests/test-diff-indent-heuristic.t
new file mode 100644
--- /dev/null
+++ b/tests/test-diff-indent-heuristic.t
@@ -0,0 +1,227 @@
+#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
diff --git a/mercurial/thirdparty/xdiff.c b/mercurial/thirdparty/xdiff.c
--- a/mercurial/thirdparty/xdiff.c
+++ b/mercurial/thirdparty/xdiff.c
@@ -38,9 +38,9 @@
 		return PyErr_NoMemory();
 
 	xpparam_t xpp = {
-	    0,    /* flags */
-	    NULL, /* anchors */
-	    0,    /* anchors_nr */
+	    XDF_INDENT_HEURISTIC, /* flags */
+	    NULL,                 /* anchors */
+	    0,                    /* anchors_nr */
 	};
 	xdemitconf_t xecfg = {
 	    0,                  /* ctxlen */



To: ryanmce, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list