| 172 | }) |
| 173 | |
| 174 | func addAuthors(authors *authorSet) { |
| 175 | // All existing source-tracked files |
| 176 | bs, err := exec.Command("git", "ls-tree", "-r", "HEAD", "--name-only").CombinedOutput() |
| 177 | if err != nil { |
| 178 | fmt.Println(string(bs)) |
| 179 | log.Fatal("git ls-tree:", err) |
| 180 | } |
| 181 | files := strings.Split(string(bs), "\n") |
| 182 | files = slices.DeleteFunc(files, func(s string) bool { |
| 183 | return !(strings.HasPrefix(s, "assets/") || |
| 184 | strings.HasPrefix(s, "cmd/") || |
| 185 | strings.HasPrefix(s, "etc/") || |
| 186 | strings.HasPrefix(s, "gui/") || |
| 187 | strings.HasPrefix(s, "internal/") || |
| 188 | strings.HasPrefix(s, "lib/") || |
| 189 | strings.HasPrefix(s, "proto/") || |
| 190 | strings.HasPrefix(s, "script/") || |
| 191 | strings.HasPrefix(s, "test/") || |
| 192 | strings.HasPrefix(s, "Dockerfile") || |
| 193 | s == "build.go") |
| 194 | }) |
| 195 | |
| 196 | coAuthoredPrefix := "Co-authored-by: " |
| 197 | for _, file := range files { |
| 198 | // All commits affecting those files, following any renames to their |
| 199 | // origin. Format is hash, email, name, newline, body. The body is |
| 200 | // indented with one space, to differentiate from the hash lines. |
| 201 | args := []string{"log", "--format=%H %ae %an%n%w(,1,1)%b", "--follow", "--", file} |
| 202 | bs, err = exec.Command("git", args...).CombinedOutput() |
| 203 | if err != nil { |
| 204 | fmt.Println(string(bs)) |
| 205 | log.Fatal("git log:", err) |
| 206 | } |
| 207 | |
| 208 | skipCommit := false |
| 209 | var hash, email, name string |
| 210 | for _, line := range bytes.Split(bs, []byte{'\n'}) { |
| 211 | if len(line) == 0 { |
| 212 | continue |
| 213 | } |
| 214 | |
| 215 | switch line[0] { |
| 216 | case ' ': |
| 217 | // Look for Co-authored-by: lines in the commit body. |
| 218 | if skipCommit { |
| 219 | continue |
| 220 | } |
| 221 | |
| 222 | line = line[1:] |
| 223 | if bytes.HasPrefix(line, []byte(coAuthoredPrefix)) { |
| 224 | // Co-authored-by: Name Name <email@example.com> |
| 225 | line = line[len(coAuthoredPrefix):] |
| 226 | if name, email, ok := strings.Cut(string(line), "<"); ok { |
| 227 | name = strings.TrimSpace(name) |
| 228 | email = strings.Trim(strings.TrimSpace(email), "<>") |
| 229 | if email == "@" { |
| 230 | // GitHub special for users who hide their email. |
| 231 | continue |