~ubuntu-branches/ubuntu/lucid/loggerhead/lucid-security

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Bazaar Package Importer
  • Author(s): James Westby, Roland Mas, Jelmer Vernooij, James Westby
  • Date: 2009-08-26 13:18:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090826131803-0ce1fhaetci8b0c5
Tags: 1.17-0ubuntu1
[ Roland Mas ]
* Use the YUI library provided by libjs-yui. (Closes: #511286)

[ Jelmer Vernooij ]
* Use my debian.org address in Uploaders field.
* Add ${misc:Depends} to please lintian.
* Suggest recent version of paste, which doesn't expose internal port
  numbers in links. (Closes: #507000)
* Bump standards version to 3.8.1.

[ James Westby ]
* New upstream release.
* Drop get-orig-source rule in favour of debian/watch.
* Add python-pkg-resources and python-paste to Build-Depends,
  python-pkg-resources to Depends and python-simplejson to
  Recommends due to dependency changes.

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
try:
 
21
    import simplejson
 
22
except ImportError:
 
23
    import json as simplejson
 
24
import urllib
 
25
 
20
26
from paste.httpexceptions import HTTPServerError
21
27
 
22
28
from loggerhead import util
23
29
from loggerhead.controllers import TemplatedBranchView
 
30
from loggerhead.controllers.filediff_ui import diff_chunks_for_file
24
31
 
25
32
 
26
33
DEFAULT_LINE_COUNT_LIMIT = 3000
27
34
 
 
35
def dq(p):
 
36
    return urllib.quote(urllib.quote(p, safe=''))
 
37
 
28
38
 
29
39
class RevisionUI(TemplatedBranchView):
30
40
 
57
67
            navigation.query = query
58
68
        util.fill_in_navigation(navigation)
59
69
 
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
 
        # FIXME: not currently in use. Should be
72
 
        side_by_side = not kwargs.get('unified', False)
73
 
        if side_by_side:
74
 
            h.add_side_by_side([change])
 
70
        change = h.get_changes([revid])[0]
 
71
 
 
72
        if compare_revid is None:
 
73
            file_changes = h.get_file_changes(change)
 
74
        else:
 
75
            file_changes = h.file_changes_for_revision_ids(
 
76
                compare_revid, change.revid)
 
77
 
 
78
        if path in ('', '/'):
 
79
            path = None
 
80
 
 
81
        link_data = {}
 
82
        path_to_id = {}
 
83
        if path:
 
84
            item = [x for x in file_changes.text_changes if x.filename == path][0]
 
85
            diff_chunks = diff_chunks_for_file(
 
86
                self._history._branch.repository, item.file_id,
 
87
                item.old_revision, item.new_revision)
 
88
        else:
 
89
            diff_chunks = None
 
90
            for i, item in enumerate(file_changes.text_changes):
 
91
                item.index = i
 
92
                link_data['diff-' + str(i)] = '%s/%s/%s' % (
 
93
                    dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
 
94
                path_to_id[item.filename] = 'diff-' + str(i)
 
95
 
 
96
        h.add_branch_nicks(change)
 
97
 
 
98
        if '.' in change.revno:
 
99
            # Walk "up" though the merge-sorted graph until we find a
 
100
            # revision with merge depth 0: this is the revision that merged
 
101
            # this one to mainline.
 
102
            ri = self._history._rev_info
 
103
            i = self._history._rev_indices[change.revid]
 
104
            while ri[i][0][2] > 0:
 
105
                i -= 1
 
106
            merged_in = ri[i][0][3]
 
107
        else:
 
108
            merged_in = None
75
109
 
76
110
        # Directory Breadcrumbs
77
111
        directory_breadcrumbs = (
84
118
            'branch': self._branch,
85
119
            'revid': revid,
86
120
            'change': change,
 
121
            'file_changes': file_changes,
 
122
            'diff_chunks': diff_chunks,
 
123
            'link_data': simplejson.dumps(link_data),
 
124
            'specific_path': path,
 
125
            'json_specific_path': simplejson.dumps(path),
 
126
            'path_to_id': simplejson.dumps(path_to_id),
87
127
            'start_revid': start_revid,
88
128
            'filter_file_id': filter_file_id,
89
129
            'util': util,
90
130
            'history': h,
 
131
            'merged_in': merged_in,
91
132
            'navigation': navigation,
92
133
            'query': query,
93
134
            'remember': remember,
94
135
            'compare_revid': compare_revid,
95
 
            'side_by_side': side_by_side,
96
136
            'url': self._branch.context_url,
97
 
            'line_count': line_count,
98
 
            'line_count_limit': line_count_limit,
99
 
            'show_plain_diffs': line_count > line_count_limit,
100
137
            'directory_breadcrumbs': directory_breadcrumbs,
101
138
        }