From ef95802907e72bbea5174c46648ff8d28bf52d0d Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 20 Mar 2023 10:01:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Afiles=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/hat.go | 2 +- routers/hat/repo/file.go | 25 +++++-------------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/routers/hat/hat.go b/routers/hat/hat.go index e047e27..1e247b4 100644 --- a/routers/hat/hat.go +++ b/routers/hat/hat.go @@ -140,7 +140,7 @@ func Routers(ctx gocontext.Context) *web.Route { m.Post("", bind(hat_api.BatchChangeFileOptions{}), repo.BatchChangeFile) }, reqRepoWriter(unit.TypeCode), reqToken()) }, reqRepoReader(unit.TypeCode)) - m.Get("/find", reqRepoReader(unit.TypeCode), repo.FindFiles) + m.Get("/find", context.RepoRef(), reqRepoReader(unit.TypeCode), repo.FindFiles) m.Group("/git", func() { m.Group("/commits", func() { m.Get("/{sha}", repo.GetSingleCommit) diff --git a/routers/hat/repo/file.go b/routers/hat/repo/file.go index 6a1fead..e7b03bc 100644 --- a/routers/hat/repo/file.go +++ b/routers/hat/repo/file.go @@ -266,12 +266,10 @@ func FindFiles(ctx *context.APIContext) { keyWords := ctx.FormString("q") var fileList []*SearchFileItem var err error - if keyWords != "" { - fileList, err = FindFileFromPath(ctx, treePath, ref, keyWords) - if err != nil { - ctx.Error(http.StatusInternalServerError, "FindFileFromPath", err) - return - } + fileList, err = FindFileFromPath(ctx, treePath, ref, keyWords) + if err != nil { + ctx.Error(http.StatusInternalServerError, "FindFileFromPath", err) + return } ctx.JSON(http.StatusOK, fileList) } @@ -287,18 +285,6 @@ type SearchFileItem struct { } func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileList []*SearchFileItem, err error) { - if ctx.Repo.GitRepo == nil { - ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) - if err != nil { - ctx.ServerError("OpenRepository", err) - return nil, err - } - defer func() { - if ctx.Repo.GitRepo != nil { - ctx.Repo.GitRepo.Close() - } - }() - } // get the commit object for the ref commit, err := ctx.Repo.GitRepo.GetCommit(ref) if err != nil { @@ -315,7 +301,7 @@ func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileL ctx.ServerError("ListEntries", err3) return nil, err3 } - fileList = make([]*SearchFileItem, 0, 0) + fileList = make([]*SearchFileItem, 0) for _, entry := range entries { if entry.IsDir() { @@ -345,7 +331,6 @@ func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileL Name: filename, Path: treePath, SHA: entry.ID.String(), - Type: entry.Type(), Size: entry.Size(), URL: &selfURLString, HTMLURL: &htmlURLString,