History

Use native git variants by default with go-git variants as build tag (#13673)

* 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>

zeripath committed 5 years ago

Commit 511f6131 parent 0851a8981 files · +3952 −1492Browse files

Showing the changes to modules/git/commit_reader.go (1 of 81 files). Show all

Unified · Split

modules/git/commit_reader.go+20−26
@@ -9,13 +9,13 @@ import ( · 8 unmodified lines
99 "bytes"
1010 "io"
1111 "strings"
12−
13− "github.com/go-git/go-git/v5/plumbing"
1412 )
1513
1614 // 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) {
1919 commit := &Commit{
2020 ID: sha,
2121 }
@@ -26,26 +26,20 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 4 unmodified lines
2626 message := false
2727 pgpsig := false
2828
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+ }
4633
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+ }
4943 if pgpsig {
5044 if len(line) > 0 && line[0] == ' ' {
5145 _, _ = signatureSB.Write(line[1:])
@@ -72,10 +66,10 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 20 unmodified lines
7266
7367 switch string(split[0]) {
7468 case "tree":
75− commit.Tree = *NewTree(gitRepo, plumbing.NewHash(string(data)))
69+ commit.Tree = *NewTree(gitRepo, MustIDFromString(string(data)))
7670 _, _ = payloadSB.Write(line)
7771 case "parent":
78− commit.Parents = append(commit.Parents, plumbing.NewHash(string(data)))
72+ commit.Parents = append(commit.Parents, MustIDFromString(string(data)))
7973 _, _ = payloadSB.Write(line)
8074 case "author":
8175 commit.Author = &Signature{}
@@ -104,5 +98,5 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 22 unmodified lines
10498 commit.Signature = nil
10599 }
106100
107− return commit, scanner.Err()
101+ return commit, nil
108102 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t