Skip to content

Commit

Permalink
Merge pull request #218 from vmarkovtsev/master
Browse files Browse the repository at this point in the history
Add blame info per file with --burndown-file
  • Loading branch information
vmarkovtsev authored Feb 26, 2019
2 parents 1d3e068 + de3c384 commit 0a3e606
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 183 deletions.
36 changes: 22 additions & 14 deletions internal/burndown/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ func (file *File) Delete() {

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

// Nodes returns the number of RBTree nodes in the file.
func (file *File) Nodes() int {
func (file File) Nodes() int {
return file.tree.Len()
}

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

// Dump formats the underlying line interval tree into a string.
// Useful for error messages, panic()-s and debugging.
func (file *File) Dump() string {
func (file File) Dump() string {
buffer := ""
for iter := file.tree.Min(); !iter.Limit(); iter = iter.Next() {
node := iter.Item()
var val int
if node.Value == math.MaxUint32 {
val = -1
} else {
val = int(node.Value)
}
buffer += fmt.Sprintf("%d %d\n", node.Key, val)
}
file.ForEach(func(line, value int) {
buffer += fmt.Sprintf("%d %d\n", line, value)
})
return buffer
}

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

// ForEach visits each node in the underlying tree, in ascending key order.
func (file File) ForEach(callback func(line, value int)) {
for iter := file.tree.Min(); !iter.Limit(); iter = iter.Next() {
item := iter.Item()
key := int(item.Key)
var value int
if item.Value == math.MaxUint32 {
value = -1
} else {
value = int(item.Value)
}
callback(key, value)
}
}

// flatten represents the file as a slice of lines, each line's value being the corresponding day.
func (file *File) flatten() []int {
lines := make([]int, 0, file.Len())
Expand Down
236 changes: 134 additions & 102 deletions internal/pb/pb.pb.go

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions internal/pb/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,26 @@ message BurndownSparseMatrix {
repeated BurndownSparseMatrixRow rows = 4;
}

message FilesOwnership {
// The sum always equals to the total number of lines in the file.
map<int32, int32> value = 1;
}

message BurndownAnalysisResults {
// how many days are in each band [burndown_project, burndown_file, burndown_developer]
int32 granularity = 1;
// how frequently we measure the state of each band [burndown_project, burndown_file, burndown_developer]
int32 sampling = 2;
// always exists
BurndownSparseMatrix project = 3;
// this is included if `-burndown-files` was specified
// this is included if `--burndown-files` was specified
repeated BurndownSparseMatrix files = 4;
// these two are included if `-burndown-people` was specified
// these two are included if `--burndown-people` was specified
repeated BurndownSparseMatrix people = 5;
// rows and cols order correspond to `burndown_developer`
CompressedSparseRowMatrix people_interaction = 6;
// How many lines belong to relevant developers for each file. The order is the same as in `files`.
repeated FilesOwnership files_ownership = 7;
}

message CompressedSparseRowMatrix {
Expand Down
Loading

0 comments on commit 0a3e606

Please sign in to comment.