summaryrefslogtreecommitdiffstats
path: root/brainch/views/repositories/diff.py
blob: 8d54b53d4cc1782cb090da86ed5d9d3e9a7d13b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
## This file is part of Brainch, a software for distributed text editing.
## Copyright (C) 2009, 2010 Alexandre Leray -- http://stdin.fr/
##
## Brainch is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as
## published by the Free Software Foundation, either version 3 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with Brainch.  If not, see <http://www.gnu.org/licenses/>.


from diff_match_patch import diff_match_patch
from django.http import Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext 
from brainch.models import Repository
from brainch.utils import diff_prettyXhtml


diff_match_patch.diff_prettyXhtml = diff_prettyXhtml


def diff(request, username, name): 
    """Shows a single wiki page."""
    # Does the repo exist?
    if request.method == "GET": # If the form has been submitted...
        repo = get_object_or_404(
            Repository,
            slug=name,
            user__username=username,
        )
        
        c1 = request.GET.get("c1", None)
        c2 = request.GET.get("c2", None)
        
        if c1 is None or c2 is None:
            raise Http404

        #commit_1 = repo.repo.commit(c1)
        #commit_2 = repo.repo.commit(c2)
        #f1 = commit_1.tree["CONTENT"].data
        #f2 = commit_2.tree["CONTENT"].data
        #ui = diff_match_patch()
        #diff = ui.diff_main(f1, f2)
        #ui.diff_cleanupSemantic(diff)
        #content = ui.diff_prettyXhtml(diff)
        #content = repo.repo.git.diff(c1, c2, color_words=True)
        content = repo.wdiff(c1, c2)
        ctx = {
            "repo": repo,
            "content": content,
        }
    return render_to_response("brainch/diff.html", ctx, \
            context_instance=RequestContext(request))