Browse Source

Fix the panic on identity list misses

Vadim Markovtsev 7 years ago
parent
commit
7ab067d012
3 changed files with 13 additions and 6 deletions
  1. 5 2
      cmd/hercules/main.go
  2. 7 4
      couples.go
  3. 1 0
      identity.go

+ 5 - 2
cmd/hercules/main.go

@@ -256,11 +256,14 @@ func main() {
 	pipeline.AddItem(&hercules.RenameAnalysis{SimilarityThreshold: similarity_threshold})
 	pipeline.AddItem(&hercules.TreeDiff{})
 	id_matcher := &hercules.IdentityDetector{}
+	var peopleCount int
 	if with_people || with_couples {
 		if people_dict_path != "" {
 			id_matcher.LoadPeopleDict(people_dict_path)
+			peopleCount = len(id_matcher.ReversePeopleDict) - 1
 		} else {
 			id_matcher.GeneratePeopleDict(commits)
+			peopleCount = len(id_matcher.ReversePeopleDict)
 		}
 	}
 	pipeline.AddItem(id_matcher)
@@ -268,12 +271,12 @@ func main() {
 		Granularity:  granularity,
 		Sampling:     sampling,
 		Debug:        debug,
-		PeopleNumber: len(id_matcher.ReversePeopleDict),
+		PeopleNumber: peopleCount,
 	}
 	pipeline.AddItem(burndowner)
 	var coupler *hercules.Couples
 	if with_couples {
-		coupler = &hercules.Couples{PeopleNumber: len(id_matcher.ReversePeopleDict)}
+		coupler = &hercules.Couples{PeopleNumber: peopleCount}
 		pipeline.AddItem(coupler)
 	}
 

+ 7 - 4
couples.go

@@ -41,16 +41,19 @@ func (couples *Couples) Requires() []string {
 }
 
 func (couples *Couples) Initialize(repository *git.Repository) {
-	couples.people = make([]map[string]int, couples.PeopleNumber)
+	couples.people = make([]map[string]int, couples.PeopleNumber + 1)
 	for i := range couples.people {
 		couples.people[i] = map[string]int{}
 	}
-	couples.people_commits = make([]int, couples.PeopleNumber)
+	couples.people_commits = make([]int, couples.PeopleNumber + 1)
 	couples.files = map[string]map[string]int{}
 }
 
 func (couples *Couples) Consume(deps map[string]interface{}) (map[string]interface{}, error) {
 	author := deps["author"].(int)
+	if author == MISSING_AUTHOR {
+		author = couples.PeopleNumber
+	}
 	couples.people_commits[author] += 1
 	tree_diff := deps["renamed_changes"].(object.Changes)
 	context := make([]string, 0)
@@ -104,8 +107,8 @@ func (couples *Couples) Consume(deps map[string]interface{}) (map[string]interfa
 }
 
 func (couples *Couples) Finalize() interface{} {
-	peopleMatrix := make([]map[int]int64, couples.PeopleNumber)
-	peopleFiles := make([][]string, couples.PeopleNumber)
+	peopleMatrix := make([]map[int]int64, couples.PeopleNumber + 1)
+	peopleFiles := make([][]string, couples.PeopleNumber + 1)
 	for i := range peopleMatrix {
 		peopleMatrix[i] = map[int]int64{}
 		for file, commits := range couples.people[i] {

+ 1 - 0
identity.go

@@ -70,6 +70,7 @@ func (id *IdentityDetector) LoadPeopleDict(path string) error {
 		reverse_dict = append(reverse_dict, ids[0])
 		size += 1
 	}
+	reverse_dict = append(reverse_dict, "<unmatched>")
 	id.PeopleDict = dict
 	id.ReversePeopleDict = reverse_dict
 	return nil