Changeset - 5c4074db01d3
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-12-26 05:28:52
mads@kiilerich.com
Grafted from: 141ad83c9259
vcs: prepare hg inmemory commit callbacks that given bytes have to find corresponding vcs nodes that use unicode str
1 file changed with 8 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/hg/inmemory.py
Show inline comments
 
@@ -8,13 +8,13 @@ from kallithea.lib.vcs.exceptions import
 
from kallithea.lib.vcs.utils import ascii_str, safe_bytes
 

	
 

	
 
class MercurialInMemoryChangeset(BaseInMemoryChangeset):
 

	
 
    def commit(self, message, author, parents=None, branch=None, date=None,
 
            **kwargs):
 
               **kwargs):
 
        """
 
        Performs in-memory commit (doesn't check workdir in any way) and
 
        returns newly created ``Changeset``. Updates repository's
 
        ``revisions``.
 

	
 
        :param message: message of the commit
 
@@ -37,41 +37,42 @@ class MercurialInMemoryChangeset(BaseInM
 
                                  % (type(message), type(author)))
 

	
 
        if branch is None:
 
            branch = MercurialRepository.DEFAULT_BRANCH_NAME
 
        kwargs[b'branch'] = branch
 

	
 
        def filectxfn(_repo, memctx, path):
 
        def filectxfn(_repo, memctx, bytes_path):
 
            """
 
            Marks given path as added/changed/removed in a given _repo. This is
 
            for internal mercurial commit function.
 
            Callback from Mercurial, returning ctx to commit for the given
 
            path.
 
            """
 
            path = bytes_path  # will be different for py3
 

	
 
            # check if this path is removed
 
            if path in (node.path for node in self.removed):
 
                return None
 

	
 
            # check if this path is added
 
            for node in self.added:
 
                if node.path == path:
 
                    return mercurial.context.memfilectx(_repo, memctx, path=node.path,
 
                    return mercurial.context.memfilectx(_repo, memctx, path=bytes_path,
 
                        data=node.content,
 
                        islink=False,
 
                        isexec=node.is_executable,
 
                        copysource=False)
 

	
 
            # or changed
 
            for node in self.changed:
 
                if node.path == path:
 
                    return mercurial.context.memfilectx(_repo, memctx, path=node.path,
 
                    return mercurial.context.memfilectx(_repo, memctx, path=bytes_path,
 
                        data=node.content,
 
                        islink=False,
 
                        isexec=node.is_executable,
 
                        copysource=False)
 

	
 
            raise RepositoryError("Given path haven't been marked as added,"
 
            raise RepositoryError("Given path haven't been marked as added, "
 
                                  "changed or removed (%s)" % path)
 

	
 
        parents = [None, None]
 
        for i, parent in enumerate(self.parents):
 
            if parent is not None:
 
                parents[i] = parent._ctx.node()
0 comments (0 inline, 0 general)