aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorGusted <postmaster@gusted.xyz>2022-12-27 02:15:35 +0100
committerGitHub <noreply@github.com>2022-12-27 09:15:35 +0800
commitb48cf03717e99ff33d1e845c97e6f8c469cd2e6d (patch)
tree35227df20ccfc6738d4cae6ab8f31afba30351b2 /modules/git
parent83640c449eb6a1b31bc09b1372cc156d114804f8 (diff)
downloadgitea-b48cf03717e99ff33d1e845c97e6f8c469cd2e6d.tar.gz
gitea-b48cf03717e99ff33d1e845c97e6f8c469cd2e6d.zip
Remove deadcode (#22245)
- Remove code that isn't being used. Found this is my stash from a few weeks ago, not sure how I found this in the first place. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/repo_attribute.go98
-rw-r--r--modules/git/repo_attribute_test.go61
2 files changed, 0 insertions, 159 deletions
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go
index d3a3dc8c83..404d9e502c 100644
--- a/modules/git/repo_attribute.go
+++ b/modules/git/repo_attribute.go
@@ -9,8 +9,6 @@ import (
"fmt"
"io"
"os"
- "strconv"
- "strings"
"code.gitea.io/gitea/modules/log"
)
@@ -288,102 +286,6 @@ func (wr *nulSeparatedAttributeWriter) Close() error {
return nil
}
-type lineSeparatedAttributeWriter struct {
- tmp []byte
- attributes chan attributeTriple
- closed chan struct{}
-}
-
-func (wr *lineSeparatedAttributeWriter) Write(p []byte) (n int, err error) {
- l := len(p)
-
- nlIdx := bytes.IndexByte(p, '\n')
- for nlIdx >= 0 {
- wr.tmp = append(wr.tmp, p[:nlIdx]...)
-
- if len(wr.tmp) == 0 {
- // This should not happen
- if len(p) > nlIdx+1 {
- wr.tmp = wr.tmp[:0]
- p = p[nlIdx+1:]
- nlIdx = bytes.IndexByte(p, '\n')
- continue
- } else {
- return l, nil
- }
- }
-
- working := attributeTriple{}
- if wr.tmp[0] == '"' {
- sb := new(strings.Builder)
- remaining := string(wr.tmp[1:])
- for len(remaining) > 0 {
- rn, _, tail, err := strconv.UnquoteChar(remaining, '"')
- if err != nil {
- if len(remaining) > 2 && remaining[0] == '"' && remaining[1] == ':' && remaining[2] == ' ' {
- working.Filename = sb.String()
- wr.tmp = []byte(remaining[3:])
- break
- }
- return l, fmt.Errorf("unexpected tail %s", remaining)
- }
- _, _ = sb.WriteRune(rn)
- remaining = tail
- }
- } else {
- idx := bytes.IndexByte(wr.tmp, ':')
- if idx < 0 {
- return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
- }
- working.Filename = string(wr.tmp[:idx])
- if len(wr.tmp) < idx+2 {
- return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
- }
- wr.tmp = wr.tmp[idx+2:]
- }
-
- idx := bytes.IndexByte(wr.tmp, ':')
- if idx < 0 {
- return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
- }
-
- working.Attribute = string(wr.tmp[:idx])
- if len(wr.tmp) < idx+2 {
- return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
- }
-
- working.Value = string(wr.tmp[idx+2:])
-
- wr.attributes <- working
- wr.tmp = wr.tmp[:0]
- if len(p) > nlIdx+1 {
- p = p[nlIdx+1:]
- nlIdx = bytes.IndexByte(p, '\n')
- continue
- } else {
- return l, nil
- }
- }
-
- wr.tmp = append(wr.tmp, p...)
- return l, nil
-}
-
-func (wr *lineSeparatedAttributeWriter) ReadAttribute() <-chan attributeTriple {
- return wr.attributes
-}
-
-func (wr *lineSeparatedAttributeWriter) Close() error {
- select {
- case <-wr.closed:
- return nil
- default:
- }
- close(wr.attributes)
- close(wr.closed)
- return nil
-}
-
// Create a check attribute reader for the current repository and provided commit ID
func (repo *Repository) CheckAttributeReader(commitID string) (*CheckAttributeReader, context.CancelFunc) {
indexFilename, worktree, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)
diff --git a/modules/git/repo_attribute_test.go b/modules/git/repo_attribute_test.go
index 6882874d2d..f88ae95407 100644
--- a/modules/git/repo_attribute_test.go
+++ b/modules/git/repo_attribute_test.go
@@ -95,64 +95,3 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
Value: "unspecified",
}, attr)
}
-
-func Test_lineSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
- wr := &lineSeparatedAttributeWriter{
- attributes: make(chan attributeTriple, 5),
- }
-
- testStr := `".gitignore\"\n": linguist-vendored: unspecified
-`
- n, err := wr.Write([]byte(testStr))
-
- assert.Equal(t, n, len(testStr))
- assert.NoError(t, err)
-
- select {
- case attr := <-wr.ReadAttribute():
- assert.Equal(t, ".gitignore\"\n", attr.Filename)
- assert.Equal(t, "linguist-vendored", attr.Attribute)
- assert.Equal(t, "unspecified", attr.Value)
- case <-time.After(100 * time.Millisecond):
- assert.Fail(t, "took too long to read an attribute from the list")
- }
-
- // Write a second attribute again
- n, err = wr.Write([]byte(testStr))
-
- assert.Equal(t, n, len(testStr))
- assert.NoError(t, err)
-
- select {
- case attr := <-wr.ReadAttribute():
- assert.Equal(t, ".gitignore\"\n", attr.Filename)
- assert.Equal(t, "linguist-vendored", attr.Attribute)
- assert.Equal(t, "unspecified", attr.Value)
- case <-time.After(100 * time.Millisecond):
- assert.Fail(t, "took too long to read an attribute from the list")
- }
-
- // Write a partial attribute
- _, err = wr.Write([]byte("incomplete-file"))
- assert.NoError(t, err)
- _, err = wr.Write([]byte("name: "))
- assert.NoError(t, err)
- select {
- case <-wr.ReadAttribute():
- assert.Fail(t, "There should not be an attribute ready to read")
- case <-time.After(100 * time.Millisecond):
- }
- _, err = wr.Write([]byte("attribute: "))
- assert.NoError(t, err)
- select {
- case <-wr.ReadAttribute():
- assert.Fail(t, "There should not be an attribute ready to read")
- case <-time.After(100 * time.Millisecond):
- }
- _, err = wr.Write([]byte("value\n"))
- assert.NoError(t, err)
- attr := <-wr.ReadAttribute()
- assert.Equal(t, "incomplete-filename", attr.Filename)
- assert.Equal(t, "attribute", attr.Attribute)
- assert.Equal(t, "value", attr.Value)
-}