~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

Merge Francesco's fix for bug #820065. Don't break when annotating a zero-sized file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Copyright (C) 2008, 2009 Canonical Ltd.
2
3
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
4
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
4
5
#
17
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
#
19
20
 
 
21
import urllib
 
22
 
 
23
import simplejson
 
24
 
20
25
from paste.httpexceptions import HTTPServerError
21
26
 
22
27
from loggerhead import util
27
32
 
28
33
    template_path = 'loggerhead.templates.changelog'
29
34
 
30
 
    def get_values(self, h, args, kw, headers):
31
 
        if args:
32
 
            revid = h.fix_revid(args[0])
33
 
        else:
34
 
            revid = None
35
 
 
36
 
        filter_file_id = kw.get('filter_file_id', None)
37
 
        query = kw.get('q', None)
38
 
        start_revid = h.fix_revid(kw.get('start_revid', None))
 
35
    def get_values(self, path, kwargs, headers):
 
36
        history = self._history
 
37
        revid = self.get_revid()
 
38
        filter_file_id = kwargs.get('filter_file_id', None)
 
39
        query = kwargs.get('q', None)
 
40
        start_revid = history.fix_revid(kwargs.get('start_revid', None))
39
41
        orig_start_revid = start_revid
40
42
        pagesize = 20#int(config.get('pagesize', '20'))
41
43
        search_failed = False
42
44
 
 
45
        if filter_file_id is None and path is not None:
 
46
            filter_file_id = history.get_file_id(revid, path)
 
47
 
43
48
        try:
44
 
            revid, start_revid, revid_list = h.get_view(
45
 
                revid, start_revid, filter_file_id, query)
46
 
            util.set_context(kw)
 
49
            revid, start_revid, revid_list = history.get_view(
 
50
                revid, start_revid, filter_file_id, query,
 
51
                extra_rev_count=pagesize+1)
 
52
            util.set_context(kwargs)
47
53
 
48
54
            if (query is not None) and (len(revid_list) == 0):
49
55
                search_failed = True
57
63
                    i = None
58
64
                scan_list = revid_list[i:]
59
65
            change_list = scan_list[:pagesize]
60
 
            changes = list(h.get_changes(change_list))
61
 
            h.add_changes(changes)
 
66
            changes = list(history.get_changes(change_list))
 
67
            data = {}
 
68
            for i, c in enumerate(changes):
 
69
                c.index = i
 
70
                data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
62
71
        except:
63
72
            self.log.exception('Exception fetching changes')
64
73
            raise HTTPServerError('Could not fetch changes')
66
75
        navigation = util.Container(
67
76
            pagesize=pagesize, revid=revid, start_revid=start_revid,
68
77
            revid_list=revid_list, filter_file_id=filter_file_id,
69
 
            scan_url='/changes', branch=self._branch, feed=True, history=h)
 
78
            scan_url='/changes', branch=self._branch, feed=True, history=history)
70
79
        if query is not None:
71
80
            navigation.query = query
72
81
        util.fill_in_navigation(navigation)
73
82
 
74
 
        # add parent & merge-point branch-nick info, in case it's useful
75
 
        h.get_branch_nicks(changes)
76
 
 
77
 
        # does every change on this page have the same committer?  if so,
78
 
        # tell the template to show committer info in the "details block"
79
 
        # instead of on each line.
80
 
        all_same_author = True
81
 
 
82
 
        if changes:
83
 
            author = changes[0].author
84
 
            for e in changes[1:]:
85
 
                if e.author != author:
86
 
                    all_same_author = False
87
 
                    break
 
83
        # Directory Breadcrumbs
 
84
        directory_breadcrumbs = (
 
85
            util.directory_breadcrumbs(
 
86
                self._branch.friendly_name,
 
87
                self._branch.is_root,
 
88
                'changes'))
 
89
 
 
90
        show_tag_col = False
 
91
        for change in changes:
 
92
            if change.tags is not None:
 
93
                show_tag_col = True
 
94
                break
88
95
 
89
96
        return {
90
97
            'branch': self._branch,
91
98
            'changes': changes,
 
99
            'show_tag_col': show_tag_col,
 
100
            'data': simplejson.dumps(data),
92
101
            'util': util,
93
 
            'history': h,
 
102
            'history': history,
94
103
            'revid': revid,
95
104
            'navigation': navigation,
96
105
            'filter_file_id': filter_file_id,
97
106
            'start_revid': start_revid,
98
 
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
107
            'viewing_from': (orig_start_revid is not None) and
 
108
                            (orig_start_revid != history.last_revid),
99
109
            'query': query,
100
110
            'search_failed': search_failed,
101
 
            'all_same_author': all_same_author,
102
111
            'url': self._branch.context_url,
 
112
            'directory_breadcrumbs': directory_breadcrumbs,
103
113
        }