mirror of
https://github.com/correl/codereview.git
synced 2024-11-23 19:19:50 +00:00
Merge branch 'navigation'
This commit is contained in:
commit
0469b99527
11 changed files with 111 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
from django.template import Library
|
from django.template import Library
|
||||||
from django.template.defaultfilters import stringfilter
|
from django.template.defaultfilters import stringfilter
|
||||||
|
|
||||||
|
@ -8,3 +9,13 @@ register = Library()
|
||||||
def oneline(value):
|
def oneline(value):
|
||||||
line = value.split('\n')[0].strip()
|
line = value.split('\n')[0].strip()
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
@stringfilter
|
||||||
|
def dirname(value):
|
||||||
|
return os.path.dirname(value)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
@stringfilter
|
||||||
|
def basename(value):
|
||||||
|
return os.path.basename(value)
|
||||||
|
|
|
@ -2,5 +2,6 @@ from django.conf.urls.defaults import *
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(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'),
|
||||||
(r'^(?P<repository>.*?)/view/(?P<ref>.*?)/$', 'codereview.browser.views.view'),
|
(r'^(?P<repository>.*?)/view/(?P<ref>.*?)/$', 'codereview.browser.views.view'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -144,7 +144,7 @@ class Git(VCS):
|
||||||
def log(self, commit=None, path=None, max=50, offset=0):
|
def log(self, commit=None, path=None, max=50, offset=0):
|
||||||
commit = commit if commit else self._ref
|
commit = commit if commit else self._ref
|
||||||
result = []
|
result = []
|
||||||
for c in self._repo.iter_commits(commit, path, max_count=max,
|
for c in self._repo.iter_commits(rev=commit, paths=path, max_count=max,
|
||||||
skip=offset):
|
skip=offset):
|
||||||
result.append(self.commit(c))
|
result.append(self.commit(c))
|
||||||
return result
|
return result
|
||||||
|
@ -176,6 +176,26 @@ class Git(VCS):
|
||||||
diff.b_blob.data_stream.read())
|
diff.b_blob.data_stream.read())
|
||||||
result.append(d)
|
result.append(d)
|
||||||
return result
|
return result
|
||||||
|
def browse(self, commit=None, path=''):
|
||||||
|
if not commit:
|
||||||
|
commit = self.ref()
|
||||||
|
files = []
|
||||||
|
dirs = []
|
||||||
|
|
||||||
|
# Locate the tree matching the requested path
|
||||||
|
tree = self._repo.commit(commit).tree
|
||||||
|
if path:
|
||||||
|
for i in tree.traverse():
|
||||||
|
if type(i) == git.objects.Tree and i.path == path:
|
||||||
|
tree = i
|
||||||
|
if path != tree.path:
|
||||||
|
raise Exception('Path not found')
|
||||||
|
|
||||||
|
for node in tree:
|
||||||
|
if type(node) == git.objects.Blob:
|
||||||
|
files.append(node.path)
|
||||||
|
elif type(node) == git.objects.Tree:
|
||||||
|
dirs.append(node.path)
|
||||||
|
return dirs, files
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
g = Git('/home/correlr/code/voiceaxis')
|
g = Git('/home/correlr/code/voiceaxis')
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
import os
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.shortcuts import render_to_response
|
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):
|
def log(request,repository, path=None):
|
||||||
try:
|
try:
|
||||||
repository = Repository.objects.get(name=repository)
|
repository = Repository.objects.get(name=repository)
|
||||||
except:
|
except:
|
||||||
|
@ -12,7 +13,10 @@ def log(request,repository):
|
||||||
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
|
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
|
||||||
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
|
||||||
log = repo.log(ref, max=limit, offset=offset)
|
|
||||||
|
path = path if path else ''
|
||||||
|
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
|
||||||
|
@ -23,8 +27,10 @@ def log(request,repository):
|
||||||
return render_to_response('browser/log.html',
|
return render_to_response('browser/log.html',
|
||||||
{
|
{
|
||||||
'repository': repository,
|
'repository': repository,
|
||||||
|
'path': path,
|
||||||
'repo': repo,
|
'repo': repo,
|
||||||
'log': log,
|
'log': log,
|
||||||
|
'navigation': navigation,
|
||||||
'ref': ref,
|
'ref': ref,
|
||||||
'offset': offset,
|
'offset': offset,
|
||||||
'newer': newer,
|
'newer': newer,
|
||||||
|
|
|
@ -16,5 +16,14 @@
|
||||||
"type": 0,
|
"type": 0,
|
||||||
"name": "MTG"
|
"name": "MTG"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pk": 3,
|
||||||
|
"model": "dashboard.repository",
|
||||||
|
"fields": {
|
||||||
|
"path": "/srv/git/codereview.git",
|
||||||
|
"type": 0,
|
||||||
|
"name": "CodeReview"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,6 +5,20 @@ body, th, td {
|
||||||
a {
|
a {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
div.navigation {
|
||||||
|
width: 300px;
|
||||||
|
float: left;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
div.content {
|
||||||
|
margin-left: 300px;
|
||||||
|
}
|
||||||
|
ul.tree li.dir {
|
||||||
|
list-style-type: circle;
|
||||||
|
}
|
||||||
|
ul.tree li.file {
|
||||||
|
list-style-type: square;
|
||||||
|
}
|
||||||
span.marker {
|
span.marker {
|
||||||
display: block;
|
display: block;
|
||||||
float: left;
|
float: left;
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
{% extends "layouts/default.html" %}
|
{% extends "layouts/default.html" %}
|
||||||
{% load gravatar %}
|
{% load gravatar %}
|
||||||
|
|
||||||
{% load vcs %}
|
{% load vcs %}
|
||||||
|
|
||||||
|
{% block navigation %}
|
||||||
|
{% include "browser/navigation.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Commit Log</h2>
|
<h2>Commit Log</h2>
|
||||||
Branches:
|
|
||||||
<ul>
|
|
||||||
{% for branch, commit in repo.branches.items %}
|
|
||||||
<li><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{branch}}">{{ branch }}</a> ({{commit.id}})</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
<table class="vcs-log">
|
<table class="vcs-log">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Commit Date</th>
|
<th>Commit Date</th>
|
||||||
|
|
35
templates/browser/navigation.html
Normal file
35
templates/browser/navigation.html
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{% load vcs %}
|
||||||
|
<h2><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ ref }}">{{ repository.name }}</a></h2>
|
||||||
|
<h3>Branches</h3>
|
||||||
|
<ul>
|
||||||
|
{% for branch, commit in repo.branches.items %}
|
||||||
|
<li>
|
||||||
|
{% if ref == branch or ref == commit.id %}
|
||||||
|
<strong>{{ branch }}</strong>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url codereview.browser.views.log repository=repository.name %}?c={{branch}}">{{ branch }}</a>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
<h3>Browse</h3>
|
||||||
|
{% if path|dirname %}
|
||||||
|
<strong>{{ path|dirname }}/</strong><br />
|
||||||
|
<a href="{% url codereview.browser.views.log repository=repository.name path=path|dirname %}?c={{ ref }}">Up one</a>
|
||||||
|
{% endif %}
|
||||||
|
<ul class="tree">
|
||||||
|
{% for dir in navigation.dirs %}
|
||||||
|
<li class="dir">
|
||||||
|
<a href="{% url codereview.browser.views.log repository=repository.name path=dir %}/?c={{ ref }}">{{ dir|basename }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% for file in navigation.files %}
|
||||||
|
<li class="file">
|
||||||
|
{% if file == path %}
|
||||||
|
<strong>{{ file|basename }}</strong>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url codereview.browser.views.log repository=repository.name path=file %}?c={{ ref }}">{{ file|basename }}</a>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
|
@ -2,6 +2,10 @@
|
||||||
{% load gravatar %}
|
{% load gravatar %}
|
||||||
{% load vcs %}
|
{% load vcs %}
|
||||||
|
|
||||||
|
{% block navigation %}
|
||||||
|
{% include "browser/navigation.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>{{ commit.message|oneline }}</h2>
|
<h2>{{ commit.message|oneline }}</h2>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "layouts/default.html" %}
|
{% extends "layouts/default.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block navigation %}
|
||||||
<h2>Repositories</h2>
|
<h2>Repositories</h2>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
<h1><a href="{% url codereview.dashboard.views.index %}">CodeReview</a></title>
|
<h1><a href="{% url codereview.dashboard.views.index %}">CodeReview</a></title>
|
||||||
</div>
|
</div>
|
||||||
<div class="navigation">
|
<div class="navigation">
|
||||||
|
{% block navigation %}
|
||||||
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
Loading…
Reference in a new issue