You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/01/10 17:26:07 UTC
[2/2] git commit: [#7005] Added Repository.set_status to ensure long
clones or refreshes don't flush stale project data
[#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/1af790d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1af790d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1af790d7
Branch: refs/heads/master
Commit: 1af790d720ac656c7963d3b25a48aaf312eb8c8b
Parents: abd53ba
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Wed Jan 8 23:50:04 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Jan 10 16:25:41 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/1af790d7/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index b0f567e..3e84ab6 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -579,13 +579,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)
@@ -614,6 +612,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/1af790d7/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 9debcc9..961539c 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/1af790d7/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index a547913..b55c397 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)