changeset 8041:5f3101d54c32

vcs: drop special character encodings and some hardcoded UTF-8 - just use safe_unicode/safe_bytes
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 26 Dec 2019 15:14:55 +0100
parents 0f69b5c35b2b
children 43ee4d4d68f2
files kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/git/inmemory.py kallithea/lib/vcs/backends/hg/inmemory.py kallithea/lib/vcs/utils/hgcompat.py
diffstat 4 files changed, 7 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/changeset.py	Fri Dec 27 23:30:56 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/changeset.py	Thu Dec 26 15:14:55 2019 +0100
@@ -448,8 +448,6 @@
         Returns ``Node`` object from the given ``path``. If there is no node at
         the given ``path``, ``ChangesetError`` would be raised.
         """
-        if isinstance(path, unicode):
-            path = path.encode('utf-8')
         path = self._fix_path(path)
         if path not in self.nodes:
             try:
--- a/kallithea/lib/vcs/backends/git/inmemory.py	Fri Dec 27 23:30:56 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/inmemory.py	Thu Dec 26 15:14:55 2019 +0100
@@ -7,7 +7,7 @@
 
 from kallithea.lib.vcs.backends.base import BaseInMemoryChangeset
 from kallithea.lib.vcs.exceptions import RepositoryError
-from kallithea.lib.vcs.utils import safe_str
+from kallithea.lib.vcs.utils import safe_bytes, safe_str
 
 
 class GitInMemoryChangeset(BaseInMemoryChangeset):
@@ -39,7 +39,7 @@
         repo = self.repository._repo
         object_store = repo.object_store
 
-        ENCODING = "UTF-8"
+        ENCODING = "UTF-8"  # TODO: should probably be kept in sync with safe_unicode/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
 
         # Create tree and populates it with blobs
         commit_tree = self.parents[0] and repo[self.parents[0]._commit.tree] or \
@@ -74,7 +74,7 @@
                 content = node.content
             blob = objects.Blob.from_string(content)
 
-            node_path = node.name.encode(ENCODING)
+            node_path = safe_bytes(node.name)
             if dirnames:
                 # If there are trees which should be created we need to build
                 # them now (in reverse order)
--- a/kallithea/lib/vcs/backends/hg/inmemory.py	Fri Dec 27 23:30:56 2019 +0100
+++ b/kallithea/lib/vcs/backends/hg/inmemory.py	Thu Dec 26 15:14:55 2019 +0100
@@ -2,7 +2,8 @@
 
 from kallithea.lib.vcs.backends.base import BaseInMemoryChangeset
 from kallithea.lib.vcs.exceptions import RepositoryError
-from kallithea.lib.vcs.utils.hgcompat import hex, memctx, memfilectx, tolocal
+from kallithea.lib.vcs.utils import safe_bytes
+from kallithea.lib.vcs.utils.hgcompat import hex, memctx, memfilectx
 
 
 class MercurialInMemoryChangeset(BaseInMemoryChangeset):
@@ -87,11 +88,9 @@
             date=date,
             extra=kwargs)
 
-        loc = lambda u: tolocal(u.encode('utf-8'))
-
         # injecting given _repo params
-        commit_ctx._text = loc(message)
-        commit_ctx._user = loc(author)
+        commit_ctx._text = safe_bytes(message)
+        commit_ctx._user = safe_bytes(author)
         commit_ctx._date = date
 
         # TODO: Catch exceptions!
--- a/kallithea/lib/vcs/utils/hgcompat.py	Fri Dec 27 23:30:56 2019 +0100
+++ b/kallithea/lib/vcs/utils/hgcompat.py	Thu Dec 26 15:14:55 2019 +0100
@@ -9,7 +9,6 @@
 from mercurial.commands import clone, nullid, pull
 from mercurial.context import memctx, memfilectx
 from mercurial.discovery import findcommonoutgoing
-from mercurial.encoding import tolocal
 from mercurial.error import Abort, RepoError, RepoLookupError
 from mercurial.hg import peer
 from mercurial.hgweb import hgweb_mod