~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Michael Hudson-Doyle
  • Date: 2012-01-23 21:10:07 UTC
  • mfrom: (461.2.1 bug-321325)
  • Revision ID: michael.hudson@linaro.org-20120123211007-ah835d7bc2s320l3
show exe bit changes on the revision page

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
 
20
23
from paste.httpexceptions import HTTPServerError
21
24
 
22
25
from loggerhead import util
23
26
from loggerhead.controllers import TemplatedBranchView
 
27
from loggerhead.controllers.filediff_ui import diff_chunks_for_file
24
28
 
25
29
 
26
30
DEFAULT_LINE_COUNT_LIMIT = 3000
27
31
 
 
32
def dq(p):
 
33
    return urllib.quote(urllib.quote(p, safe=''))
 
34
 
28
35
 
29
36
class RevisionUI(TemplatedBranchView):
30
37
 
31
38
    template_path = 'loggerhead.templates.revision'
32
 
 
33
 
    def get_values(self, h, args, kw, headers):
34
 
 
35
 
        if len(args) > 0:
36
 
            revid = h.fix_revid(args[0])
37
 
        else:
38
 
            revid = None
39
 
 
40
 
        filter_file_id = kw.get('filter_file_id', None)
41
 
        start_revid = h.fix_revid(kw.get('start_revid', None))
42
 
        query = kw.get('q', None)
43
 
        remember = h.fix_revid(kw.get('remember', None))
44
 
        compare_revid = h.fix_revid(kw.get('compare_revid', None))
45
 
 
 
39
    supports_json = True
 
40
 
 
41
    def get_values(self, path, kwargs, headers):
 
42
        h = self._history
 
43
        revid = self.get_revid()
 
44
 
 
45
        filter_file_id = kwargs.get('filter_file_id', None)
 
46
        start_revid = h.fix_revid(kwargs.get('start_revid', None))
 
47
        query = kwargs.get('q', None)
 
48
        compare_revid = h.fix_revid(kwargs.get('compare_revid', None))
 
49
 
 
50
        # TODO: This try/except looks to date before real exception handling
 
51
        # and should be removed
46
52
        try:
47
 
            revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
 
53
            revid, start_revid, revid_list = h.get_view(revid,
 
54
                                                        start_revid,
 
55
                                                        filter_file_id,
 
56
                                                        query)
48
57
        except:
49
58
            self.log.exception('Exception fetching changes')
50
59
            raise HTTPServerError('Could not fetch changes')
51
 
 
 
60
        # XXX: Some concern about namespace collisions. These are only stored
 
61
        # here so they can be expanded into the template later. Should probably
 
62
        # be stored in a specific dict/etc.
 
63
        self.revid_list = revid_list
 
64
        self.compare_revid = compare_revid
 
65
        self.path = path
 
66
        kwargs['start_revid'] = start_revid
 
67
 
 
68
        change = h.get_changes([revid])[0]
 
69
 
 
70
        if compare_revid is None:
 
71
            file_changes = h.get_file_changes(change)
 
72
        else:
 
73
            file_changes = h.file_changes_for_revision_ids(
 
74
                compare_revid, change.revid)
 
75
 
 
76
        h.add_branch_nicks(change)
 
77
 
 
78
        if '.' in change.revno:
 
79
            # Walk "up" though the merge-sorted graph until we find a
 
80
            # revision with merge depth 0: this is the revision that merged
 
81
            # this one to mainline.
 
82
            ri = self._history._rev_info
 
83
            i = self._history._rev_indices[change.revid]
 
84
            while ri[i][0][2] > 0:
 
85
                i -= 1
 
86
            merged_in = ri[i][0][3]
 
87
        else:
 
88
            merged_in = None
 
89
 
 
90
        return {
 
91
            'revid': revid,
 
92
            'change': change,
 
93
            'file_changes': file_changes,
 
94
            'merged_in': merged_in,
 
95
        }
 
96
 
 
97
    def add_template_values(self, values):
 
98
        super(RevisionUI, self).add_template_values(values)
 
99
        remember = self._history.fix_revid(self.kwargs.get('remember', None))
 
100
        query = self.kwargs.get('q', None)
 
101
        filter_file_id = self.kwargs.get('filter_file_id', None)
 
102
        start_revid = self.kwargs['start_revid']
52
103
        navigation = util.Container(
53
 
            revid_list=revid_list, revid=revid, start_revid=start_revid,
 
104
            revid_list=self.revid_list, revid=values['revid'],
 
105
            start_revid=start_revid,
54
106
            filter_file_id=filter_file_id, pagesize=1,
55
 
            scan_url='/revision', branch=self._branch, feed=True, history=h)
 
107
            scan_url='/revision', branch=self._branch, feed=True,
 
108
            history=self._history)
56
109
        if query is not None:
57
110
            navigation.query = query
58
111
        util.fill_in_navigation(navigation)
59
 
 
60
 
        change = h.get_change_with_diff(revid, compare_revid)
61
 
        # add parent & merge-point branch-nick info, in case it's useful
62
 
        h.get_branch_nicks([ change ])
63
 
 
64
 
        line_count_limit = DEFAULT_LINE_COUNT_LIMIT
65
 
        line_count = 0
66
 
        for file in change.changes.modified:
67
 
            for chunk in file.chunks:
68
 
                line_count += len(chunk.diff)
69
 
 
70
 
        # let's make side-by-side diff be the default
71
 
        side_by_side = not kw.get('unified', False)
72
 
        if side_by_side:
73
 
            h.add_side_by_side([ change ])
 
112
        path = self.path
 
113
        if path in ('', '/'):
 
114
            path = None
 
115
 
 
116
 
 
117
        file_changes = values['file_changes']
 
118
        link_data = {}
 
119
        path_to_id = {}
 
120
        if path:
 
121
            items = [x for x in file_changes.text_changes if x.filename == path]
 
122
            if len(items) > 0:
 
123
                item = items[0]
 
124
                diff_chunks = diff_chunks_for_file(
 
125
                    self._history._branch.repository, item.file_id,
 
126
                    item.old_revision, item.new_revision)
 
127
            else:
 
128
                diff_chunks = None
 
129
        else:
 
130
            diff_chunks = None
 
131
            for i, item in enumerate(file_changes.text_changes):
 
132
                item.index = i
 
133
                link_data['diff-' + str(i)] = '%s/%s/%s' % (
 
134
                    dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
 
135
                path_to_id[item.filename] = 'diff-' + str(i)
74
136
 
75
137
        # Directory Breadcrumbs
76
138
        directory_breadcrumbs = (
78
140
                self._branch.friendly_name,
79
141
                self._branch.is_root,
80
142
                'changes'))
 
143
        can_export = self._branch.export_tarballs
81
144
 
82
 
        return {
83
 
            'branch': self._branch,
84
 
            'revid': revid,
85
 
            'change': change,
86
 
            'start_revid': start_revid,
 
145
        values.update({
 
146
            'history': self._history,
 
147
            'link_data': simplejson.dumps(link_data),
 
148
            'json_specific_path': simplejson.dumps(path),
 
149
            'path_to_id': simplejson.dumps(path_to_id),
 
150
            'directory_breadcrumbs': directory_breadcrumbs,
 
151
            'navigation': navigation,
 
152
            'remember': remember,
 
153
            'compare_revid': self.compare_revid,
87
154
            'filter_file_id': filter_file_id,
88
 
            'util': util,
89
 
            'history': h,
90
 
            'navigation': navigation,
 
155
            'diff_chunks': diff_chunks,
91
156
            'query': query,
92
 
            'remember': remember,
93
 
            'compare_revid': compare_revid,
94
 
            'side_by_side': side_by_side,
95
 
            'url': self._branch.context_url,
96
 
            'line_count': line_count,
97
 
            'line_count_limit': line_count_limit,
98
 
            'show_plain_diffs': line_count > line_count_limit,
99
 
            'directory_breadcrumbs': directory_breadcrumbs,
100
 
        }
 
157
            'can_export': can_export,
 
158
            'specific_path': path,
 
159
            'start_revid': start_revid,
 
160
        })