* Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net>
Showing the changes to modules/git/commit_reader.go (1 of 81 files). Show all
Unified · Split
| @@ -9,13 +9,13 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "bytes" |
| 10 | 10 | "io" |
| 11 | 11 | "strings" |
| 12 | − | |
| 13 | − "github.com/go-git/go-git/v5/plumbing" | |
| 14 | 12 | ) |
| 15 | 13 | |
| 16 | 14 | // CommitFromReader will generate a Commit from a provided reader |
| 17 | −// We will need this to interpret commits from cat-file | |
| 18 | −func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) (*Commit, error) { | |
| 15 | +// We need this to interpret commits from cat-file or cat-file --batch | |
| 16 | +// | |
| 17 | +// If used as part of a cat-file --batch stream you need to limit the reader to the correct size | |
| 18 | +func CommitFromReader(gitRepo *Repository, sha SHA1, reader io.Reader) (*Commit, error) { | |
| 19 | 19 | commit := &Commit{ |
| 20 | 20 | ID: sha, |
| 21 | 21 | } |
| @@ -26,26 +26,20 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 4 unmodified lines | ||
| 26 | 26 | message := false |
| 27 | 27 | pgpsig := false |
| 28 | 28 | |
| 29 | − scanner := bufio.NewScanner(reader) | |
| 30 | − // Split by '\n' but include the '\n' | |
| 31 | − scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) { | |
| 32 | − if atEOF && len(data) == 0 { | |
| 33 | − return 0, nil, nil | |
| 34 | − } | |
| 35 | − if i := bytes.IndexByte(data, '\n'); i >= 0 { | |
| 36 | − // We have a full newline-terminated line. | |
| 37 | − return i + 1, data[0 : i+1], nil | |
| 38 | − } | |
| 39 | − // If we're at EOF, we have a final, non-terminated line. Return it. | |
| 40 | − if atEOF { | |
| 41 | − return len(data), data, nil | |
| 42 | − } | |
| 43 | − // Request more data. | |
| 44 | − return 0, nil, nil | |
| 45 | − }) | |
| 29 | + bufReader, ok := reader.(*bufio.Reader) | |
| 30 | + if !ok { | |
| 31 | + bufReader = bufio.NewReader(reader) | |
| 32 | + } | |
| 46 | 33 | |
| 47 | − for scanner.Scan() { | |
| 48 | − line := scanner.Bytes() | |
| 34 | +readLoop: | |
| 35 | + for { | |
| 36 | + line, err := bufReader.ReadBytes('\n') | |
| 37 | + if err != nil { | |
| 38 | + if err == io.EOF { | |
| 39 | + break readLoop | |
| 40 | + } | |
| 41 | + return nil, err | |
| 42 | + } | |
| 49 | 43 | if pgpsig { |
| 50 | 44 | if len(line) > 0 && line[0] == ' ' { |
| 51 | 45 | _, _ = signatureSB.Write(line[1:]) |
| @@ -72,10 +66,10 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 20 unmodified lines | ||
| 72 | 66 | |
| 73 | 67 | switch string(split[0]) { |
| 74 | 68 | case "tree": |
| 75 | − commit.Tree = *NewTree(gitRepo, plumbing.NewHash(string(data))) | |
| 69 | + commit.Tree = *NewTree(gitRepo, MustIDFromString(string(data))) | |
| 76 | 70 | _, _ = payloadSB.Write(line) |
| 77 | 71 | case "parent": |
| 78 | − commit.Parents = append(commit.Parents, plumbing.NewHash(string(data))) | |
| 72 | + commit.Parents = append(commit.Parents, MustIDFromString(string(data))) | |
| 79 | 73 | _, _ = payloadSB.Write(line) |
| 80 | 74 | case "author": |
| 81 | 75 | commit.Author = &Signature{} |
| @@ -104,5 +98,5 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 22 unmodified lines | ||
| 104 | 98 | commit.Signature = nil |
| 105 | 99 | } |
| 106 | 100 | |
| 107 | − return commit, scanner.Err() | |
| 101 | + return commit, nil | |
| 108 | 102 | } |