loadDiff loads a diff, either for a specific commit or the full branch.
(storyID, commitHash string)
| 70 | |
| 71 | // loadDiff loads a diff, either for a specific commit or the full branch. |
| 72 | func (d *DiffViewer) loadDiff(storyID, commitHash string) { |
| 73 | d.offset = 0 |
| 74 | d.loaded = true |
| 75 | |
| 76 | var diff string |
| 77 | var err error |
| 78 | |
| 79 | if commitHash != "" { |
| 80 | diff, err = git.GetDiffForCommit(d.baseDir, commitHash) |
| 81 | } else { |
| 82 | diff, err = git.GetDiff(d.baseDir) |
| 83 | } |
| 84 | |
| 85 | if err != nil { |
| 86 | d.err = err |
| 87 | d.lines = nil |
| 88 | d.stats = "" |
| 89 | return |
| 90 | } |
| 91 | |
| 92 | d.err = nil |
| 93 | |
| 94 | if strings.TrimSpace(diff) == "" { |
| 95 | d.lines = nil |
| 96 | d.stats = "" |
| 97 | return |
| 98 | } |
| 99 | |
| 100 | d.lines = strings.Split(diff, "\n") |
| 101 | |
| 102 | if commitHash != "" { |
| 103 | stats, err := git.GetDiffStatsForCommit(d.baseDir, commitHash) |
| 104 | if err == nil { |
| 105 | d.stats = stats |
| 106 | } |
| 107 | } else { |
| 108 | stats, err := git.GetDiffStats(d.baseDir) |
| 109 | if err == nil { |
| 110 | d.stats = stats |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // ScrollUp scrolls up one line. |
| 116 | func (d *DiffViewer) ScrollUp() { |
no test coverage detected