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/01/24 23:10:10 UTC
[allura] branch master updated: [#7878] GitLikeTree fixes for
forgehg; other fixes for unicode in repo filenames and repo file contents
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 854f5ed [#7878] GitLikeTree fixes for forgehg; other fixes for unicode in repo filenames and repo file contents
854f5ed is described below
commit 854f5ed2d93b1cab23ad264a7424ff8273860142
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Jan 24 18:09:54 2020 -0500
[#7878] GitLikeTree fixes for forgehg; other fixes for unicode in repo filenames and repo file contents
---
Allura/allura/controllers/repository.py | 2 +-
Allura/allura/lib/diff.py | 9 ++++++---
Allura/allura/lib/utils.py | 4 +++-
Allura/allura/model/repository.py | 15 +++++++++++----
4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 9687741..46705b0 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -922,7 +922,7 @@ class FileBrowser(BaseController):
hd = HtmlSideBySideDiff()
diff = hd.make_table(la, lb, adesc, bdesc)
else:
- diff = ''.join(difflib.unified_diff(la, lb, adesc, bdesc))
+ diff = str('').join(difflib.unified_diff(la, lb, adesc, bdesc))
return dict(a=a, b=b, diff=diff)
diff --git a/Allura/allura/lib/diff.py b/Allura/allura/lib/diff.py
index 6c54673..ae46742 100644
--- a/Allura/allura/lib/diff.py
+++ b/Allura/allura/lib/diff.py
@@ -17,6 +17,9 @@
from __future__ import unicode_literals
import difflib
+
+import six
+
from allura.lib import helpers as h
@@ -55,7 +58,7 @@ class HtmlSideBySideDiff(object):
def _preprocess(self, line):
if not line:
return line
- line = line.expandtabs(self._tabsize)
+ line = six.ensure_text(line).expandtabs(self._tabsize)
return line.replace('&', '&').replace('<', '<').replace('>', '>')
def _replace_marks(self, line):
@@ -110,8 +113,8 @@ class HtmlSideBySideDiff(object):
Uses difflib._mdiff function to generate diff.
"""
- adesc = adesc or ''
- bdesc = bdesc or ''
+ adesc = six.ensure_text(adesc) or ''
+ bdesc = six.ensure_text(bdesc) or ''
diff = difflib._mdiff(a, b, context=context)
lines = [self._make_line(d) for d in diff]
return h.really_unicode(
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 585f344..45bee24 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -477,10 +477,12 @@ class LineAnchorCodeHtmlFormatter(HtmlFormatter):
def generate_code_stats(blob):
+ from allura.lib import helpers as h
+
stats = {'line_count': 0,
'code_size': 0,
'data_line_count': 0}
- code = blob.text
+ code = h.really_unicode(blob.text)
lines = code.split('\n')
stats['code_size'] = blob.size
stats['line_count'] = len(lines)
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index cf688df..ece93d7 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -40,6 +40,7 @@ from tg import app_globals as g
import pymongo
import pymongo.errors
import bson
+import six
from ming import schema as S
from ming import Field, collection, Index
@@ -1235,7 +1236,7 @@ class Commit(RepoObject, ActivityObject):
changes = self.repo.get_changes(self._id)
changed_paths = set()
for change in changes:
- node = change.strip('/')
+ node = six.ensure_text(change).strip('/')
changed_paths.add(node)
node_path = os.path.dirname(node)
while node_path:
@@ -1521,6 +1522,9 @@ class Blob(object):
@LazyProperty
def text(self):
+ """
+ Direct binary contents of file. Convert with h.really_unicode() if you think it is textual.
+ """
return self.open().read()
@@ -1816,6 +1820,7 @@ class GitLikeTree(object):
self._hex = None
def get_tree(self, path):
+ path = six.ensure_text(path)
if path.startswith('/'):
path = path[1:]
if not path:
@@ -1826,6 +1831,7 @@ class GitLikeTree(object):
return cur
def get_blob(self, path):
+ path = six.ensure_text(path)
if path.startswith('/'):
path = path[1:]
path_parts = path.split('/')
@@ -1836,6 +1842,7 @@ class GitLikeTree(object):
return cur.blobs[last]
def set_blob(self, path, oid):
+ path = six.ensure_text(path)
if path.startswith('/'):
path = path[1:]
path_parts = path.split('/')
@@ -1849,15 +1856,15 @@ class GitLikeTree(object):
'''Compute a recursive sha1 hash on the tree'''
# dependent on __repr__ below
if self._hex is None:
- sha_obj = sha1('tree\n' + repr(self))
+ sha_obj = sha1(b'tree\n' + repr(self))
self._hex = sha_obj.hexdigest()
return self._hex
def __repr__(self):
# this can't change, is used in hex() above
- lines = ['t %s %s' % (t.hex(), name)
+ lines = ['t %s %s' % (t.hex(), h.really_unicode(name))
for name, t in self.trees.iteritems()]
- lines += ['b %s %s' % (oid, name)
+ lines += ['b %s %s' % (oid, h.really_unicode(name))
for name, oid in self.blobs.iteritems()]
return h.really_unicode('\n'.join(sorted(lines))).encode('utf-8')