Browse Source

Sort listed files

Directories first, files seconds, otherwise alphabetically.  This is the
same order that GitHub uses.
Lucas Stadler 8 years ago
parent
commit
10117678a1
1 changed files with 17 additions and 0 deletions
  1. 17 0
      quit.go

+ 17 - 0
quit.go

368
	return fc.commit.Message()
368
	return fc.commit.Message()
369
}
369
}
370
370
371
type byTypeAndName []*FancyFile
372
373
func (b byTypeAndName) Len() int           { return len(b) }
374
func (b byTypeAndName) Less(i, j int) bool { return b[i].Less(b[j]) }
375
func (b byTypeAndName) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }
376
371
func (fc *FancyCommit) Files(recursive bool) ([]*FancyFile, error) {
377
func (fc *FancyCommit) Files(recursive bool) ([]*FancyFile, error) {
372
	tree, err := fc.commit.Tree()
378
	tree, err := fc.commit.Tree()
373
	if err != nil {
379
	if err != nil {
387
		return nil, err
393
		return nil, err
388
	}
394
	}
389
395
396
	sort.Sort(byTypeAndName(files))
397
390
	return files, nil
398
	return files, nil
391
}
399
}
392
400
546
	return template.HTML(buf.String()), nil
554
	return template.HTML(buf.String()), nil
547
}
555
}
548
556
557
func (fc *FancyFile) Less(file *FancyFile) bool {
558
	if fc.entry.Type == file.entry.Type {
559
		return fc.entry.Name < file.entry.Name
560
	}
561
562
	return fc.entry.Type < file.entry.Type
563
564
}
565
549
var repoFuncs = template.FuncMap{
566
var repoFuncs = template.FuncMap{
550
	"languageToColor": func(l string) string {
567
	"languageToColor": func(l string) string {
551
		c, ok := languageColors[l]
568
		c, ok := languageColors[l]