~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/diff_ui.py

  • Committer: Martin Pool
  • Date: 2011-11-23 08:18:35 UTC
  • mfrom: (431.2.27 export-tarball)
  • mto: This revision was merged to the branch mainline in revision 461.
  • Revision ID: mbp@canonical.com-20111123081835-mhqxfi9pwpyullub
Merge tarball download support from xaav

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008  Canonical Ltd.
 
1
# Copyright (C) 2008-2011 Canonical Ltd.
2
2
#                     (Authored by Martin Albisetti <argentina@gmail.com>)
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
17
17
#
18
18
 
19
19
from cStringIO import StringIO
20
 
import logging
21
20
import time
22
21
 
23
22
from paste.request import path_info_pop
24
23
 
25
24
from bzrlib.diff import show_diff_trees
 
25
from bzrlib.revision import NULL_REVISION
26
26
 
27
27
from loggerhead.controllers import TemplatedBranchView
28
28
 
29
 
log = logging.getLogger("loggerhead.controllers")
30
 
 
31
29
 
32
30
class DiffUI(TemplatedBranchView):
33
31
    """Class to output a diff for a single file or revisions."""
38
36
        z = time.time()
39
37
 
40
38
        args = []
41
 
        while 1:
 
39
        while True:
42
40
            arg = path_info_pop(environ)
43
41
            if arg is None:
44
42
                break
49
47
        revid_from = self._history.fix_revid(revid_from)
50
48
        change = self._history.get_changes([revid_from])[0]
51
49
 
52
 
        if len(args) is 2:
 
50
        if len(args) == 2:
53
51
            revid_to = self._history.fix_revid(args[1])
 
52
        elif len(change.parents) == 0:
 
53
            revid_to = NULL_REVISION
54
54
        else:
55
55
            revid_to = change.parents[0].revid
56
56
 
72
72
        filename = '%s_%s.diff' % (revno1, revno2)
73
73
        headers = [
74
74
            ('Content-Type', 'application/octet-stream'),
75
 
            ('Content-Length', len(content)),
76
 
            ('Content-Disposition', 'attachment; filename=%s' % filename),
 
75
            ('Content-Length', str(len(content))),
 
76
            ('Content-Disposition', 'attachment; filename=%s' % (filename,)),
77
77
            ]
78
78
        start_response('200 OK', headers)
79
79
        return [content]