Goit

Simple and lightweight Git web server
git clone http://git.omkov.net/Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2023-11-20 09:14:10
Commit1c90d8bf4e04b11a27a31e77762870e7bbde7122
Parentb4de62691eccd59541652dc3c7b00c6da85e85b3

Allow log filtering by directories

Diffstat

M res/repo/tree.html | 4 ++--
M src/repo/log.go | 4 ++--
M src/repo/tree.go | 8 ++++++--

3 files changed, 10 insertions, 6 deletions

diff --git a/res/repo/tree.html b/res/repo/tree.html
index 77bfb3b..c3a1a6e 100644
--- a/res/repo/tree.html
+++ b/res/repo/tree.html
@@ -20,8 +20,8 @@
 							<td><a href="/{{$.Name}}/{{.Path}}">{{.Name}}</a></td>
 							<td align="right" {{if .B}}style="padding-right: calc(2ch + 0.4em);"{{end}}>{{.Size}}</td>
 							<td>
-								{{if .RawPath}}
-									<a href="/{{$.Name}}/log/{{.RawPath}}">log</a>
+								<a href="/{{$.Name}}/log/{{.RawPath}}">log</a>
+								{{if .IsFile}}
 									blame
 									<a href="/{{$.Name}}/raw/{{.RawPath}}">raw</a>
 									<a href="/{{$.Name}}/download/{{.RawPath}}">download</a>
diff --git a/src/repo/log.go b/src/repo/log.go
index ec3d2a1..1a7b47d 100644
--- a/src/repo/log.go
+++ b/src/repo/log.go
@@ -92,8 +92,8 @@ func HandleLog(w http.ResponseWriter, r *http.Request) {
 			log.Println("[/repo/log]", err.Error())
 		} else if path != "" {
 			for _, s := range stats {
-				if s.Name == path {
-					files = 1
+				if strings.HasPrefix(s.Name, path) {
+					files += 1
 					additions += s.Addition
 					deletions += s.Deletion
 				}
diff --git a/src/repo/tree.go b/src/repo/tree.go
index 2be34d4..5657b60 100644
--- a/src/repo/tree.go
+++ b/src/repo/tree.go
@@ -32,7 +32,7 @@ func HandleTree(w http.ResponseWriter, r *http.Request) {
 
 	type row struct {
 		Mode, Name, Path, RawPath, Size string
-		B                               bool
+		IsFile, B                       bool
 	}
 	data := struct {
 		Title, Name, Description, Url string
@@ -106,6 +106,7 @@ func HandleTree(w http.ResponseWriter, r *http.Request) {
 
 		for _, v := range tree.Entries {
 			var fpath, rpath, size string
+			var isFile bool
 
 			if v.Mode&0o40000 == 0 {
 				file, err := tree.File(v.Name)
@@ -118,6 +119,8 @@ func HandleTree(w http.ResponseWriter, r *http.Request) {
 				fpath = filepath.Join("file", path, v.Name)
 				rpath = filepath.Join(path, v.Name)
 				size = humanize.IBytes(uint64(file.Size))
+
+				isFile = true
 			} else {
 				var dirSize uint64
 
@@ -138,12 +141,13 @@ func HandleTree(w http.ResponseWriter, r *http.Request) {
 				}
 
 				fpath = filepath.Join("tree", path, v.Name)
+				rpath = filepath.Join(path, v.Name)
 				size = humanize.IBytes(dirSize)
 			}
 
 			data.Files = append(data.Files, row{
 				Mode: util.ModeString(uint32(v.Mode)), Name: v.Name, Path: fpath, RawPath: rpath, Size: size,
-				B: util.If(strings.HasSuffix(size, " B"), true, false),
+				IsFile: isFile, B: util.If(strings.HasSuffix(size, " B"), true, false),
 			})
 		}
 	}