Switch to side-by-side view

--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -63,22 +63,14 @@
         '''
         raise NotImplementedError, 'new_commits'
 
-    def commit_parents(self, commit):
+    def commit_parents(self, commit): # pragma no cover
         '''Return a list of native commits for the parents of the given (native)
         commit'''
         raise NotImplementedError, 'commit_parents'
 
-    def commit_context(self, object_id): # pragma no cover
-        '''Returns {'prev':Commit, 'next':Commit}'''
-        raise NotImplementedError, 'context'
-
     def refresh_heads(self): # pragma no cover
         '''Sets repository metadata such as heads, tags, and branches'''
         raise NotImplementedError, 'refresh_heads'
-
-    def refresh_commit(self, ci, seen_object_ids=None, lazy=True): # pragma no cover
-        '''Refresh the data in the commit object 'ci' with data from the repo'''
-        raise NotImplementedError, 'refresh_commit'
 
     def refresh_commit_info(self, oid, lazy=True): # pragma no cover
         '''Refresh the data in the commit with id oid'''
@@ -96,11 +88,7 @@
         exhausted).'''
         raise NotImplementedError, 'log'
 
-    def compute_tree(self, commit, path='/'):
-        '''Used in hg and svn to compute a git-like-tree lazily'''
-        raise NotImplementedError, 'compute_tree'
-
-    def compute_tree_new(self, commit, path='/'):
+    def compute_tree_new(self, commit, path='/'): # pragma no cover
         '''Used in hg and svn to compute a git-like-tree lazily with the new models'''
         raise NotImplementedError, 'compute_tree'
 
@@ -120,8 +108,8 @@
         '''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.object_id]
-        tags = [t.name for t in self._repo.repo_tags if t.object_id == commit.object_id]
+        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
 
     def url_for_commit(self, commit):
@@ -129,7 +117,7 @@
         if isinstance(commit, basestring):
             object_id = commit
         else:
-            object_id = commit.object_id
+            object_id = commit._id
         return '%sci/%s/' % (self._repo.url(), object_id)
 
     def _setup_paths(self, create_repo_dir=True):
@@ -204,8 +192,6 @@
         return self._impl.all_commit_ids()
     def refresh_commit_info(self, oid, seen, lazy=True):
         return self._impl.refresh_commit_info(oid, seen, lazy)
-    def commit_context(self, commit):
-        return self._impl.commit_context(commit)
     def open_blob(self, blob):
         return self._impl.open_blob(blob)
     def blob_size(self, blob):
@@ -216,8 +202,6 @@
         return self._impl.symbolics_for_commit(commit)
     def url_for_commit(self, commit):
         return self._impl.url_for_commit(commit)
-    def compute_tree(self, commit, path='/'):
-        return self._impl.compute_tree(commit, path)
     def compute_tree_new(self, commit, path='/'):
         return self._impl.compute_tree_new(commit, path)
 
@@ -328,113 +312,12 @@
         if asbool(tg.config.get('scm.new_refresh')):
             refresh_repo(self, all_commits, notify)
             notify = False # don't double notify
-
-        self.status = 'analyzing'
-        session(self).flush()
-        sess = session(Commit)
-        log.info('Refreshing repository %s', self)
-        commit_ids = self._impl.new_commits(all_commits)
-        log.info('... %d new commits', len(commit_ids))
-        # Refresh history
-        seen_object_ids = set()
-        commit_msgs = []
-        base_url = tg.config.get('base_url', 'sourceforge.net')
-        i=0
-        for i, oid in enumerate(commit_ids):
-            if len(seen_object_ids) > 10000: # pragma no cover
-                log.info('... flushing seen object cache')
-                seen_object_ids = set()
-            ci, isnew = Commit.upsert(oid)
-            if not isnew and not all_commits:
-                sess.expunge(ci)
-                continue
-            ci.set_context(self)
-            self._impl.refresh_commit(ci, seen_object_ids, lazy=not all_commits)
-            if (i+1) % self.BATCH_SIZE == 0:
-                log.info('...... flushing %d commits (%d total)',
-                         self.BATCH_SIZE, (i+1))
-                sess.flush()
-                sess.clear()
-            if notify:
-                Feed.post(
-                    self,
-                    title='New commit',
-                    description='%s<br><a href="%s%s">View Changes</a>' % (
-                        h.really_unicode(ci.summary),config.common_prefix,ci.url()),
-                    author_link = ci.author_url,
-                    author_name = ci.authored.name,
-                )
-                branches = ci.symbolic_ids[0]
-                commit_msgs.append('%s: %s by %s %s%s' % (
-                        ",".join(b for b in branches),
-                        h.really_unicode(ci.summary), h.really_unicode(ci.committed.name), base_url, ci.url()))
-        if commit_msgs:
-            if len(commit_msgs) > 1:
-                subject = '%d new commits to %s %s' % (
-                    len(commit_msgs), self.app.project.name, self.app.config.options.mount_label)
-                text='\n\n'.join(commit_msgs)
-            else:
-                subject = '%s committed to %s %s: %s' % (
-                    h.really_unicode(ci.committed.name),
-                    self.app.project.name,
-                    self.app.config.options.mount_label,
-                    h.really_unicode(ci.summary))
-                ci.set_context(self)
-                branches = ci.symbolic_ids[0]
-                message = "%s: %s %s%s" % (",".join(b for b in branches),
-                                           ci.message,
-                                           base_url, ci.url())
-                text = h.really_unicode(message)
-            Notification.post(
-                artifact=self,
-                topic='metadata',
-                subject=subject,
-                text=text)
-        log.info('...... flushing %d commits (%d total)',
-                 (i+1) % self.BATCH_SIZE, i+1)
-        sess.flush()
-        sess.clear()
-        # Mark all commits in this repo as being in this repo
-        all_commit_ids = self._impl.new_commits(True)
-        Commit.query.update(
-            dict(
-                object_id={'$in':all_commit_ids},
-                repositories={'$ne':self._id}),
-            {'$push':dict(repositories=self._id)},
-            upsert=False, multi=True)
-        if all_commits:
-            LastCommitFor.query.remove(dict(repo_id=self._id))
-        self.compute_diffs()
-        log.info('... refreshed repository %s.  Found %d new commits',
-                 self, len(commit_ids))
         self.status = 'ready'
         for head in self.heads + self.branches + self.repo_tags:
             ci = self.commit(head.object_id)
             if ci is not None:
                 head.count = ci.count_revisions()
         session(self).flush()
-        return len(commit_ids)
-
-    def compute_diffs(self):
-        commit_ids = self._impl.new_commits(all_commits=True)
-        sess = session(Commit)
-        # Compute diffs on all commits
-        log.info('... computing diffs')
-        i=0
-        for i, oid in enumerate(commit_ids):
-            ci = self._impl.commit(oid)
-            ci.tree.set_last_commit(ci, self)
-            if not ci.diffs_computed:
-                ci.compute_diffs()
-            if (i+1) % self.BATCH_SIZE == 0:
-                log.info('...... flushing %d commits (%d total)',
-                         self.BATCH_SIZE, (i+1))
-                sess.flush()
-                sess.clear()
-        log.info('...... flushing %d commits (%d total)',
-                 (i+1) % self.BATCH_SIZE, i+1)
-        sess.flush()
-        sess.clear()
 
     def push_upstream_context(self):
         project, rest=h.find_project(self.upstream_repo.name)
@@ -451,8 +334,9 @@
             return MergeRequest.query.find(q).count()
 
     def get_last_commit(self, obj):
-        lc = LastCommitFor.query.get(
-            repo_id=self._id, object_id=obj.object_id)
+        from .repo import LastCommitDoc
+        lc = LastCommitDoc.m.get(
+            repo_id=self._id, object_id=obj._id)
         if lc is None:
             return dict(
                 author=None,
@@ -460,10 +344,9 @@
                 author_url=None,
                 date=None,
                 id=None,
-                href=None,
                 shortlink=None,
                 summary=None)
-        return lc.last_commit
+        return lc.commit_info
 
     @property
     def forks(self):
@@ -522,12 +405,13 @@
         return self._commits()
 
     def _commits(self):
+        from .repo import Commit
         result = []
         next = [ self.downstream.commit_id ]
         while next:
             oid = next.pop(0)
-            ci = Commit.query.get(object_id=oid)
-            if self.app.repo._id in ci.repositories:
+            ci = Commit.query.get(_id=oid)
+            if self.app.repo._id in ci.repo_ids:
                 continue
             result.append(ci)
             next += ci.parent_ids
@@ -1152,6 +1036,7 @@
         else:
             return '<change %s>' % (self.a_path)
 
+
 class GitLikeTree(object):
     '''
     A tree node similar to that which is used in git