mirror of
https://github.com/correl/codereview.git
synced 2024-12-27 11:07:33 +00:00
Added a blob view
This commit is contained in:
parent
0e5e36698f
commit
d5312f2361
8 changed files with 128 additions and 67 deletions
|
@ -10,6 +10,11 @@ def oneline(value):
|
||||||
line = value.split('\n')[0].strip()
|
line = value.split('\n')[0].strip()
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
@stringfilter
|
||||||
|
def lines(value):
|
||||||
|
return value.split('\n')
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
@stringfilter
|
@stringfilter
|
||||||
def dirname(value):
|
def dirname(value):
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
|
# Root log
|
||||||
(r'^(?P<repository>.*?)/log/$', 'codereview.browser.views.log'),
|
(r'^(?P<repository>.*?)/log/$', 'codereview.browser.views.log'),
|
||||||
(r'^(?P<repository>.*?)/log/(?P<path>.*?/?)$', 'codereview.browser.views.log'),
|
# File (Blob) view
|
||||||
|
(r'^(?P<repository>.*?)/blob/(?P<path>.*?)$', 'codereview.browser.views.blob'),
|
||||||
|
# Path log
|
||||||
|
(r'^(?P<repository>.*?)/log/(?P<path>.*?)/$', 'codereview.browser.views.log'),
|
||||||
|
# Commit view
|
||||||
(r'^(?P<repository>.*?)/view/(?P<ref>.*?)/$', 'codereview.browser.views.view'),
|
(r'^(?P<repository>.*?)/view/(?P<ref>.*?)/$', 'codereview.browser.views.view'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import difflib
|
import difflib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -197,5 +198,18 @@ class Git(VCS):
|
||||||
elif type(node) == git.objects.Tree:
|
elif type(node) == git.objects.Tree:
|
||||||
dirs.append(node.path)
|
dirs.append(node.path)
|
||||||
return dirs, files
|
return dirs, files
|
||||||
|
def blob(self, commit, path):
|
||||||
|
tree = self._repo.commit(commit).tree
|
||||||
|
dir = os.path.dirname(path)
|
||||||
|
if dir:
|
||||||
|
for i in tree.traverse():
|
||||||
|
if type(i) == git.objects.Tree and i.path == dir:
|
||||||
|
tree = i
|
||||||
|
if dir != tree.path:
|
||||||
|
raise Exception('Path not found')
|
||||||
|
for node in tree:
|
||||||
|
if type(node) == git.objects.Blob and node.path == path:
|
||||||
|
return Blob(node.path, node.data_stream.read())
|
||||||
|
raise Exception('Blob Path not found')
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
g = Git('/home/correlr/code/voiceaxis')
|
g = Git('/home/correlr/code/voiceaxis')
|
||||||
|
|
|
@ -4,38 +4,45 @@ from django.shortcuts import render_to_response
|
||||||
from codereview.dashboard.models import Repository
|
from codereview.dashboard.models import Repository
|
||||||
from codereview.browser import vcs
|
from codereview.browser import vcs
|
||||||
|
|
||||||
def log(request,repository, path=None):
|
def _repo(request, name):
|
||||||
try:
|
try:
|
||||||
repository = Repository.objects.get(name=repository)
|
repository = Repository.objects.get(name=name)
|
||||||
except:
|
except:
|
||||||
raise Http404
|
raise Http404
|
||||||
repo = vcs.create(repository.type, repository.path)
|
repo = vcs.create(repository.type, repository.path)
|
||||||
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
|
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
|
||||||
|
return repo, ref
|
||||||
|
def _nav_data(request, repo, ref, path=None):
|
||||||
|
path = path if path else ''
|
||||||
|
navigation = dict(zip(('dirs', 'files'), repo.browse(ref, path)))
|
||||||
|
return {'navigation': navigation}
|
||||||
|
def _log_data(request, repo, ref, path=None):
|
||||||
offset = int(request.GET['o']) if 'o' in request.GET else 0
|
offset = int(request.GET['o']) if 'o' in request.GET else 0
|
||||||
limit = 20
|
limit = 20
|
||||||
|
|
||||||
path = path if path else ''
|
path = path if path else ''
|
||||||
log = repo.log(ref, path=path, max=limit, offset=offset)
|
log = repo.log(ref, path=path, max=limit, offset=offset)
|
||||||
navigation = dict(zip(('dirs', 'files'), repo.browse(ref, os.path.dirname(path))))
|
|
||||||
|
|
||||||
newer = offset - limit if offset > limit else 0
|
newer = offset - limit if offset > limit else 0
|
||||||
# Inspect the last commit. If it has no parents, we can't go any further
|
# Inspect the last commit. If it has no parents, we can't go any further
|
||||||
# back.
|
# back.
|
||||||
last = log[-1]
|
last = log[-1]
|
||||||
older = offset + limit if last.parents else 0
|
older = offset + limit if last.parents else 0
|
||||||
|
return {
|
||||||
return render_to_response('browser/log.html',
|
|
||||||
{
|
|
||||||
'repository': repository,
|
|
||||||
'path': path,
|
'path': path,
|
||||||
'repo': repo,
|
'repo': repo,
|
||||||
'log': log,
|
'log': log,
|
||||||
'navigation': navigation,
|
|
||||||
'ref': ref,
|
'ref': ref,
|
||||||
'offset': offset,
|
'offset': offset,
|
||||||
'newer': newer,
|
'newer': newer,
|
||||||
'older': older,
|
'older': older,
|
||||||
})
|
}
|
||||||
|
def log(request, repository, path=None):
|
||||||
|
repo, ref = _repo(request, repository)
|
||||||
|
data = {'repository': repository}
|
||||||
|
data.update(_log_data(request, repo, ref, path))
|
||||||
|
data.update(_nav_data(request, repo, ref, path))
|
||||||
|
return render_to_response('browser/log.html', data)
|
||||||
def view(request, repository, ref):
|
def view(request, repository, ref):
|
||||||
try:
|
try:
|
||||||
repository = Repository.objects.get(name=repository)
|
repository = Repository.objects.get(name=repository)
|
||||||
|
@ -53,3 +60,12 @@ def view(request, repository, ref):
|
||||||
'commit': commit,
|
'commit': commit,
|
||||||
'diffs': diffs,
|
'diffs': diffs,
|
||||||
})
|
})
|
||||||
|
def blob(request, repository, path):
|
||||||
|
repo, ref = _repo(request, repository)
|
||||||
|
data = {
|
||||||
|
'repository': repository,
|
||||||
|
'blob': repo.blob(ref, path),
|
||||||
|
}
|
||||||
|
data.update(_log_data(request, repo, ref, path))
|
||||||
|
data.update(_nav_data(request, repo, ref, os.path.dirname(path)))
|
||||||
|
return render_to_response('browser/blob.html', data)
|
||||||
|
|
19
templates/browser/blob.html
Normal file
19
templates/browser/blob.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends "layouts/default.html" %}
|
||||||
|
{% load vcs %}
|
||||||
|
|
||||||
|
{% block navigation %}
|
||||||
|
{% include "browser/navigation.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Blob View</h2>
|
||||||
|
<table class="diff">
|
||||||
|
{% for line in blob.data|lines %}
|
||||||
|
<tr>
|
||||||
|
<td class="number">{{ forloop.counter }}</td>
|
||||||
|
<td class="text">{{ line }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% include "browser/commitlog.html" %}
|
||||||
|
{% endblock %}
|
44
templates/browser/commitlog.html
Normal file
44
templates/browser/commitlog.html
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
{% load gravatar %}
|
||||||
|
{% load vcs %}
|
||||||
|
|
||||||
|
<h2>Commit Log</h2>
|
||||||
|
<table class="vcs-log">
|
||||||
|
<tr>
|
||||||
|
<th>Commit Date</th>
|
||||||
|
<th>Author</th>
|
||||||
|
<th>Commit Message</th>
|
||||||
|
</tr>
|
||||||
|
{% for commit in log %}
|
||||||
|
<tr>
|
||||||
|
<td class="date">{{ commit.authored_date }}</td>
|
||||||
|
<td class="author">
|
||||||
|
<img src="{{ commit.author_email|gravatar:16 }}" />
|
||||||
|
{{ commit.author }}
|
||||||
|
</td>
|
||||||
|
<td class="message">
|
||||||
|
{% for branch, c in repo.branches.items %}
|
||||||
|
{% if commit.id == c.id %}
|
||||||
|
<span class="marker branch"><a href="{% url codereview.browser.views.log repository=repository %}?c={{ branch }}">{{ branch }}</a></span>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for tag, c in repo.tags.items %}
|
||||||
|
{% if commit.id == c.id %}
|
||||||
|
<span class="marker tag"><a href="{% url codereview.browser.views.log repository=repository %}?c={{ tag }}">{{ tag }}</a></span>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<a href="{% url codereview.browser.views.view repository=repository ref=commit.id %}">{{ commit.message|oneline }}</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<div class="vcs-nav">
|
||||||
|
{% if older %}
|
||||||
|
<a href="{% url codereview.browser.views.log repository=repository %}?c={{ ref }}&o={{ older }}">Older</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if offset and older %}
|
||||||
|
·
|
||||||
|
{% endif %}
|
||||||
|
{% if offset %}
|
||||||
|
<a href="{% url codereview.browser.views.log repository=repository %}?c={{ ref }}&o={{ newer }}">Newer</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
|
@ -1,51 +1,9 @@
|
||||||
{% extends "layouts/default.html" %}
|
{% extends "layouts/default.html" %}
|
||||||
{% load gravatar %}
|
|
||||||
{% load vcs %}
|
|
||||||
|
|
||||||
{% block navigation %}
|
{% block navigation %}
|
||||||
{% include "browser/navigation.html" %}
|
{% include "browser/navigation.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Commit Log</h2>
|
{% include "browser/commitlog.html" %}
|
||||||
<table class="vcs-log">
|
|
||||||
<tr>
|
|
||||||
<th>Commit Date</th>
|
|
||||||
<th>Author</th>
|
|
||||||
<th>Commit Message</th>
|
|
||||||
</tr>
|
|
||||||
{% for commit in log %}
|
|
||||||
<tr>
|
|
||||||
<td class="date">{{ commit.authored_date }}</td>
|
|
||||||
<td class="author">
|
|
||||||
<img src="{{ commit.author_email|gravatar:16 }}" />
|
|
||||||
{{ commit.author }}
|
|
||||||
</td>
|
|
||||||
<td class="message">
|
|
||||||
{% for branch, c in repo.branches.items %}
|
|
||||||
{% if commit.id == c.id %}
|
|
||||||
<span class="marker branch"><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ branch }}">{{ branch }}</a></span>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% for tag, c in repo.tags.items %}
|
|
||||||
{% if commit.id == c.id %}
|
|
||||||
<span class="marker tag"><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ tag }}">{{ tag }}</a></span>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
<a href="{% url codereview.browser.views.view repository=repository.name ref=commit.id %}">{{ commit.message|oneline }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
<div class="vcs-nav">
|
|
||||||
{% if older %}
|
|
||||||
<a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ ref }}&o={{ older }}">Older</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if offset and older %}
|
|
||||||
·
|
|
||||||
{% endif %}
|
|
||||||
{% if offset %}
|
|
||||||
<a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ ref }}&o={{ newer }}">Newer</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% load vcs %}
|
{% load vcs %}
|
||||||
<h2><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ ref }}">{{ repository.name }}</a></h2>
|
<h2><a href="{% url codereview.browser.views.log repository=repository %}?c={{ ref }}">{{ repository }}</a></h2>
|
||||||
<h3>Branches</h3>
|
<h3>Branches</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for branch, commit in repo.branches.items %}
|
{% for branch, commit in repo.branches.items %}
|
||||||
|
@ -7,20 +7,20 @@
|
||||||
{% if ref == branch or ref == commit.id %}
|
{% if ref == branch or ref == commit.id %}
|
||||||
<strong>{{ branch }}</strong>
|
<strong>{{ branch }}</strong>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url codereview.browser.views.log repository=repository.name %}?c={{branch}}">{{ branch }}</a>
|
<a href="{% url codereview.browser.views.log repository=repository %}?c={{branch}}">{{ branch }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<h3>Browse</h3>
|
<h3>Browse</h3>
|
||||||
{% if path|dirname %}
|
{% if path %}
|
||||||
<strong>{{ path|dirname }}/</strong><br />
|
<strong>{{ path }}</strong><br />
|
||||||
<a href="{% url codereview.browser.views.log repository=repository.name path=path|dirname %}?c={{ ref }}">Up one</a>
|
<a href="{% url codereview.browser.views.log repository=repository path=path|dirname %}?c={{ ref }}">Up one</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul class="tree">
|
<ul class="tree">
|
||||||
{% for dir in navigation.dirs %}
|
{% for dir in navigation.dirs %}
|
||||||
<li class="dir">
|
<li class="dir">
|
||||||
<a href="{% url codereview.browser.views.log repository=repository.name path=dir %}/?c={{ ref }}">{{ dir|basename }}</a>
|
<a href="{% url codereview.browser.views.log repository=repository path=dir %}?c={{ ref }}">{{ dir|basename }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for file in navigation.files %}
|
{% for file in navigation.files %}
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
{% if file == path %}
|
{% if file == path %}
|
||||||
<strong>{{ file|basename }}</strong>
|
<strong>{{ file|basename }}</strong>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url codereview.browser.views.log repository=repository.name path=file %}?c={{ ref }}">{{ file|basename }}</a>
|
<a href="{% url codereview.browser.views.blob repository=repository path=file %}?c={{ ref }}">{{ file|basename }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue