This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8060
in repository https://gitbox.apache.org/repos/asf/allura.git

commit f3496e94f3317c111ce9528d5f45f42c6ba6ff32
Author: Dave Brondsema <dbronds...@slashdotmedia.com>
AuthorDate: Mon Jul 25 10:53:55 2022 -0400

    [#8060] handle missing newlines on diffs; drop old py2 logic
---
 Allura/allura/controllers/repository.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/Allura/allura/controllers/repository.py 
b/Allura/allura/controllers/repository.py
index 9059526bf..f8fc76daa 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -927,9 +927,8 @@ class FileBrowser(BaseController):
             return dict(a=a, b=b, diff=diff)
 
         # could consider making Blob.__iter__ do unicode conversion?
-        # py2 unified_diff can handle some unicode but not consistently, so 
best to do ensure_str (can drop it on py3)
-        la = [six.ensure_str(h.really_unicode(line)) for line in a]
-        lb = [six.ensure_str(h.really_unicode(line)) for line in b]
+        la = [h.really_unicode(line) for line in a]
+        lb = [h.really_unicode(line) for line in b]
         adesc = 'a' + h.really_unicode(apath)
         bdesc = 'b' + h.really_unicode(b.path())
 
@@ -943,9 +942,14 @@ class FileBrowser(BaseController):
             hd = HtmlSideBySideDiff()
             diff = hd.make_table(la, lb, adesc, bdesc)
         else:
-            # py2 unified_diff can handle some unicode but not consistently, 
so best to do str() and ensure_str()
-            # (can drop it on py3)
-            diff = ''.join(difflib.unified_diff(la, lb, six.ensure_str(adesc), 
six.ensure_str(bdesc)))
+            # always end with a newline, and indicate if original file didn't
+            # doesn't work well with sidebyside (above), but that's ok without 
this too
+            if la and not la[-1].endswith('\n'):
+                la[-1] += '\n\\ No newline at end of file\n'
+            if lb and not lb[-1].endswith('\n'):
+                lb[-1] += '\n\\ No newline at end of file\n'
+
+            diff = ''.join(difflib.unified_diff(la, lb, adesc, bdesc))
         return dict(a=a, b=b, diff=diff)
 
 

Reply via email to