diff --git a/django_git/templates/django_git/commit.html b/django_git/templates/django_git/commit.html
new file mode 100644
index 0000000..fbc2dd6
--- /dev/null
+++ b/django_git/templates/django_git/commit.html
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+
+{% load stylize %}
+{% load repositories %}
+
+{% block extra_head %}
+
+{% endblock %}
+
+{% block title %}
+ {{ repo.path|name }} : {{ commit|first_eight }}
+{% endblock %}
+
+{% block main_content %}
+
{{ commit }}
+ {% if diffs %}
+ {% for d in diffs %}
+
+ {{ d.a_path }}
+
+ diff |
+ blob
+
+ {% stylize 'diff' %}{{ d.diff|safe }}{% endstylize %}
+
+ {% endfor %}
+ {% else %}
+ No diff information.
+ {% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/django_git/templates/django_git/diff.html b/django_git/templates/django_git/diff.html
deleted file mode 100644
index 2dd3457..0000000
--- a/django_git/templates/django_git/diff.html
+++ /dev/null
@@ -1,19 +0,0 @@
-{% extends "base.html" %}
-
-{% load stylize %}
-{% load repositories %}
-
-{% block title %}
- {{ repo.path|name }} : {{ commit|first_eight }}
-{% endblock %}
-
-{% block main_content %}
- {% if diffs %}
- {% for d in diffs %}
- {{ d.a_path }} diff
- {% stylize 'diff' %}{{ d.diff|safe }}{% endstylize %}
- {% endfor %}
- {% else %}
- No diff information.
- {% endif %}
-{% endblock %}
\ No newline at end of file
diff --git a/django_git/templates/django_git/repo.html b/django_git/templates/django_git/repo.html
index 02ff66b..535ad43 100644
--- a/django_git/templates/django_git/repo.html
+++ b/django_git/templates/django_git/repo.html
@@ -16,11 +16,20 @@
{% for commit in repo.commits %}
- {{ commit|first_eight }} |
+ {{ commit|first_eight }} |
{{ commit.message }} |
{{ commit.committer.name }} |
{{ commit.committed_date|tuple_to_date|date:"m/d/Y" }} |
{% endfor %}
+
+ {% if repo.heads %}
+ Heads
+
+ {% for head in repo.heads %}
+ - {{ head.name }}
+ {% endfor %}
+
+ {% endif %}
{% endblock %}
\ No newline at end of file
diff --git a/django_git/urls.py b/django_git/urls.py
index c6c93d1..94d7f08 100644
--- a/django_git/urls.py
+++ b/django_git/urls.py
@@ -3,7 +3,8 @@
urlpatterns = []
urlpatterns += patterns('django_git.views',
- url(r'^(?P[\w_-]+)/diff/(?P[\w\d]+)/$', 'diff', name='django-git-diff'),
+ url(r'^(?P[\w_-]+)/commit/(?P[\w\d]+)/blob/$', 'blob', name='django-git-blob'),
+ url(r'^(?P[\w_-]+)/commit/(?P[\w\d]+)/$', 'commit', name='django-git-commit'),
url(r'^(?P[\w_-]+)/$', 'repo', name='django-git-repo'),
url(r'^$', 'index', name='django-git-index'),
)
diff --git a/django_git/utils.py b/django_git/utils.py
index 0a74b06..7614144 100644
--- a/django_git/utils.py
+++ b/django_git/utils.py
@@ -9,7 +9,20 @@ def get_repos():
def get_repo(name):
return Repo(os.path.join(settings.REPOS_ROOT, name))
-def get_diff(name, commit):
+def get_commit(name, commit):
repo = get_repo(name)
commit = repo.commit(commit)
- return commit.diffs
\ No newline at end of file
+ return commit
+
+def get_blob(repo, commit, file):
+ repo = get_repo(repo)
+ commit = repo.commit(commit)
+ file = file.split('/')
+ length = len(file)
+ tree = commit.tree
+ for item in xrange(len(file)):
+ if isinstance(tree.get(file[item]), Tree):
+ tree = tree.get(file[item])
+ else:
+ blob = tree.get(file[item])
+ return blob
\ No newline at end of file
diff --git a/django_git/views.py b/django_git/views.py
index d9752c4..b10e2cd 100644
--- a/django_git/views.py
+++ b/django_git/views.py
@@ -1,7 +1,12 @@
+from pygments import highlight
+from pygments.lexers import guess_lexer_for_filename
+from pygments.formatters import HtmlFormatter
+
+from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
from django.template import RequestContext
-from django_git.utils import get_repos, get_repo, get_diff
+from django_git.utils import *
def index(request, template_name='django_git/index.html'):
return render_to_response(template_name, {'repos': get_repos()}, context_instance=RequestContext(request))
@@ -9,5 +14,11 @@ def index(request, template_name='django_git/index.html'):
def repo(request, repo, template_name='django_git/repo.html'):
return render_to_response(template_name, {'repo': get_repo(repo)}, context_instance=RequestContext(request))
-def diff(request, repo, commit, template_name='django_git/diff.html'):
- return render_to_response(template_name, {'diffs': get_diff(repo, commit), 'repo': get_repo(repo), 'commit': commit }, context_instance=RequestContext(request))
\ No newline at end of file
+def commit(request, repo, commit, template_name='django_git/commit.html'):
+ return render_to_response(template_name, {'diffs': get_commit(repo, commit).diffs, 'repo': get_repo(repo), 'commit': commit }, context_instance=RequestContext(request))
+
+def blob(request, repo, commit):
+ file = request.GET.get('file', '')
+ blob = get_blob(repo, commit, file)
+ lexer = guess_lexer_for_filename(blob.basename, blob.data)
+ return HttpResponse(highlight(blob.data, lexer, HtmlFormatter(cssclass="pygment_highlight")))
\ No newline at end of file