Skip to content

Commit 0a3e606

Browse files
authored
Merge pull request #218 from vmarkovtsev/master
Add blame info per file with --burndown-file
2 parents 1d3e068 + de3c384 commit 0a3e606

File tree

7 files changed

+403
-183
lines changed

7 files changed

+403
-183
lines changed

internal/burndown/file.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ func (file *File) Delete() {
123123

124124
// Len returns the File's size - that is, the maximum key in the tree of line
125125
// intervals.
126-
func (file *File) Len() int {
126+
func (file File) Len() int {
127127
return int(file.tree.Max().Item().Key)
128128
}
129129

130130
// Nodes returns the number of RBTree nodes in the file.
131-
func (file *File) Nodes() int {
131+
func (file File) Nodes() int {
132132
return file.tree.Len()
133133
}
134134

@@ -327,18 +327,11 @@ func (file *File) Merge(day int, others ...*File) {
327327

328328
// Dump formats the underlying line interval tree into a string.
329329
// Useful for error messages, panic()-s and debugging.
330-
func (file *File) Dump() string {
330+
func (file File) Dump() string {
331331
buffer := ""
332-
for iter := file.tree.Min(); !iter.Limit(); iter = iter.Next() {
333-
node := iter.Item()
334-
var val int
335-
if node.Value == math.MaxUint32 {
336-
val = -1
337-
} else {
338-
val = int(node.Value)
339-
}
340-
buffer += fmt.Sprintf("%d %d\n", node.Key, val)
341-
}
332+
file.ForEach(func(line, value int) {
333+
buffer += fmt.Sprintf("%d %d\n", line, value)
334+
})
342335
return buffer
343336
}
344337

@@ -351,7 +344,7 @@ func (file *File) Dump() string {
351344
// which marks the ending of the last line interval.
352345
//
353346
// 3. Node keys must monotonically increase and never duplicate.
354-
func (file *File) Validate() {
347+
func (file File) Validate() {
355348
if file.tree.Min().Item().Key != 0 {
356349
log.Panic("the tree must start with key 0")
357350
}
@@ -371,6 +364,21 @@ func (file *File) Validate() {
371364
}
372365
}
373366

367+
// ForEach visits each node in the underlying tree, in ascending key order.
368+
func (file File) ForEach(callback func(line, value int)) {
369+
for iter := file.tree.Min(); !iter.Limit(); iter = iter.Next() {
370+
item := iter.Item()
371+
key := int(item.Key)
372+
var value int
373+
if item.Value == math.MaxUint32 {
374+
value = -1
375+
} else {
376+
value = int(item.Value)
377+
}
378+
callback(key, value)
379+
}
380+
}
381+
374382
// flatten represents the file as a slice of lines, each line's value being the corresponding day.
375383
func (file *File) flatten() []int {
376384
lines := make([]int, 0, file.Len())

internal/pb/pb.pb.go

+134-102
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/pb/pb.proto

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,26 @@ message BurndownSparseMatrix {
3333
repeated BurndownSparseMatrixRow rows = 4;
3434
}
3535

36+
message FilesOwnership {
37+
// The sum always equals to the total number of lines in the file.
38+
map<int32, int32> value = 1;
39+
}
40+
3641
message BurndownAnalysisResults {
3742
// how many days are in each band [burndown_project, burndown_file, burndown_developer]
3843
int32 granularity = 1;
3944
// how frequently we measure the state of each band [burndown_project, burndown_file, burndown_developer]
4045
int32 sampling = 2;
4146
// always exists
4247
BurndownSparseMatrix project = 3;
43-
// this is included if `-burndown-files` was specified
48+
// this is included if `--burndown-files` was specified
4449
repeated BurndownSparseMatrix files = 4;
45-
// these two are included if `-burndown-people` was specified
50+
// these two are included if `--burndown-people` was specified
4651
repeated BurndownSparseMatrix people = 5;
4752
// rows and cols order correspond to `burndown_developer`
4853
CompressedSparseRowMatrix people_interaction = 6;
54+
// How many lines belong to relevant developers for each file. The order is the same as in `files`.
55+
repeated FilesOwnership files_ownership = 7;
4956
}
5057

5158
message CompressedSparseRowMatrix {

0 commit comments

Comments
 (0)