@@ -66,27 +66,20 @@ type PageMeta struct {
66
66
67
67
// findEntryForFile finds the tree entry for a target filepath.
68
68
func findEntryForFile (commit * git.Commit , target string ) (* git.TreeEntry , error ) {
69
- entries , err := commit .ListEntries ( )
70
- if err != nil {
69
+ entry , err := commit .GetTreeEntryByPath ( target )
70
+ if err != nil && ! git . IsErrNotExist ( err ) {
71
71
return nil , err
72
72
}
73
- // The longest name should be checked first
74
- for _ , entry := range entries {
75
- if entry .IsRegular () && entry .Name () == target {
76
- return entry , nil
77
- }
73
+ if entry != nil {
74
+ return entry , nil
78
75
}
76
+
79
77
// Then the unescaped, shortest alternative
80
78
var unescapedTarget string
81
79
if unescapedTarget , err = url .QueryUnescape (target ); err != nil {
82
80
return nil , err
83
81
}
84
- for _ , entry := range entries {
85
- if entry .IsRegular () && entry .Name () == unescapedTarget {
86
- return entry , nil
87
- }
88
- }
89
- return nil , nil
82
+ return commit .GetTreeEntryByPath (unescapedTarget )
90
83
}
91
84
92
85
func findWikiRepoCommit (ctx * context.Context ) (* git.Repository , * git.Commit , error ) {
@@ -123,10 +116,9 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
123
116
// wikiContentsByName returns the contents of a wiki page, along with a boolean
124
117
// indicating whether the page exists. Writes to ctx if an error occurs.
125
118
func wikiContentsByName (ctx * context.Context , commit * git.Commit , wikiName string ) ([]byte , * git.TreeEntry , string , bool ) {
126
- var entry * git.TreeEntry
127
- var err error
128
119
pageFilename := wiki_service .NameToFilename (wikiName )
129
- if entry , err = findEntryForFile (commit , pageFilename ); err != nil {
120
+ entry , err := findEntryForFile (commit , pageFilename )
121
+ if err != nil && ! git .IsErrNotExist (err ) {
130
122
ctx .ServerError ("findEntryForFile" , err )
131
123
return nil , nil , "" , false
132
124
} else if entry == nil {
@@ -518,7 +510,7 @@ func WikiRaw(ctx *context.Context) {
518
510
if commit != nil {
519
511
// Try to find a file with that name
520
512
entry , err = findEntryForFile (commit , providedPath )
521
- if err != nil {
513
+ if err != nil && ! git . IsErrNotExist ( err ) {
522
514
ctx .ServerError ("findFile" , err )
523
515
return
524
516
}
@@ -531,7 +523,7 @@ func WikiRaw(ctx *context.Context) {
531
523
532
524
wikiPath := wiki_service .NameToFilename (providedPath )
533
525
entry , err = findEntryForFile (commit , wikiPath )
534
- if err != nil {
526
+ if err != nil && ! git . IsErrNotExist ( err ) {
535
527
ctx .ServerError ("findFile" , err )
536
528
return
537
529
}
0 commit comments