~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/branchview.py

  • Committer: Michael Hudson
  • Date: 2008-06-16 09:48:20 UTC
  • mto: This revision was merged to the branch mainline in revision 160.
  • Revision ID: michael.hudson@canonical.com-20080616094820-fgsn8vbl1sqly01h
readme changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from cherrypy import HTTPRedirect
30
30
 
31
31
from loggerhead import util
32
 
from loggerhead.changecache import ChangeCache, FileChangeCache
 
32
from loggerhead.changecache import FileChangeCache
33
33
from loggerhead.history import History
34
 
from loggerhead.textindex import TextIndex
35
34
from loggerhead.controllers.changelog_ui import ChangeLogUI
36
35
from loggerhead.controllers.atom_ui import AtomUI
37
36
from loggerhead.controllers.revision_ui import RevisionUI
45
44
 
46
45
 
47
46
class BranchView (object):
48
 
    def __init__(self, group_name, name, subfolder, absfolder, config, project_config):
 
47
    def __init__(self, group_name, name, subfolder, absfolder, config,
 
48
                 project_config, root_config):
49
49
        self._group_name = group_name
50
50
        self._name = name
51
51
        self._folder = subfolder
52
52
        self._absfolder = absfolder
53
53
        self._config = config
54
54
        self._project_config = project_config
 
55
        self._root_config = root_config
55
56
        self.log = logging.getLogger('loggerhead.%s' % (name,))
56
57
 
57
58
        # branch history
58
59
        self._history_lock = threading.RLock()
59
60
        self._history = None
60
 
        self._closed = False
61
61
 
62
62
        self.changes = ChangeLogUI(self)
63
63
        self.revision = RevisionUI(self)
70
70
        # force history object to be loaded:
71
71
        self.get_history()
72
72
 
73
 
        turbogears.startup.call_on_shutdown.append(self.close)
74
 
 
75
 
    @with_history_lock
76
 
    def close(self):
77
 
        # it's important that we cleanly detach the history, so the cache
78
 
        # files can be closed correctly and hopefully remain uncorrupted.
79
 
        # this should also stop any ongoing indexing.
80
 
        self._history.detach()
81
 
        self._history = None
82
 
        self._closed = True
83
 
 
84
73
    config = property(lambda self: self._config)
85
74
 
86
75
    name = property(lambda self: self._name)
127
116
    def index(self):
128
117
        raise HTTPRedirect(self.url('/changes'))
129
118
 
 
119
    def get_config_item(self, item, default=None):
 
120
        for conf in self._config, self._project_config, self._root_config:
 
121
            if item in conf:
 
122
                return conf[item]
 
123
        return default
 
124
 
130
125
    @with_history_lock
131
126
    def get_history(self):
132
127
        """
135
130
        calls.  but if the bazaar branch on-disk has been updated since this
136
131
        History was created, a new object will be created and returned.
137
132
        """
138
 
        if self._closed:
139
 
            return None
140
133
        if (self._history is None) or self._history.out_of_date():
141
134
            self.log.debug('Reload branch history...')
142
 
            if self._history is not None:
143
 
                self._history.detach()
144
135
            _history = self._history = History.from_folder(
145
136
                self._absfolder, self._name)
146
137
            cache_path = self._config.get('cachepath', None)
148
139
                # try the project config
149
140
                cache_path = self._project_config.get('cachepath', None)
150
141
            if cache_path is not None:
151
 
                _history.use_cache(ChangeCache(_history, cache_path))
152
142
                _history.use_file_cache(FileChangeCache(_history, cache_path))
153
 
                _history.use_search_index(TextIndex(_history, cache_path))
154
143
        return self._history
155
144
 
156
 
    def check_rebuild(self):
157
 
        h = self.get_history()
158
 
        if h is not None:
159
 
            h.check_rebuild()
160
 
 
161
145
    def url(self, elements, **kw):
162
146
        "build an url relative to this branch"
163
147
        if not isinstance(elements, list):