~mnordhoff/loggerhead/statictuples_and_jam_integration

« back to all changes in this revision

Viewing changes to loggerhead/apps/branch.py

  • Committer: Matt Nordhoff
  • Date: 2010-05-15 05:04:55 UTC
  • mfrom: (388.17.10 integration)
  • Revision ID: mnordhoff@mattnordhoff.com-20100515050455-s21ic6hvgfhsp1gb
MergeĀ lp:~jameinel/loggerhead/integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import logging
20
20
import urllib
21
21
import sys
 
22
import time
22
23
 
23
24
import bzrlib.branch
24
25
import bzrlib.errors
49
50
    def __init__(self, branch, friendly_name=None, config={},
50
51
                 graph_cache=None, branch_link=None, is_root=False,
51
52
                 served_url=_DEFAULT, use_cdn=False):
 
53
        # XXX: Why is config here a simple dictionary (which only ever has a
 
54
        #      single item that I can find), while every other 'self._config'
 
55
        #      is a LoggerheadConfig object. The latter seems a lot more
 
56
        #      useful.
52
57
        self.branch = branch
53
58
        self._config = config
54
59
        self.friendly_name = friendly_name
64
69
    def get_history(self):
65
70
        file_cache = None
66
71
        revinfo_disk_cache = None
 
72
        show_merge_points = self._config.get('show_merge_points', True)
67
73
        cache_path = self._config.get('cachepath', None)
68
74
        if cache_path is not None:
69
75
            # Only import the cache if we're going to use it.
79
85
                revinfo_disk_cache = RevInfoDiskCache(cache_path)
80
86
        return History(
81
87
            self.branch, self.graph_cache, file_cache=file_cache,
82
 
            revinfo_disk_cache=revinfo_disk_cache, cache_key=self.friendly_name)
 
88
            revinfo_disk_cache=revinfo_disk_cache,
 
89
            cache_key=self.friendly_name,
 
90
            show_merge_points=show_merge_points,
 
91
            cache_path=cache_path,
 
92
            )
83
93
 
84
94
    def url(self, *args, **kw):
85
95
        if isinstance(args[0], list):
156
166
                    self.served_url = self.url([])
157
167
                except bzrlib.errors.InvalidURL:
158
168
                    self.served_url = None
 
169
        path_info = environ.get('PATH_INFO', None)
159
170
        path = request.path_info_pop(environ)
160
171
        if not path:
161
172
            raise httpexceptions.HTTPMovedPermanently(
162
173
                self.absolute_url('/changes'))
163
174
        if path == 'static':
 
175
            # TODO: Unfortunately, we still call Branch.open() even if we are
 
176
            #       serving a static path. This probably adds a fair amount of
 
177
            #       overhead...
164
178
            return static_app(environ, start_response)
165
179
        cls = self.controllers_dict.get(path)
166
180
        if cls is None:
167
181
            raise httpexceptions.HTTPNotFound()
168
 
        self.branch.lock_read()
169
 
        try:
 
182
        def do_stuff():
 
183
            self.branch.lock_read()
170
184
            try:
171
 
                c = cls(self, self.get_history)
172
 
                return c(environ, start_response)
173
 
            except:
174
 
                environ['exc_info'] = sys.exc_info()
175
 
                environ['branch'] = self
176
 
                raise
177
 
        finally:
178
 
            self.branch.unlock()
 
185
                try:
 
186
                    c = cls(self, self.get_history)
 
187
                    return c(environ, start_response)
 
188
                except:
 
189
                    environ['exc_info'] = sys.exc_info()
 
190
                    environ['branch'] = self
 
191
                    raise
 
192
            finally:
 
193
                self.branch.unlock()
 
194
        t = time.time()
 
195
        val = do_stuff()
 
196
        tdelta = time.time() - t
 
197
        self.log.info('Took %.3fs to generate: %s' % (tdelta, path_info))
 
198
        return val