29
27
from cherrypy import HTTPRedirect
31
29
from loggerhead import util
32
from loggerhead.changecache import ChangeCache, FileChangeCache
30
from loggerhead.changecache import ChangeCache
33
31
from loggerhead.history import History
34
32
from loggerhead.textindex import TextIndex
35
33
from loggerhead.controllers.changelog_ui import ChangeLogUI
47
45
class BranchView (object):
48
def __init__(self, group_name, name, subfolder, absfolder, config, project_config):
46
def __init__(self, group_name, name, config):
49
47
self._group_name = group_name
51
self._folder = subfolder
52
self._absfolder = absfolder
53
49
self._config = config
54
self._project_config = project_config
55
50
self.log = logging.getLogger('loggerhead.%s' % (name,))
58
53
self._history_lock = threading.RLock()
59
54
self._history = None
62
56
self.changes = ChangeLogUI(self)
63
57
self.revision = RevisionUI(self)
70
64
# force history object to be loaded:
73
turbogears.startup.call_on_shutdown.append(self.close)
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()
84
67
config = property(lambda self: self._config)
86
69
name = property(lambda self: self._name)
88
71
group_name = property(lambda self: self._group_name)
90
def _get_friendly_name(self):
91
name = self._config.get('branch_name', None)
94
# try branch-specific config?
95
name = self.get_history().get_config().get_nickname()
100
friendly_name = property(_get_friendly_name)
102
def _get_description(self):
103
description = self._config.get('description', None)
104
if description is not None:
106
# try branch-specific config?
107
description = self.get_history().get_config().get_user_option('description')
110
description = property(_get_description)
112
def _get_branch_url(self):
113
url = self._config.get('url', None)
116
# try to assemble one from the project, if an url_prefix was defined.
117
url = self._project_config.get('url_prefix', None)
119
return posixpath.join(url, self._folder) + '/'
120
# try branch-specific config?
121
url = self.get_history().get_config().get_user_option('public_branch')
124
branch_url = property(_get_branch_url)
73
friendly_name = property(lambda self: self._config.get('branch_name', self._name))
75
description = property(lambda self: self._config.get('description', ''))
77
branch_url = property(lambda self: self._config.get('url', ''))
126
79
@turbogears.expose()
128
81
raise HTTPRedirect(self.url('/changes'))
135
88
calls. but if the bazaar branch on-disk has been updated since this
136
89
History was created, a new object will be created and returned.
140
91
if (self._history is None) or self._history.out_of_date():
141
92
self.log.debug('Reload branch history...')
142
93
if self._history is not None:
143
94
self._history.detach()
144
_history = self._history = History.from_folder(
145
self._absfolder, self._name)
95
self._history = History.from_folder(self._config.get('folder'), self._name)
146
96
cache_path = self._config.get('cachepath', None)
147
if cache_path is None:
148
# try the project config
149
cache_path = self._project_config.get('cachepath', None)
150
97
if cache_path is not None:
151
_history.use_cache(ChangeCache(_history, cache_path))
152
_history.use_file_cache(FileChangeCache(_history, cache_path))
153
_history.use_search_index(TextIndex(_history, cache_path))
98
self._history.use_cache(ChangeCache(self._history, cache_path))
99
self._history.use_search_index(TextIndex(self._history, cache_path))
154
100
return self._history
156
102
def check_rebuild(self):
157
103
h = self.get_history()
161
106
def url(self, elements, **kw):
162
"build an url relative to this branch"
163
107
if not isinstance(elements, list):
164
108
elements = [elements]
165
109
if elements[0].startswith('/'):
166
110
elements[0] = elements[0][1:]
167
elements = [urllib.quote(x) for x in elements]
168
111
return turbogears.url([ '/' + self.group_name, self.name ] + elements, **kw)
170
def context_url(self, elements, **kw):
171
"build an url relative to this branch, bringing along browsing context"
172
return self.url(elements, **util.get_context(**kw))
174
113
def last_updated(self):
175
114
h = self.get_history()
176
115
change = h.get_changes([ h.last_revid ])[0]