func sanitize(s string) (r string) { r = s r = RemoveUrl(r) r = strings.Replace(r, ">", ">", -1) r = strings.Replace(r, "<", "<", -1) r = regexp.MustCompile(", |,|^|[^<,]+ ?\\.").ReplaceAllString(r, "") r = strings.Trim(r, " ") return }
func main() { flag.Parse() lg := &bufIOReaderLineGetter{bufio.NewReader(os.Stdin)} start, _ := time.Parse("2006-01-02", *startdate) end, _ := time.Parse("2006-01-02", *enddate) filter := &Filter{regexp.MustCompile(*path), regexp.MustCompile(*reviewer), regexp.MustCompile(*reviewer), start, end, *reviewed} changes := parseLog(lg, filter) commits := make(map[string]int) reviews := make(map[string]int) numCommits := 0 numReviewedCommits := 0 for _, change := range changes { commits[change.committer]++ numCommits++ if change.reviewer != "" { reviews[change.reviewer]++ numReviewedCommits++ } } if *mincommits != -1 { for committer, count := range commits { if count > *mincommits { fmt.Printf("commits %d %s %.1f%% of total, %.1f%% of reviewed\n", count, committer, 100.0*float64(count)/float64(numCommits), 100.0*float64(count)/float64(numReviewedCommits)) } } } if *minreviews != -1 { for reviewer, count := range reviews { if count > *minreviews { fmt.Printf("reviews %d %s %.1f%%\n", count, reviewer, 100.0*float64(count)/float64(numReviewedCommits)) } } } }
package main import ( "exp/regexp" // Using perl character classes \d and \s "time" ) type Change struct { author, reviewer, committer string paths []string rollout bool date *time.Time } // Adapted from webkitpy/common/checkout/changelog.py var dateLineRE = regexp.MustCompile(`^(20\d{2}-\d{2}-\d{2})\s+(.+?)\s+<[^<>]+>$`) var reviewerRE = regexp.MustCompile(`Reviewed by (.*?)[\.]`) var rolloutRE = regexp.MustCompile(`Unreviewed, rolling out r(\d+)[\.]`) var pathRE = regexp.MustCompile(`\* ([\w/\.]+):`) func parseDateAndCommitter(line string) (*time.Time, string) { submatches := dateLineRE.FindStringSubmatch(line) if submatches == nil { return nil, "" } t, _ := time.Parse("2006-01-02", submatches[1]) return t, submatches[2] } func parseReviewer(lines []string) string {
"log" "os" "strings" ) type feature struct { name string datatype string } type header struct { name string features vector.Vector } var attrRE *regexp.Regexp = regexp.MustCompile("^@attribute\\s+(\\w+)\\s+(\\w+)") var relRE *regexp.Regexp = regexp.MustCompile("^@relation\\s+(\\S+)") // For now just skips the header func readHeader(infile *bufio.Reader) header { var hdr header for line, err := infile.ReadString('\n'); err == nil && !strings.HasPrefix(strings.ToLower(line), "@data"); line, err = infile.ReadString('\n') { line = strings.ToLower(line) match := attrRE.FindStringSubmatch(line) if match != nil { //This line is defining an attribute if len(match) < 3 { log.Fatalf("Invalid header on line:\n%s", line) } hdr.features.Push(match[1])
// Used for adding *'s to included newlines func javaDoc(j JavaDoc) (s string) { s = j.String() s = strings.Replace(s, "\n", "\n * ", -1) s = regexp.MustCompile(" * $").ReplaceAllString(s, " *") return }
package main import ( "exp/regexp" "flag" "fmt" "strings" ) // Used for Stripping out hyperlinks var UrlReg *regexp.Regexp = regexp.MustCompile("</?a.*?>") var tabs bool func init() { flag.BoolVar(&tabs, "t", false, "Use tabs instead of spaces.") } func RemoveUrl(s string) string { return UrlReg.ReplaceAllString(s, "") } // Used for properly tabbing nested things func tab(s string, i int) (result string) { if tabs { result = "\t" + strings.Replace(s, "\n", "\n\t", -1) } else { result = " " + strings.Replace(s, "\n", "\n ", -1) } return }