diff options
| author | bnewbold <bnewbold@manus.(none)> | 2007-02-20 02:21:25 -0800 | 
|---|---|---|
| committer | bnewbold <bnewbold@manus.(none)> | 2007-02-20 02:21:25 -0800 | 
| commit | 3d203c153301d4dd9c3285e7dea86ee09eb3b0c5 (patch) | |
| tree | 47bf5bb676c5f25def0a4a37852c1783961a03e6 /bn_django/git_browse | |
| parent | 566473abe7aac915429a633e996bdb719f1a308b (diff) | |
| download | bnewnet-3d203c153301d4dd9c3285e7dea86ee09eb3b0c5.tar.gz bnewnet-3d203c153301d4dd9c3285e7dea86ee09eb3b0c5.zip | |
mid-progress, work on git-browser
fan is dying, more work to do though!
TODO: seperate style for git_browser, use "block.super"
Diffstat (limited to 'bn_django/git_browse')
| -rw-r--r-- | bn_django/git_browse/models.py | 25 | ||||
| -rw-r--r-- | bn_django/git_browse/templates/git_browse/obj.html | 2 | ||||
| -rw-r--r-- | bn_django/git_browse/templates/git_browse/repository_info.html | 52 | ||||
| -rw-r--r-- | bn_django/git_browse/urls.py | 11 | ||||
| -rw-r--r-- | bn_django/git_browse/views.py | 33 | 
5 files changed, 104 insertions, 19 deletions
| diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index 765fe02..be097f8 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -5,6 +5,13 @@ try:      GITBROWSE_BASE = settings.GITBROWSE_BASE  except AttributeError:      GITBROWSE_BASE='/home' +if GITBROWSE_BASE[-1] != '/': +    GITBROWSE_BASE += '/' + +try: +    GITCOMMAND = settings.GITCOMMAND +except AttributeError: +    GITCOMMAND='git'  try:      ADMIN_URL = settings.ADMIN_URL @@ -34,6 +41,24 @@ class Repository(models.Model):      def get_admin_url(self):          return "%s/code/repository/%s/" % (ADMIN_URL, self.slug) +    def scan(self): +        import os + +        GITPREFIX = 'cd ' + GITBROWSE_BASE + self.slug + '; ' + GITCOMMAND \ +                + ' --git-dir=' + GITBROWSE_BASE + self.slug + '/.git ' +        heads = dict() +        for h in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/heads/'): +            f = open(GITBROWSE_BASE + self.slug + '/.git/refs/heads/' + h,'r') +            heads[h] = f.readline() +            f.close +        tags = dict() +        for t in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/tags/'): +            f = open(GITBROWSE_BASE + self.slug + '/.git/refs/tags/' + t,'r') +            tags[t] = f.readline() +            f.close + +        return (GITPREFIX, heads, tags) +  class Tree(models.Model):      repo = models.ForeignKey(Repository)      mode = models.CharField("file mode/permissions", blank=False,maxlength=4) diff --git a/bn_django/git_browse/templates/git_browse/obj.html b/bn_django/git_browse/templates/git_browse/obj.html index be0b556..0170eab 100644 --- a/bn_django/git_browse/templates/git_browse/obj.html +++ b/bn_django/git_browse/templates/git_browse/obj.html @@ -3,7 +3,7 @@  {% block gitbrowse %}      {% if contents %}      <h3>Object sha1 hash: {{ hash }}<br /> -    Size: {{ size }} kB<br /> +    Size: {{ size|filesizeformat }}<br />      Type: "{{ type }}"</h3>      <pre>{{ contents }}</pre>      {% else %} diff --git a/bn_django/git_browse/templates/git_browse/repository_info.html b/bn_django/git_browse/templates/git_browse/repository_info.html index 72f30b1..b3028a2 100644 --- a/bn_django/git_browse/templates/git_browse/repository_info.html +++ b/bn_django/git_browse/templates/git_browse/repository_info.html @@ -5,7 +5,55 @@  {% if shortlog %}  <h3>Shortlog (<a href="/code/{{object.slug}}/log/">full log</a>)</h3>  <pre>{{ shortlog }}</pre> -<h3>Filelist (<a href="/code/{{object.slug}}/tree/">browse</a>)</h3> -<pre>{{ filelist }}</pre> +<h3>Heads (<a href="/code/{{object.slug}}/tree/">browse</a>)</h3> +{% if heads %} +<table class="gitbrowser"> +{% for h in heads.iteritems %} +<tr> +    <td class="head"> +        <a href="/code/{{object.slug}}/commit/{{ h.1 }}" class="subtle"> +            {{ h.0 }}</a></td> +    <td class="links"> +        <a href="/code/{{object.slug}}/commit/{{ h.1 }}">commit</a> | +        <a href="/code/{{object.slug}}/commit/{{ h.1 }}/zip"> zip </a></td> +    <td class="commit_hash"> +        <a href="/code/{{object.slug}}/obj/{{ h.1 }}" class="subtle"> +        {{ h.1 }}</a> +        {% for t in tags.iteritems %} +            {% ifequal h.1 t.1 %}  +                <a href="/code/{{object.slug}}/tag/{{ h.1 }}/" class="tag"> +                [{{ t.0 }}]</a>  +        {% endifequal %}{% endfor %}  +        </td></tr> +{% endfor %} +</table> +{% else %}No heads!{% endif %} +<h3>Tags (<a href="/code/{{object.slug}}/tree/">browse</a>)</h3> +{% if tags %} +<table class="gitbrowser"> +{% for t in tags.iteritems %} +<tr> +    <td class="tag"> +        <a href="/code/{{object.slug}}/tag/{{ h.1 }}" class="subtle"> +            {{ t.0 }}</a></td> +    <td class="links"> +        <a href="/code/{{object.slug}}/tag/{{ t.1 }}">tag</a> | +        <a href="/code/{{object.slug}}/commit/{{ t.1 }}">commit</a> | +        <a href="/code/{{object.slug}}/commit/{{ t.1 }}/zip"> zip </a></td> +    <td class="commit_hash"> +        <a href="/code/{{object.slug}}/obj/{{ t.1 }}" class="subtle"> +        <span class="hash">{{ t.1 }}</span></a> +        {% for t in tags.iteritems %} +            {% ifequal h.1 t.1 %}  +                <a href="/code/{{object.slug}}/tag/{{ h.1 }}/" class="tag"> +                [{{ t.0 }}]</a>  +            {% endifequal %}</td></tr> +        {% endfor %}  +{% endfor %} +</table> +{% else %}No tags!{% endif %} +<h3>Filelist (<a href="/code/{{object.slug}}/tree/">browse tree</a>)</h3> +{% if filelist %} <pre class="large">{{ filelist }}</pre> +{% else %}No files!{% endif %}  {% endif %}  {% endblock %} diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py index 909bfcd..77fabd3 100644 --- a/bn_django/git_browse/urls.py +++ b/bn_django/git_browse/urls.py @@ -32,10 +32,17 @@ urlpatterns = patterns('django.views.generic.list_detail',  urlpatterns += patterns('bn_django.git_browse.views',      (r'^(?P<repo>[\w\-\_]*)/$', 'repo_info',),  -    (r'^(?P<repo>[\w\-\_]*)/tree/$', 'view_tree',),       (r'^(?P<repo>[\w\-\_]*)/branches/$', 'view_branches',),  -    (r'^(?P<repo>[\w\-\_]*)/history/$', 'view_history',),       (r'^(?P<repo>[\w\-\_]*)/log/$', 'view_log',),       (r'^(?P<repo>[\w\-\_]*)/obj/(?P<hash>[0-9a-z]{40})/$', 'view_obj',),  +    (r'^(?P<repo>[\w\-\_]*)/obj/(?P<hash>[0-9a-z]{40})/log/$', 'view_log',),  +    (r'^(?P<repo>[\w\-\_]*)/commit/(?P<hash>[0-9a-z]{40})/$', 'view_commit',),  +    (r'^(?P<repo>[\w\-\_]*)/commit/$', 'view_commit',),  +    (r'^(?P<repo>[\w\-\_]*)/tag/(?P<hash>[0-9a-z]{40})/$', 'view_tag',),  +    (r'^(?P<repo>[\w\-\_]*)/blob/(?P<hash>[0-9a-z]{40})/$', 'view_blob',),  +    (r'^(?P<repo>[\w\-\_]*)/blob/(?P<hash>[0-9a-z]{40})/raw/$', 'view_blob',),  +    (r'^(?P<repo>[\w\-\_]*)/tree/$', 'view_tree',),       (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/$', 'view_tree',),  +    (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/gz/$', 'view_tree',),  +    (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/tar/$', 'view_tree',),   ) diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index c8a7a40..d8e01d7 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -23,26 +23,29 @@ except AttributeError:  def repo_info(request, repo,branch=None):      therepo = get_object_or_404(Repository, slug=repo) +    (GITPREFIX, heads, tags) = therepo.scan() -    GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' - -    shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND + '-shortlog') +    shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND \ +            + '-shortlog') +    branches = commands.getoutput(GITPREFIX + ' branch')      filelist = commands.getoutput(GITPREFIX + ' ls-files') - -    return render_to_response('git_browse/repository_info.html', -                      dict(object=therepo, -                            filelist=filelist, +    return render_to_response('git_browse/repository_info.html', \ +                      dict(object=therepo, \ +                            filelist=filelist, \ +                            tags=tags, \ +                            heads=heads, \                              shortlog=shortlog,))  def view_tree(request, repo, hash=None,branch=None):      therepo = get_object_or_404(Repository, slug=repo) +    (GITPREFIX, heads, tags) = therepo.scan() -    GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' -      if(hash == None):  -        head_ref = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat HEAD') +        head_ref = commands.getoutput('cd ' + GITBROWSE_BASE \ +                + therepo.slug +'/.git; cat HEAD')          head_ref = head_ref.split()[1] -        hash = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat ' + head_ref) +        hash = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug \ +                +'/.git; cat ' + head_ref)      tree_ls = commands.getoutput(GITPREFIX + ' ls-tree ' + hash)      tree_objs = list() @@ -65,8 +68,10 @@ def view_tree(request, repo, hash=None,branch=None):  def view_log(request, repo, tree_hash=None, branch=None):      therepo = get_object_or_404(Repository, slug=repo) +    (GITPREFIX, heads, tags) = therepo.scan() -    GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' +    GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND \ +            + ' --git-dir=' + GITBROWSE_BASE  + therepo.slug + '/.git '      logtxt = commands.getoutput(GITPREFIX + ' log | cat')      log_items = logtxt.split('\ncommit ') @@ -94,8 +99,8 @@ def view_log(request, repo, tree_hash=None, branch=None):  def view_obj(request, repo, hash, branch=None):      therepo = get_object_or_404(Repository, slug=repo) +    (GITPREFIX, heads, tags) = therepo.scan() -    GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git '      obj_type = commands.getoutput(GITPREFIX + ' cat-file -t  ' + hash)      #if(obj_type == 'tree'):      #    redirect_to('../tree/' + hash); @@ -109,5 +114,5 @@ def view_obj(request, repo, hash, branch=None):                        dict(object=therepo,                          hash=hash,                          type=obj_type, -                        size=float(obj_size)/1024.0, +                        size=float(obj_size),                          contents=obj_contents)) | 
