~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/diff_ui.py

  • Committer: Michael Hudson
  • Date: 2008-09-29 21:35:13 UTC
  • Revision ID: michael.hudson@canonical.com-20080929213513-ools0krfn8l9wwf0
clean up flakes and whitespace in diff_ui.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd.
 
1
# Copyright (C) 2008  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
20
21
import time
21
22
 
22
23
from paste.request import path_info_pop
23
24
 
24
25
from bzrlib.diff import show_diff_trees
25
 
from bzrlib.revision import NULL_REVISION
26
 
 
27
 
from loggerhead.controllers import TemplatedBranchView
28
 
 
29
 
 
30
 
class DiffUI(TemplatedBranchView):
 
26
 
 
27
 
 
28
log = logging.getLogger("loggerhead.controllers")
 
29
 
 
30
class DiffUI(object):
31
31
    """Class to output a diff for a single file or revisions."""
32
32
 
 
33
    def __init__(self, branch, history):
 
34
        self._branch = branch
 
35
        self._history = history
 
36
        self.log = history.log
 
37
 
33
38
    def __call__(self, environ, start_response):
34
39
        # /diff/<rev_id>/<rev_id>
35
40
        """Default method called from /diff URL."""
36
41
        z = time.time()
37
42
 
38
43
        args = []
39
 
        while True:
 
44
        while 1:
40
45
            arg = path_info_pop(environ)
41
46
            if arg is None:
42
47
                break
47
52
        revid_from = self._history.fix_revid(revid_from)
48
53
        change = self._history.get_changes([revid_from])[0]
49
54
 
50
 
        if len(args) == 2:
 
55
        if len(args) is 2:
51
56
            revid_to = self._history.fix_revid(args[1])
52
 
        elif len(change.parents) == 0:
53
 
            revid_to = NULL_REVISION
54
57
        else:
55
58
            revid_to = change.parents[0].revid
56
59
 
 
60
 
57
61
        repo = self._branch.branch.repository
58
 
        revtree1 = repo.revision_tree(revid_to)
59
 
        revtree2 = repo.revision_tree(revid_from)
 
62
        revtree1 = repo.revision_tree(revid_from)
 
63
        revtree2 = repo.revision_tree(revid_to)
60
64
 
61
65
        diff_content_stream = StringIO()
62
66
        show_diff_trees(revtree1, revtree2, diff_content_stream,
72
76
        filename = '%s_%s.diff' % (revno1, revno2)
73
77
        headers = [
74
78
            ('Content-Type', 'application/octet-stream'),
75
 
            ('Content-Length', str(len(content))),
76
 
            ('Content-Disposition', 'attachment; filename=%s' % (filename,)),
 
79
            ('Content-Length', len(content)),
 
80
            ('Content-Disposition', 'attachment; filename=%s'%(filename,)),
77
81
            ]
78
82
        start_response('200 OK', headers)
79
83
        return [content]
 
84