2020-09-25 00:09:23 -04:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-09-25 00:09:23 -04:00
|
|
|
|
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
2021-09-23 11:45:36 -04:00
|
|
|
"context"
|
2020-09-25 00:09:23 -04:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-10-31 19:16:48 -04:00
|
|
|
"path"
|
2020-09-25 00:09:23 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2021-09-19 07:49:59 -04:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2023-06-29 06:03:20 -04:00
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-24 04:49:20 -05:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-10-12 01:18:26 -04:00
|
|
|
"code.gitea.io/gitea/modules/container"
|
2020-09-25 00:09:23 -04:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
Simplify how git repositories are opened (#28937)
## Purpose
This is a refactor toward building an abstraction over managing git
repositories.
Afterwards, it does not matter anymore if they are stored on the local
disk or somewhere remote.
## What this PR changes
We used `git.OpenRepository` everywhere previously.
Now, we should split them into two distinct functions:
Firstly, there are temporary repositories which do not change:
```go
git.OpenRepository(ctx, diskPath)
```
Gitea managed repositories having a record in the database in the
`repository` table are moved into the new package `gitrepo`:
```go
gitrepo.OpenRepository(ctx, repo_model.Repo)
```
Why is `repo_model.Repository` the second parameter instead of file
path?
Because then we can easily adapt our repository storage strategy.
The repositories can be stored locally, however, they could just as well
be stored on a remote server.
## Further changes in other PRs
- A Git Command wrapper on package `gitrepo` could be created. i.e.
`NewCommand(ctx, repo_model.Repository, commands...)`. `git.RunOpts{Dir:
repo.RepoPath()}`, the directory should be empty before invoking this
method and it can be filled in the function only. #28940
- Remove the `RepoPath()`/`WikiPath()` functions to reduce the
possibility of mistakes.
---------
Co-authored-by: delvh <dev.lh@web.de>
2024-01-27 15:09:51 -05:00
|
|
|
"code.gitea.io/gitea/modules/gitrepo"
|
2020-09-25 00:09:23 -04:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2024-02-22 21:18:33 -05:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2021-11-16 08:30:11 -05:00
|
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
2020-09-25 00:09:23 -04:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
2023-09-05 14:37:47 -04:00
|
|
|
notify_service "code.gitea.io/gitea/services/notify"
|
2021-11-16 08:30:11 -05:00
|
|
|
|
2020-09-25 00:09:23 -04:00
|
|
|
"github.com/gobwas/glob"
|
|
|
|
)
|
|
|
|
|
2021-11-16 08:30:11 -05:00
|
|
|
// AdoptRepository adopts pre-existing repository files for the user/organization.
|
2023-09-06 08:08:51 -04:00
|
|
|
func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error) {
|
2020-09-25 00:09:23 -04:00
|
|
|
if !doer.IsAdmin && !u.CanCreateRepo() {
|
2021-12-12 10:48:20 -05:00
|
|
|
return nil, repo_model.ErrReachLimitOfRepo{
|
2020-09-25 00:09:23 -04:00
|
|
|
Limit: u.MaxRepoCreation,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(opts.DefaultBranch) == 0 {
|
|
|
|
opts.DefaultBranch = setting.Repository.DefaultBranch
|
|
|
|
}
|
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
repo := &repo_model.Repository{
|
2020-09-25 00:09:23 -04:00
|
|
|
OwnerID: u.ID,
|
|
|
|
Owner: u,
|
|
|
|
OwnerName: u.Name,
|
|
|
|
Name: opts.Name,
|
|
|
|
LowerName: strings.ToLower(opts.Name),
|
|
|
|
Description: opts.Description,
|
|
|
|
OriginalURL: opts.OriginalURL,
|
|
|
|
OriginalServiceType: opts.GitServiceType,
|
|
|
|
IsPrivate: opts.IsPrivate,
|
|
|
|
IsFsckEnabled: !opts.IsMirror,
|
|
|
|
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
|
|
|
|
Status: opts.Status,
|
|
|
|
IsEmpty: !opts.AutoInit,
|
|
|
|
}
|
|
|
|
|
2023-02-28 17:17:51 -05:00
|
|
|
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
2021-12-09 20:27:50 -05:00
|
|
|
repoPath := repo_model.RepoPath(u.Name, repo.Name)
|
2020-11-27 21:42:08 -05:00
|
|
|
isExist, err := util.IsExist(repoPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !isExist {
|
2021-12-09 20:27:50 -05:00
|
|
|
return repo_model.ErrRepoNotExist{
|
2020-09-25 00:09:23 -04:00
|
|
|
OwnerName: u.Name,
|
|
|
|
Name: repo.Name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-04 01:48:38 -05:00
|
|
|
if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true, false); err != nil {
|
2020-09-25 00:09:23 -04:00
|
|
|
return err
|
|
|
|
}
|
2023-06-26 02:59:15 -04:00
|
|
|
|
|
|
|
// Re-fetch the repository from database before updating it (else it would
|
|
|
|
// override changes that were done earlier with sql)
|
|
|
|
if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil {
|
|
|
|
return fmt.Errorf("getRepositoryByID: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := adoptRepository(ctx, repoPath, doer, repo, opts.DefaultBranch); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("createDelegateHooks: %w", err)
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
2023-06-26 02:59:15 -04:00
|
|
|
|
2022-06-06 04:01:49 -04:00
|
|
|
if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("checkDaemonExportOK: %w", err)
|
2021-10-13 15:47:02 -04:00
|
|
|
}
|
2020-09-25 00:09:23 -04:00
|
|
|
|
|
|
|
// Initialize Issue Labels if selected
|
|
|
|
if len(opts.IssueLabels) > 0 {
|
2022-03-29 03:23:45 -04:00
|
|
|
if err := repo_module.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("InitializeLabels: %w", err)
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 22:55:30 -04:00
|
|
|
if stdout, _, err := git.NewCommand(ctx, "update-server-info").
|
2020-09-25 00:09:23 -04:00
|
|
|
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
|
2022-03-31 22:55:30 -04:00
|
|
|
RunStdString(&git.RunOpts{Dir: repoPath}); err != nil {
|
2020-09-25 00:09:23 -04:00
|
|
|
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-09-05 14:37:47 -04:00
|
|
|
notify_service.AdoptRepository(ctx, doer, u, repo)
|
2021-11-16 08:30:11 -05:00
|
|
|
|
2020-09-25 00:09:23 -04:00
|
|
|
return repo, nil
|
|
|
|
}
|
|
|
|
|
2023-06-26 02:59:15 -04:00
|
|
|
func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, defaultBranch string) (err error) {
|
2021-11-16 08:30:11 -05:00
|
|
|
isExist, err := util.IsExist(repoPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !isExist {
|
|
|
|
return fmt.Errorf("adoptRepository: path does not already exist: %s", repoPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := repo_module.CreateDelegateHooks(repoPath); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("createDelegateHooks: %w", err)
|
2021-11-16 08:30:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
repo.IsEmpty = false
|
2022-01-19 18:26:57 -05:00
|
|
|
|
2023-06-26 02:59:15 -04:00
|
|
|
if len(defaultBranch) > 0 {
|
|
|
|
repo.DefaultBranch = defaultBranch
|
2021-11-16 08:30:11 -05:00
|
|
|
|
2024-03-08 02:30:10 -05:00
|
|
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
2021-11-16 08:30:11 -05:00
|
|
|
}
|
|
|
|
} else {
|
2024-03-08 02:30:10 -05:00
|
|
|
repo.DefaultBranch, err = gitrepo.GetDefaultBranch(ctx, repo)
|
2021-11-16 08:30:11 -05:00
|
|
|
if err != nil {
|
|
|
|
repo.DefaultBranch = setting.Repository.DefaultBranch
|
2024-03-08 02:30:10 -05:00
|
|
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
2021-11-16 08:30:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-29 06:03:20 -04:00
|
|
|
|
|
|
|
branches, _ := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{
|
2024-03-22 08:53:52 -04:00
|
|
|
RepoID: repo.ID,
|
|
|
|
ListOptions: db.ListOptionsAll,
|
2024-02-22 21:18:33 -05:00
|
|
|
IsDeletedBranch: optional.Some(false),
|
2023-06-29 06:03:20 -04:00
|
|
|
})
|
|
|
|
|
2021-11-16 08:30:11 -05:00
|
|
|
found := false
|
|
|
|
hasDefault := false
|
|
|
|
hasMaster := false
|
|
|
|
hasMain := false
|
|
|
|
for _, branch := range branches {
|
|
|
|
if branch == repo.DefaultBranch {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
} else if branch == setting.Repository.DefaultBranch {
|
|
|
|
hasDefault = true
|
|
|
|
} else if branch == "master" {
|
|
|
|
hasMaster = true
|
|
|
|
} else if branch == "main" {
|
|
|
|
hasMain = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
if hasDefault {
|
|
|
|
repo.DefaultBranch = setting.Repository.DefaultBranch
|
|
|
|
} else if hasMaster {
|
|
|
|
repo.DefaultBranch = "master"
|
|
|
|
} else if hasMain {
|
|
|
|
repo.DefaultBranch = "main"
|
|
|
|
} else if len(branches) > 0 {
|
|
|
|
repo.DefaultBranch = branches[0]
|
|
|
|
} else {
|
|
|
|
repo.IsEmpty = true
|
|
|
|
repo.DefaultBranch = setting.Repository.DefaultBranch
|
|
|
|
}
|
|
|
|
|
2024-03-08 02:30:10 -05:00
|
|
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
2021-11-16 08:30:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 04:01:49 -04:00
|
|
|
if err = repo_module.UpdateRepository(ctx, repo, false); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("updateRepository: %w", err)
|
2021-11-16 08:30:11 -05:00
|
|
|
}
|
|
|
|
|
2024-03-08 02:30:10 -05:00
|
|
|
// Don't bother looking this repo in the context it won't be there
|
|
|
|
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("openRepository: %w", err)
|
|
|
|
}
|
|
|
|
defer gitRepo.Close()
|
|
|
|
|
2023-09-25 09:17:37 -04:00
|
|
|
if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil {
|
2023-08-30 21:42:42 -04:00
|
|
|
return fmt.Errorf("SyncReleasesWithTags: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-16 08:30:11 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-25 00:09:23 -04:00
|
|
|
// DeleteUnadoptedRepository deletes unadopted repository files from the filesystem
|
2023-02-28 17:17:51 -05:00
|
|
|
func DeleteUnadoptedRepository(ctx context.Context, doer, u *user_model.User, repoName string) error {
|
2021-12-12 10:48:20 -05:00
|
|
|
if err := repo_model.IsUsableRepoName(repoName); err != nil {
|
2020-09-25 00:09:23 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
repoPath := repo_model.RepoPath(u.Name, repoName)
|
2020-11-27 21:42:08 -05:00
|
|
|
isExist, err := util.IsExist(repoPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !isExist {
|
2021-12-09 20:27:50 -05:00
|
|
|
return repo_model.ErrRepoNotExist{
|
2020-09-25 00:09:23 -04:00
|
|
|
OwnerName: u.Name,
|
|
|
|
Name: repoName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 14:14:26 -04:00
|
|
|
if exist, err := repo_model.IsRepositoryModelExist(ctx, u, repoName); err != nil {
|
2020-09-25 00:09:23 -04:00
|
|
|
return err
|
|
|
|
} else if exist {
|
2021-12-12 10:48:20 -05:00
|
|
|
return repo_model.ErrRepoAlreadyExist{
|
2020-09-25 00:09:23 -04:00
|
|
|
Uname: u.Name,
|
|
|
|
Name: repoName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return util.RemoveAll(repoPath)
|
|
|
|
}
|
|
|
|
|
2022-10-31 19:16:48 -04:00
|
|
|
type unadoptedRepositories struct {
|
2021-12-31 21:52:00 -05:00
|
|
|
repositories []string
|
|
|
|
index int
|
|
|
|
start int
|
|
|
|
end int
|
|
|
|
}
|
|
|
|
|
2022-10-31 19:16:48 -04:00
|
|
|
func (unadopted *unadoptedRepositories) add(repository string) {
|
2021-12-31 21:52:00 -05:00
|
|
|
if unadopted.index >= unadopted.start && unadopted.index < unadopted.end {
|
|
|
|
unadopted.repositories = append(unadopted.repositories, repository)
|
|
|
|
}
|
|
|
|
unadopted.index++
|
|
|
|
}
|
|
|
|
|
2023-02-28 17:17:51 -05:00
|
|
|
func checkUnadoptedRepositories(ctx context.Context, userName string, repoNamesToCheck []string, unadopted *unadoptedRepositories) error {
|
2021-12-31 21:52:00 -05:00
|
|
|
if len(repoNamesToCheck) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2023-02-28 17:17:51 -05:00
|
|
|
ctxUser, err := user_model.GetUserByName(ctx, userName)
|
2021-12-31 21:52:00 -05:00
|
|
|
if err != nil {
|
|
|
|
if user_model.IsErrUserNotExist(err) {
|
|
|
|
log.Debug("Missing user: %s", userName)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2023-10-15 11:46:06 -04:00
|
|
|
repos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{
|
2021-12-31 21:52:00 -05:00
|
|
|
Actor: ctxUser,
|
|
|
|
Private: true,
|
|
|
|
ListOptions: db.ListOptions{
|
|
|
|
Page: 1,
|
|
|
|
PageSize: len(repoNamesToCheck),
|
2022-01-20 12:46:10 -05:00
|
|
|
}, LowerNames: repoNamesToCheck,
|
|
|
|
})
|
2021-12-31 21:52:00 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(repos) == len(repoNamesToCheck) {
|
|
|
|
return nil
|
|
|
|
}
|
2022-10-12 01:18:26 -04:00
|
|
|
repoNames := make(container.Set[string], len(repos))
|
2021-12-31 21:52:00 -05:00
|
|
|
for _, repo := range repos {
|
2022-10-12 01:18:26 -04:00
|
|
|
repoNames.Add(repo.LowerName)
|
2021-12-31 21:52:00 -05:00
|
|
|
}
|
|
|
|
for _, repoName := range repoNamesToCheck {
|
2022-10-12 01:18:26 -04:00
|
|
|
if !repoNames.Contains(repoName) {
|
2022-10-31 19:16:48 -04:00
|
|
|
unadopted.add(path.Join(userName, repoName)) // These are not used as filepaths - but as reponames - therefore use path.Join not filepath.Join
|
2021-12-31 21:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-25 00:09:23 -04:00
|
|
|
// ListUnadoptedRepositories lists all the unadopted repositories that match the provided query
|
2023-02-28 17:17:51 -05:00
|
|
|
func ListUnadoptedRepositories(ctx context.Context, query string, opts *db.ListOptions) ([]string, int, error) {
|
2020-09-25 00:09:23 -04:00
|
|
|
globUser, _ := glob.Compile("*")
|
|
|
|
globRepo, _ := glob.Compile("*")
|
|
|
|
|
|
|
|
qsplit := strings.SplitN(query, "/", 2)
|
|
|
|
if len(qsplit) > 0 && len(query) > 0 {
|
|
|
|
var err error
|
|
|
|
globUser, err = glob.Compile(qsplit[0])
|
|
|
|
if err != nil {
|
2021-07-08 07:38:13 -04:00
|
|
|
log.Info("Invalid glob expression '%s' (skipped): %v", qsplit[0], err)
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
|
|
|
if len(qsplit) > 1 {
|
|
|
|
globRepo, err = glob.Compile(qsplit[1])
|
|
|
|
if err != nil {
|
2021-07-08 07:38:13 -04:00
|
|
|
log.Info("Invalid glob expression '%s' (skipped): %v", qsplit[1], err)
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 21:52:00 -05:00
|
|
|
var repoNamesToCheck []string
|
2020-09-25 00:09:23 -04:00
|
|
|
|
2021-12-31 21:52:00 -05:00
|
|
|
start := (opts.Page - 1) * opts.PageSize
|
2022-10-31 19:16:48 -04:00
|
|
|
unadopted := &unadoptedRepositories{
|
2021-12-31 21:52:00 -05:00
|
|
|
repositories: make([]string, 0, opts.PageSize),
|
|
|
|
start: start,
|
|
|
|
end: start + opts.PageSize,
|
|
|
|
index: 0,
|
|
|
|
}
|
2020-09-25 00:09:23 -04:00
|
|
|
|
2021-12-31 21:52:00 -05:00
|
|
|
var userName string
|
2020-09-25 00:09:23 -04:00
|
|
|
|
|
|
|
// We're going to iterate by pagesize.
|
2021-11-15 01:02:53 -05:00
|
|
|
root := filepath.Clean(setting.RepoRootPath)
|
2023-01-16 11:21:44 -05:00
|
|
|
if err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
|
2020-09-25 00:09:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-16 11:21:44 -05:00
|
|
|
if !d.IsDir() || path == root {
|
2020-09-25 00:09:23 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-16 11:21:44 -05:00
|
|
|
name := d.Name()
|
|
|
|
|
2020-09-25 00:09:23 -04:00
|
|
|
if !strings.ContainsRune(path[len(root)+1:], filepath.Separator) {
|
|
|
|
// Got a new user
|
2023-02-28 17:17:51 -05:00
|
|
|
if err = checkUnadoptedRepositories(ctx, userName, repoNamesToCheck, unadopted); err != nil {
|
2021-12-31 21:52:00 -05:00
|
|
|
return err
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
2021-12-31 21:52:00 -05:00
|
|
|
repoNamesToCheck = repoNamesToCheck[:0]
|
2020-09-25 00:09:23 -04:00
|
|
|
|
2023-01-16 11:21:44 -05:00
|
|
|
if !globUser.Match(name) {
|
2020-09-25 00:09:23 -04:00
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
|
2023-01-16 11:21:44 -05:00
|
|
|
userName = name
|
2020-09-25 00:09:23 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasSuffix(name, ".git") {
|
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
name = name[:len(name)-4]
|
2021-12-12 10:48:20 -05:00
|
|
|
if repo_model.IsUsableRepoName(name) != nil || strings.ToLower(name) != name || !globRepo.Match(name) {
|
2020-09-25 00:09:23 -04:00
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
2021-12-31 21:52:00 -05:00
|
|
|
|
|
|
|
repoNamesToCheck = append(repoNamesToCheck, name)
|
2022-12-16 03:58:56 -05:00
|
|
|
if len(repoNamesToCheck) >= setting.Database.IterateBufferSize {
|
2023-02-28 17:17:51 -05:00
|
|
|
if err = checkUnadoptedRepositories(ctx, userName, repoNamesToCheck, unadopted); err != nil {
|
2022-03-21 04:09:42 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
repoNamesToCheck = repoNamesToCheck[:0]
|
|
|
|
}
|
2020-09-25 00:09:23 -04:00
|
|
|
return filepath.SkipDir
|
|
|
|
}); err != nil {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
|
2023-02-28 17:17:51 -05:00
|
|
|
if err := checkUnadoptedRepositories(ctx, userName, repoNamesToCheck, unadopted); err != nil {
|
2021-12-31 21:52:00 -05:00
|
|
|
return nil, 0, err
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|
2021-12-31 21:52:00 -05:00
|
|
|
|
|
|
|
return unadopted.repositories, unadopted.index, nil
|
2020-09-25 00:09:23 -04:00
|
|
|
}
|