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
9 "bytes"9 "bytes"
10 "io"10 "io"
11 "strings"11 "strings"
12
13 "github.com/go-git/go-git/v5/plumbing"
14)12)
15 13
16// CommitFromReader will generate a Commit from a provided reader14// CommitFromReader will generate a Commit from a provided reader
17// We will need this to interpret commits from cat-file15// We need this to interpret commits from cat-file or cat-file --batch
18func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) (*Commit, error) {16//
17// If used as part of a cat-file --batch stream you need to limit the reader to the correct size
18func CommitFromReader(gitRepo *Repository, sha SHA1, reader io.Reader) (*Commit, error) {
19 commit := &Commit{19 commit := &Commit{
20 ID: sha,20 ID: sha,
21 }21 }
@@ -26,26 +26,20 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 4 unmodified lines
26 message := false26 message := false
27 pgpsig := false27 pgpsig := false
28 28
29 scanner := bufio.NewScanner(reader)29 bufReader, ok := reader.(*bufio.Reader)
30 // Split by '\n' but include the '\n'30 if !ok {
31 scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {31 bufReader = bufio.NewReader(reader)
32 if atEOF && len(data) == 0 {32 }
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 })
46 33
47 for scanner.Scan() {34readLoop:
48 line := scanner.Bytes()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 if pgpsig {43 if pgpsig {
50 if len(line) > 0 && line[0] == ' ' {44 if len(line) > 0 && line[0] == ' ' {
51 _, _ = signatureSB.Write(line[1:])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 switch string(split[0]) {67 switch string(split[0]) {
74 case "tree":68 case "tree":
75 commit.Tree = *NewTree(gitRepo, plumbing.NewHash(string(data)))69 commit.Tree = *NewTree(gitRepo, MustIDFromString(string(data)))
76 _, _ = payloadSB.Write(line)70 _, _ = payloadSB.Write(line)
77 case "parent":71 case "parent":
78 commit.Parents = append(commit.Parents, plumbing.NewHash(string(data)))72 commit.Parents = append(commit.Parents, MustIDFromString(string(data)))
79 _, _ = payloadSB.Write(line)73 _, _ = payloadSB.Write(line)
80 case "author":74 case "author":
81 commit.Author = &Signature{}75 commit.Author = &Signature{}
@@ -104,5 +98,5 @@ func CommitFromReader(gitRepo *Repository, sha plumbing.Hash, reader io.Reader) · 22 unmodified lines
104 commit.Signature = nil98 commit.Signature = nil
105 }99 }
106 100
107 return commit, scanner.Err()101 return commit, nil
108}102}

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