From df60de22bc5376c3dab6f7439b1abb001876e04e Mon Sep 17 00:00:00 2001 From: DmitryFrolovTri <23313323+DmitryFrolovTri@users.noreply.github.com> Date: Sat, 12 Nov 2022 23:47:06 +0000 Subject: [PATCH] Fixing Merge errors - still few to go --- models/repo/repo.go | 2 +- modules/git/repo.go | 73 ++++++---------------------- routers/api/v1/repo/repo.go | 2 +- routers/private/hook_pre_receive.go | 6 ++- routers/web/repo/setting.go | 2 +- templates/repo/settings/options.tmpl | 4 +- 6 files changed, 25 insertions(+), 64 deletions(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 99289f4f1ef..bcf315c6740 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -522,7 +522,7 @@ func (repo *Repository) computeSize() (int64, error) { return 0, fmt.Errorf("computeSize: %v", err) } - objs, err := repo.GetLFSMetaObjects(-1, 0) + objs, err := repo.GetLFSMetaObjects(repo.ID, -1, 0) if err != nil { return 0, fmt.Errorf("computeSize: GetLFSMetaObjects: %v", err) } diff --git a/modules/git/repo.go b/modules/git/repo.go index c5be571a051..c6e080da764 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -257,50 +257,6 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error { return err } -// CheckoutOptions options when heck out some branch -type CheckoutOptions struct { - Timeout time.Duration - Branch string - OldBranch string -} - -// Checkout checkouts a branch -func Checkout(repoPath string, opts CheckoutOptions) error { - cmd := NewCommand("checkout") - if len(opts.OldBranch) > 0 { - cmd.AddArguments("-b") - } - - if opts.Timeout <= 0 { - opts.Timeout = -1 - } - - cmd.AddArguments(opts.Branch) - - if len(opts.OldBranch) > 0 { - cmd.AddArguments(opts.OldBranch) - } - - _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) - return err -} - -// ResetHEAD resets HEAD to given revision or head of branch. -func ResetHEAD(repoPath string, hard bool, revision string) error { - cmd := NewCommand("reset") - if hard { - cmd.AddArguments("--hard") - } - _, err := cmd.AddArguments(revision).RunInDir(repoPath) - return err -} - -// MoveFile moves a file to another file or directory. -func MoveFile(repoPath, oldTreeName, newTreeName string) error { - _, err := NewCommand("mv").AddArguments(oldTreeName, newTreeName).RunInDir(repoPath) - return err -} - // CountObject represents repository count objects report type CountObject struct { Count int64 @@ -325,14 +281,14 @@ const ( ) // CountObjects returns the results of git count-objects on the repoPath -func CountObjects(repoPath string) (*CountObject, error) { - return CountObjectsWithEnv(repoPath, nil) +func CountObjects(ctx context.Context, repoPath string) (*CountObject, error) { + return CountObjectsWithEnv(ctx, repoPath, nil) } // CountObjectsWithEnv returns the results of git count-objects on the repoPath with custom env setup -func CountObjectsWithEnv(repoPath string, env []string) (*CountObject, error) { - cmd := NewCommand("count-objects", "-v") - stdout, err := cmd.RunInDirWithEnv(repoPath, env) +func CountObjectsWithEnv(ctx context.Context, repoPath string, env []string) (*CountObject, error) { + cmd := NewCommand(ctx, "count-objects", "-v") + stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath, Env: env}) if err != nil { return nil, err } @@ -346,21 +302,24 @@ func parseSize(objects string) *CountObject { for _, line := range strings.Split(objects, "\n") { switch { case strings.HasPrefix(line, statCount): - repoSize.Count = com.StrTo(line[7:]).MustInt64() + repoSize.Count, _ = strconv.ParseInt(line[7:], 10, 64) case strings.HasPrefix(line, statSize): - repoSize.Size = com.StrTo(line[6:]).MustInt64() * 1024 + number, _ := strconv.ParseInt(line[6:], 10, 64) + repoSize.Size = number * 1024 case strings.HasPrefix(line, statInpack): - repoSize.InPack = com.StrTo(line[9:]).MustInt64() + repoSize.InPack, _ = strconv.ParseInt(line[9:], 10, 64) case strings.HasPrefix(line, statPacks): - repoSize.Packs = com.StrTo(line[7:]).MustInt64() + repoSize.Packs, _ = strconv.ParseInt(line[7:], 10, 64) case strings.HasPrefix(line, statSizePack): - repoSize.SizePack = com.StrTo(line[11:]).MustInt64() * 1024 + number, _ := strconv.ParseInt(line[11:], 10, 64) + repoSize.SizePack = number * 1024 case strings.HasPrefix(line, statPrunePackage): - repoSize.PrunePack = com.StrTo(line[16:]).MustInt64() + repoSize.PrunePack, _ = strconv.ParseInt(line[16:], 10, 64) case strings.HasPrefix(line, statGarbage): - repoSize.Garbage = com.StrTo(line[9:]).MustInt64() + repoSize.Garbage, _ = strconv.ParseInt(line[9:], 10, 64) case strings.HasPrefix(line, statSizeGarbage): - repoSize.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024 + number, _ := strconv.ParseInt(line[14:], 10, 64) + repoSize.SizeGarbage = number * 1024 } } return repoSize diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 8f47f068649..66616d76128 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -719,7 +719,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err if opts.SizeLimit != nil { repo.SizeLimit = *opts.SizeLimit } - if err := models.UpdateRepository(repo, visibilityChanged); err != nil { + if err := repo_service.UpdateRepository(repo, visibilityChanged); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateRepository", err) return err diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index 821ea7b9fbf..1def8172089 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -114,9 +114,11 @@ func HookPreReceive(ctx *gitea_context.PrivateContext) { opts: opts, } - pushSize, err := git.CountObjectsWithEnv(repo.RepoPath(), env) + repo := ourCtx.Repo.Repository + + pushSize, err := git.CountObjectsWithEnv(ctx, repo.RepoPath(), ourCtx.env) if err != nil { - log.Error("Unable to get repository size with env %v: %s Error: %v", repo.RepoPath(), env, err) + log.Error("Unable to get repository size with env %v: %s Error: %v", repo.RepoPath(), ourCtx.env, err) ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ "err": err.Error(), }) diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 14822a15f1f..c794da3b70b 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -192,7 +192,7 @@ func SettingsPost(ctx *context.Context) { return } - if !ctx.User.IsAdmin && repo.SizeLimit != form.RepoSizeLimit { + if !ctx.Doer.IsAdmin && repo.SizeLimit != form.RepoSizeLimit { ctx.Data["Err_RepoSizeLimit"] = true ctx.RenderWithErr(ctx.Tr("repo.form.repo_size_limit_only_by_admins"), tplSettingsOptions, &form) return diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 8db03349819..eb86d95670b 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -18,10 +18,10 @@