1package main23import (4 "bytes"5 "html/template"6 "strings"78 "github.com/nmeum/depp/gitweb"9)1011func summarize(msg string) string {12 newline := strings.IndexByte(msg, '\n')13 if newline != -1 {14 msg = msg[0:newline]15 }16 return msg17}1819func getRelPath(n int) string {20 var ret string21 for i := 0; i < n; i++ {22 ret += "../"23 }2425 if ret == "" {26 return "./"27 } else {28 return ret29 }30}3132func getLines(data string) []string {33 if len(data) == 0 {34 return []string{""} // empty file35 }3637 // Remove terminating newline (if any)38 if data[len(data)-1] == '\n' {39 data = data[0 : len(data)-1]40 }4142 lines := strings.Split(data, "\n")43 for i, line := range lines {44 // Deal with files containing DOS line endings.45 lines[i] = strings.TrimRight(line, "\r")46 }4748 return lines49}5051func padNumber(maxnum int, curnum int) template.HTML {52 const nonBreakingSpace string = " "53 digitsReq := func(n int) int {54 r := 155 for n/10 > 0 {56 n /= 1057 r++58 }59 return r60 }6162 max := digitsReq(maxnum)63 cur := digitsReq(curnum)6465 diff := max - cur66 if diff == 0 {67 return ""68 }6970 buf := new(bytes.Buffer)71 buf.Grow(diff)7273 for i := 0; i < diff; i++ {74 buf.WriteString(nonBreakingSpace)75 }7677 return template.HTML(buf.String())78}7980func relIndex(file *gitweb.RepoFile) string {81 elems := file.PathElements()82 return getRelPath(len(elems) - 1)83}8485func isIndexPage(page *gitweb.RepoPage) bool {86 return page.CurrentFile.Path == ""87}8889func increment(n int) int {90 return n + 191}9293func decrement(n int) int {94 return n - 195}