From 242b0eb219dbb269deacdae76de2f8b0b788ac40 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Tue, 28 Jul 2020 15:55:14 -0500 Subject: pkg: get and store Maintainers data Create a struct on pkg/vcs to store data of syzkaller email recipients and update its users. The struct contains default name, email, and a label to divide user into To and Cc when sending the emails. --- pkg/vcs/linux.go | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'pkg/vcs/linux.go') diff --git a/pkg/vcs/linux.go b/pkg/vcs/linux.go index a9a823621..069493411 100644 --- a/pkg/vcs/linux.go +++ b/pkg/vcs/linux.go @@ -12,12 +12,12 @@ import ( "net/mail" "os" "path/filepath" + "regexp" "sort" "strconv" "strings" "time" - "github.com/google/syzkaller/pkg/email" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/prog" ) @@ -214,21 +214,22 @@ func (ctx *linux) Bisect(bad, good string, trace io.Writer, pred func() (BisectR } func (ctx *linux) addMaintainers(com *Commit) { - if len(com.CC) > 2 { + if len(com.Recipients) > 2 { return } - list := ctx.getMaintainers(com.Hash, false) - if len(list) < 3 { - list = ctx.getMaintainers(com.Hash, true) + mtrs := ctx.getMaintainers(com.Hash, false) + if len(mtrs) < 3 { + mtrs = ctx.getMaintainers(com.Hash, true) } - com.CC = email.MergeEmailLists(com.CC, list) + com.Recipients = append(com.Recipients, mtrs...) + sort.Sort(com.Recipients) } -func (ctx *linux) getMaintainers(hash string, blame bool) []string { +func (ctx *linux) getMaintainers(hash string, blame bool) Recipients { // See #1441 re --git-min-percent. args := "git show " + hash + " | " + filepath.FromSlash("scripts/get_maintainer.pl") + - " --no-n --no-rolestats --git-min-percent=20" + " --git-min-percent=20" if blame { args += " --git-blame" } @@ -236,15 +237,42 @@ func (ctx *linux) getMaintainers(hash string, blame bool) []string { if err != nil { return nil } - var list []string - for _, line := range strings.Split(string(output), "\n") { - addr, err := mail.ParseAddress(line) + return ParseMaintainersLinux(output) +} + +func ParseMaintainersLinux(text []byte) Recipients { + lines := strings.Split(string(text), "\n") + reRole := regexp.MustCompile(` \([^)]+\)$`) + var mtrs Recipients + // LMKL is To by default, but it changes to Cc if there's also a subsystem list. + lkmlType := To + foundLkml := false + for _, line := range lines { + role := reRole.FindString(line) + address := strings.Replace(line, role, "", 1) + addr, err := mail.ParseAddress(address) if err != nil { continue } - list = append(list, strings.ToLower(addr.Address)) + var roleType RecipientType + if addr.Address == "linux-kernel@vger.kernel.org" { + foundLkml = true + continue + } else if strings.Contains(role, "list") { + lkmlType = Cc + roleType = To + } else if strings.Contains(role, "maintainer") || strings.Contains(role, "supporter") { + roleType = To + } else { + roleType = Cc // Reviewer or other role; default to Cc. + } + mtrs = append(mtrs, RecipientInfo{*addr, roleType}) + } + if foundLkml { + mtrs = append(mtrs, RecipientInfo{mail.Address{Address: "linux-kernel@vger.kernel.org"}, lkmlType}) } - return list + sort.Sort(mtrs) + return mtrs } const configBisectTag = "# Minimized by syzkaller" -- cgit mrf-deployment