ronantakizawa/codereview-bench huggingface dataset:
Repository: gogs/gogs
File: docker/runtime/backup-job.sh (Shell)

Code before:
#!/usr/bin/env sh

execute_backup_job() {
	BACKUP_ARG_PATH="${1:-}"
	BACKUP_ARG_CONFIG="${BACKUP_ARG_CONFIG:-}"
	BACKUP_ARG_EXCLUDE_REPOS="${BACKUP_ARG_EXCLUDE_REPOS:-}"
	BACKUP_EXTRA_ARGS="${BACKUP_EXTRA_ARGS:-}"
	cd "/app/gogs" || exit 1

	BACKUP_ARGS="--target=${BACKUP_ARG_PATH}"

	if [ -n "${BACKUP_ARG_CONFIG}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --config=${BACKUP_ARG_CONFIG}"
	fi

	if [ -n "${BACKUP_ARG_EXCLUDE_REPOS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --exclude-repos=${BACKUP_ARG_EXCLUDE_REPOS}"
	fi

	if [ -n "${BACKUP_EXTRA_ARGS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} ${BACKUP_EXTRA_ARGS}"
	fi

	./gogs backup ${BACKUP_ARGS} || echo "Error: Backup job returned non-successful code." && exit 1
}

main() {
	BACKUP_PATH="${1:-}"

	if [ -z "${BACKUP_PATH}" ]; then
		echo "Required argument missing BACKUP_PATH" 1>&2
		exit 1
	fi

	execute_backup_job "${BACKUP_PATH}"
}

main "$@"


Review comment (bug):
```suggestion
	./gogs backup "${BACKUP_ARGS}" || echo "Error: Backup job returned non-successful code." && exit 1
```

Is removing the double quotes here on purpose (i.e. fix the bug you mentioned)? Because shell lint is complaining about it.

Code after:
#!/usr/bin/env sh

execute_backup_job() {
	BACKUP_ARG_PATH="${1:-}"
	BACKUP_ARG_CONFIG="${BACKUP_ARG_CONFIG:-}"
	BACKUP_ARG_EXCLUDE_REPOS="${BACKUP_ARG_EXCLUDE_REPOS:-}"
	BACKUP_EXTRA_ARGS="${BACKUP_EXTRA_ARGS:-}"
	cd "/app/gogs" || exit 1

	BACKUP_ARGS="--target=${BACKUP_ARG_PATH}"

	if [ -n "${BACKUP_ARG_CONFIG}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --config=${BACKUP_ARG_CONFIG}"
	fi

	if [ -n "${BACKUP_ARG_EXCLUDE_REPOS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --exclude-repos=${BACKUP_ARG_EXCLUDE_REPOS}"
	fi

	if [ -n "${BACKUP_EXTRA_ARGS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} ${BACKUP_EXTRA_ARGS}"
	fi

	# NOTE: We actually need word splitting to be able to pass multiple arguments.
	# shellcheck disable=SC2086
	./gogs backup ${BACKUP_ARGS} || echo "Error: Backup job returned non-successful code." && exit 1
}

main() {
	BACKUP_PATH="${1:-}"

	if [ -z "${BACKUP_PATH}" ]; then
		echo "Required argument missing BACKUP_PATH" 1>&2
		exit 1
	fi

	execute_backup_job "${BACKUP_PATH}"
}

main "$@"
Repository: gogs/gogs
File: docker/runtime/backup-job.sh (Shell)

Code before:
#!/usr/bin/env sh

execute_backup_job() {
	BACKUP_ARG_PATH="${1:-}"
	BACKUP_ARG_CONFIG="${BACKUP_ARG_CONFIG:-}"
	BACKUP_ARG_EXCLUDE_REPOS="${BACKUP_ARG_EXCLUDE_REPOS:-}"
	BACKUP_EXTRA_ARGS="${BACKUP_EXTRA_ARGS:-}"
	cd "/app/gogs" || exit 1

	BACKUP_ARGS="--target=${BACKUP_ARG_PATH}"

	if [ -n "${BACKUP_ARG_CONFIG}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --config=${BACKUP_ARG_CONFIG}"
	fi

	if [ -n "${BACKUP_ARG_EXCLUDE_REPOS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --exclude-repos=${BACKUP_ARG_EXCLUDE_REPOS}"
	fi

	if [ -n "${BACKUP_EXTRA_ARGS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} ${BACKUP_EXTRA_ARGS}"
	fi

	./gogs backup ${BACKUP_ARGS} || echo "Error: Backup job returned non-successful code." && exit 1
}

main() {
	BACKUP_PATH="${1:-}"

	if [ -z "${BACKUP_PATH}" ]; then
		echo "Required argument missing BACKUP_PATH" 1>&2
		exit 1
	fi

	execute_backup_job "${BACKUP_PATH}"
}

main "$@"


Review comment (suggestion):
```suggestion
	# NOTE: We actually need word splitting to be able to pass multiple arguments.
	# shellcheck disable=SC2086
	./gogs backup ${BACKUP_ARGS} || echo "Error: Backup job returned non-successful code." && exit 1
```

Code after:
#!/usr/bin/env sh

execute_backup_job() {
	BACKUP_ARG_PATH="${1:-}"
	BACKUP_ARG_CONFIG="${BACKUP_ARG_CONFIG:-}"
	BACKUP_ARG_EXCLUDE_REPOS="${BACKUP_ARG_EXCLUDE_REPOS:-}"
	BACKUP_EXTRA_ARGS="${BACKUP_EXTRA_ARGS:-}"
	cd "/app/gogs" || exit 1

	BACKUP_ARGS="--target=${BACKUP_ARG_PATH}"

	if [ -n "${BACKUP_ARG_CONFIG}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --config=${BACKUP_ARG_CONFIG}"
	fi

	if [ -n "${BACKUP_ARG_EXCLUDE_REPOS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} --exclude-repos=${BACKUP_ARG_EXCLUDE_REPOS}"
	fi

	if [ -n "${BACKUP_EXTRA_ARGS}" ]; then
		BACKUP_ARGS="${BACKUP_ARGS} ${BACKUP_EXTRA_ARGS}"
	fi

	# NOTE: We actually need word splitting to be able to pass multiple arguments.
	# shellcheck disable=SC2086
	./gogs backup ${BACKUP_ARGS} || echo "Error: Backup job returned non-successful code." && exit 1
}

main() {
	BACKUP_PATH="${1:-}"

	if [ -z "${BACKUP_PATH}" ]; then
		echo "Required argument missing BACKUP_PATH" 1>&2
		exit 1
	fi

	execute_backup_job "${BACKUP_PATH}"
}

main "$@"
Repository: gogs/gogs
File: internal/route/api/v1/repo/blob.go (Go)

Code before:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params("username"), c.Params("reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		Sha      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
	}

	c.JSONSuccess(&repoGitBlob{

Review comment (suggestion):
```suggestion
	gitRepo, err := git.Open(c.Repo.Repository.RepoPath())
```

Code after:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
	}
Repository: gogs/gogs
File: internal/route/api/v1/repo/blob.go (Go)

Code before:

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params("username"), c.Params("reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		Sha      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
	}

	c.JSONSuccess(&repoGitBlob{
		Content:  base64.StdEncoding.EncodeToString(content),
		Encoding: "base64",
		URL:      fmt.Sprintf("%s/repos/%s/%s/git/blobs/%s", c.BaseURL, c.Params(":username"), c.Params(":reponame"), sha),
		Sha:      sha,
		Size:     blob.Size(),
	})
}


Review comment (suggestion):
```suggestion
		SHA      string `json:"sha"`
```

Code after:

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
	}

	c.JSONSuccess(&repoGitBlob{
		Content:  base64.StdEncoding.EncodeToString(content),
		Encoding: "base64",
		URL:      fmt.Sprintf("%s/repos/%s/%s/git/blobs/%s", c.BaseURL, c.Params(":username"), c.Params(":reponame"), sha),
		SHA:      sha,
		Size:     blob.Size(),
	})
}
Repository: gogs/gogs
File: internal/route/api/v1/repo/blob.go (Go)

Code before:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params("username"), c.Params("reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		Sha      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
	}

	c.JSONSuccess(&repoGitBlob{
		Content:  base64.StdEncoding.EncodeToString(content),
		Encoding: "base64",
		URL:      fmt.Sprintf("%s/repos/%s/%s/git/blobs/%s", c.BaseURL, c.Params(":username"), c.Params(":reponame"), sha),
		Sha:      sha,
		Size:     blob.Size(),
	})
}


Review comment (suggestion):
```suggestion
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
```

Code after:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
	}

	c.JSONSuccess(&repoGitBlob{
		Content:  base64.StdEncoding.EncodeToString(content),
		Encoding: "base64",
		URL:      fmt.Sprintf("%s/repos/%s/%s/git/blobs/%s", c.BaseURL, c.Params(":username"), c.Params(":reponame"), sha),
		SHA:      sha,
		Size:     blob.Size(),
	})
}
Repository: gogs/gogs
File: internal/route/api/v1/repo/blob.go (Go)

Code before:

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params("username"), c.Params("reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		Sha      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
	}

	c.JSONSuccess(&repoGitBlob{
		Content:  base64.StdEncoding.EncodeToString(content),
		Encoding: "base64",
		URL:      fmt.Sprintf("%s/repos/%s/%s/git/blobs/%s", c.BaseURL, c.Params(":username"), c.Params(":reponame"), sha),
		Sha:      sha,
		Size:     blob.Size(),
	})
}


Review comment (suggestion):
```suggestion
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
```

Code after:

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
	}

	c.JSONSuccess(&repoGitBlob{
		Content:  base64.StdEncoding.EncodeToString(content),
		Encoding: "base64",
		URL:      fmt.Sprintf("%s/repos/%s/%s/git/blobs/%s", c.BaseURL, c.Params(":username"), c.Params(":reponame"), sha),
		SHA:      sha,
		Size:     blob.Size(),
	})
}
Repository: gogs/gogs
File: internal/route/api/v1/repo/blob.go (Go)

Code before:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(c.Repo.Repository.RepoPath())
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
	}

Review comment (suggestion):
```suggestion
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
```

Code after:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob content")
		return
Repository: gogs/gogs
File: internal/route/api/v1/repo/blob.go (Go)

Code before:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(c.Repo.Repository.RepoPath())
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}

	content, err := blob.Blob().Bytes()

Review comment (suggestion):
```suggestion
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
```

Code after:
package repo

import (
	"encoding/base64"
	"fmt"

	"github.com/gogs/git-module"

	"gogs.io/gogs/internal/context"
	"gogs.io/gogs/internal/gitutil"
	"gogs.io/gogs/internal/repoutil"
)

func RepoGitBlob(c *context.APIContext) {
	gitRepo, err := git.Open(repoutil.RepositoryPath(c.Params(":username"), c.Params(":reponame")))
	if err != nil {
		c.Error(err, "open repository")
		return
	}

	sha := c.Params(":sha")
	blob, err := gitRepo.CatFileBlob(sha)
	if err != nil {
		c.NotFoundOrError(gitutil.NewError(err), "get blob")
		return
	}

	type repoGitBlob struct {
		Content  string `json:"content"`
		Encoding string `json:"encoding"`
		URL      string `json:"url"`
		SHA      string `json:"sha"`
		Size     int64  `json:"size"`
	}
Repository: gogs/gogs
File: internal/route/lfs/basic.go (Go)

Code before:
	if err != nil {
		// NOTE: It is OK to leave the file when the whole operation failed
		// with a DB error, a retry on client side can safely overwrite the
		// same file as OID is seen as unique to every file.
		internalServerError(c.Resp)
		log.Error("Failed to create object [repo_id: %d, oid: %s]: %v", repo.ID, oid, err)
		return
	}
	c.Status(http.StatusOK)

	log.Trace("[LFS] Object created %q", oid)
}

// POST /{owner}/{repo}.git/info/lfs/object/basic/verify
func (*basicHandler) serveVerify(c *macaron.Context, repo *db.Repository) {
	var request basicVerifyRequest
	
	defer func() {
		err := c.Req.Request.Body.Close()
		if err != nil {
			responseJSON(c.Resp, http.StatusBadRequest, responseError{
				Message: strutil.ToUpperFirst(err.Error()),
			})
			return
		}
	}()

	err := json.NewDecoder(c.Req.Request.Body).Decode(&request)
	if err != nil {
		responseJSON(c.Resp, http.StatusBadRequest, responseError{
			Message: strutil.ToUpperFirst(err.Error()),
		})
		return
	}

	if !lfsutil.ValidOID(request.Oid) {
		responseJSON(c.Resp, http.StatusBadRequest, responseError{
			Message: "Invalid oid",
		})
		return
	}

	object, err := db.LFS.GetObjectByOID(c.Req.Context(), repo.ID, request.Oid)
	if err != nil {
		if db.IsErrLFSObjectNotExist(err) {
			responseJSON(c.Resp, http.StatusNotFound, responseError{
				Message: "Object does not exist",
			})
		} else {
			internalServerError(c.Resp)
			log.Error("Failed to get object [repo_id: %d, oid: %s]: %v", repo.ID, request.Oid, err)

Review comment (suggestion):
```suggestion
	defer func() { _ = c.Req.Request.Body.Close() }()
```

Code after:
	if err != nil {
		// NOTE: It is OK to leave the file when the whole operation failed
		// with a DB error, a retry on client side can safely overwrite the
		// same file as OID is seen as unique to every file.
		internalServerError(c.Resp)
		log.Error("Failed to create object [repo_id: %d, oid: %s]: %v", repo.ID, oid, err)
		return
	}
	c.Status(http.StatusOK)

	log.Trace("[LFS] Object created %q", oid)
}

// POST /{owner}/{repo}.git/info/lfs/object/basic/verify
func (*basicHandler) serveVerify(c *macaron.Context, repo *db.Repository) {
	var request basicVerifyRequest
	defer func() { _ = c.Req.Request.Body.Close() }()

	err := json.NewDecoder(c.Req.Request.Body).Decode(&request)
	if err != nil {
		responseJSON(c.Resp, http.StatusBadRequest, responseError{
			Message: strutil.ToUpperFirst(err.Error()),
		})
		return
	}

	if !lfsutil.ValidOID(request.Oid) {
		responseJSON(c.Resp, http.StatusBadRequest, responseError{
			Message: "Invalid oid",
		})
		return
	}

	object, err := db.LFS.GetObjectByOID(c.Req.Context(), repo.ID, request.Oid)
	if err != nil {
		if db.IsErrLFSObjectNotExist(err) {
			responseJSON(c.Resp, http.StatusNotFound, responseError{
				Message: "Object does not exist",
			})
		} else {
			internalServerError(c.Resp)
			log.Error("Failed to get object [repo_id: %d, oid: %s]: %v", repo.ID, request.Oid, err)
		}
		return
	}

	if object.Size != request.Size {
		responseJSON(c.Resp, http.StatusBadRequest, responseError{
			Message: "Object size mismatch",
		})
		return
Repository: gogs/gogs
File: internal/database/repo.go (Go)

Code before:
	}

	return repo.loadAttributes(e)
}

type ErrReachLimitOfRepo struct {
	Limit int
}

func IsErrReachLimitOfRepo(err error) bool {
	_, ok := err.(ErrReachLimitOfRepo)
	return ok
}

func (err ErrReachLimitOfRepo) Error() string {
	return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
}

// CreateRepository creates a repository for given user or organization.
func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repository, err error) {
	if !owner.canCreateRepo() {
		return nil, ErrReachLimitOfRepo{Limit: owner.maxNumRepos()}
	}
	repoPath := RepoPath(owner.Name, opts.Name)
	if osutil.IsExist(repoPath) {
		return nil, fmt.Errorf("repository directory already exists: %s", repoPath)
	}
	repo := &Repository{
		OwnerID:      owner.ID,
		Owner:        owner,
		Name:         opts.Name,
		LowerName:    strings.ToLower(opts.Name),
		Description:  opts.Description,
		IsPrivate:    opts.IsPrivate,
		IsUnlisted:   opts.IsUnlisted,
		EnableWiki:   true,
		EnableIssues: true,
		EnablePulls:  true,
	}

	sess := x.NewSession()
	defer sess.Close()
	if err = sess.Begin(); err != nil {
		return nil, err
	}

	if err = createRepository(sess, doer, owner, repo); err != nil {
		return nil, err
	}

	// No need for init mirror.

Review comment (suggestion):
Since we are touching this line, let's use `github.com/pkg/errors` package:
```suggestion
		return nil, errors.Errorf("repository directory already exists: %s", repoPath)
```

Code after:
	}

	return repo.loadAttributes(e)
}

type ErrReachLimitOfRepo struct {
	Limit int
}

func IsErrReachLimitOfRepo(err error) bool {
	_, ok := err.(ErrReachLimitOfRepo)
	return ok
}

func (err ErrReachLimitOfRepo) Error() string {
	return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
}

// CreateRepository creates a repository for given user or organization.
func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repository, err error) {
	repoPath := RepoPath(owner.Name, opts.Name)
	if osutil.IsExist(repoPath) {
		return nil, errors.Errorf("repository directory already exists: %s", repoPath)
	}
	if !owner.canCreateRepo() {
		return nil, ErrReachLimitOfRepo{Limit: owner.maxNumRepos()}
	}

	repo := &Repository{
		OwnerID:      owner.ID,
		Owner:        owner,
		Name:         opts.Name,
		LowerName:    strings.ToLower(opts.Name),
		Description:  opts.Description,
		IsPrivate:    opts.IsPrivate,
		IsUnlisted:   opts.IsUnlisted,
		EnableWiki:   true,
		EnableIssues: true,
		EnablePulls:  true,
	}

	sess := x.NewSession()
	defer sess.Close()
	if err = sess.Begin(); err != nil {
		return nil, err
	}

	if err = createRepository(sess, doer, owner, repo); err != nil {
		return nil, err
	}