Changeset - 5a3cef4a331f
[Not reviewed]
default
0 2 0
Mads Kiilerich - 6 years ago 2019-12-25 21:27:00
mads@kiilerich.com
Grafted from: e7c36201353b
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.)
2 files changed with 7 insertions and 28 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/git/changeset.py
Show inline comments
 
@@ -98,15 +98,6 @@ class GitChangeset(BaseChangeset):
 
        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 @@ class GitChangeset(BaseChangeset):
 
            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 @@ class GitChangeset(BaseChangeset):
 
        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 @@ class GitChangeset(BaseChangeset):
 
        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)
kallithea/lib/vcs/backends/hg/changeset.py
Show inline comments
 
@@ -193,19 +193,8 @@ class MercurialChangeset(BaseChangeset):
 
        # 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('/'):
 
    def _get_kind(self, path):
 
            path = path.rstrip('/')
 

	
 
        return path
 

	
 
    def _get_kind(self, path):
 
        path = self._fix_path(path)
 
        if path in self._file_paths:
 
            return NodeKind.FILE
 
        elif path in self._dir_paths:
 
@@ -215,7 +204,7 @@ class MercurialChangeset(BaseChangeset):
 
                % (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 @@ class MercurialChangeset(BaseChangeset):
 
        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 @@ class MercurialChangeset(BaseChangeset):
 
        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)
0 comments (0 inline, 0 general)