changeset 1311:6705eeebc41b beta

moved out commit into scm model, and added cache invalidation after commit.
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 04 May 2011 18:37:32 +0200
parents 4d37c3f2a410
children 70a5a9a57864
files rhodecode/controllers/files.py rhodecode/model/scm.py
diffstat 2 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/files.py	Wed May 04 16:57:27 2011 +0200
+++ b/rhodecode/controllers/files.py	Wed May 04 18:37:32 2011 +0200
@@ -218,11 +218,6 @@
     def edit(self, repo_name, revision, f_path):
         r_post = request.POST
 
-        if c.rhodecode_repo.alias == 'hg':
-            from vcs.backends.hg import MercurialInMemoryChangeset as IMC
-        elif c.rhodecode_repo.alias == 'git':
-            from vcs.backends.git import GitInMemoryChangeset as IMC
-
         c.cs = self.__get_cs_or_redirect(revision, repo_name)
         c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path)
 
@@ -240,6 +235,7 @@
 
             message = r_post.get('message') or (_('Edited %s via RhodeCode')
                                                 % (f_path))
+            author = self.rhodecode_user.full_contact
 
             if content == old_content:
                 h.flash(_('No changes'),
@@ -248,21 +244,14 @@
                                     revision='tip'))
 
             try:
-                # decoding here will force that we have proper encoded values
-                # in any other case this will throw exceptions and deny commit
-                content = content.encode('utf8')
-                message = message.encode('utf8')
-                path = f_path.encode('utf8')
-                author = self.rhodecode_user.full_contact.encode('utf8')
-                m = IMC(c.rhodecode_repo)
-                m.change(FileNode(path, content))
-                m.commit(message=message,
-                         author=author,
-                         parents=[c.cs], branch=c.cs.branch)
+                self.scm_model.commit_change(repo=c.rhodecode_repo,
+                                             repo_name=repo_name, cs=c.cs,
+                                             author=author, message=message,
+                                             content=content, f_path=f_path)
                 h.flash(_('Successfully committed to %s' % f_path),
                         category='success')
 
-            except Exception, e:
+            except Exception:
                 log.error(traceback.format_exc())
                 h.flash(_('Error occurred during commit'), category='error')
             return redirect(url('changeset_home',
--- a/rhodecode/model/scm.py	Wed May 04 16:57:27 2011 +0200
+++ b/rhodecode/model/scm.py	Wed May 04 18:37:32 2011 +0200
@@ -38,6 +38,7 @@
 from vcs.utils.helpers import get_scm
 from vcs.exceptions import RepositoryError, VCSError
 from vcs.utils.lazy import LazyProperty
+from vcs.nodes import FileNode
 
 from rhodecode import BACKENDS
 from rhodecode.lib import helpers as h
@@ -376,6 +377,30 @@
             log.error(traceback.format_exc())
             raise
 
+
+    def commit_change(self, repo, repo_name, cs, author, message, content,
+                      f_path):
+
+        if repo.alias == 'hg':
+            from vcs.backends.hg import MercurialInMemoryChangeset as IMC
+        elif repo.alias == 'git':
+            from vcs.backends.git import GitInMemoryChangeset as IMC
+
+        # decoding here will force that we have proper encoded values
+        # in any other case this will throw exceptions and deny commit
+        content = content.encode('utf8')
+        message = message.encode('utf8')
+        path = f_path.encode('utf8')
+        author = author.encode('utf8')
+        m = IMC(repo)
+        m.change(FileNode(path, content))
+        m.commit(message=message,
+                 author=author,
+                 parents=[cs], branch=cs.branch)
+
+        self.mark_for_invalidation(repo_name)
+
+
     def get_unread_journal(self):
         return self.sa.query(UserLog).count()