Skip to content

Commit e7e9a04

Browse files
committed
test
1 parent 533687c commit e7e9a04

File tree

25 files changed

+63
-44
lines changed

25 files changed

+63
-44
lines changed

modules/git/repo_commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818

1919
// GetBranchCommitID returns last commit ID string of given branch.
2020
func (repo *Repository) GetBranchCommitID(name string) (string, error) {
21-
return repo.GetRefCommitID(BranchPrefix + name)
21+
return repo.GetRefCommitIDOld(BranchPrefix + name)
2222
}
2323

2424
// GetTagCommitID returns last commit ID string of given tag.
2525
func (repo *Repository) GetTagCommitID(name string) (string, error) {
26-
return repo.GetRefCommitID(TagPrefix + name)
26+
return repo.GetRefCommitIDOld(TagPrefix + name)
2727
}
2828

2929
// GetCommit returns commit object of by ID string.

modules/git/repo_commit_nogogit.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,26 @@ func (repo *Repository) ResolveReference(name string) (string, error) {
3535
}
3636

3737
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
38-
func (repo *Repository) GetRefCommitID(name string) (string, error) {
38+
func (repo *Repository) GetRefCommitIDOld(name string) (string, error) {
39+
batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // here is the real fatal point?
40+
if err != nil {
41+
return "", err
42+
}
43+
defer cancel()
44+
rd, err := batch.QueryInfo(name)
45+
if err != nil {
46+
return "", err
47+
}
48+
shaBs, _, _, err := ReadBatchLine(rd)
49+
if IsErrNotExist(err) {
50+
return "", ErrNotExist{name, ""}
51+
}
52+
53+
return string(shaBs), nil
54+
}
55+
56+
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
57+
func (repo *Repository) GetRefCommitIDNew(name string) (string, error) {
3958
batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // here is the real fatal point?
4059
if err != nil {
4160
return "", err

modules/git/repo_commit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestGetRefCommitID(t *testing.T) {
124124
}
125125

126126
for _, testCase := range testCases {
127-
commitID, err := bareRepo1.GetRefCommitID(testCase.Ref)
127+
commitID, err := bareRepo1.GetRefCommitIDNew(testCase.Ref)
128128
if assert.NoError(t, err) {
129129
assert.Equal(t, testCase.ExpectedCommitID, commitID)
130130
}

modules/git/repo_compare_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestReadWritePullHead(t *testing.T) {
9696
defer repo.Close()
9797

9898
// Try to open non-existing Pull
99-
_, err = repo.GetRefCommitID(PullPrefix + "0/head")
99+
_, err = repo.GetRefCommitIDNew(PullPrefix + "0/head")
100100
assert.Error(t, err)
101101

102102
// Write a fake sha1 with only 40 zeros
@@ -111,7 +111,7 @@ func TestReadWritePullHead(t *testing.T) {
111111
}
112112

113113
// Read the file created
114-
headContents, err := repo.GetRefCommitID(PullPrefix + "1/head")
114+
headContents, err := repo.GetRefCommitIDNew(PullPrefix + "1/head")
115115
if err != nil {
116116
assert.NoError(t, err)
117117
return

modules/git/repo_tree_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) {
8888
return nil, err
8989
}
9090
if len(idStr) != objectFormat.FullLength() {
91-
res, err := repo.GetRefCommitID(idStr)
91+
res, err := repo.GetRefCommitIDOld(idStr)
9292
if err != nil {
9393
return nil, err
9494
}

modules/indexer/code/gitgrep/gitgrep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Rep
4242
// TODO: if no branch exists, it reports: exit status 128, fatal: this operation must be run in a work tree.
4343
return nil, 0, fmt.Errorf("git.GrepSearch: %w", err)
4444
}
45-
commitID, err := gitRepo.GetRefCommitID(ref.String())
45+
commitID, err := gitRepo.GetRefCommitIDOld(ref.String())
4646
if err != nil {
4747
return nil, 0, fmt.Errorf("gitRepo.GetRefCommitID: %w", err)
4848
}

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
15671567
return
15681568
}
15691569

1570-
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
1570+
headCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName())
15711571
if err != nil {
15721572
ctx.APIErrorInternal(err)
15731573
return

routers/api/v1/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func CreatePullReview(ctx *context.APIContext) {
336336
}
337337
defer closer.Close()
338338

339-
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
339+
headCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName())
340340
if err != nil {
341341
ctx.APIErrorInternal(err)
342342
return
@@ -455,7 +455,7 @@ func SubmitPullReview(ctx *context.APIContext) {
455455
return
456456
}
457457

458-
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitHeadRefName())
458+
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName())
459459
if err != nil {
460460
ctx.APIErrorInternal(err)
461461
return

routers/web/repo/pull.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func GetPullDiffStats(ctx *context.Context) {
197197
}
198198

199199
// do not report 500 server error to end users if error occurs, otherwise a PR missing ref won't be able to view.
200-
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName())
200+
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName())
201201
if err != nil {
202202
log.Error("Failed to GetRefCommitID: %v, repo: %v", err, ctx.Repo.Repository.FullName())
203203
return
@@ -219,7 +219,7 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri
219219
if pull.MergeBase == "" {
220220
var commitSHA, parentCommit string
221221
// If there is a head or a patch file, and it is readable, grab info
222-
commitSHA, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName())
222+
commitSHA, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName())
223223
if err != nil {
224224
// Head File does not exist, try the patch
225225
commitSHA, err = ctx.Repo.GitRepo.ReadPatchCommit(pull.Index)
@@ -364,7 +364,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_
364364
ctx.Data["BaseTarget"] = pull.BaseBranch
365365
ctx.Data["HeadTarget"] = pull.HeadBranch
366366

367-
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName())
367+
sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName())
368368
if err != nil {
369369
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitHeadRefName()), err)
370370
return nil
@@ -422,7 +422,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_
422422

423423
if headBranchExist {
424424
if pull.Flow != issues_model.PullRequestFlowGithub {
425-
headBranchSha, err = baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName())
425+
headBranchSha, err = baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName())
426426
} else {
427427
headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch)
428428
}
@@ -445,7 +445,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_
445445
ctx.Data["GetCommitMessages"] = ""
446446
}
447447

448-
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName())
448+
sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName())
449449
if err != nil {
450450
if git.IsErrNotExist(err) {
451451
ctx.Data["IsPullRequestBroken"] = true
@@ -702,7 +702,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
702702
return
703703
}
704704

705-
headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitHeadRefName())
705+
headCommitID, err := gitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName())
706706
if err != nil {
707707
ctx.ServerError("GetRefCommitID", err)
708708
return

routers/web/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
4949
ctx.Data["PageIsPullFiles"] = true
5050
ctx.Data["Issue"] = issue
5151
ctx.Data["CurrentReview"] = currentReview
52-
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(issue.PullRequest.GetGitHeadRefName())
52+
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(issue.PullRequest.GetGitHeadRefName())
5353
if err != nil {
5454
ctx.ServerError("GetRefCommitID", err)
5555
return
@@ -199,7 +199,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
199199
ctx.ServerError("comment.Issue.LoadPullRequest", err)
200200
return
201201
}
202-
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(comment.Issue.PullRequest.GetGitHeadRefName())
202+
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(comment.Issue.PullRequest.GetGitHeadRefName())
203203
if err != nil {
204204
ctx.ServerError("GetRefCommitID", err)
205205
return

0 commit comments

Comments
 (0)