# HG changeset patch
# User Sean Farley <s...@farley.io>
# Date 1483989858 28800
#      Mon Jan 09 11:24:18 2017 -0800
# Node ID 57b97693c687ab32b57bd3a75311237106992de9
# Parent  f755adaeac8d325dbb99f759929e88a342368ed2
patch: use opt.showsimilarity to calculate and show the similarity

Tests have been added.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -33,10 +33,11 @@ from . import (
     error,
     mail,
     mdiff,
     pathutil,
     scmutil,
+    similar,
     util,
 )
 stringio = util.stringio
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
@@ -2519,10 +2520,13 @@ def trydiff(repo, revs, ctx1, ctx2, modi
                 mode1, mode2 = gitmode[flag1], gitmode[flag2]
                 if mode1 != mode2:
                     header.append('old mode %s' % mode1)
                     header.append('new mode %s' % mode2)
                 if copyop is not None:
+                    if opts.showsimilarity:
+                        sim = similar.score(ctx1[path1], ctx2[path2]) * 100
+                        header.append('similarity index %d%%' % sim)
                     header.append('%s from %s' % (copyop, path1))
                     header.append('%s to %s' % (copyop, path2))
         elif revs and not repo.ui.quiet:
             header.append(diffline(path1, revs))
 
diff --git a/tests/test-diff-unified.t b/tests/test-diff-unified.t
--- a/tests/test-diff-unified.t
+++ b/tests/test-diff-unified.t
@@ -227,10 +227,24 @@ Git diff, adding space
   +++ b/f 1    
   @@ -1,1 +1,1 @@
   -a
   +b
 
+Git diff, adding extended headers
+
+  $ hg diff --git --config experimental.extendedheader.index=7 --config 
experimental.extendedheader.similarity=True
+  diff --git a/f1 b/f 1
+  similarity index 0%
+  rename from f1
+  rename to f 1
+  index 7898192..6178079 100644
+  --- a/f1
+  +++ b/f 1    
+  @@ -1,1 +1,1 @@
+  -a
+  +b
+
 Git diff with noprefix
 
   $ hg --config diff.noprefix=True diff --git --nodates
   diff --git f1 f 1
   rename from f1
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to