Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2018-06-25 12:54:08 +0300
committerJacob Vosmaer <jacob@gitlab.com>2018-06-25 12:54:08 +0300
commita984dfa4dee018c6d5f5f57ffec0d0e22763df16 (patch)
tree13b552b21c26b6a64e5020e146dbae75b201b48d
parentcc65e0f234f6d2c3999b35fbdc65f281783369a2 (diff)
Lint, more deletions
-rw-r--r--internal/git/log/commit.go4
-rw-r--r--internal/git/log/commitmessage.go127
-rw-r--r--internal/git/log/lastcommit.go4
-rw-r--r--internal/git/log/log.go6
4 files changed, 9 insertions, 132 deletions
diff --git a/internal/git/log/commit.go b/internal/git/log/commit.go
index a2136c925..91aaa539e 100644
--- a/internal/git/log/commit.go
+++ b/internal/git/log/commit.go
@@ -147,3 +147,7 @@ func parseCommitAuthor(line string) (*pb.CommitAuthor, error) {
return author, nil
}
+
+func subjectFromBody(body []byte) []byte {
+ return bytes.TrimRight(bytes.SplitN(body, []byte("\n"), 2)[0], "\r\n")
+}
diff --git a/internal/git/log/commitmessage.go b/internal/git/log/commitmessage.go
deleted file mode 100644
index 95eca5e72..000000000
--- a/internal/git/log/commitmessage.go
+++ /dev/null
@@ -1,127 +0,0 @@
-package log
-
-import (
- "bytes"
- "context"
- "fmt"
- "io/ioutil"
-
- pb "gitlab.com/gitlab-org/gitaly-proto/go"
- "gitlab.com/gitlab-org/gitaly/internal/git/catfile"
-)
-
-type commitMessageResponse struct {
- subject string
- body string
- err error
-}
-
-type commitMessageRequest struct {
- commitID string
- response chan commitMessageResponse
-}
-
-type commitMessageHelper struct {
- ctx context.Context
- requests chan commitMessageRequest
- catFileErr chan error
-}
-
-func newCommitMessageHelper(ctx context.Context, repo *pb.Repository) (*commitMessageHelper, error) {
- cmh := &commitMessageHelper{
- ctx: ctx,
- requests: make(chan commitMessageRequest),
- catFileErr: make(chan error),
- }
-
- c, err := catfile.New(ctx, repo)
- if err != nil {
- return nil, err
- }
-
- go func() {
- select {
- case cmh.catFileErr <- cmh.handleCatFile(c):
- case <-ctx.Done():
- // This case is here to ensure this goroutine won't leak. We can't assume
- // someone is listening on the cmh.catFileErr channel.
- }
-
- close(cmh.catFileErr)
- }()
-
- return cmh, nil
-}
-
-// commitMessage returns the raw binary subject and body for the given commitID.
-func (cmh *commitMessageHelper) commitMessage(commitID string) (string, string, error) {
- response := make(chan commitMessageResponse)
-
- select {
- case cmh.requests <- commitMessageRequest{commitID: commitID, response: response}:
- result := <-response
- return result.subject, result.body, result.err
- case err := <-cmh.catFileErr:
- return "", "", fmt.Errorf("git cat-file is not running: %v", err)
- }
-}
-
-// handleCatFile gets the raw commit message for a sequence of commit
-// ID's from a git-cat-file process.
-func (cmh *commitMessageHelper) handleCatFile(c *catfile.Batch) error {
- for {
- select {
- case messageRequest := <-cmh.requests:
- subject, body, err := getCommitMessage(c, messageRequest.commitID)
-
- // Always return a response, because a client is blocked waiting for it.
- messageRequest.response <- commitMessageResponse{
- subject: subject,
- body: body,
- err: err,
- }
-
- if err != nil {
- // Shut down the current goroutine.
- return err
- }
- case <-cmh.ctx.Done():
- // We need this case because we cannot count on the client to close the
- // requests channel.
- return cmh.ctx.Err()
- }
- }
-}
-
-// getCommitMessage returns subject, body, error by querying git cat-file via stdin and stdout.
-func getCommitMessage(c *catfile.Batch, commitID string) (string, string, error) {
- objInfo, err := c.Info(commitID)
- if err != nil {
- return "", "", err
- }
-
- if objInfo.Oid == "" || objInfo.Type != "commit" {
- return "", "", fmt.Errorf("invalid ObjectInfo for %q: %v", commitID, objInfo)
- }
-
- commitReader, err := c.Commit(objInfo.Oid)
- if err != nil {
- return "", "", err
- }
-
- rawCommit, err := ioutil.ReadAll(commitReader)
- if err != nil {
- return "", "", err
- }
-
- var body []byte
- if split := bytes.SplitN(rawCommit, []byte("\n\n"), 2); len(split) == 2 {
- body = split[1]
- }
-
- return string(subjectFromBody(body)), string(body), nil
-}
-
-func subjectFromBody(body []byte) []byte {
- return bytes.TrimRight(bytes.SplitN(body, []byte("\n"), 2)[0], "\r\n")
-}
diff --git a/internal/git/log/lastcommit.go b/internal/git/log/lastcommit.go
index 582650f57..950b2eefb 100644
--- a/internal/git/log/lastcommit.go
+++ b/internal/git/log/lastcommit.go
@@ -21,12 +21,12 @@ func LastCommitForPath(ctx context.Context, repo *pb.Repository, revision string
return nil, err
}
- commitId, err := ioutil.ReadAll(cmd)
+ commitID, err := ioutil.ReadAll(cmd)
if err != nil {
return nil, err
}
- return GetCommit(ctx, repo, strings.TrimSpace(string(commitId)))
+ return GetCommit(ctx, repo, strings.TrimSpace(string(commitID)))
}
// GitLogCommand returns a Command that executes git log with the given the arguments
diff --git a/internal/git/log/log.go b/internal/git/log/log.go
index cd2e917dc..da8c8f4cc 100644
--- a/internal/git/log/log.go
+++ b/internal/git/log/log.go
@@ -41,16 +41,16 @@ func (parser *Parser) Parse() bool {
return false
}
- commitId := parser.scanner.Text()
+ commitID := parser.scanner.Text()
- commit, err := GetCommitCatfile(parser.c, commitId)
+ commit, err := GetCommitCatfile(parser.c, commitID)
if err != nil {
parser.err = err
return false
}
if commit == nil {
- parser.err = fmt.Errorf("could not retrieve commit %q", commitId)
+ parser.err = fmt.Errorf("could not retrieve commit %q", commitID)
return false
}