Switch to unified view

a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
...
...
8
from hashlib import sha1
8
from hashlib import sha1
9
from datetime import datetime
9
from datetime import datetime
10
from collections import defaultdict
10
from collections import defaultdict
11
11
12
import tg
12
import tg
13
from paste.deploy.converters import asbool
13
from pylons import c,g, request
14
from pylons import c,g, request
14
import pymongo.errors
15
import pymongo.errors
15
16
16
from ming import schema as S
17
from ming import schema as S
17
from ming.base import Object
18
from ming.base import Object
...
...
26
27
27
from .artifact import Artifact, VersionedArtifact, Feed
28
from .artifact import Artifact, VersionedArtifact, Feed
28
from .auth import User
29
from .auth import User
29
from .session import repository_orm_session, project_orm_session, main_doc_session
30
from .session import repository_orm_session, project_orm_session, main_doc_session
30
from .notification import Notification
31
from .notification import Notification
32
from .repo_refresh import refresh_repo
31
33
32
log = logging.getLogger(__name__)
34
log = logging.getLogger(__name__)
33
config = utils.ConfigProxy(
35
config = utils.ConfigProxy(
34
    common_suffix='forgemail.domain',
36
    common_suffix='forgemail.domain',
35
    common_prefix='forgemail.url')
37
    common_prefix='forgemail.url')
...
...
77
        raise NotImplementedError, 'refresh_commit'
79
        raise NotImplementedError, 'refresh_commit'
78
80
79
    def refresh_commit_info(self, oid): # pragma no cover
81
    def refresh_commit_info(self, oid): # pragma no cover
80
        '''Refresh the data in the commit with id oid'''
82
        '''Refresh the data in the commit with id oid'''
81
        raise NotImplementedError, 'refresh_commit_info'
83
        raise NotImplementedError, 'refresh_commit_info'
82
83
    def object_id(self, obj): # pragma no cover
84
        '''Return the object_id for the given native object'''
85
        raise NotImplementedError, 'object_id'
86
84
87
    def _setup_hooks(self): # pragma no cover
85
    def _setup_hooks(self): # pragma no cover
88
        '''Install a hook in the repository that will ping the refresh url for
86
        '''Install a hook in the repository that will ping the refresh url for
89
        the repo'''
87
        the repo'''
90
        raise NotImplementedError, '_setup_hooks'
88
        raise NotImplementedError, '_setup_hooks'
...
...
103
    def open_blob(self, blob): # pragma no cover
101
    def open_blob(self, blob): # pragma no cover
104
        '''Return a file-like object that contains the contents of the blob'''
102
        '''Return a file-like object that contains the contents of the blob'''
105
        raise NotImplementedError, 'open_blob'
103
        raise NotImplementedError, 'open_blob'
106
104
107
    def shorthand_for_commit(self, oid):
105
    def shorthand_for_commit(self, oid):
108
        return '[%s]' % oid
106
        return '[%s]' % oid[:6]
109
107
110
    def symbolics_for_commit(self, commit):
108
    def symbolics_for_commit(self, commit):
111
        '''Return symbolic branch and tag names for a commit.
109
        '''Return symbolic branch and tag names for a commit.
112
        Default generic implementation is provided, subclasses
110
        Default generic implementation is provided, subclasses
113
        may override if they have more efficient means.'''
111
        may override if they have more efficient means.'''
...
...
304
                content_type, encoding = 'application/octet-stream', None
302
                content_type, encoding = 'application/octet-stream', None
305
        return content_type, encoding
303
        return content_type, encoding
306
304
307
    def refresh(self, all_commits=False, notify=True):
305
    def refresh(self, all_commits=False, notify=True):
308
        '''Find any new commits in the repository and update'''
306
        '''Find any new commits in the repository and update'''
307
        if asbool(tg.config.get('scm.new_refresh')):
308
            refresh_repo(self, all_commits, notify)
309
        self._impl.refresh_heads()
309
        self._impl.refresh_heads()
310
        self.status = 'analyzing'
310
        self.status = 'analyzing'
311
        session(self).flush()
311
        session(self).flush()
312
        sess = session(Commit)
312
        sess = session(Commit)
313
        log.info('Refreshing repository %s', self)
313
        log.info('Refreshing repository %s', self)
314
        commit_ids = self._impl.new_commits(all_commits)
314
        commit_ids = self._impl.new_commits(all_commits)
315
        log.info('... %d new commits', len(commit_ids))
315
        log.info('... %d new commits', len(commit_ids))
316
        # Refresh history
316
        # Refresh history
317
        seen_object_ids = set()
317
        seen_object_ids = set()
318
        commit_msgs = []
318
        commit_msgs = []
319
        i=0
319
        for i, oid in enumerate(commit_ids):
320
        for i, oid in enumerate(commit_ids):
320
            if len(seen_object_ids) > 10000: # pragma no cover
321
            if len(seen_object_ids) > 10000: # pragma no cover
321
                log.info('... flushing seen object cache')
322
                log.info('... flushing seen object cache')
322
                seen_object_ids = set()
323
                seen_object_ids = set()
323
            ci, isnew = Commit.upsert(oid)
324
            ci, isnew = Commit.upsert(oid)
...
...
385
    def compute_diffs(self):
386
    def compute_diffs(self):
386
        commit_ids = self._impl.new_commits(all_commits=True)
387
        commit_ids = self._impl.new_commits(all_commits=True)
387
        sess = session(Commit)
388
        sess = session(Commit)
388
        # Compute diffs on all commits
389
        # Compute diffs on all commits
389
        log.info('... computing diffs')
390
        log.info('... computing diffs')
391
        i=0
390
        for i, oid in enumerate(commit_ids):
392
        for i, oid in enumerate(commit_ids):
391
            ci = self._impl.commit(oid)
393
            ci = self._impl.commit(oid)
392
            ci.tree.set_last_commit(ci, self)
394
            ci.tree.set_last_commit(ci, self)
393
            if not ci.diffs_computed:
395
            if not ci.diffs_computed:
394
                ci.compute_diffs()
396
                ci.compute_diffs()