changeset 8227:5a3cef4a331f

vcs: drop _fix_path The reasoning in hg _fix_path is no longer correct. We only need it for stripping the trailing '/' ... but we would rather be explicit about that. (But it is also questionable if we actually want it at all - we should just pass the right data and fail on wrong data.)
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 25 Dec 2019 21:27:00 +0100
parents 103bb1129d44
children d122a9532630
files kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/hg/changeset.py
diffstat 2 files changed, 7 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/changeset.py	Thu Feb 06 03:39:22 2020 +0100
+++ b/kallithea/lib/vcs/backends/git/changeset.py	Wed Dec 25 21:27:00 2019 +0100
@@ -98,15 +98,6 @@
         heads = self.repository._heads(reverse=True)
         return [safe_str(b) for b in heads if heads[b] == self._commit.id] # FIXME: Inefficient ... and returning None!
 
-    def _fix_path(self, path):
-        """
-        Paths are stored without trailing slash so we need to get rid off it if
-        needed.
-        """
-        if path.endswith('/'):
-            path = path.rstrip('/')
-        return path
-
     def _get_id_for_path(self, path):
         # FIXME: Please, spare a couple of minutes and make those codes cleaner;
         if path not in self._paths:
@@ -167,7 +158,7 @@
             return NodeKind.DIR
 
     def _get_filectx(self, path):
-        path = self._fix_path(path)
+        path = path.rstrip('/')
         if self._get_kind(path) != NodeKind.FILE:
             raise ChangesetError("File does not exist for revision %s at "
                 " '%s'" % (self.raw_id, path))
@@ -396,7 +387,7 @@
         if self._get_kind(path) != NodeKind.DIR:
             raise ChangesetError("Directory does not exist for revision %s at "
                 " '%s'" % (self.revision, path))
-        path = self._fix_path(path)
+        path = path.rstrip('/')
         id = self._get_id_for_path(path)
         tree = self.repository._repo[id]
         dirnodes = []
@@ -436,7 +427,7 @@
         Returns ``Node`` object from the given ``path``. If there is no node at
         the given ``path``, ``ChangesetError`` would be raised.
         """
-        path = self._fix_path(path)
+        path = path.rstrip('/')
         if path not in self.nodes:
             try:
                 id_ = self._get_id_for_path(path)
--- a/kallithea/lib/vcs/backends/hg/changeset.py	Thu Feb 06 03:39:22 2020 +0100
+++ b/kallithea/lib/vcs/backends/hg/changeset.py	Wed Dec 25 21:27:00 2019 +0100
@@ -193,19 +193,8 @@
         # Only used to feed diffstat
         return b''.join(self._ctx.diff())
 
-    def _fix_path(self, path):
-        """
-        Paths are stored without trailing slash so we need to get rid off it if
-        needed. Also mercurial keeps filenodes as str so we need to decode
-        from unicode to str
-        """
-        if path.endswith('/'):
-            path = path.rstrip('/')
-
-        return path
-
     def _get_kind(self, path):
-        path = self._fix_path(path)
+        path = path.rstrip('/')
         if path in self._file_paths:
             return NodeKind.FILE
         elif path in self._dir_paths:
@@ -215,7 +204,7 @@
                 % (path))
 
     def _get_filectx(self, path):
-        path = self._fix_path(path)
+        path = path.rstrip('/')
         if self._get_kind(path) != NodeKind.FILE:
             raise ChangesetError("File does not exist for revision %s at "
                 " '%s'" % (self.raw_id, path))
@@ -330,8 +319,7 @@
         if self._get_kind(path) != NodeKind.DIR:
             raise ChangesetError("Directory does not exist for revision %s at "
                 " '%s'" % (self.revision, path))
-        path = self._fix_path(path)
-
+        path = path.rstrip('/')
         filenodes = [FileNode(f, changeset=self) for f in self._file_paths
             if os.path.dirname(f) == path]
         dirs = path == '' and '' or [d for d in self._dir_paths
@@ -357,7 +345,7 @@
         Returns ``Node`` object from the given ``path``. If there is no node at
         the given ``path``, ``ChangesetError`` would be raised.
         """
-        path = self._fix_path(path)
+        path = path.rstrip('/')
         if path not in self.nodes:
             if path in self._file_paths:
                 node = FileNode(path, changeset=self)