From 19db4c223b2cf0b7f4ae170a83470667ffdf5446 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 16 Apr 2023 16:14:12 +0200 Subject: [PATCH] nits to improve git backend (#7) --- internal/git/commands.go | 8 +++++--- internal/models/gist.go | 2 +- internal/web/gist.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/git/commands.go b/internal/git/commands.go index d6e86fe..7797e8c 100644 --- a/internal/git/commands.go +++ b/internal/git/commands.go @@ -7,6 +7,7 @@ import ( "os/exec" "path" "path/filepath" + "strconv" "strings" ) @@ -62,8 +63,9 @@ func GetFilesOfRepository(user string, gist string, revision string) ([]string, cmd := exec.Command( "git", "ls-tree", - revision, "--name-only", + "--", + revision, ) cmd.Dir = repositoryPath @@ -101,7 +103,7 @@ func GetFileContent(user string, gist string, revision string, filename string, return truncateCommandOutput(stdout, maxBytes) } -func GetLog(user string, gist string, skip string) ([]*Commit, error) { +func GetLog(user string, gist string, skip int) ([]*Commit, error) { repositoryPath := RepositoryPath(user, gist) cmd := exec.Command( @@ -113,7 +115,7 @@ func GetLog(user string, gist string, skip string) ([]*Commit, error) { "--no-color", "-p", "--skip", - skip, + strconv.Itoa(skip), "--format=format:c %H%na %aN%nm %ae%nt %at", "--shortstat", "HEAD", diff --git a/internal/models/gist.go b/internal/models/gist.go index 4bea1a3..a04be33 100644 --- a/internal/models/gist.go +++ b/internal/models/gist.go @@ -228,7 +228,7 @@ func (gist *Gist) File(revision string, filename string, truncate bool) (*git.Fi }, err } -func (gist *Gist) Log(skip string) ([]*git.Commit, error) { +func (gist *Gist) Log(skip int) ([]*git.Commit, error) { return git.GetLog(gist.User.Username, gist.Uuid, skip) } diff --git a/internal/web/gist.go b/internal/web/gist.go index dc09b52..d03bdef 100644 --- a/internal/web/gist.go +++ b/internal/web/gist.go @@ -178,7 +178,7 @@ func revisions(ctx echo.Context) error { pageInt := getPage(ctx) - commits, err := gist.Log(strconv.Itoa((pageInt - 1) * 10)) + commits, err := gist.Log((pageInt - 1) * 10) if err != nil { return errorRes(500, "Error fetching commits log", err) }