Skip to content

Commit b48cf03

Browse files
Gustedlunny
andauthored
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 <[email protected]>
1 parent 83640c4 commit b48cf03

File tree

4 files changed

+0
-187
lines changed

4 files changed

+0
-187
lines changed

modules/git/repo_attribute.go

-98
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12-
"strconv"
13-
"strings"
1412

1513
"code.gitea.io/gitea/modules/log"
1614
)
@@ -288,102 +286,6 @@ func (wr *nulSeparatedAttributeWriter) Close() error {
288286
return nil
289287
}
290288

291-
type lineSeparatedAttributeWriter struct {
292-
tmp []byte
293-
attributes chan attributeTriple
294-
closed chan struct{}
295-
}
296-
297-
func (wr *lineSeparatedAttributeWriter) Write(p []byte) (n int, err error) {
298-
l := len(p)
299-
300-
nlIdx := bytes.IndexByte(p, '\n')
301-
for nlIdx >= 0 {
302-
wr.tmp = append(wr.tmp, p[:nlIdx]...)
303-
304-
if len(wr.tmp) == 0 {
305-
// This should not happen
306-
if len(p) > nlIdx+1 {
307-
wr.tmp = wr.tmp[:0]
308-
p = p[nlIdx+1:]
309-
nlIdx = bytes.IndexByte(p, '\n')
310-
continue
311-
} else {
312-
return l, nil
313-
}
314-
}
315-
316-
working := attributeTriple{}
317-
if wr.tmp[0] == '"' {
318-
sb := new(strings.Builder)
319-
remaining := string(wr.tmp[1:])
320-
for len(remaining) > 0 {
321-
rn, _, tail, err := strconv.UnquoteChar(remaining, '"')
322-
if err != nil {
323-
if len(remaining) > 2 && remaining[0] == '"' && remaining[1] == ':' && remaining[2] == ' ' {
324-
working.Filename = sb.String()
325-
wr.tmp = []byte(remaining[3:])
326-
break
327-
}
328-
return l, fmt.Errorf("unexpected tail %s", remaining)
329-
}
330-
_, _ = sb.WriteRune(rn)
331-
remaining = tail
332-
}
333-
} else {
334-
idx := bytes.IndexByte(wr.tmp, ':')
335-
if idx < 0 {
336-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
337-
}
338-
working.Filename = string(wr.tmp[:idx])
339-
if len(wr.tmp) < idx+2 {
340-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
341-
}
342-
wr.tmp = wr.tmp[idx+2:]
343-
}
344-
345-
idx := bytes.IndexByte(wr.tmp, ':')
346-
if idx < 0 {
347-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
348-
}
349-
350-
working.Attribute = string(wr.tmp[:idx])
351-
if len(wr.tmp) < idx+2 {
352-
return l, fmt.Errorf("unexpected input %s", string(wr.tmp))
353-
}
354-
355-
working.Value = string(wr.tmp[idx+2:])
356-
357-
wr.attributes <- working
358-
wr.tmp = wr.tmp[:0]
359-
if len(p) > nlIdx+1 {
360-
p = p[nlIdx+1:]
361-
nlIdx = bytes.IndexByte(p, '\n')
362-
continue
363-
} else {
364-
return l, nil
365-
}
366-
}
367-
368-
wr.tmp = append(wr.tmp, p...)
369-
return l, nil
370-
}
371-
372-
func (wr *lineSeparatedAttributeWriter) ReadAttribute() <-chan attributeTriple {
373-
return wr.attributes
374-
}
375-
376-
func (wr *lineSeparatedAttributeWriter) Close() error {
377-
select {
378-
case <-wr.closed:
379-
return nil
380-
default:
381-
}
382-
close(wr.attributes)
383-
close(wr.closed)
384-
return nil
385-
}
386-
387289
// Create a check attribute reader for the current repository and provided commit ID
388290
func (repo *Repository) CheckAttributeReader(commitID string) (*CheckAttributeReader, context.CancelFunc) {
389291
indexFilename, worktree, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)

modules/git/repo_attribute_test.go

-61
Original file line numberDiff line numberDiff line change
@@ -95,64 +95,3 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
9595
Value: "unspecified",
9696
}, attr)
9797
}
98-
99-
func Test_lineSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
100-
wr := &lineSeparatedAttributeWriter{
101-
attributes: make(chan attributeTriple, 5),
102-
}
103-
104-
testStr := `".gitignore\"\n": linguist-vendored: unspecified
105-
`
106-
n, err := wr.Write([]byte(testStr))
107-
108-
assert.Equal(t, n, len(testStr))
109-
assert.NoError(t, err)
110-
111-
select {
112-
case attr := <-wr.ReadAttribute():
113-
assert.Equal(t, ".gitignore\"\n", attr.Filename)
114-
assert.Equal(t, "linguist-vendored", attr.Attribute)
115-
assert.Equal(t, "unspecified", attr.Value)
116-
case <-time.After(100 * time.Millisecond):
117-
assert.Fail(t, "took too long to read an attribute from the list")
118-
}
119-
120-
// Write a second attribute again
121-
n, err = wr.Write([]byte(testStr))
122-
123-
assert.Equal(t, n, len(testStr))
124-
assert.NoError(t, err)
125-
126-
select {
127-
case attr := <-wr.ReadAttribute():
128-
assert.Equal(t, ".gitignore\"\n", attr.Filename)
129-
assert.Equal(t, "linguist-vendored", attr.Attribute)
130-
assert.Equal(t, "unspecified", attr.Value)
131-
case <-time.After(100 * time.Millisecond):
132-
assert.Fail(t, "took too long to read an attribute from the list")
133-
}
134-
135-
// Write a partial attribute
136-
_, err = wr.Write([]byte("incomplete-file"))
137-
assert.NoError(t, err)
138-
_, err = wr.Write([]byte("name: "))
139-
assert.NoError(t, err)
140-
select {
141-
case <-wr.ReadAttribute():
142-
assert.Fail(t, "There should not be an attribute ready to read")
143-
case <-time.After(100 * time.Millisecond):
144-
}
145-
_, err = wr.Write([]byte("attribute: "))
146-
assert.NoError(t, err)
147-
select {
148-
case <-wr.ReadAttribute():
149-
assert.Fail(t, "There should not be an attribute ready to read")
150-
case <-time.After(100 * time.Millisecond):
151-
}
152-
_, err = wr.Write([]byte("value\n"))
153-
assert.NoError(t, err)
154-
attr := <-wr.ReadAttribute()
155-
assert.Equal(t, "incomplete-filename", attr.Filename)
156-
assert.Equal(t, "attribute", attr.Attribute)
157-
assert.Equal(t, "value", attr.Value)
158-
}

modules/markup/markdown/markdown.go

-6
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,3 @@ func RenderRawString(ctx *markup.RenderContext, content string) (string, error)
289289
}
290290
return buf.String(), nil
291291
}
292-
293-
// IsMarkdownFile reports whether name looks like a Markdown file
294-
// based on its extension.
295-
func IsMarkdownFile(name string) bool {
296-
return markup.IsMarkupFile(name, MarkupName)
297-
}

modules/markup/markdown/markdown_test.go

-22
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,6 @@ func TestRender_StandardLinks(t *testing.T) {
7474
`<p><a href="`+lnkWiki+`" rel="nofollow">WikiPage</a></p>`)
7575
}
7676

77-
func TestMisc_IsMarkdownFile(t *testing.T) {
78-
setting.Markdown.FileExtensions = []string{".md", ".markdown", ".mdown", ".mkd"}
79-
trueTestCases := []string{
80-
"test.md",
81-
"wow.MARKDOWN",
82-
"LOL.mDoWn",
83-
}
84-
falseTestCases := []string{
85-
"test",
86-
"abcdefg",
87-
"abcdefghijklmnopqrstuvwxyz",
88-
"test.md.test",
89-
}
90-
91-
for _, testCase := range trueTestCases {
92-
assert.True(t, IsMarkdownFile(testCase))
93-
}
94-
for _, testCase := range falseTestCases {
95-
assert.False(t, IsMarkdownFile(testCase))
96-
}
97-
}
98-
9977
func TestRender_Images(t *testing.T) {
10078
setting.AppURL = AppURL
10179
setting.AppSubURL = AppSubURL

0 commit comments

Comments
 (0)