aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http_handle_repo_index.go27
-rw-r--r--http_template_funcs.go2
-rw-r--r--resources.go6
-rw-r--r--templates/repo_index.tmpl108
4 files changed, 74 insertions, 69 deletions
diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go
index 66116c7..15b5173 100644
--- a/http_handle_repo_index.go
+++ b/http_handle_repo_index.go
@@ -23,29 +23,28 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string
repo, repo_name, group_path = params["repo"].(*git.Repository), params["repo_name"].(string), params["group_path"].([]string)
- if ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
- http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError)
- return
+ ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string))
+ if err != nil {
+ goto no_ref
}
if recent_commits, err = get_recent_commits(repo, ref_hash, 3); err != nil {
- http.Error(w, "Error getting recent commits: "+err.Error(), http.StatusInternalServerError)
- return
+ goto no_ref
}
params["commits"] = recent_commits
- commit_object, err = repo.CommitObject(ref_hash)
- if err != nil {
- http.Error(w, "Error getting commit object: "+err.Error(), http.StatusInternalServerError)
- return
+
+ if commit_object, err = repo.CommitObject(ref_hash); err != nil {
+ goto no_ref
}
- tree, err = commit_object.Tree()
- if err != nil {
- http.Error(w, "Error getting file tree: "+err.Error(), http.StatusInternalServerError)
- return
+
+ if tree, err = commit_object.Tree(); err != nil {
+ goto no_ref
}
- params["readme_filename"], params["readme"] = render_readme_at_tree(tree)
params["files"] = build_display_git_tree(tree)
+ params["readme_filename"], params["readme"] = render_readme_at_tree(tree)
+
+no_ref:
params["http_clone_url"] = generate_http_remote_url(group_path, repo_name)
params["ssh_clone_url"] = generate_ssh_remote_url(group_path, repo_name)
diff --git a/http_template_funcs.go b/http_template_funcs.go
index a7ebb1e..016d268 100644
--- a/http_template_funcs.go
+++ b/http_template_funcs.go
@@ -4,9 +4,9 @@
package main
import (
+ "net/url"
"path"
"strings"
- "net/url"
)
func first_line(s string) string {
diff --git a/resources.go b/resources.go
index ff1286f..7ada53f 100644
--- a/resources.go
+++ b/resources.go
@@ -34,9 +34,9 @@ var templates *template.Template
func load_templates() (err error) {
templates, err = template.New("templates").Funcs(template.FuncMap{
- "first_line": first_line,
- "base_name": base_name,
- "path_escape": path_escape,
+ "first_line": first_line,
+ "base_name": base_name,
+ "path_escape": path_escape,
"query_escape": query_escape,
}).ParseFS(resources_fs, "templates/*")
return err
diff --git a/templates/repo_index.tmpl b/templates/repo_index.tmpl
index 617b8ad..da67df4 100644
--- a/templates/repo_index.tmpl
+++ b/templates/repo_index.tmpl
@@ -41,61 +41,67 @@
<a href="contrib/" class="btn-normal">Merge requests</a>
</p>
</div>
- <div class="padding-wrapper scroll">
- <table id="recent-commits" class="wide">
- <thead>
- <tr class="title-row">
- <th colspan="3">Recent commits (<a href="log/{{ if .ref_type }}?{{ .ref_type }}={{ .ref_name }}{{ end }}">see all</a>)</th>
- </tr>
- <tr>
- <th scope="col">Title</th>
- <th scope="col">Author</th>
- <th scope="col">Author Date</th>
- </tr>
- </thead>
- <tbody>
- {{- range .commits }}
+ {{ if .commits }}
+ <div class="padding-wrapper scroll">
+ <table id="recent-commits" class="wide">
+ <thead>
+ <tr class="title-row">
+ <th colspan="3">Recent commits (<a href="log/{{ if .ref_type }}?{{ .ref_type }}={{ .ref_name }}{{ end }}">see all</a>)</th>
+ </tr>
<tr>
- <td class="commit-title"><a href="commit/{{ .ID }}">{{ .Message | first_line }}</a></td>
- <td class="commit-author">
- <a class="email-name" href="mailto:{{ .Author.Email }}">{{ .Author.Name }}</a>
- </td>
- <td class="commit-time">
- {{ .Author.When.Format "2006-01-02 15:04:05 -0700" }}
- </td>
+ <th scope="col">Title</th>
+ <th scope="col">Author</th>
+ <th scope="col">Author Date</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{- range .commits }}
+ <tr>
+ <td class="commit-title"><a href="commit/{{ .ID }}">{{ .Message | first_line }}</a></td>
+ <td class="commit-author">
+ <a class="email-name" href="mailto:{{ .Author.Email }}">{{ .Author.Name }}</a>
+ </td>
+ <td class="commit-time">
+ {{ .Author.When.Format "2006-01-02 15:04:05 -0700" }}
+ </td>
+ </tr>
+ {{- end }}
+ </tbody>
+ </table>
+ </div>
+ {{ end }}
+ {{ if .files }}
+ <div class="padding-wrapper scroll">
+ <table id="file-tree" class="wide">
+ <thead>
+ <tr class="title-row">
+ <th colspan="3">/{{ if .ref_name }} on {{ .ref_name }}{{ end }}</th>
</tr>
- {{- end }}
- </tbody>
- </table>
- </div>
- <div class="padding-wrapper scroll">
- <table id="file-tree" class="wide">
- <thead>
- <tr class="title-row">
- <th colspan="3">/{{ if .ref_name }} on {{ .ref_name }}{{ end }}</th>
- </tr>
- <tr>
- <th scope="col">Mode</th>
- <th scope="col">Filename</th>
- <th scope="col">Size</th>
- </tr>
- </thead>
- <tbody>
- {{- $ref_type := .ref_type }}
- {{- $ref := .ref_name }}
- {{- range .files }}
<tr>
- <td class="file-mode">{{ .Mode }}</td>
- <td class="file-name"><a href="tree/{{ .Name }}{{ if not .Is_file }}/{{ end }}{{ if $ref_type }}?{{ $ref_type }}={{ $ref }}{{ end }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td>
- <td class="file-size">{{ .Size }}</td>
+ <th scope="col">Mode</th>
+ <th scope="col">Filename</th>
+ <th scope="col">Size</th>
</tr>
- {{- end }}
- </tbody>
- </table>
- </div>
- <div class="padding-wrapper" id="readme">
- {{ .readme }}
- </div>
+ </thead>
+ <tbody>
+ {{- $ref_type := .ref_type }}
+ {{- $ref := .ref_name }}
+ {{- range .files }}
+ <tr>
+ <td class="file-mode">{{ .Mode }}</td>
+ <td class="file-name"><a href="tree/{{ .Name }}{{ if not .Is_file }}/{{ end }}{{ if $ref_type }}?{{ $ref_type }}={{ $ref }}{{ end }}">{{ .Name }}</a>{{ if not .Is_file }}/{{ end }}</td>
+ <td class="file-size">{{ .Size }}</td>
+ </tr>
+ {{- end }}
+ </tbody>
+ </table>
+ </div>
+ {{ end }}
+ {{ if .readme }}
+ <div class="padding-wrapper" id="readme">
+ {{ .readme }}
+ </div>
+ {{ end }}
<footer>
{{ template "footer" . }}
</footer>