2
# Copyright (C) 2006 Robey Pointer <robey@lag.net>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
collection of configuration and objects related to a bazaar branch.
27
from cherrypy import HTTPRedirect
29
from loggerhead import util
30
from loggerhead.changecache import ChangeCache
31
from loggerhead.history import History
32
from loggerhead.textindex import TextIndex
33
from loggerhead.controllers.changelog_ui import ChangeLogUI
34
from loggerhead.controllers.atom_ui import AtomUI
35
from loggerhead.controllers.revision_ui import RevisionUI
36
from loggerhead.controllers.inventory_ui import InventoryUI
37
from loggerhead.controllers.annotate_ui import AnnotateUI
38
from loggerhead.controllers.download_ui import DownloadUI
41
with_history_lock = util.with_lock('_history_lock')
44
class BranchView (object):
45
def __init__(self, name, config):
48
self.log = logging.getLogger('loggerhead.%s' % (name,))
51
self._history_lock = threading.RLock()
54
self.changes = ChangeLogUI(self)
55
self.revision = RevisionUI(self)
56
self.files = InventoryUI(self)
57
self.annotate = AnnotateUI(self)
58
self.download = DownloadUI(self)
59
self.atom = AtomUI(self)
61
# force history object to be loaded:
64
config = property(lambda self: self._config)
66
name = property(lambda self: self._name)
68
friendly_name = property(lambda self: self._config.get('branch_name', self._name))
72
raise HTTPRedirect(self.url('/changes'))
75
def get_history(self):
77
get an up-to-date History object, safely. each page-view calls this
78
method, and normally it will get the same History object as on previous
79
calls. but if the bazaar branch on-disk has been updated since this
80
History was created, a new object will be created and returned.
82
if (self._history is None) or self._history.out_of_date():
83
self.log.debug('Reload branch history...')
84
if self._history is not None:
85
self._history.detach()
86
self._history = History.from_folder(self._config.get('folder'), self._name)
87
cache_path = self._config.get('cachepath', None)
88
if cache_path is not None:
89
self._history.use_cache(ChangeCache(self._history, cache_path))
90
self._history.use_search_index(TextIndex(self._history, cache_path))
93
def check_rebuild(self):
94
h = self.get_history()
97
def url(self, elements, **kw):
98
if not isinstance(elements, list):
100
if elements[0].startswith('/'):
101
elements[0] = elements[0][1:]
102
return turbogears.url([ '/' + self.name ] + elements, **kw)