浏览代码

Sort listed files

Directories first, files seconds, otherwise alphabetically.  This is the
same order that GitHub uses.
Lucas Stadler 8 年之前
父节点
当前提交
10117678a1
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17 0
      quit.go

+ 17 - 0
quit.go

@ -368,6 +368,12 @@ func (fc *FancyCommit) Description() string {
368 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 377
func (fc *FancyCommit) Files(recursive bool) ([]*FancyFile, error) {
372 378
	tree, err := fc.commit.Tree()
373 379
	if err != nil {
@ -387,6 +393,8 @@ func (fc *FancyCommit) Files(recursive bool) ([]*FancyFile, error) {
387 393
		return nil, err
388 394
	}
389 395
396
	sort.Sort(byTypeAndName(files))
397
390 398
	return files, nil
391 399
}
392 400
@ -546,6 +554,15 @@ func (fc *FancyFile) Contents() (template.HTML, error) {
546 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 566
var repoFuncs = template.FuncMap{
550 567
	"languageToColor": func(l string) string {
551 568
		c, ok := languageColors[l]