// scanHg is a helper function for ScanContributions which takes care of the git part func scanHg(project Project, emails []string, contributions []Contribution) (int, error) { var sum int for _, repo := range project.Hgrepos { util.PrintInfo("Working on "+repo, util.PI_TASK) if PullSources { err := hg.GetLatestRepo(repo) if err != nil { util.PrintInfo("Problem loading repo", util.PI_MILD_ERROR) return 0, err } } for _, email := range emails { path := filepath.Join("repos-hg", util.LocalRepoName(repo)) hgCount, err := hg.CountCommits(path, email) if err != nil { return 0, err } if hgCount != 0 { util.PrintInfoF("%s: %d commits", util.PI_RESULT, email, hgCount) sum += hgCount } } } return sum, nil }
// GetLatestRepo either clones a new repo or updates an existing one // into the 'repos' directory. func GetLatestRepo(url string) (err error) { var local string local = util.LocalRepoName(url) rd := RepoData{url: url, workingDirectory: "repos-hg", localName: local} if util.FileExists(filepath.Join("repos-hg", local)) { err = updateRepo(rd) } else { err = cloneRepo(rd) } return }
// CountCommits returns how often email occurs in the log for // the git repository at url. func CountCommits(url string, email string) (int, error) { local := util.LocalRepoName(url) authorSwitch := "--author=" + email cmd := exec.Command("git", "log", "--pretty=tformat:%s", authorSwitch) cmd.Dir = "repos/" + local cmdOutput := &bytes.Buffer{} cmd.Stdout = cmdOutput err := cmd.Run() if err != nil { return 0, err } //fmt.Println(strings.Join(cmd.Args, " ") + " in " + cmd.Dir) s := (string(cmdOutput.Bytes())) return strings.Count(s, "\n"), nil }
// GetLatestGitRepo either clones a new repo or updates an existing one // into the 'repos' directory. func GetLatestGitRepo(url string, isTest bool) error { var err error var local string if isTest { local = "dummy-git-repo" } else { local = util.LocalRepoName(url) } rd := RepoData{url: url, workingDirectory: "repos", localName: local} if util.FileExists("repos/" + local) { err = updateRepo(rd) } else { err = cloneRepo(rd) } return err }