gitshow

Log | Files | Refs

commit 7a4c864ad9ebef818f57a75b5606ec70d3c5e28b
parent 65e269983829831f6869baf213f3675ca2bb6dc5
Author: Thomas Vigouroux <thomas.vigouroux@univ-grenoble-alpes.fr>
Date:   Thu, 11 Apr 2024 08:36:27 +0200

refactor(log,repo): move to go-git

Also, display author name in log view

Diffstat:
Mcommit.go | 202++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mfile.go | 194++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mgitshow.go | 4++--
Mgo.mod | 24++++++++++++++++++++++--
Mgo.sum | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mlog.go | 29++++++++++++++++++-----------
Mrepo.go | 30+++++++++++++-----------------
Mstatic/style.css | 4++++
Mtemplates/log.html | 6++++--
Mtemplates/repo.html | 2+-
Mtree.go | 198++++++++++++++++++++++++++++++++++++++++----------------------------------------
11 files changed, 502 insertions(+), 335 deletions(-)

diff --git a/commit.go b/commit.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gorilla/mux" - "github.com/libgit2/git2go/v31" - "log" + // "github.com/gorilla/mux" + // "github.com/libgit2/git2go/v31" + // "log" "net/http" // "path/filepath" // "strings" @@ -30,102 +30,102 @@ type CommitPageData struct { } func getCommit(w http.ResponseWriter, r *http.Request) { - logger := log.Default() - vars := mux.Vars(r) - reponame := vars["repository"] - - repo, err := checkRepo(reponame) - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - defer repo.Free() - - obj, err := repo.RevparseSingle(vars["hash"]) - if err != nil { - logger.Printf("Object not found: %s", vars["hash"]) - w.WriteHeader(http.StatusNotFound) - return - } - defer obj.Free() - - commit, err := obj.AsCommit() - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - defer commit.Free() - - if commit.ParentCount() != 1 { - w.WriteHeader(http.StatusInternalServerError) - logger.Print("TODO: initial commit and merge commit") - return - } - - ctree, err := commit.Tree() - if err != nil { - logger.Fatal(err) - } - defer ctree.Free() - - parent := commit.Parent(0) - defer parent.Free() - - ptree, err := parent.Tree() - if err != nil { - logger.Fatal(err) - } - defer ptree.Free() - - parentid, err := parent.ShortId() - if err != nil { - logger.Fatal(err) - } - - commitid, err := parent.ShortId() - if err != nil { - logger.Fatal(err) - } - - diff, err := repo.DiffTreeToTree(ptree, ctree, &git.DiffOptions{ - Flags: git.DiffIgnoreWhitespaceChange, - MaxSize: 2000, - ContextLines: 5, - OldPrefix: parentid, - NewPrefix: commitid, - }) - if err != nil { - logger.Fatal(err) - } - defer diff.Free() - - deltadatas := make([]DeltaData, 0) - - diff.ForEach(func(delta git.DiffDelta, progress float64) (git.DiffForEachHunkCallback, error) { - deltadata := DeltaData { - NewFile: delta.NewFile.Path, - OldFile: delta.OldFile.Path, - } - - if delta.OldFile.Oid.IsZero() { - deltadata.Action = DeltaActionCreated - } else if delta.NewFile.Oid.IsZero() { - deltadata.Action = DeltaActionDeleted - } else if delta.NewFile.Path == delta.OldFile.Path { - deltadata.Action = DeltaActionChanged - } else { - deltadata.Action = DeltaActionMoved - } - - deltadatas = append(deltadatas, deltadata) - - logger.Print("Delta", deltadata) - return func(hunk git.DiffHunk) (git.DiffForEachLineCallback, error) { - logger.Print("Hunk", hunk.Header) - return func(line git.DiffLine) error { - logger.Print("Line", line) - return nil - }, nil - }, nil - }, git.DiffDetailHunks) + // logger := log.Default() + // vars := mux.Vars(r) + // reponame := vars["repository"] + // + // repo, err := checkRepo(reponame) + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // defer repo.Free() + // + // obj, err := repo.RevparseSingle(vars["hash"]) + // if err != nil { + // logger.Printf("Object not found: %s", vars["hash"]) + // w.WriteHeader(http.StatusNotFound) + // return + // } + // defer obj.Free() + // + // commit, err := obj.AsCommit() + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // defer commit.Free() + // + // if commit.ParentCount() != 1 { + // w.WriteHeader(http.StatusInternalServerError) + // logger.Print("TODO: initial commit and merge commit") + // return + // } + // + // ctree, err := commit.Tree() + // if err != nil { + // logger.Fatal(err) + // } + // defer ctree.Free() + // + // parent := commit.Parent(0) + // defer parent.Free() + // + // ptree, err := parent.Tree() + // if err != nil { + // logger.Fatal(err) + // } + // defer ptree.Free() + // + // parentid, err := parent.ShortId() + // if err != nil { + // logger.Fatal(err) + // } + // + // commitid, err := parent.ShortId() + // if err != nil { + // logger.Fatal(err) + // } + // + // diff, err := repo.DiffTreeToTree(ptree, ctree, &git.DiffOptions{ + // Flags: git.DiffIgnoreWhitespaceChange, + // MaxSize: 2000, + // ContextLines: 5, + // OldPrefix: parentid, + // NewPrefix: commitid, + // }) + // if err != nil { + // logger.Fatal(err) + // } + // defer diff.Free() + // + // deltadatas := make([]DeltaData, 0) + // + // diff.ForEach(func(delta git.DiffDelta, progress float64) (git.DiffForEachHunkCallback, error) { + // deltadata := DeltaData { + // NewFile: delta.NewFile.Path, + // OldFile: delta.OldFile.Path, + // } + // + // if delta.OldFile.Oid.IsZero() { + // deltadata.Action = DeltaActionCreated + // } else if delta.NewFile.Oid.IsZero() { + // deltadata.Action = DeltaActionDeleted + // } else if delta.NewFile.Path == delta.OldFile.Path { + // deltadata.Action = DeltaActionChanged + // } else { + // deltadata.Action = DeltaActionMoved + // } + // + // deltadatas = append(deltadatas, deltadata) + // + // logger.Print("Delta", deltadata) + // return func(hunk git.DiffHunk) (git.DiffForEachLineCallback, error) { + // logger.Print("Hunk", hunk.Header) + // return func(line git.DiffLine) error { + // logger.Print("Line", line) + // return nil + // }, nil + // }, nil + // }, git.DiffDetailHunks) } diff --git a/file.go b/file.go @@ -1,19 +1,19 @@ package main import ( - "github.com/gorilla/mux" - "fmt" + // "github.com/gorilla/mux" + // "fmt" "github.com/libgit2/git2go/v31" "html/template" - "log" + // "log" "net/http" - "path/filepath" - "strings" + // "path/filepath" + // "strings" // Chroma - chromahtml "github.com/alecthomas/chroma/v2/formatters/html" - "github.com/alecthomas/chroma/v2/lexers" - "github.com/alecthomas/chroma/v2/styles" + // chromahtml "github.com/alecthomas/chroma/v2/formatters/html" + // "github.com/alecthomas/chroma/v2/lexers" + // "github.com/alecthomas/chroma/v2/styles" ) type FilePageData struct { @@ -23,93 +23,93 @@ type FilePageData struct { } func getFile(w http.ResponseWriter, r *http.Request) { - logger := log.Default() - vars := mux.Vars(r) - reponame := vars["repository"] - - repo, err := checkRepo(reponame) - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - - ref, err := repo.RevparseSingle(vars["ref"]) - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - - commit, err := ref.AsCommit() - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - - tree, err := commit.Tree() - if err != nil { - logger.Fatalf("Could not get tree") - } - - // Get the path of the entry - path := r.RequestURI[len("/repos/") + len(reponame) + len("/file/") + len(vars["ref"]) + 1:len(r.RequestURI)] - logger.Printf("Trying to get file: %s (%s)", path, r.RequestURI) - entry, err := tree.EntryByPath(path) - if err != nil || entry.Type != git.ObjectBlob { - w.WriteHeader(http.StatusNotFound) - return - } - - blob, err := repo.LookupBlob(entry.Id) - if err != nil { - logger.Fatalf("Could not find file") - } - - lexer := lexers.Match(path) - if lexer == nil { - lexer = lexers.Fallback - } - - if err != nil { - logger.Fatal(err) - } - - var formatter = chromahtml.New( - chromahtml.WithLineNumbers(true), - chromahtml.WithClasses(true), - chromahtml.WithLinkableLineNumbers(true, ""), - ) - - if formatter == nil { - logger.Fatal("Could not get html formatter") - } - - iterator, err := lexer.Tokenise(nil, fmt.Sprintf("%s", blob.Contents())) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - return - } - - sbuilder := new(strings.Builder) - formatter.Format(sbuilder, styles.Fallback, iterator) - - w.WriteHeader(http.StatusOK) - - tmpl := template.Must(template.ParseFiles( - filepath.Join("templates", "file.html"), - filepath.Join("templates", "wrap.html"), - )) - - _, ishtmx := r.Header["Hx-Request"] - - data := FilePageData { - Name: reponame, - Content: template.HTML(sbuilder.String()), - Ref: ref.Id(), - } - - if ishtmx { - tmpl.ExecuteTemplate(w, "file_content", data) - } else { - tmpl.ExecuteTemplate(w, "file_full", data) - } + // logger := log.Default() + // vars := mux.Vars(r) + // reponame := vars["repository"] + // + // repo, err := checkRepo(reponame) + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // + // ref, err := repo.RevparseSingle(vars["ref"]) + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // + // commit, err := ref.AsCommit() + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // + // tree, err := commit.Tree() + // if err != nil { + // logger.Fatalf("Could not get tree") + // } + // + // // Get the path of the entry + // path := r.RequestURI[len("/repos/") + len(reponame) + len("/file/") + len(vars["ref"]) + 1:len(r.RequestURI)] + // logger.Printf("Trying to get file: %s (%s)", path, r.RequestURI) + // entry, err := tree.EntryByPath(path) + // if err != nil || entry.Type != git.ObjectBlob { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // + // blob, err := repo.LookupBlob(entry.Id) + // if err != nil { + // logger.Fatalf("Could not find file") + // } + // + // lexer := lexers.Match(path) + // if lexer == nil { + // lexer = lexers.Fallback + // } + // + // if err != nil { + // logger.Fatal(err) + // } + // + // var formatter = chromahtml.New( + // chromahtml.WithLineNumbers(true), + // chromahtml.WithClasses(true), + // chromahtml.WithLinkableLineNumbers(true, ""), + // ) + // + // if formatter == nil { + // logger.Fatal("Could not get html formatter") + // } + // + // iterator, err := lexer.Tokenise(nil, fmt.Sprintf("%s", blob.Contents())) + // if err != nil { + // w.WriteHeader(http.StatusInternalServerError) + // return + // } + // + // sbuilder := new(strings.Builder) + // formatter.Format(sbuilder, styles.Fallback, iterator) + // + // w.WriteHeader(http.StatusOK) + // + // tmpl := template.Must(template.ParseFiles( + // filepath.Join("templates", "file.html"), + // filepath.Join("templates", "wrap.html"), + // )) + // + // _, ishtmx := r.Header["Hx-Request"] + // + // data := FilePageData { + // Name: reponame, + // Content: template.HTML(sbuilder.String()), + // Ref: ref.Id(), + // } + // + // if ishtmx { + // tmpl.ExecuteTemplate(w, "file_content", data) + // } else { + // tmpl.ExecuteTemplate(w, "file_full", data) + // } } diff --git a/gitshow.go b/gitshow.go @@ -7,7 +7,7 @@ import ( "net/http" "os" "time" - "github.com/libgit2/git2go/v31" + "github.com/go-git/go-git/v5" "errors" "path/filepath" ) @@ -23,7 +23,7 @@ func checkRepo(reponame string) (repo *git.Repository, err error) { scanner := bufio.NewScanner(content) for scanner.Scan() { if scanner.Text() == reponame { - return git.OpenRepositoryExtended(filepath.Join("repositories", reponame), git.RepositoryOpenBare | git.RepositoryOpenNoSearch, "") + return git.PlainOpen(filepath.Join("repositories", reponame)) } } diff --git a/go.mod b/go.mod @@ -4,12 +4,32 @@ go 1.21.7 require ( github.com/alecthomas/chroma/v2 v2.13.0 + github.com/go-git/go-git/v5 v5.12.0 github.com/gorilla/mux v1.8.1 github.com/libgit2/git2go/v31 v31.7.9 ) require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v1.0.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/dlclark/regexp2 v1.11.0 // indirect - golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect - golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/tools v0.13.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum @@ -1,27 +1,165 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= +github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU= github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI= github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= +github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/libgit2/git2go/v31 v31.7.9 h1:RUDiYm7+i3GY414acI31oDD8x5P0PZyWeZZfwpPuynE= github.com/libgit2/git2go/v31 v31.7.9/go.mod h1:c/rkJcBcUFx6wHaT++UwNpKvIsmPNqCeQ/vzO4DrEec= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k= golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201204225414-ed752295db88 h1:KmZPnMocC93w341XZp26yTJg8Za7lhb2KhkYmixoeso= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/log.go b/log.go @@ -4,15 +4,16 @@ import ( // "fmt" "log" "net/http" - "github.com/libgit2/git2go/v31" "path/filepath" + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/go-git/go-git/v5/plumbing" "html/template" ) type LogPageData struct { Name string - State string - Commits []*git.Commit + Commits []*object.Commit } func getLog(w http.ResponseWriter, r *http.Request) { @@ -33,18 +34,25 @@ func getLog(w http.ResponseWriter, r *http.Request) { return } - commit, err := repo.LookupCommit(head.Target()) + hash, err := repo.ResolveRevision(plumbing.Revision(head.Strings()[0])) if err != nil { logger.Fatal(err) } - var commits []*git.Commit = make([]*git.Commit, 0) + // commit, err := repo.LookupCommit(head.Target()) + // if err != nil { + // logger.Fatal(err) + // } + // + var commits []*object.Commit = make([]*object.Commit, 0) + cIter, err := repo.Log(&git.LogOptions { + From: *hash, + }) - for commit.ParentCount() > 0 { + cIter.ForEach(func(commit *object.Commit) error { commits = append(commits, commit) - commit = commit.Parent(0) - } - commits = append(commits, commit) + return nil + }) tmpl := template.Must(template.ParseFiles( filepath.Join("templates", "log.html"), @@ -56,12 +64,11 @@ func getLog(w http.ResponseWriter, r *http.Request) { data := LogPageData { Name: vars["repository"], Commits: commits, - State: "log", } if ishtmx { tmpl.ExecuteTemplate(w, "log_content", data) } else { tmpl.ExecuteTemplate(w, "log_full", data) - } + } } diff --git a/repo.go b/repo.go @@ -1,19 +1,17 @@ package main import ( "github.com/gorilla/mux" - "fmt" "log" "net/http" - "github.com/libgit2/git2go/v31" "path/filepath" + "github.com/go-git/go-git/v5/plumbing" "html/template" ) type RepoPageData struct { Name string - Repo *git.Repository + Refname string Readme string - State string } func getRepo(w http.ResponseWriter, r *http.Request) { @@ -35,31 +33,30 @@ func getRepo(w http.ResponseWriter, r *http.Request) { return } - oid := head.Target() - - commit, err := repo.LookupCommit(oid) + hash, err := repo.ResolveRevision(plumbing.Revision(head.Strings()[0])) if err != nil { logger.Fatal(err) } - tree, err := commit.Tree() + commit, err := repo.CommitObject(*hash) if err != nil { logger.Fatal(err) } - entry, err := tree.EntryByPath("README") + readmef, err := commit.File("README") - var readme string + isbinary, err := readmef.IsBinary() if err != nil { + logger.Fatal(err) + } + + var readme string + if err != nil || isbinary { readme = "No readme" } else { - blob, err := repo.LookupBlob(entry.Id) + readme, err = readmef.Contents() if err != nil { logger.Fatal(err) - } else if blob.IsBinary() { - readme = "Binary readme" - } else { - readme = fmt.Sprintf("%s", blob.Contents()) } } @@ -74,9 +71,8 @@ func getRepo(w http.ResponseWriter, r *http.Request) { data := RepoPageData { Name: reponame, - Repo: repo, + Refname: head.Name().Short(), Readme: readme, - State: "about", } if ishtmx { diff --git a/static/style.css b/static/style.css @@ -32,6 +32,10 @@ padding-right: 20px; } +.commit-message { + width: 30em; +} + /* Inspired from HTMX tab example */ #tab-list { border-bottom: solid 3px lightgray; diff --git a/templates/log.html b/templates/log.html @@ -8,8 +8,10 @@ <table> {{range .Commits}} <tr> - <td class="commit-hash" hx-push-url=true hx-get="/repos/{{$repoName}}/commit/{{.Id.String}}">{{.ShortId}}</td> - <td>{{.Message}}</td> + <td class="commit-hash" hx-push-url=true + hx-get="/repos/{{$repoName}}/commit/{{.Hash.String}}">{{.Hash.String}}</td> + <td class="commit-message">{{.Message}}</td> + <td class="commit-author">{{.Author.Name}}</td> </tr> {{end}} </table> diff --git a/templates/repo.html b/templates/repo.html @@ -2,7 +2,7 @@ <div id="tab-list" role="tablist" hx-push-url="true"> <button hx-get="/repos/{{.Name}}" class="selected">about</button> <button hx-get="/repos/{{.Name}}/log">log</button> - <button hx-get="/repos/{{.Name}}/tree/{{.Repo.Head.Shorthand}}">tree</button> + <button hx-get="/repos/{{.Name}}/tree/{{.Refname}}">tree</button> </div> <pre> {{.Readme}} diff --git a/tree.go b/tree.go @@ -1,13 +1,13 @@ package main import ( - "github.com/gorilla/mux" + // "github.com/gorilla/mux" // "fmt" "github.com/libgit2/git2go/v31" - "html/template" - "log" + // "html/template" + // "log" "net/http" - "path/filepath" + // "path/filepath" ) type TreePageData struct { @@ -17,99 +17,99 @@ type TreePageData struct { } func getTree(w http.ResponseWriter, r *http.Request) { - logger := log.Default() - vars := mux.Vars(r) - reponame := vars["repository"] - - repo, err := checkRepo(reponame) - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - - var commit *git.Commit - refname, present := vars["ref"] - - if !present { - head, err := repo.Head() - if err != nil { - // TODO: handle no head - w.WriteHeader(http.StatusInternalServerError) - return - } - - branch := head.Branch() - // Now get the corresponding commit - ref, err := branch.Resolve() - if err != nil { - logger.Fatalf("Malformed repository") - } - - commit, err = repo.LookupCommit(ref.Target()) - if err != nil { - logger.Fatalf("Could not get commit") - } - } else { - obj, err := repo.RevparseSingle(refname) - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - commit, err = obj.AsCommit() - if err != nil { - w.WriteHeader(http.StatusNotFound) - return - } - } - logger.Printf("Called %s: ref to %s", refname, commit.Id().String()) - - tree, err := commit.Tree() - if err != nil { - logger.Fatalf("Could not get tree") - } - - url, err := reporouter.Get("tree").URL("repository", reponame, "ref", commit.Id().String()) - if err != nil { - logger.Fatalf("Could not generate URL") - } - - url.Host = r.URL.Host - url.Scheme = r.URL.Scheme - - w.Header().Add("HX-Push-Url", url.String()) - w.WriteHeader(http.StatusOK) - - tmpl := template.Must(template.New("tree_root").Funcs(template.FuncMap{ - "isFile": func(obj *git.TreeEntry) bool { - blob, err := repo.LookupBlob(obj.Id) - if err != nil { - return false - } - - - return obj.Type == git.ObjectBlob && !blob.IsBinary() - }, - }).ParseFiles( - filepath.Join("templates", "tree.html"), - filepath.Join("templates", "wrap.html"), - )) - - _, ishtmx := r.Header["Hx-Request"] - - var entries []*git.TreeEntry = make([]*git.TreeEntry, 0) - for i := uint64(0); i < tree.EntryCount(); i++ { - entries = append(entries, tree.EntryByIndex(i)) - } - - data := TreePageData{ - Name: reponame, - Entries: entries, - Ref: commit.Id(), - } - - if ishtmx { - tmpl.ExecuteTemplate(w, "tree_content", data) - } else { - tmpl.ExecuteTemplate(w, "tree_full", data) - } + // logger := log.Default() + // vars := mux.Vars(r) + // reponame := vars["repository"] + // + // repo, err := checkRepo(reponame) + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // + // var commit *git.Commit + // refname, present := vars["ref"] + // + // if !present { + // head, err := repo.Head() + // if err != nil { + // // TODO: handle no head + // w.WriteHeader(http.StatusInternalServerError) + // return + // } + // + // branch := head.Branch() + // // Now get the corresponding commit + // ref, err := branch.Resolve() + // if err != nil { + // logger.Fatalf("Malformed repository") + // } + // + // commit, err = repo.LookupCommit(ref.Target()) + // if err != nil { + // logger.Fatalf("Could not get commit") + // } + // } else { + // obj, err := repo.RevparseSingle(refname) + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // commit, err = obj.AsCommit() + // if err != nil { + // w.WriteHeader(http.StatusNotFound) + // return + // } + // } + // logger.Printf("Called %s: ref to %s", refname, commit.Id().String()) + // + // tree, err := commit.Tree() + // if err != nil { + // logger.Fatalf("Could not get tree") + // } + // + // url, err := reporouter.Get("tree").URL("repository", reponame, "ref", commit.Id().String()) + // if err != nil { + // logger.Fatalf("Could not generate URL") + // } + // + // url.Host = r.URL.Host + // url.Scheme = r.URL.Scheme + // + // w.Header().Add("HX-Push-Url", url.String()) + // w.WriteHeader(http.StatusOK) + // + // tmpl := template.Must(template.New("tree_root").Funcs(template.FuncMap{ + // "isFile": func(obj *git.TreeEntry) bool { + // blob, err := repo.LookupBlob(obj.Id) + // if err != nil { + // return false + // } + // + // + // return obj.Type == git.ObjectBlob && !blob.IsBinary() + // }, + // }).ParseFiles( + // filepath.Join("templates", "tree.html"), + // filepath.Join("templates", "wrap.html"), + // )) + // + // _, ishtmx := r.Header["Hx-Request"] + // + // var entries []*git.TreeEntry = make([]*git.TreeEntry, 0) + // for i := uint64(0); i < tree.EntryCount(); i++ { + // entries = append(entries, tree.EntryByIndex(i)) + // } + // + // data := TreePageData{ + // Name: reponame, + // Entries: entries, + // Ref: commit.Id(), + // } + // + // if ishtmx { + // tmpl.ExecuteTemplate(w, "tree_content", data) + // } else { + // tmpl.ExecuteTemplate(w, "tree_full", data) + // } }