printStat prints the stats of changes in content of files. Original implementation: https://github.com/git/git/blob/1a87c842ece327d03d08096395969aca5e0a6996/diff.c#L2615 Parts of the output: | <+++/---> example: " main.go | 10 +++++++--- "
(fileStats []FileStat)
| 240 | // <pad><filename><pad>|<pad><changeNumber><pad><+++/---><newline> |
| 241 | // example: " main.go | 10 +++++++--- " |
| 242 | func printStat(fileStats []FileStat) string { |
| 243 | maxGraphWidth := uint(53) |
| 244 | maxNameLen := 0 |
| 245 | maxChangeLen := 0 |
| 246 | |
| 247 | scaleLinear := func(it, width, max uint) uint { |
| 248 | if it == 0 || max == 0 { |
| 249 | return 0 |
| 250 | } |
| 251 | |
| 252 | return 1 + (it * (width - 1) / max) |
| 253 | } |
| 254 | |
| 255 | for _, fs := range fileStats { |
| 256 | if len(fs.Name) > maxNameLen { |
| 257 | maxNameLen = len(fs.Name) |
| 258 | } |
| 259 | |
| 260 | changes := strconv.Itoa(fs.Addition + fs.Deletion) |
| 261 | if len(changes) > maxChangeLen { |
| 262 | maxChangeLen = len(changes) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | result := "" |
| 267 | for _, fs := range fileStats { |
| 268 | add := uint(fs.Addition) |
| 269 | del := uint(fs.Deletion) |
| 270 | np := maxNameLen - len(fs.Name) |
| 271 | cp := maxChangeLen - len(strconv.Itoa(fs.Addition+fs.Deletion)) |
| 272 | |
| 273 | total := add + del |
| 274 | if total > maxGraphWidth { |
| 275 | add = scaleLinear(add, maxGraphWidth, total) |
| 276 | del = scaleLinear(del, maxGraphWidth, total) |
| 277 | } |
| 278 | |
| 279 | adds := strings.Repeat("+", int(add)) |
| 280 | dels := strings.Repeat("-", int(del)) |
| 281 | namePad := strings.Repeat(" ", np) |
| 282 | changePad := strings.Repeat(" ", cp) |
| 283 | |
| 284 | result += fmt.Sprintf(" %s%s | %s%d %s%s\n", fs.Name, namePad, changePad, total, adds, dels) |
| 285 | } |
| 286 | return result |
| 287 | } |
| 288 | |
| 289 | func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats { |
| 290 | var fileStats FileStats |
no outgoing calls