~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Robert Collins
  • Date: 2008-12-05 05:14:01 UTC
  • Revision ID: robertc@robertcollins.net-20081205051401-r8gabzs27mspi1bu
Fix the error_ui to render (at allbzr search TemplatedBranchView) - Robert Collins and Martin Albisetti.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
#
19
19
 
20
 
import simplejson
21
 
import urllib
22
 
 
23
20
from paste.httpexceptions import HTTPServerError
24
21
 
25
22
from loggerhead import util
26
23
from loggerhead.controllers import TemplatedBranchView
27
 
from loggerhead.controllers.filediff_ui import diff_chunks_for_file
28
24
 
29
25
 
30
26
DEFAULT_LINE_COUNT_LIMIT = 3000
31
27
 
32
 
def dq(p):
33
 
    return urllib.quote(urllib.quote(p, safe=''))
34
 
 
35
28
 
36
29
class RevisionUI(TemplatedBranchView):
37
30
 
38
31
    template_path = 'loggerhead.templates.revision'
39
32
 
40
 
    def get_values(self, path, kwargs, headers):
41
 
        h = self._history
42
 
        revid = self.get_revid()
 
33
    def get_values(self, h, revid, path, kwargs, headers):
43
34
 
44
35
        filter_file_id = kwargs.get('filter_file_id', None)
45
36
        start_revid = h.fix_revid(kwargs.get('start_revid', None))
64
55
            navigation.query = query
65
56
        util.fill_in_navigation(navigation)
66
57
 
67
 
        change = h.get_changes([revid])[0]
68
 
 
69
 
        if compare_revid is None:
70
 
            file_changes = h.get_file_changes(change)
71
 
        else:
72
 
            file_changes = h.file_changes_for_revision_ids(
73
 
                compare_revid, change.revid)
74
 
 
75
 
        if path in ('', '/'):
76
 
            path = None
77
 
 
78
 
        link_data = {}
79
 
        path_to_id = {}
80
 
        if path:
81
 
            item = [x for x in file_changes.text_changes if x.filename == path][0]
82
 
            diff_chunks = diff_chunks_for_file(
83
 
                self._history._branch.repository, item.file_id,
84
 
                item.old_revision, item.new_revision)
85
 
        else:
86
 
            diff_chunks = None
87
 
            for i, item in enumerate(file_changes.text_changes):
88
 
                item.index = i
89
 
                link_data['diff-' + str(i)] = '%s/%s/%s' % (
90
 
                    dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
91
 
                path_to_id[item.filename] = 'diff-' + str(i)
92
 
 
93
 
        h.add_branch_nicks(change)
94
 
 
95
 
        if '.' in change.revno:
96
 
            # Walk "up" though the merge-sorted graph until we find a
97
 
            # revision with merge depth 0: this is the revision that merged
98
 
            # this one to mainline.
99
 
            ri = self._history._rev_info
100
 
            i = self._history._rev_indices[change.revid]
101
 
            while ri[i][0][2] > 0:
102
 
                i -= 1
103
 
            merged_in = ri[i][0][3]
104
 
        else:
105
 
            merged_in = None
 
58
        change = h.get_change_with_diff(revid, compare_revid)
 
59
        # add parent & merge-point branch-nick info, in case it's useful
 
60
        h.get_branch_nicks([change])
 
61
 
 
62
        line_count_limit = DEFAULT_LINE_COUNT_LIMIT
 
63
        line_count = 0
 
64
        for file in change.changes.modified:
 
65
            for chunk in file.chunks:
 
66
                line_count += len(chunk.diff)
 
67
 
 
68
        # let's make side-by-side diff be the default
 
69
        # FIXME: not currently in use. Should be
 
70
        side_by_side = not kwargs.get('unified', False)
 
71
        if side_by_side:
 
72
            h.add_side_by_side([change])
106
73
 
107
74
        # Directory Breadcrumbs
108
75
        directory_breadcrumbs = (
110
77
                self._branch.friendly_name,
111
78
                self._branch.is_root,
112
79
                'changes'))
113
 
        can_export = self._branch.export_tarballs
 
80
 
114
81
        return {
115
82
            'branch': self._branch,
116
83
            'revid': revid,
117
84
            'change': change,
118
 
            'file_changes': file_changes,
119
 
            'diff_chunks': diff_chunks,
120
 
            'link_data': simplejson.dumps(link_data),
121
 
            'specific_path': path,
122
 
            'json_specific_path': simplejson.dumps(path),
123
 
            'path_to_id': simplejson.dumps(path_to_id),
124
85
            'start_revid': start_revid,
125
86
            'filter_file_id': filter_file_id,
126
87
            'util': util,
127
88
            'history': h,
128
 
            'merged_in': merged_in,
129
89
            'navigation': navigation,
130
90
            'query': query,
131
91
            'remember': remember,
132
92
            'compare_revid': compare_revid,
 
93
            'side_by_side': side_by_side,
133
94
            'url': self._branch.context_url,
 
95
            'line_count': line_count,
 
96
            'line_count_limit': line_count_limit,
 
97
            'show_plain_diffs': line_count > line_count_limit,
134
98
            'directory_breadcrumbs': directory_breadcrumbs,
135
 
            'can_export': can_export,
136
99
        }