diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-04-01 10:55:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 10:55:30 +0800 |
commit | 124b072f0b69650baff086b9688d198f5a6761af (patch) | |
tree | fa18f7930053a8408e124875b5dec20e0309332b /modules/indexer/code/git.go | |
parent | 3a73645502392110369b5d78fa2c9136e77e4aa2 (diff) | |
download | gitea-124b072f0b69650baff086b9688d198f5a6761af.tar.gz gitea-124b072f0b69650baff086b9688d198f5a6761af.zip |
Remove `git.Command.Run` and `git.Command.RunInDir*` (#19280)
Follows #19266, #8553, Close #18553, now there are only three `Run..(&RunOpts{})` functions.
* before: `stdout, err := RunInDir(path)`
* now: `stdout, _, err := RunStdString(&git.RunOpts{Dir:path})`
Diffstat (limited to 'modules/indexer/code/git.go')
-rw-r--r-- | modules/indexer/code/git.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/modules/indexer/code/git.go b/modules/indexer/code/git.go index 62444f6251..60018af20c 100644 --- a/modules/indexer/code/git.go +++ b/modules/indexer/code/git.go @@ -29,7 +29,7 @@ type repoChanges struct { } func getDefaultBranchSha(ctx context.Context, repo *repo_model.Repository) (string, error) { - stdout, err := git.NewCommand(ctx, "show-ref", "-s", git.BranchPrefix+repo.DefaultBranch).RunInDir(repo.RepoPath()) + stdout, _, err := git.NewCommand(ctx, "show-ref", "-s", git.BranchPrefix+repo.DefaultBranch).RunStdString(&git.RunOpts{Dir: repo.RepoPath()}) if err != nil { return "", err } @@ -92,30 +92,32 @@ func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) { // genesisChanges get changes to add repo to the indexer for the first time func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision string) (*repoChanges, error) { var changes repoChanges - stdout, err := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l", "-r", revision). - RunInDirBytes(repo.RepoPath()) - if err != nil { - return nil, err + stdout, _, runErr := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l", "-r", revision).RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()}) + if runErr != nil { + return nil, runErr } + + var err error changes.Updates, err = parseGitLsTreeOutput(stdout) return &changes, err } // nonGenesisChanges get changes since the previous indexer update func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revision string) (*repoChanges, error) { - diffCmd := git.NewCommand(ctx, "diff", "--name-status", - repo.CodeIndexerStatus.CommitSha, revision) - stdout, err := diffCmd.RunInDir(repo.RepoPath()) - if err != nil { + diffCmd := git.NewCommand(ctx, "diff", "--name-status", repo.CodeIndexerStatus.CommitSha, revision) + stdout, _, runErr := diffCmd.RunStdString(&git.RunOpts{Dir: repo.RepoPath()}) + if runErr != nil { // previous commit sha may have been removed by a force push, so // try rebuilding from scratch - log.Warn("git diff: %v", err) - if err = indexer.Delete(repo.ID); err != nil { + log.Warn("git diff: %v", runErr) + if err := indexer.Delete(repo.ID); err != nil { return nil, err } return genesisChanges(ctx, repo, revision) } + var changes repoChanges + var err error updatedFilenames := make([]string, 0, 10) for _, line := range strings.Split(stdout, "\n") { line = strings.TrimSpace(line) @@ -169,7 +171,7 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio cmd := git.NewCommand(ctx, "ls-tree", "--full-tree", "-l", revision, "--") cmd.AddArguments(updatedFilenames...) - lsTreeStdout, err := cmd.RunInDirBytes(repo.RepoPath()) + lsTreeStdout, _, err := cmd.RunStdBytes(&git.RunOpts{Dir: repo.RepoPath()}) if err != nil { return nil, err } |