Mercurial > kallithea
changeset 8023:439b3aea3479
vcs: improved alignment between hg and git changeset.py
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 19 Dec 2019 22:15:55 +0100 |
parents | 5b6174420e30 |
children | ae12fabba699 |
files | kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/hg/changeset.py |
diffstat | 2 files changed, 19 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/changeset.py Thu Dec 19 23:24:29 2019 +0100 +++ b/kallithea/lib/vcs/backends/git/changeset.py Thu Dec 19 22:15:55 2019 +0100 @@ -17,7 +17,7 @@ class GitChangeset(BaseChangeset): """ - Represents state of the repository at single revision. + Represents state of the repository at a revision. """ def __init__(self, repository, revision): @@ -243,6 +243,7 @@ return cs def diff(self, ignore_whitespace=True, context=3): + # Only used to feed diffstat rev1 = self.parents[0] if self.parents else self.repository.EMPTY_CHANGESET rev2 = self return ''.join(self.repository.get_diff(rev1, rev2, @@ -353,13 +354,16 @@ :raise ImproperArchiveTypeError: If given kind is wrong. :raise VcsError: If given stream is None - """ allowed_kinds = settings.ARCHIVE_SPECS.keys() if kind not in allowed_kinds: raise ImproperArchiveTypeError('Archive kind not supported use one' 'of %s' % allowed_kinds) + if stream is None: + raise VCSError('You need to pass in a valid stream for filling' + ' with archival data') + if prefix is None: prefix = '%s-%s' % (self.repository.name, self.short_id) elif prefix.startswith('/'): @@ -394,6 +398,12 @@ popen.communicate() def get_nodes(self, path): + """ + Returns combined ``DirNode`` and ``FileNode`` objects list representing + state of changeset at the given ``path``. If node at the given ``path`` + is not instance of ``DirNode``, ChangesetError would be raised. + """ + if self._get_kind(path) != NodeKind.DIR: raise ChangesetError("Directory does not exist for revision %s at " " '%s'" % (self.revision, path)) @@ -434,6 +444,10 @@ return nodes def get_node(self, path): + """ + 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) @@ -465,7 +479,7 @@ node._blob = obj else: raise NodeDoesNotExistError("There is no file nor directory " - "at the given path '%s' at revision %s" + "at the given path: '%s' at revision %s" % (path, self.short_id)) # cache node self.nodes[path] = node
--- a/kallithea/lib/vcs/backends/hg/changeset.py Thu Dec 19 23:24:29 2019 +0100 +++ b/kallithea/lib/vcs/backends/hg/changeset.py Thu Dec 19 22:15:55 2019 +0100 @@ -14,7 +14,7 @@ class MercurialChangeset(BaseChangeset): """ - Represents state of the repository at the single revision. + Represents state of the repository at a revision. """ def __init__(self, repository, revision): @@ -202,7 +202,7 @@ return cs def diff(self): - # Only used for feed diffstat + # Only used to feed diffstat return ''.join(self._ctx.diff()) def _fix_path(self, path): @@ -316,7 +316,6 @@ :raise ImproperArchiveTypeError: If given kind is wrong. :raise VcsError: If given stream is None """ - allowed_kinds = settings.ARCHIVE_SPECS.keys() if kind not in allowed_kinds: raise ImproperArchiveTypeError('Archive kind not supported use one' @@ -363,11 +362,9 @@ dirnodes.append(SubModuleNode(k, url=loc, changeset=cs, alias=als)) nodes = dirnodes + filenodes - # cache nodes for node in nodes: self.nodes[node.path] = node nodes.sort() - return nodes def get_node(self, path): @@ -375,9 +372,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) - if path not in self.nodes: if path in self._file_paths: node = FileNode(path, changeset=self)