~qbzr-dev/qbzr/0.20

« back to all changes in this revision

Viewing changes to diff.py

  • Committer: Lukáš Lalinský
  • Date: 2007-10-06 08:54:28 UTC
  • mfrom: (122.1.15 i18n)
  • Revision ID: lalinsky@gmail.com-20071006085428-0ueaj3v3s9j3cyv1
Merge Alexander's I18N branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from bzrlib.workingtree import WorkingTree
34
34
from bzrlib.patiencediff import PatienceSequenceMatcher as SequenceMatcher
35
35
 
 
36
from bzrlib.plugins.qbzr.i18n import _
36
37
from bzrlib.plugins.qbzr.util import QBzrWindow, get_branch_config
37
38
from bzrlib.plugins.qbzr.diffview import DiffView
38
39
 
100
101
        a = self.old_lines
101
102
        b = self.new_lines
102
103
        groups = self.groups
 
104
        # XXX more complicated encoding support needed
103
105
        a = [a.decode("utf-8", "replace").rstrip("\n") for a in a]
104
106
        b = [b.decode("utf-8", "replace").rstrip("\n") for b in b]
105
107
        for group in groups:
153
155
    def html_side_by_side(self):
154
156
        """Make HTML for side-by-side diff view."""
155
157
        if self.binary:
156
 
            line = '<p>[binary file]</p>'
 
158
            line = '<p>%s</p>' % _('[binary file]')
157
159
            return line, line
158
160
        else:
159
161
            lines1 = []
164
166
    def html_inline(self):
165
167
        """Make HTML for in-line diff view."""
166
168
        if self.binary:
167
 
            line = '<p>[binary file]</p>'
 
169
            line = '<p>%s</p>' % _('[binary file]')
168
170
            return line, line
169
171
        else:
170
172
            lines = []
187
189
        delta = new_tree.changes_from(old_tree, specific_files=specific_files, require_versioned=True)
188
190
 
189
191
        for path, file_id, kind in delta.removed:
190
 
            diff = FileDiff('removed', path)
 
192
            diff = FileDiff(_('removed'), path)
191
193
            diff.kind = kind
192
194
            diff.old_date = self._date(old_tree, file_id, path)
193
195
            diff.new_date = self._date(new_tree, file_id, path)
196
198
            self.append(diff)
197
199
 
198
200
        for path, file_id, kind in delta.added:
199
 
            diff = FileDiff('added', path)
 
201
            diff = FileDiff(_('added'), path)
200
202
            diff.kind = kind
201
203
            diff.old_date = self._date(old_tree, file_id, path, 0)
202
204
            diff.new_date = self._date(new_tree, file_id, path)
205
207
            self.append(diff)
206
208
 
207
209
        for old_path, new_path, file_id, kind, text_modified, meta_modified in delta.renamed:
208
 
            diff = FileDiff('renamed', u'%s \u2192 %s' % (old_path, new_path))
 
210
            diff = FileDiff(_('renamed'), u'%s \u2192 %s' % (old_path, new_path))
209
211
            diff.kind = kind
210
212
            diff.old_date = self._date(old_tree, file_id, old_path)
211
213
            diff.new_date = self._date(new_tree, file_id, new_path)
216
218
            self.append(diff)
217
219
 
218
220
        for path, file_id, kind, text_modified, meta_modified in delta.modified:
219
 
            diff = FileDiff('modified', path)
 
221
            diff = FileDiff(_('modified'), path)
220
222
            diff.kind = kind
221
223
            diff.old_date = self._date(old_tree, file_id, path)
222
224
            diff.new_date = self._date(new_tree, file_id, path)
227
229
            self.append(diff)
228
230
 
229
231
    def __init__(self, old_tree, new_tree, specific_files=[], complete=False):
 
232
        self._metainfo_template = None
230
233
        old_tree.lock_read()
231
234
        new_tree.lock_read()
232
235
        try:
235
238
            old_tree.unlock()
236
239
            new_tree.unlock()
237
240
 
 
241
    def _get_metainfo_template(self):
 
242
        if self._metainfo_template is None:
 
243
            self._metainfo_template = (
 
244
                '<div style="%%s"><small>'
 
245
                '<b>%s</b> %%s, '
 
246
                '<b>%s</b> %%s, '
 
247
                '<b>%s</b> %%s'
 
248
                '</small></div>') % (_('Last modified:'),
 
249
                                     _('Status:'),
 
250
                                     _('Kind:'))
 
251
        return self._metainfo_template
 
252
 
238
253
    def html_inline(self):
239
254
        html = []
240
255
        for diff in self:
241
256
            html.append('<div style="%s">%s</div>' % (STYLES['title'], diff.path))
242
 
            html.append('<div style="%s"><small><b>Last modified:</b> %s, <b>Status:</b> %s, <b>Kind:</b> %s</small></div>' % (STYLES['metainfo'], diff.old_date, diff.status, diff.kind))
 
257
            html.append(self._get_metainfo_template() % (STYLES['metainfo'],
 
258
                                                         diff.old_date,
 
259
                                                         diff.status,
 
260
                                                         diff.kind))
243
261
            html.append(diff.html_inline())
244
262
        return ''.join(html)
245
263
 
248
266
        html2 = []
249
267
        for diff in self:
250
268
            html1.append('<div style="%s">%s</div>' % (STYLES['title'], diff.path))
251
 
            html1.append('<div style="%s"><small><b>Last modified:</b> %s, <b>Status:</b> %s, <b>Kind:</b> %s</small></div>' % (STYLES['metainfo'], diff.old_date, diff.status, diff.kind))
 
269
            html1.append(self._get_metainfo_template() % (STYLES['metainfo'],
 
270
                                                          diff.old_date,
 
271
                                                          diff.status,
 
272
                                                          diff.kind))
252
273
            html2.append('<div style="%s">%s</div>' % (STYLES['title'], diff.path))
253
 
            html2.append('<div style="%s"><small><b>Last modified:</b> %s, <b>Status:</b> %s, <b>Kind:</b> %s</small></div>' % (STYLES['metainfo'], diff.new_date, diff.status, diff.kind))
 
274
            html2.append(self._get_metainfo_template() % (STYLES['metainfo'],
 
275
                                                          diff.new_date,
 
276
                                                          diff.status,
 
277
                                                          diff.kind))
254
278
            lines1, lines2 = diff.html_side_by_side()
255
279
            html1.append(lines1)
256
280
            html2.append(lines2)
262
286
    def __init__(self, tree1=None, tree2=None, specific_files=None,
263
287
                 parent=None, custom_title=None, inline=False,
264
288
                 complete=False, branch=None):
265
 
        title = ["Diff"]
 
289
        title = [_("Diff")]
266
290
        if custom_title:
267
291
            title.append(custom_title)
268
292
        if specific_files:
269
293
            if len(specific_files) > 2:
270
 
                title.append("%s files" % len(specific_files))
 
294
                title.append(_("%s files") % len(specific_files))
271
295
            else:
272
296
                title.append(", ".join(specific_files))
273
297