commit 4884661b
Include ability to select tags
Changed files
| M | src/application.cpp before |
| M | src/content.h before |
| M | src/git_repo.cpp before |
| M | src/git_repo.h before |
| M | static/style.css before |
| M | templates/skin.tmpl before |
diff --git a/src/application.cpp b/src/application.cpp
index 4738c64..8e39241 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -163,6 +163,7 @@ void GitApp::tree(std::string name, std::string path) {
// their source so it can be shown below the preview.
c.text = is_binary ? "" : text;
c.size = text.size();
+ c.tags = repo->tags_for_commit(commit);
render(SKIN, "file_view", c);
return;
}
@@ -176,6 +177,7 @@ void GitApp::tree(std::string name, std::string path) {
c.is_root = clean.empty();
c.parent_path = util::parent_path(clean);
c.entries = repo->list_tree(commit, clean);
+ c.tags = repo->tags_for_commit(commit);
render(SKIN, "tree_view", c);
} catch (const GitError &e) {
show_error(404, e.what());
diff --git a/src/content.h b/src/content.h
index 4b227ee..0fbdcf2 100644
--- a/src/content.h
+++ b/src/content.h
@@ -39,6 +39,7 @@ struct tree_view : public master {
std::string parent_path; // for the ".." link
bool is_root = true;
std::vector<TreeEntry> entries;
+ std::vector<std::string> tags; // tags pointing at commit_oid
};
struct file_view : public master {
@@ -50,6 +51,7 @@ struct file_view : public master {
bool is_markdown = false;
bool is_image = false;
uint64_t size = 0;
+ std::vector<std::string> tags; // tags pointing at commit_oid
};
struct blame_view : public master {
diff --git a/src/git_repo.cpp b/src/git_repo.cpp
index 8163583..4230eeb 100644
--- a/src/git_repo.cpp
+++ b/src/git_repo.cpp
@@ -446,6 +446,15 @@ std::vector<TagInfo> GitRepo::tags() const {
return result;
}
+std::vector<std::string> GitRepo::tags_for_commit(const std::string &commit_oid) const {
+ std::vector<std::string> result;
+ for (const TagInfo &tag : tags()) {
+ if (tag.target_oid == commit_oid)
+ result.push_back(tag.name);
+ }
+ return result;
+}
+
TagDetail GitRepo::tag_detail(const std::string &name) const {
TagDetail detail;
detail.name = name;
diff --git a/src/git_repo.h b/src/git_repo.h
index acba856..42e30be 100644
--- a/src/git_repo.h
+++ b/src/git_repo.h
@@ -137,6 +137,9 @@ public:
// All tags, sorted by name.
std::vector<TagInfo> tags() const;
+ // Names of tags whose target commit is `commit_oid`, sorted by name.
+ std::vector<std::string> tags_for_commit(const std::string &commit_oid) const;
+
// Details of a single tag by short name (e.g. "v1.0").
TagDetail tag_detail(const std::string &name) const;
diff --git a/static/style.css b/static/style.css
index 8b59db0..af201b1 100644
--- a/static/style.css
+++ b/static/style.css
@@ -35,8 +35,9 @@ a:hover { text-decoration: underline; }
main { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.25rem; }
h1 { font-size: 1.4rem; word-break: break-all; }
-.meta, .actions { color: var(--muted); font-size: 0.9rem; }
+.meta, .actions, .tags { color: var(--muted); font-size: 0.9rem; }
.actions a { font-size: 0.9rem; }
+.tags a { display: inline-block; padding: 0 0.4rem; border: 1px solid var(--muted); border-radius: 3px; }
.repo-list { list-style: none; padding: 0; }
.repo-list li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
diff --git a/templates/skin.tmpl b/templates/skin.tmpl
index e5dfd08..6ecc5e5 100644
--- a/templates/skin.tmpl
+++ b/templates/skin.tmpl
@@ -77,6 +77,9 @@
<% view tree_view uses content::tree_view extends master %>
<% template content_body() %>
<h1><%= repo %><% if (content.path.length() > 0) %>/<%= path %><% end %></h1>
+<% if (content.tags.size() > 0) %>
+<p class="tags">tags: <% foreach t in tags %><% item %><a href="/repos/<%= repo %>/tags/<%= t %>"><%= t %></a> <% end item %><% end foreach %></p>
+<% end %>
<table class="tree">
<% if (not content.is_root) %>
<tr><td class="name"><a href="/repos/<%= repo %>/tree/<%= parent_path %><%= query %>">..</a></td><td></td></tr>
@@ -106,6 +109,9 @@
<% view file_view uses content::file_view extends master %>
<% template content_body() %>
<h1><%= path %></h1>
+<% if (content.tags.size() > 0) %>
+<p class="tags">tags: <% foreach t in tags %><% item %><a href="/repos/<%= repo %>/tags/<%= t %>"><%= t %></a> <% end item %><% end foreach %></p>
+<% end %>
<p class="actions">
<a href="/repos/<%= repo %>/raw/<%= path %><%= query %>">raw</a> ·
<a href="/repos/<%= repo %>/blame/<%= path %><%= query %>">blame</a> ·
@@ -197,6 +203,7 @@
<tr>
<td class="commit"><a href="/repos/<%= repo %>/commit/<%= t.target_oid %>"><%= t.short_oid %></a></td>
<td class="msg"><a href="/repos/<%= repo %>/tags/<%= t.name %>"><%= t.name %></a></td>
+<td class="msg"><a href="/repos/<%= repo %>/tree/?id=<%= t.target_oid %>">browse files</a></td>
<td class="date"><% c++ out() << util::format_time(t.time); %></td>
</tr>
<% end item %><% empty %>
@@ -213,6 +220,7 @@
<% if tag.annotated %>annotated<% else %>lightweight<% end %> ·
points to <a href="/repos/<%= repo %>/commit/<%= tag.target_oid %>"><%= tag.short_oid %></a>
· <% c++ out() << util::format_time(content.tag.time); %>
+· <a href="/repos/<%= repo %>/tree/?id=<%= tag.target_oid %>">browse files</a>
<% if (content.tag.tagger_name.length() > 0) %><br>tagger: <%= tag.tagger_name %><% end %>
</p>
<% if (content.tag.message.length() > 0) %>