Changeset - 6705eeebc41b
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 15 years ago 2011-05-04 18:37:32
marcin@python-works.com
moved out commit into scm model, and added cache invalidation after commit.
2 files changed with 31 insertions and 17 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/files.py
Show inline comments
 
@@ -218,11 +218,6 @@ class FilesController(BaseRepoController
 
    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 @@ class FilesController(BaseRepoController
 

	
 
            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 @@ class FilesController(BaseRepoController
 
                                    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',
rhodecode/model/scm.py
Show inline comments
 
@@ -38,6 +38,7 @@ from vcs import get_backend
 
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 @@ class ScmModel(BaseModel):
 
            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()
 

	
0 comments (0 inline, 0 general)