27
29
from cherrypy import HTTPRedirect
29
31
from loggerhead import util
30
from loggerhead.changecache import ChangeCache
32
from loggerhead.changecache import ChangeCache, FileChangeCache
31
33
from loggerhead.history import History
32
34
from loggerhead.textindex import TextIndex
33
35
from loggerhead.controllers.changelog_ui import ChangeLogUI
45
47
class BranchView (object):
46
def __init__(self, group_name, name, config):
48
def __init__(self, group_name, name, subfolder, absfolder, config,
49
project_config, root_config):
47
50
self._group_name = group_name
52
self._folder = subfolder
53
self._absfolder = absfolder
49
54
self._config = config
55
self._project_config = project_config
56
self._root_config = root_config
50
57
self.log = logging.getLogger('loggerhead.%s' % (name,))
53
60
self._history_lock = threading.RLock()
54
61
self._history = None
56
64
self.changes = ChangeLogUI(self)
57
65
self.revision = RevisionUI(self)
58
66
self.files = InventoryUI(self)
60
68
self.download = DownloadUI(self)
61
69
self.atom = AtomUI(self)
62
70
self.bundle = BundleUI(self)
64
72
# force history object to be loaded:
75
turbogears.startup.call_on_shutdown.append(self.close)
79
# it's important that we cleanly detach the history, so the cache
80
# files can be closed correctly and hopefully remain uncorrupted.
81
# this should also stop any ongoing indexing.
82
self._history.detach()
67
86
config = property(lambda self: self._config)
69
88
name = property(lambda self: self._name)
71
90
group_name = property(lambda self: self._group_name)
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', ''))
92
def _get_friendly_name(self):
93
name = self._config.get('branch_name', None)
96
# try branch-specific config?
97
name = self.get_history().get_config().get_nickname()
102
friendly_name = property(_get_friendly_name)
104
def _get_description(self):
105
description = self._config.get('description', None)
106
if description is not None:
108
# try branch-specific config?
109
description = self.get_history().get_config().get_user_option('description')
112
description = property(_get_description)
114
def _get_branch_url(self):
115
url = self._config.get('url', None)
118
# try to assemble one from the project, if an url_prefix was defined.
119
url = self._project_config.get('url_prefix', None)
121
return posixpath.join(url, self._folder) + '/'
122
# try branch-specific config?
123
url = self.get_history().get_config().get_user_option('public_branch')
126
branch_url = property(_get_branch_url)
79
128
@turbogears.expose()
81
130
raise HTTPRedirect(self.url('/changes'))
132
def get_config_item(self, item, default=None):
133
for conf in self._config, self._project_config, self._root_config:
83
138
@with_history_lock
84
139
def get_history(self):
88
143
calls. but if the bazaar branch on-disk has been updated since this
89
144
History was created, a new object will be created and returned.
91
148
if (self._history is None) or self._history.out_of_date():
92
149
self.log.debug('Reload branch history...')
93
150
if self._history is not None:
94
151
self._history.detach()
95
self._history = History.from_folder(self._config.get('folder'), self._name)
152
_history = self._history = History.from_folder(
153
self._absfolder, self._name)
96
154
cache_path = self._config.get('cachepath', None)
155
if cache_path is None:
156
# try the project config
157
cache_path = self._project_config.get('cachepath', None)
97
158
if cache_path is not None:
98
self._history.use_cache(ChangeCache(self._history, cache_path))
99
self._history.use_search_index(TextIndex(self._history, cache_path))
159
_history.use_cache(ChangeCache(_history, cache_path))
160
_history.use_file_cache(FileChangeCache(_history, cache_path))
161
_history.use_search_index(TextIndex(_history, cache_path))
100
162
return self._history
102
164
def check_rebuild(self):
103
165
h = self.get_history()
106
169
def url(self, elements, **kw):
170
"build an url relative to this branch"
107
171
if not isinstance(elements, list):
108
172
elements = [elements]
109
173
if elements[0].startswith('/'):
110
174
elements[0] = elements[0][1:]
175
elements = [urllib.quote(x) for x in elements]
111
176
return turbogears.url([ '/' + self.group_name, self.name ] + elements, **kw)
178
def context_url(self, elements, **kw):
179
"build an url relative to this branch, bringing along browsing context"
180
return self.url(elements, **util.get_context(**kw))
113
182
def last_updated(self):
114
183
h = self.get_history()
115
184
change = h.get_changes([ h.last_revid ])[0]