incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [04/10] git commit: [#6218] Deprecated and removed references to cached heads, branches and tags
Date Tue, 04 Jun 2013 20:04:13 GMT
[#6218] Deprecated and removed references to cached heads, branches and tags

Signed-off-by: Cory Johns <cjohns@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/7437ce52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/7437ce52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/7437ce52

Branch: refs/heads/master
Commit: 7437ce52a9e2339873395470937d8fc6a5bfee00
Parents: 28f8651
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Tue May 28 19:26:58 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Jun 4 18:53:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py            |   12 ++--
 Allura/allura/lib/repository.py                    |    2 +-
 Allura/allura/model/repository.py                  |   43 ++++++-------
 ForgeGit/forgegit/model/git_repo.py                |   51 +++++----------
 .../forgegit/tests/functional/test_controllers.py  |    2 +-
 ForgeGit/forgegit/tests/model/test_repository.py   |   19 ++----
 ForgeSVN/forgesvn/model/svn.py                     |   49 +++++++--------
 ForgeSVN/forgesvn/tests/model/test_repository.py   |    9 +--
 ForgeUserStats/forgeuserstats/tests/test_model.py  |    3 +-
 ForgeUserStats/forgeuserstats/tests/test_stats.py  |    3 +-
 10 files changed, 76 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index e4832aa..084e17a 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -147,11 +147,11 @@ class RepoRootController(BaseController, FeedController):
     def mr_widget(self):
         source_branches = [
             b.name
-            for b in c.app.repo.branches + c.app.repo.repo_tags]
+            for b in c.app.repo.get_branches() + c.app.repo.get_tags()]
         with c.app.repo.push_upstream_context():
             target_branches = [
                 b.name
-                for b in c.app.repo.branches + c.app.repo.repo_tags]
+                for b in c.app.repo.get_branches() + c.app.repo.get_tags()]
         return SCMMergeRequestWidget(
             source_branches=source_branches,
             target_branches=target_branches)
@@ -162,7 +162,7 @@ class RepoRootController(BaseController, FeedController):
         security.require(security.has_access(c.app.repo, 'admin'))
         c.form = self.mr_widget
         if branch is None:
-            source_branch=c.app.repo.branches[0].name
+            source_branch=c.app.default_branch_name
         return dict(source_branch=source_branch)
 
     @expose()
@@ -205,7 +205,7 @@ class RepoRootController(BaseController, FeedController):
     @without_trailing_slash
     @expose('json:')
     def commit_browser_data(self):
-        head_ids = [ head.object_id for head in c.app.repo.heads ]
+        head_ids = [ head.object_id for head in c.app.repo.get_heads() ]
         commit_ids = list(c.app.repo.commitlog(head_ids))
         log.info('Grab %d commit objects by ID', len(commit_ids))
         commits_by_id = dict(
@@ -394,12 +394,12 @@ class BranchBrowser(BaseController):
     @expose('jinja:allura:templates/repo/tags.html')
     @with_trailing_slash
     def tags(self, **kw):
-        return dict(tags=c.app.repo.repo_tags)
+        return dict(tags=c.app.repo.get_tags())
 
     @expose('jinja:allura:templates/repo/tags.html')
     @with_trailing_slash
     def branches(self, **kw):
-        return dict(title='Branches', tags=c.app.repo.branches)
+        return dict(title='Branches', tags=c.app.repo.get_branches())
 
     @expose()
     @with_trailing_slash

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/Allura/allura/lib/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index afd5557..5798b21 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -119,7 +119,7 @@ class RepositoryApp(Application):
                     (repo_path_parts[1], repo_path_parts[-1]),
                     self.repo.upstream_repo.name)
                 ]
-            if len(c.app.repo.branches) and has_access(c.app.repo, 'admin'):
+            if not c.app.repo.is_empty() and has_access(c.app.repo, 'admin'):
                 links.append(SitemapEntry('Request Merge', c.app.url + 'request_merge',
                              ui_icon=g.icons['merge'],
                              ))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 1960d59..78e16e2 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -92,10 +92,6 @@ class RepositoryImplementation(object):
         commit'''
         raise NotImplementedError, 'commit_parents'
 
-    def refresh_heads(self): # pragma no cover
-        '''Sets repository metadata such as heads, tags, and branches'''
-        raise NotImplementedError, 'refresh_heads'
-
     def refresh_commit_info(self, oid, lazy=True): # pragma no cover
         '''Refresh the data in the commit with id oid'''
         raise NotImplementedError, 'refresh_commit_info'
@@ -173,12 +169,8 @@ class RepositoryImplementation(object):
         return '[%s]' % oid[:6]
 
     def symbolics_for_commit(self, commit):
-        '''Return symbolic branch and tag names for a commit.
-        Default generic implementation is provided, subclasses
-        may override if they have more efficient means.'''
-        branches = [b.name for b in self._repo.branches if b.object_id == commit._id]
-        tags = [t.name for t in self._repo.repo_tags if t.object_id == commit._id]
-        return branches, tags
+        '''Return symbolic branch and tag names for a commit.'''
+        raise NotImplementedError, 'symbolics_for_commit'
 
     def url_for_commit(self, commit, url_type='ci'):
         'return an URL, given either a commit or object id'
@@ -214,11 +206,17 @@ class RepositoryImplementation(object):
         os.chmod(magic_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)
         self._setup_hooks(source_path)
 
-    def get_branches(self):
-        return self.repo.branches
+    @property
+    def heads(self):
+        raise NotImplementedError, 'heads'
 
-    def get_tags(self):
-        return self.repo.tags
+    @property
+    def branches(self):
+        raise NotImplementedError, 'branches'
+
+    @property
+    def tags(self):
+        raise NotImplementedError, 'tags'
 
 class Repository(Artifact, ActivityObject):
     BATCH_SIZE=100
@@ -237,9 +235,9 @@ class Repository(Artifact, ActivityObject):
     status=FieldProperty(str)
     email_address=''
     additional_viewable_extensions=FieldProperty(str)
-    heads = FieldProperty([dict(name=str,object_id=str, count=int)])
-    branches = FieldProperty([dict(name=str,object_id=str, count=int)])
-    repo_tags = FieldProperty([dict(name=str,object_id=str, count=int)])
+    heads = FieldProperty(S.Deprecated)
+    branches = FieldProperty(S.Deprecated)
+    repo_tags = FieldProperty(S.Deprecated)
     upstream_repo = FieldProperty(dict(name=str,url=str))
 
     def __init__(self, **kw):
@@ -332,10 +330,12 @@ class Repository(Artifact, ActivityObject):
         return self._impl.last_commit_ids(commit, paths)
     def is_empty(self):
         return self._impl.is_empty()
+    def get_heads(self):
+        return self._impl.heads
     def get_branches(self):
-        return self._impl.get_branches()
+        return self._impl.branches
     def get_tags(self):
-        return self._impl.get_tags()
+        return self._impl.tags
 
     def _log(self, rev, skip, limit):
         head = self.commit(rev)
@@ -531,13 +531,8 @@ class Repository(Artifact, ActivityObject):
             log.info('... %r analyzing', self)
             self.status = 'analyzing'
             session(self).flush(self)
-            self._impl.refresh_heads()
             if asbool(tg.config.get('scm.new_refresh')):
                 refresh_repo(self, all_commits, notify, new_clone)
-            for head in self.heads + self.branches + self.repo_tags:
-                ci = self.commit(head.object_id)
-                if ci is not None:
-                    head.count = self.count_revisions(ci)
         finally:
             log.info('... %s ready', self)
             self.status = 'ready'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 5683296..27b52d9 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -148,13 +148,6 @@ class GitImplementation(M.RepositoryImplementation):
 
     def commit(self, rev):
         '''Return a Commit object.  rev can be _id or a branch/tag name'''
-        # See if the rev is a named ref that we have cached, and use the sha1
-        # from the cache. This ensures that we don't return a sha1 that we
-        # don't have indexed into mongo yet.
-        for ref in self._repo.heads + self._repo.branches + self._repo.repo_tags:
-            if ref.name == rev:
-                rev = ref.object_id
-                break
         cache = getattr(c, 'model_cache', '') or M.repo.ModelCache()
         result = cache.get(M.repo.Commit, dict(_id=rev))
         if result is None:
@@ -170,8 +163,8 @@ class GitImplementation(M.RepositoryImplementation):
                 except:
                     pass
                 log.exception('Error with rev_parse(%s)%s' % (str(rev) + '^0', url))
-        if result is None: return None
-        result.set_context(self._repo)
+        if result:
+            result.set_context(self._repo)
         return result
 
     def all_commit_ids(self):
@@ -189,7 +182,7 @@ class GitImplementation(M.RepositoryImplementation):
     def new_commits(self, all_commits=False):
         graph = {}
 
-        to_visit = [ self._git.commit(rev=hd.object_id) for hd in self._repo.heads ]
+        to_visit = [ self._git.commit(rev=hd.object_id) for hd in self.heads ]
         while to_visit:
             obj = to_visit.pop()
             if obj.hexsha in graph: continue
@@ -202,21 +195,6 @@ class GitImplementation(M.RepositoryImplementation):
             to_visit += obj.parents
         return list(topological_sort(graph))
 
-    def refresh_heads(self):
-        self._repo.heads = [
-            Object(name=head.name, object_id=head.commit.hexsha)
-            for head in self._git.heads
-            if head.is_valid() ]
-        self._repo.branches = [
-            Object(name=head.name, object_id=head.commit.hexsha)
-            for head in self._git.branches
-            if head.is_valid() ]
-        self._repo.repo_tags = [
-            Object(name=tag.name, object_id=tag.commit.hexsha)
-            for tag in self._git.tags
-            if tag.is_valid() ]
-        session(self._repo).flush()
-
     def refresh_commit_info(self, oid, seen, lazy=True):
         from allura.model.repo import CommitDoc
         ci_doc = CommitDoc.m.get(_id=oid)
@@ -331,13 +309,12 @@ class GitImplementation(M.RepositoryImplementation):
         return git.Object.new_from_sha(self._git, binsha)
 
     def symbolics_for_commit(self, commit):
-        branch_heads, tags = super(self.__class__, self).symbolics_for_commit(commit)
         try:
-            containing_branches = self._git.git.branch(contains=commit._id)
+            branches = [b.name for b in self.branches if b.object_id == commit._id]
+            tags = [t.name for t in self.tags if t.object_id == commit._id]
+            return branches, tags
         except git.GitCommandError:
-            return [], tags
-        containing_branches = [br.strip(' *') for br in containing_branches.split('\n')]
-        return containing_branches, tags
+            return [], []
 
     def compute_tree_new(self, commit, tree_path='/'):
         ci = self._git.rev_parse(commit._id)
@@ -361,11 +338,17 @@ class GitImplementation(M.RepositoryImplementation):
     def is_empty(self):
         return not self._git or len(self._git.heads) == 0
 
-    def get_branches(self):
-        return [Object(name=b.name,object_id=b.commit.hexsha) for b in self._git.heads]
+    @LazyProperty
+    def heads(self):
+        return [Object(name=b.name, object_id=b.commit.hexsha) for b in self._git.heads if
b.is_valid()]
+
+    @LazyProperty
+    def branches(self):
+        return [Object(name=b.name, object_id=b.commit.hexsha) for b in self._git.branches
if b.is_valid()]
 
-    def get_tags(self):
-        return [Object(name=t.name, object_id=t.commit.hexsha) for t in self._git.tags]
+    @LazyProperty
+    def tags(self):
+        return [Object(name=t.name, object_id=t.commit.hexsha) for t in self._git.tags if
t.is_valid()]
 
 
 class _OpenedGitBlob(object):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 204f729..32ffb69 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -467,7 +467,7 @@ class TestFork(_TestCase):
         assert 'Improve documentation' in r, r.showbrowser()
         revs = r.html.findAll('tr', attrs={'class': 'rev'})
         links = revs[0].findAll('a')
-        c_id = self.forked_repo.heads[0]['object_id']
+        c_id = self.forked_repo.get_heads()[0]['object_id']
         assert_equal(links[0].get('href'), '/p/test2/code/ci/%s/' % c_id)
         assert_equal(links[0].getText(), '[%s]' % c_id[:6])
         assert_equal(links[1].get('href'), '/p/test2/code/ci/%s/tree' % c_id)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index bae667c..4afe27f 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -63,8 +63,7 @@ class TestNewGit(unittest.TestCase):
         #     tool = 'git',
         #     status = 'creating')
         self.repo.refresh()
-        self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
-        self.rev.repo = self.repo
+        self.rev = self.repo.commit('master')
         ThreadLocalORMSession.flush_all()
         ThreadLocalORMSession.close_all()
 
@@ -76,7 +75,7 @@ class TestNewGit(unittest.TestCase):
         assert self.rev.tree._id == self.rev.tree_id
         assert self.rev.summary == self.rev.message.splitlines()[0]
         assert self.rev.shorthand_id() == '[1e146e]'
-        assert self.rev.symbolic_ids == (['master', 'zz'], ['foo'])
+        assert self.rev.symbolic_ids == (['master'], ['foo']), self.rev.symbolic_ids
         assert self.rev.url() == (
             '/p/test/src-git/ci/'
             '1e146e67985dcd71c74de79613719bef7bddca4a/')
@@ -234,12 +233,6 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         entry = self.repo.commit('HEAD')
         assert str(entry.authored.name) == 'Rick Copeland', entry.authored
         assert entry.message
-        # Test that sha1s for named refs are looked up in cache first, instead
-        # of from disk.
-        with mock.patch('forgegit.model.git_repo.M.repo.Commit.query') as q:
-            self.repo.heads.append(Object(name='HEAD', object_id='deadbeef'))
-            self.repo.commit('HEAD')
-            q.get.assert_called_with(_id='deadbeef')
         # test the auto-gen tree fall-through
         orig_tree = M.repo.Tree.query.get(_id=entry.tree_id)
         assert orig_tree
@@ -340,22 +333,22 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             assert repo2.is_empty()
 
 class TestGitImplementation(unittest.TestCase):
-    def test_get_branches(self):
+    def test_branches(self):
         repo_dir = pkg_resources.resource_filename(
             'forgegit', 'tests/data/testgit.git')
         repo = mock.Mock(full_fs_path=repo_dir)
         impl = GM.git_repo.GitImplementation(repo)
-        self.assertEqual(impl.get_branches(), [
+        self.assertEqual(impl.branches, [
                 Object(name='master', object_id='1e146e67985dcd71c74de79613719bef7bddca4a'),
                 Object(name='zz', object_id='5c47243c8e424136fd5cdd18cd94d34c66d1955c')
             ])
 
-    def test_get_tags(self):
+    def test_tags(self):
         repo_dir = pkg_resources.resource_filename(
             'forgegit', 'tests/data/testgit.git')
         repo = mock.Mock(full_fs_path=repo_dir)
         impl = GM.git_repo.GitImplementation(repo)
-        self.assertEqual(impl.get_tags(), [
+        self.assertEqual(impl.tags, [
                 Object(name='foo', object_id='1e146e67985dcd71c74de79613719bef7bddca4a'),
             ])
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index f017f0b..23c1887 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -98,8 +98,7 @@ class Repository(M.Repository):
 
     def latest(self, branch=None):
         if self._impl is None: return None
-        if not self.heads: return None
-        return self._impl.commit(self.heads[0].object_id)
+        return self._impl.commit('HEAD')
 
     def tarball_filename(self, revision, path=None):
         fn = super(Repository, self).tarball_filename(revision, path)
@@ -299,42 +298,27 @@ class SVNImplementation(M.RepositoryImplementation):
             c.app.config.options['checkout_url'] = ""
         self._setup_special_files(source_url)
 
-    def refresh_heads(self):
-        info = self._svn.info2(
-            self._url,
-            revision=pysvn.Revision(pysvn.opt_revision_kind.head),
-            recurse=False)[0][1]
-        oid = self._oid(info.rev.number)
-        self._repo.heads = [ Object(name=None, object_id=oid) ]
-        # Branches and tags aren't really supported in subversion
-        self._repo.branches = []
-        self._repo.repo_tags = []
-        session(self._repo).flush(self._repo)
-
     def commit(self, rev):
         if rev in ('HEAD', None):
-            if not self._repo.heads: return None
-            oid = self._repo.heads[0].object_id
+            oid = self._oid(self.head)
         elif isinstance(rev, int) or rev.isdigit():
             oid = self._oid(rev)
         else:
             oid = rev
         result = M.repo.Commit.query.get(_id=oid)
-        if result is None: return None
-        result.set_context(self._repo)
+        if result:
+            result.set_context(self._repo)
         return result
 
     def all_commit_ids(self):
         """Return a list of commit ids, starting with the head (most recent
         commit) and ending with the root (first commit).
         """
-        if not self._repo.heads:
-            return []
-        head_revno = self._revno(self._repo.heads[0].object_id)
+        head_revno = self.head
         return map(self._oid, range(head_revno, 0, -1))
 
     def new_commits(self, all_commits=False):
-        head_revno = self._revno(self._repo.heads[0].object_id)
+        head_revno = self.head
         oids = [ self._oid(revno) for revno in range(1, head_revno+1) ]
         if all_commits:
             return oids
@@ -689,19 +673,32 @@ class SVNImplementation(M.RepositoryImplementation):
                 os.remove(tmpfilename)
 
     def is_empty(self):
+        return self.head == 0
+
+    def symbolics_for_commit(self, commit):
+        return [], []
+
+    @LazyProperty
+    def head(self):
         try:
-            return self._svn.revpropget('revision', url=self._url)[0].number == 0
+            return int(self._svn.revpropget('revision', url=self._url)[0].number)
         except pysvn.ClientError as e:
             if str(e).startswith("Unable to connect") or \
                     str(e).startswith("Unable to open"):
-                return True
+                return 0
             else:
                 raise
 
-    def get_branches(self):
+    @LazyProperty
+    def heads(self):
+        return [Object(name=None, object_id=self._oid(self.head))]
+
+    @LazyProperty
+    def branches(self):
         return []
 
-    def get_tags(self):
+    @LazyProperty
+    def tags(self):
         return []
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 0bc2f86..9751b38 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -65,8 +65,7 @@ class TestNewRepo(unittest.TestCase):
             tool = 'svn',
             status = 'creating')
         self.repo.refresh()
-        self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
-        self.rev.repo = self.repo
+        self.rev = self.repo.commit('HEAD')
         ThreadLocalORMSession.flush_all()
         ThreadLocalORMSession.close_all()
 
@@ -723,10 +722,7 @@ class TestRepo(_TestWithRepo):
                         name=committer_name,
                         email=committer_email),
                     _id=oid)).m.insert()
-        def set_heads():
-            self.repo.heads = [ ming.base.Object(name='head', object_id='foo0', count=100)
]
         self.repo._impl.refresh_commit_info = refresh_commit_info
-        self.repo._impl.refresh_heads = mock.Mock(side_effect=set_heads)
         _id = lambda oid: getattr(oid, '_id', str(oid))
         self.repo.shorthand_for_commit = lambda oid: '[' + _id(oid) + ']'
         self.repo.url_for_commit = lambda oid: 'ci/' + _id(oid) + '/'
@@ -747,9 +743,6 @@ class TestRepo(_TestWithRepo):
         self.repo.count_revisions=mock.Mock(return_value=100)
         self.repo._impl.commit = mock.Mock(return_value=ci)
         self.repo._impl.new_commits = mock.Mock(return_value=['foo%d' % i for i in range(100)
])
-        def set_heads():
-            self.repo.heads = [ ming.base.Object(name='head', object_id='foo0', count=100)
]
-        self.repo._impl.refresh_heads = mock.Mock(side_effect=set_heads)
 
         # make unreadable by *anonymous, so additional notification logic executes
         self.repo.acl = []

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeUserStats/forgeuserstats/tests/test_model.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/tests/test_model.py b/ForgeUserStats/forgeuserstats/tests/test_model.py
index cc67e27..a6526e1 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_model.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_model.py
@@ -337,8 +337,7 @@ class TestUserStats(unittest.TestCase):
         c.app.repo.name = 'testgit.git'
         repo = c.app.repo
         repo.refresh()
-        commit = M.repo.Commit.query.get(_id=repo.heads[0]['object_id'])
-        commit.repo = repo
+        commit = repo.commit()
 
         init_commits = self.user.stats.getCommits()
         assert init_commits['number'] == 4

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7437ce52/ForgeUserStats/forgeuserstats/tests/test_stats.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/tests/test_stats.py b/ForgeUserStats/forgeuserstats/tests/test_stats.py
index 482eda8..0e747f0 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_stats.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_stats.py
@@ -192,8 +192,7 @@ class TestGitCommit(TestController, unittest.TestCase):
         c.app.repo.name = 'testgit.git'
         self.repo = c.app.repo
         self.repo.refresh()
-        self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
-        self.rev.repo = self.repo
+        self.rev = self.repo.commit()
 
     @td.with_user_project('test-admin')
     def test_commit(self):


Mime
View raw message