Luke Ross

Colorado

4 releases git clone https://lukeross.name/projects/colorado.git/

Web-based git repository viewer.

Commit e7c07a6251dfb57ea45641968231ed0928882eba

features

Committed 5 Jul 2017 by Luke Ross

src/colorado/repo.py

@@ -1,6 +1,6 @@
 import unicodedata as ud
 from git import Repo as GitRepo
-from sqlalchemy import Boolean, Column, Integer, Unicode
+from sqlalchemy import Boolean, Column, Integer, String, Unicode
 
 from .db import Base
 
@@ -25,6 +25,7 @@ class Repo(Base):
 	private = Column(Boolean, default=False)
 	description = Column(Unicode)
 	master = Column(Unicode, default="master")
+	read_clone_url = Column(String)
 
 	@property
 	def repo(self):


src/colorado/templates/repo-home.xml

@@ -25,6 +25,10 @@
 Brief introduction to the repo.
 </p>
 
+<p>
+<span meld:id="tree-part"><a href="#" meld:id="tree-part-name">foo</a> / </span>
+</p>
+
 <table id="file-list">
 <tr meld:id="file">
 <td><a href="#" meld:id="file-name">README.txt</a></td>


src/colorado/views.py

@@ -20,6 +20,17 @@ doctype = (
 )
 
 
+def nice_size(num):
+	suffixes = ("", "k", "M", "G", "T")
+	for offset, _ in enumerate(suffixes):
+		print(num)
+		if num > 1023:
+			num /= 1024
+		else:
+			return "{}{}".format(int(num), suffixes[offset])
+	return "{}{}".format(int(num), suffixes[-1])
+
+
 def run_on_meld(tpl, id, fn):
 	node = tpl.findmeld(id)
 	if node is not None:
@@ -43,6 +54,8 @@ def configure_template(tpl, repo=None):
 			".repo_home", slug=repo.slug
 		))
 		run_on_meld(tpl, "repo-desc", lambda n: n.content(repo.description))
+		run_on_meld(tpl, "repo-clone", lambda n: n.content(repo.read_clone_url))
+		run_on_meld(tpl, "repo-issues", lambda n: n.deparent())  # FIXME
 		run_on_meld(tpl, "repo-branches", lambda n: (
 			n[0].content(str(len(git.heads))),
 			n.set("href", url_for(
@@ -228,6 +241,9 @@ def tree_view(slug, type, id, path):
 	except KeyError:
 		abort(404)
 
+	if blob.type == "tree":
+		return tree_base_view(slug, type, id, repo, commit, blob, False, False)
+
 	tpl = parse_xml_for_template("repo-blob")
 	configure_template(tpl, repo=repo)
 	tpl.findmeld("file-name").content(blob.path)
@@ -243,8 +259,10 @@ def tree_view(slug, type, id, path):
 def top_level_view(slug, type, id):
 	repo, point, commit = look_up_thing(slug, type, id)
 	show_download = type in ("branch", "tag")
-	git = repo.repo
+	return tree_base_view(slug, type, id, repo, commit, commit.tree, True, show_download)
+
 
+def tree_base_view(slug, type, id, repo, commit, tree, show_readme=False, show_download=False):
 	seen = {}
 	by_file = {}
 	commit_count = 0
@@ -285,14 +303,14 @@ def top_level_view(slug, type, id):
 		tpl.findmeld("repo-download").deparent()
 		tpl.findmeld("repo-clone").deparent()
 
-	contents = chain(commit.tree.trees, commit.tree.blobs)
+	contents = chain(tree.trees, tree.blobs)
 	for ele, direntry in tpl.findmeld("file").repeat(contents):
 		ele.findmeld("file-name").content(direntry.name)
 		ele.findmeld("file-name").set("href", url_for(
 			".tree_view", slug=slug, type=type, id=id, path=direntry.path
 		))
 		if direntry.type == "blob":
-			ele.findmeld("file-size").content(str(direntry.size))
+			ele.findmeld("file-size").content(nice_size(direntry.size))
 			if direntry.hexsha in by_file:
 				file_commit = by_file[direntry.hexsha]
 				ele.findmeld("file-revdesc").content(file_commit.message)
@@ -317,7 +335,7 @@ def top_level_view(slug, type, id):
 
 	# README.*, case-insensitive, text content
 	candidate_readmes = [
-		c for c in commit.tree.blobs if
+		c for c in tree.blobs if
 		c.mime_type.startswith("text/") and
 		(c.name.lower() == "readme" or (
 			c.name.lower().startswith("readme.") and