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 2020/09/16 22:16:06 UTC
[allura] branch master updated: [#8375] fix py2 regression on
unified_diff; apply similar fixes in ForgeUserStats
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new 5f67078 [#8375] fix py2 regression on unified_diff; apply similar fixes in ForgeUserStats
5f67078 is described below
commit 5f670788349fb4ccf8ecc32fb20cff20e3307a35
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Sep 16 18:14:39 2020 -0400
[#8375] fix py2 regression on unified_diff; apply similar fixes in ForgeUserStats
py2 unified_diff only works with str (bytes) filenames since it has within it:
yield '+++ {}{}{}'.format(tofile, todate, lineterm)
py3 unified_diff only works with str (unicode) filenames
---
Allura/allura/controllers/repository.py | 2 +-
Allura/allura/model/stats.py | 10 +++++++---
ForgeUserStats/forgeuserstats/tests/test_model.py | 11 +++++------
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 3104e07..5191413 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -919,7 +919,7 @@ class FileBrowser(BaseController):
hd = HtmlSideBySideDiff()
diff = hd.make_table(la, lb, adesc, bdesc)
else:
- diff = str('').join(difflib.unified_diff(la, lb, adesc, bdesc))
+ diff = str('').join(difflib.unified_diff(la, lb, six.ensure_str(adesc), six.ensure_str(bdesc)))
return dict(a=a, b=b, diff=diff)
diff --git a/Allura/allura/model/stats.py b/Allura/allura/model/stats.py
index a153b68..80966b8 100644
--- a/Allura/allura/model/stats.py
+++ b/Allura/allura/model/stats.py
@@ -17,6 +17,8 @@
from __future__ import unicode_literals
from __future__ import absolute_import
+
+import six
from datetime import datetime
from tg import config
from paste.deploy.converters import asbool
@@ -29,6 +31,7 @@ from datetime import timedelta
import difflib
from allura.model.session import main_orm_session
+from allura.lib import helpers as h
from six.moves import range
from functools import reduce
@@ -369,9 +372,10 @@ class Stats(MappedClass):
lines = len(listnew)
elif newblob and newblob.has_html_view:
diff = difflib.unified_diff(
- listold, listnew,
- ('old' + oldblob.path()).encode('utf-8'),
- ('new' + newblob.path()).encode('utf-8'))
+ [h.really_unicode(line) for line in listold],
+ [h.really_unicode(line) for line in listnew],
+ six.ensure_str('old' + oldblob.path()),
+ six.ensure_str('new' + newblob.path()))
lines = len(
[l for l in diff if len(l) > 0 and l[0] == '+']) - 1
else:
diff --git a/ForgeUserStats/forgeuserstats/tests/test_model.py b/ForgeUserStats/forgeuserstats/tests/test_model.py
index 308728e..7156bb9 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_model.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_model.py
@@ -463,12 +463,11 @@ class TestUserStats(unittest.TestCase):
)
unified_diff.return_value = ['+++', '---', '+line']
newcommit.tree.get_blob_by_path.return_value = mock.MagicMock()
- newcommit.tree.get_blob_by_path.return_value.__iter__.return_value = [
- 'one']
- newcommit.repo.commit(
- ).tree.get_blob_by_path.return_value = mock.MagicMock()
- newcommit.repo.commit().tree.get_blob_by_path.return_value.__iter__.return_value = [
- 'two']
+ newcommit.tree.get_blob_by_path.return_value.__iter__.return_value = ['one']
+ newcommit.tree.get_blob_by_path.return_value.path.return_value = 'onepath'
+ newcommit.repo.commit().tree.get_blob_by_path.return_value = mock.MagicMock()
+ newcommit.repo.commit().tree.get_blob_by_path.return_value.__iter__.return_value = ['two']
+ newcommit.repo.commit().tree.get_blob_by_path.return_value.path.return_value = 'twopath'
commit_datetime = datetime.utcnow()
project = mock.Mock(
trove_topic=[],