~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/diff_ui.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-30 10:39:05 UTC
  • mto: This revision was merged to the branch mainline in revision 406.
  • Revision ID: mnordhoff@mattnordhoff.com-20090430103905-10si14h2i325htrj
Strip trailing whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from cStringIO import StringIO
20
20
import logging
21
21
import time
22
 
import sys
23
22
 
24
 
from paste import httpexceptions
25
23
from paste.request import path_info_pop
26
24
 
27
 
from loggerhead import history
28
 
from loggerhead import util
29
 
from loggerhead.templatefunctions import templatefunctions
30
 
 
31
 
import bzrlib
32
 
from bzrlib import branch
33
25
from bzrlib.diff import show_diff_trees
34
26
 
 
27
from loggerhead.controllers import TemplatedBranchView
35
28
 
36
29
log = logging.getLogger("loggerhead.controllers")
37
30
 
38
 
class DiffUI(object):
39
 
    """
40
 
 
41
 
    Class to output a diff for a single file or revisions.
42
 
    """
43
 
    
44
 
    def __init__(self, branch, history):
45
 
        self._branch = branch
46
 
        self._history = history
47
 
        self.log = history.log
48
 
 
49
 
    
 
31
 
 
32
class DiffUI(TemplatedBranchView):
 
33
    """Class to output a diff for a single file or revisions."""
 
34
 
50
35
    def __call__(self, environ, start_response):
51
36
        # /diff/<rev_id>/<rev_id>
52
 
        """
53
 
        Default method called from /diff URL.
54
 
        """
55
 
 
 
37
        """Default method called from /diff URL."""
56
38
        z = time.time()
57
 
        
 
39
 
58
40
        args = []
59
41
        while 1:
60
42
            arg = path_info_pop(environ)
70
52
        if len(args) is 2:
71
53
            revid_to = self._history.fix_revid(args[1])
72
54
        else:
73
 
            revid_to = change.parents[0].revid 
74
 
 
 
55
            revid_to = change.parents[0].revid
75
56
 
76
57
        repo = self._branch.branch.repository
77
 
        revtree1 = repo.revision_tree(revid_from)
78
 
        revtree2 = repo.revision_tree(revid_to)
79
 
        
 
58
        revtree1 = repo.revision_tree(revid_to)
 
59
        revtree2 = repo.revision_tree(revid_from)
 
60
 
80
61
        diff_content_stream = StringIO()
81
 
        show_diff_trees(revtree1, revtree2, diff_content_stream, 
 
62
        show_diff_trees(revtree1, revtree2, diff_content_stream,
82
63
                        old_label='', new_label='')
83
64
 
84
65
        content = diff_content_stream.getvalue()
85
66
 
86
 
        self.log.info('/diff %r:%r in %r secs' % (revid_from, revid_to, 
 
67
        self.log.info('/diff %r:%r in %r secs' % (revid_from, revid_to,
87
68
                                                  time.time() - z))
88
69
 
89
70
        revno1 = self._history.get_revno(revid_from)
92
73
        headers = [
93
74
            ('Content-Type', 'application/octet-stream'),
94
75
            ('Content-Length', len(content)),
95
 
            ('Content-Disposition', 'attachment; filename=%s'%(filename,)),
 
76
            ('Content-Disposition', 'attachment; filename=%s' % filename),
96
77
            ]
97
78
        start_response('200 OK', headers)
98
79
        return [content]
99