The new Ripple frontend.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loadchangelog.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import (
  3. "bufio"
  4. "os"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. type commit struct {
  10. Hash string
  11. UnixTimestamp time.Time
  12. Username string
  13. Subject string
  14. }
  15. func createFromString(s string) (c commit) {
  16. var r = strings.SplitN(s, "|", 4)
  17. for i, v := range r {
  18. switch i {
  19. case 0:
  20. c.Hash = v
  21. case 1:
  22. i, err := strconv.ParseInt(v, 10, 64)
  23. if err != nil {
  24. continue
  25. }
  26. c.UnixTimestamp = time.Unix(i, 0)
  27. case 2:
  28. c.Username = v
  29. case 3:
  30. c.Subject = v
  31. }
  32. }
  33. return
  34. }
  35. func loadChangelog(page int) []commit {
  36. f, err := os.Open(config.MainRippleFolder + "/ci-system/ci-system/changelog.txt")
  37. defer f.Close()
  38. if err != nil {
  39. return nil
  40. }
  41. r := bufio.NewScanner(f)
  42. if page < 0 {
  43. page = 0
  44. } else if page > 50000 {
  45. page = 50000
  46. }
  47. times := (page - 1) * 50
  48. if times < 0 {
  49. times = 0
  50. }
  51. for i := 0; i < times; i++ {
  52. // Discard n lines
  53. r.Scan()
  54. }
  55. comms := make([]commit, 0, 50)
  56. for i := 0; r.Scan() && i < 50; i++ {
  57. s := r.Text()
  58. comms = append(comms, createFromString(s))
  59. }
  60. return comms
  61. }