patch: use opt.showsimilarity to calculate and show the similarity
authorSean Farley <sean@farley.io>
Mon, 09 Jan 2017 11:24:18 -0800
changeset 30807 6381a6dbc325
parent 30806 e2796f193f06
child 30808 8540967cd9e0
patch: use opt.showsimilarity to calculate and show the similarity Tests have been added.
mercurial/patch.py
tests/test-diff-unified.t
--- a/mercurial/patch.py	Mon Jan 09 10:51:44 2017 -0800
+++ b/mercurial/patch.py	Mon Jan 09 11:24:18 2017 -0800
@@ -35,6 +35,7 @@
     mdiff,
     pathutil,
     scmutil,
+    similar,
     util,
 )
 stringio = util.stringio
@@ -2521,6 +2522,9 @@
                     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:
--- a/tests/test-diff-unified.t	Mon Jan 09 10:51:44 2017 -0800
+++ b/tests/test-diff-unified.t	Mon Jan 09 11:24:18 2017 -0800
@@ -229,6 +229,20 @@
   -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