You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/01/09 00:50:20 UTC

git commit: [#7005] Added Repository.set_status to ensure long clones or refreshes don't flush stale project data

Updated Branches:
  refs/heads/cj/7005 [created] e5fe9c3b5


[#7005] Added Repository.set_status to ensure long clones or refreshes don't flush stale project data

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/e5fe9c3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/e5fe9c3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/e5fe9c3b

Branch: refs/heads/cj/7005
Commit: e5fe9c3b5df4c452f9dab754a129f694b79fbb67
Parents: b17a9ff
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Wed Jan 8 23:50:04 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed Jan 8 23:50:04 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py   | 26 ++++++++++++++++++++++----
 ForgeGit/forgegit/model/git_repo.py |  8 +++-----
 ForgeSVN/forgesvn/model/svn.py      |  8 +++-----
 3 files changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e5fe9c3b/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 06ade3f..18dda46 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -564,13 +564,11 @@ class Repository(Artifact, ActivityObject):
         '''Find any new commits in the repository and update'''
         try:
             log.info('... %r analyzing', self)
-            self.status = 'analyzing'
-            session(self).flush(self)
+            self.set_status('analyzing')
             refresh_repo(self, all_commits, notify, new_clone)
         finally:
             log.info('... %s ready', self)
-            self.status = 'ready'
-            session(self).flush(self)
+            self.set_status('ready')
 
     def push_upstream_context(self):
         project, rest=h.find_project(self.upstream_repo.name)
@@ -599,6 +597,26 @@ class Repository(Artifact, ActivityObject):
     def rev_to_commit_id(self, rev):
         raise NotImplementedError, 'rev_to_commit_id'
 
+    def set_status(self, status):
+        '''
+        Update (and flush) the repo status indicator.
+
+        Updates to the repo status (or any Repository field) are considered
+        project updates (because Repositories are Artifacts; see
+        `Artifact.__metaclass__.before_save`) and thus change `last_updated`
+        on `c.project`, which causes `c.project` to be flushed.
+
+        Because repo status changes can come at the end or middle of a long
+        operation, `c.project` can be quite stale, so this flushes and reloads
+        `c.project`.
+        '''
+        from allura.model import Project
+        session(c.project).flush(c.project)
+        session(c.project).expunge(c.project)
+        c.project = Project.query.get(_id=c.project._id)
+        self.status = status
+        session(self).flush(self)
+
 class MergeRequest(VersionedArtifact, ActivityObject):
     statuses=['open', 'merged', 'rejected']
     class __mongometa__:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e5fe9c3b/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index ae9f63e..f318be6 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -138,7 +138,7 @@ class GitImplementation(M.RepositoryImplementation):
             shared='all')
         self.__dict__['_git'] = repo
         self._setup_special_files()
-        self._repo.status = 'ready'
+        self._repo.set_status('ready')
 
     def can_hotcopy(self, source_url):
         enabled = asbool(tg.config.get('scm.git.hotcopy', True))
@@ -148,8 +148,7 @@ class GitImplementation(M.RepositoryImplementation):
 
     def clone_from(self, source_url):
         '''Initialize a repo as a clone of another'''
-        self._repo.status = 'cloning'
-        session(self._repo).flush(self._repo)
+        self._repo.set_status('cloning')
         log.info('Initialize %r as a clone of %s',
                  self._repo, source_url)
         try:
@@ -170,8 +169,7 @@ class GitImplementation(M.RepositoryImplementation):
             self.__dict__['_git'] = repo
             self._setup_special_files(source_url)
         except:
-            self._repo.status = 'ready'
-            session(self._repo).flush(self._repo)
+            self._repo.set_status('ready')
             raise
 
     def commit(self, rev):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e5fe9c3b/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index f4d0ac0..4dca57f 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -191,7 +191,7 @@ class SVNImplementation(M.RepositoryImplementation):
                                  cwd=self._repo.fs_path)
         if not skip_special_files:
             self._setup_special_files()
-        self._repo.status = 'ready'
+        self._repo.set_status('ready')
         # make first commit with dir structure
         if default_dirs:
             tmp_working_dir = tempfile.mkdtemp(prefix='allura-svn-r1-',
@@ -225,8 +225,7 @@ class SVNImplementation(M.RepositoryImplementation):
         p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
         stdout, stderr = p.communicate(input='p\n')
         if p.returncode != 0:
-            self._repo.status = 'ready'
-            session(self._repo).flush(self._repo)
+            self._repo.set_status('ready')
             raise SVNCalledProcessError(cmd, p.returncode, stdout, stderr)
         return stdout, stderr
 
@@ -246,8 +245,7 @@ class SVNImplementation(M.RepositoryImplementation):
                               'hooks', hook_name)
             os.remove(fn)
 
-        self._repo.status = 'importing'
-        session(self._repo).flush(self._repo)
+        self._repo.set_status('importing')
         log.info('Initialize %r as a clone of %s',
                  self._repo, source_url)