changeset 8729:912563696e9e

scm: simplify InMemoryChangeset handling Avoid conditional imports.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 31 Oct 2020 16:56:12 +0100
parents f3fab7b124f2
children aee4c451566f
files kallithea/model/scm.py
diffstat 1 files changed, 4 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/scm.py	Sun Nov 01 06:29:32 2020 +0100
+++ b/kallithea/model/scm.py	Sat Oct 31 16:56:12 2020 +0100
@@ -336,23 +336,6 @@
         set_hook_environment(username, ip_addr, repo_name, repo_alias=repo.alias, action=action)
         process_pushed_raw_ids(revisions) # also calls mark_for_invalidation
 
-    def _get_IMC_module(self, scm_type):
-        """
-        Returns InMemoryCommit class based on scm_type
-
-        :param scm_type:
-        """
-        if scm_type == 'hg':
-            from kallithea.lib.vcs.backends.hg import MercurialInMemoryChangeset
-            return MercurialInMemoryChangeset
-
-        if scm_type == 'git':
-            from kallithea.lib.vcs.backends.git import GitInMemoryChangeset
-            return GitInMemoryChangeset
-
-        raise Exception('Invalid scm_type, must be one of hg,git got %s'
-                        % (scm_type,))
-
     def pull_changes(self, repo, username, ip_addr, clone_uri=None):
         """
         Pull from "clone URL" or fork origin.
@@ -393,8 +376,7 @@
         :param repo: a db_repo.scm_instance
         """
         user = db.User.guess_instance(user)
-        IMC = self._get_IMC_module(repo.alias)
-        imc = IMC(repo)
+        imc = repo.in_memory_changeset
         imc.change(FileNode(f_path, content, mode=cs.get_file_mode(f_path)))
         try:
             tip = imc.commit(message=message, author=author,
@@ -480,9 +462,6 @@
         if not author:
             author = committer
 
-        IMC = self._get_IMC_module(scm_instance.alias)
-        imc = IMC(scm_instance)
-
         if not parent_cs:
             parent_cs = EmptyChangeset(alias=scm_instance.alias)
 
@@ -492,6 +471,7 @@
         else:
             parents = [parent_cs]
         # add multiple nodes
+        imc = scm_instance.in_memory_changeset
         for path, content in processed_nodes:
             imc.add(FileNode(path, content=content))
 
@@ -524,9 +504,6 @@
         if not author:
             author = committer
 
-        imc_class = self._get_IMC_module(scm_instance.alias)
-        imc = imc_class(scm_instance)
-
         if not parent_cs:
             parent_cs = EmptyChangeset(alias=scm_instance.alias)
 
@@ -537,6 +514,7 @@
             parents = [parent_cs]
 
         # add multiple nodes
+        imc = scm_instance.in_memory_changeset
         for _filename, data in nodes.items():
             # new filename, can be renamed from the old one
             filename = self._sanitize_path(data['filename'])
@@ -605,9 +583,6 @@
         if not author:
             author = committer
 
-        IMC = self._get_IMC_module(scm_instance.alias)
-        imc = IMC(scm_instance)
-
         if not parent_cs:
             parent_cs = EmptyChangeset(alias=scm_instance.alias)
 
@@ -617,6 +592,7 @@
         else:
             parents = [parent_cs]
         # add multiple nodes
+        imc = scm_instance.in_memory_changeset
         for path, content in processed_nodes:
             imc.remove(FileNode(path, content=content))