# HG changeset patch # User Marcin Kuzminski # Date 1304527052 -7200 # Node ID 6705eeebc41bce5626cfa254f0046b8bc7438d31 # Parent 4d37c3f2a410b0b8ec3d4bcd530d371e8b17d077 moved out commit into scm model, and added cache invalidation after commit. diff -r 4d37c3f2a410 -r 6705eeebc41b rhodecode/controllers/files.py --- 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', diff -r 4d37c3f2a410 -r 6705eeebc41b rhodecode/model/scm.py --- 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()