You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2022/07/26 19:32:53 UTC

[allura] branch db/8060 created (now f3496e94f)

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

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


      at f3496e94f [#8060] handle missing newlines on diffs; drop old py2 logic

This branch includes the following new commits:

     new f3496e94f [#8060] handle missing newlines on diffs; drop old py2 logic

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[allura] 01/01: [#8060] handle missing newlines on diffs; drop old py2 logic

Posted by br...@apache.org.
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 <db...@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)