| OLD | NEW |
| 1 // gitinfo enables querying info from a Git repository. | 1 // gitinfo enables querying info from a Git repository. |
| 2 package gitinfo | 2 package gitinfo |
| 3 | 3 |
| 4 import ( | 4 import ( |
| 5 "fmt" | 5 "fmt" |
| 6 "os" | 6 "os" |
| 7 "os/exec" | 7 "os/exec" |
| 8 "path" | 8 "path" |
| 9 "regexp" | 9 "regexp" |
| 10 "sort" | 10 "sort" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // commit b7988a21fdf23cc4ace6145a06ea824aa85db099 | 168 // commit b7988a21fdf23cc4ace6145a06ea824aa85db099 |
| 169 // Author: Joe Gregorio <jcgregorio@google.com> | 169 // Author: Joe Gregorio <jcgregorio@google.com> |
| 170 // Date: Tue Aug 5 16:19:48 2014 -0400 | 170 // Date: Tue Aug 5 16:19:48 2014 -0400 |
| 171 // | 171 // |
| 172 // A description of the commit. | 172 // A description of the commit. |
| 173 // | 173 // |
| 174 // perf/go/skiaperf/perf.go | 174 // perf/go/skiaperf/perf.go |
| 175 // perf/go/types/types.go | 175 // perf/go/types/types.go |
| 176 // perf/res/js/logic.js | 176 // perf/res/js/logic.js |
| 177 // | 177 // |
| 178 func (g GitInfo) Log(begin, end string) (string, error) { | 178 func (g *GitInfo) Log(begin, end string) (string, error) { |
| 179 command := []string{"log", "--name-only"} | 179 command := []string{"log", "--name-only"} |
| 180 hashrange := begin | 180 hashrange := begin |
| 181 if end != "" { | 181 if end != "" { |
| 182 hashrange += ".." + end | 182 hashrange += ".." + end |
| 183 command = append(command, hashrange) | 183 command = append(command, hashrange) |
| 184 } else { | 184 } else { |
| 185 command = append(command, "-n", "1", hashrange) | 185 command = append(command, "-n", "1", hashrange) |
| 186 } | 186 } |
| 187 cmd := exec.Command("git", command...) | 187 cmd := exec.Command("git", command...) |
| 188 cmd.Dir = g.dir | 188 cmd.Dir = g.dir |
| 189 b, err := cmd.Output() | 189 b, err := cmd.Output() |
| 190 if err != nil { | 190 if err != nil { |
| 191 return "", err | 191 return "", err |
| 192 } | 192 } |
| 193 return string(b), nil | 193 return string(b), nil |
| 194 } | 194 } |
| 195 | 195 |
| 196 // FullHash gives the full commit hash for the given ref. | 196 // FullHash gives the full commit hash for the given ref. |
| 197 func (g GitInfo) FullHash(ref string) (string, error) { | 197 func (g *GitInfo) FullHash(ref string) (string, error) { |
| 198 cmd := exec.Command("git", "rev-parse", ref) | 198 cmd := exec.Command("git", "rev-parse", ref) |
| 199 cmd.Dir = g.dir | 199 cmd.Dir = g.dir |
| 200 b, err := cmd.Output() | 200 b, err := cmd.Output() |
| 201 if err != nil { | 201 if err != nil { |
| 202 return "", err | 202 return "", err |
| 203 } | 203 } |
| 204 return string(b), nil | 204 return string(b), nil |
| 205 } | 205 } |
| 206 | 206 |
| 207 // GetFile returns the contents of the given file at the given commit. | 207 // GetFile returns the contents of the given file at the given commit. |
| 208 func (g GitInfo) GetFile(fileName, commit string) (string, error) { | 208 func (g *GitInfo) GetFile(fileName, commit string) (string, error) { |
| 209 cmd := exec.Command("git", "show", commit+":"+fileName) | 209 cmd := exec.Command("git", "show", commit+":"+fileName) |
| 210 cmd.Dir = g.dir | 210 cmd.Dir = g.dir |
| 211 b, err := cmd.Output() | 211 b, err := cmd.Output() |
| 212 if err != nil { | 212 if err != nil { |
| 213 return "", err | 213 return "", err |
| 214 } | 214 } |
| 215 return string(b), nil | 215 return string(b), nil |
| 216 } | 216 } |
| 217 | 217 |
| 218 // InitalCommit returns the hash of the initial commit. | 218 // InitalCommit returns the hash of the initial commit. |
| 219 func (g GitInfo) InitialCommit() (string, error) { | 219 func (g *GitInfo) InitialCommit() (string, error) { |
| 220 cmd := exec.Command("git", "rev-list", "--max-parents=0", "HEAD") | 220 cmd := exec.Command("git", "rev-list", "--max-parents=0", "HEAD") |
| 221 cmd.Dir = g.dir | 221 cmd.Dir = g.dir |
| 222 b, err := cmd.Output() | 222 b, err := cmd.Output() |
| 223 if err != nil { | 223 if err != nil { |
| 224 return "", fmt.Errorf("Failed to determine initial commit: %v",
err) | 224 return "", fmt.Errorf("Failed to determine initial commit: %v",
err) |
| 225 } | 225 } |
| 226 return strings.Trim(string(b), "\n"), nil | 226 return strings.Trim(string(b), "\n"), nil |
| 227 } | 227 } |
| 228 | 228 |
| 229 // GetBranches returns a slice of strings naming the branches in the repo. | 229 // GetBranches returns a slice of strings naming the branches in the repo. |
| 230 func (g GitInfo) GetBranches() ([]*GitBranch, error) { | 230 func (g *GitInfo) GetBranches() ([]*GitBranch, error) { |
| 231 return GetBranches(g.dir) | 231 return GetBranches(g.dir) |
| 232 } | 232 } |
| 233 | 233 |
| 234 // ShortCommits stores a slice of ShortCommit struct. | 234 // ShortCommits stores a slice of ShortCommit struct. |
| 235 type ShortCommits struct { | 235 type ShortCommits struct { |
| 236 Commits []*ShortCommit | 236 Commits []*ShortCommit |
| 237 } | 237 } |
| 238 | 238 |
| 239 // ShortList returns a slice of ShortCommit for every commit in (begin, end]. | 239 // ShortList returns a slice of ShortCommit for every commit in (begin, end]. |
| 240 func (g *GitInfo) ShortList(begin, end string) (*ShortCommits, error) { | 240 func (g *GitInfo) ShortList(begin, end string) (*ShortCommits, error) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 369 } |
| 370 sort.Sort(gitHashSlice(gitHashes)) | 370 sort.Sort(gitHashSlice(gitHashes)) |
| 371 hashes := make([]string, len(timestamps), len(timestamps)) | 371 hashes := make([]string, len(timestamps), len(timestamps)) |
| 372 for i, h := range gitHashes { | 372 for i, h := range gitHashes { |
| 373 hashes[i] = h.hash | 373 hashes[i] = h.hash |
| 374 } | 374 } |
| 375 return hashes, timestamps, nil | 375 return hashes, timestamps, nil |
| 376 } | 376 } |
| 377 | 377 |
| 378 // SkpCommits returns the indices for all the commits that contain SKP updates. | 378 // SkpCommits returns the indices for all the commits that contain SKP updates. |
| 379 func (g GitInfo) SkpCommits(tile *types.Tile) ([]int, error) { | 379 func (g *GitInfo) SkpCommits(tile *types.Tile) ([]int, error) { |
| 380 // Executes a git log command that looks like: | 380 // Executes a git log command that looks like: |
| 381 // | 381 // |
| 382 // git log --format=format:%H 32956400b4d8f33394e2cdef9b66e8369ba2a0f
3..e7416bfc9858bde8fc6eb5f3bfc942bc3350953a SKP_VERSION | 382 // git log --format=format:%H 32956400b4d8f33394e2cdef9b66e8369ba2a0f
3..e7416bfc9858bde8fc6eb5f3bfc942bc3350953a SKP_VERSION |
| 383 // | 383 // |
| 384 // The output should be a \n separated list of hashes that match. | 384 // The output should be a \n separated list of hashes that match. |
| 385 first, last := tile.CommitRange() | 385 first, last := tile.CommitRange() |
| 386 cmd := exec.Command("git", "log", "--format=format:%H", first+".."+last,
"SKP_VERSION") | 386 cmd := exec.Command("git", "log", "--format=format:%H", first+".."+last,
"SKP_VERSION") |
| 387 cmd.Dir = g.dir | 387 cmd.Dir = g.dir |
| 388 b, err := cmd.Output() | 388 b, err := cmd.Output() |
| 389 if err != nil { | 389 if err != nil { |
| 390 glog.Error(string(b)) | 390 glog.Error(string(b)) |
| 391 return nil, err | 391 return nil, err |
| 392 } | 392 } |
| 393 hashes := strings.Split(string(b), "\n") | 393 hashes := strings.Split(string(b), "\n") |
| 394 | 394 |
| 395 ret := []int{} | 395 ret := []int{} |
| 396 for i, c := range tile.Commits { | 396 for i, c := range tile.Commits { |
| 397 if c.CommitTime != 0 && util.In(c.Hash, hashes) { | 397 if c.CommitTime != 0 && util.In(c.Hash, hashes) { |
| 398 ret = append(ret, i) | 398 ret = append(ret, i) |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 return ret, nil | 401 return ret, nil |
| 402 } | 402 } |
| 403 | 403 |
| 404 // LastSkpCommit returns the time of the last change to the SKP_VERSION file. | 404 // LastSkpCommit returns the time of the last change to the SKP_VERSION file. |
| 405 func (g GitInfo) LastSkpCommit() (time.Time, error) { | 405 func (g *GitInfo) LastSkpCommit() (time.Time, error) { |
| 406 // Executes a git log command that looks like: | 406 // Executes a git log command that looks like: |
| 407 // | 407 // |
| 408 // git log --format=format:%ct -n 1 SKP_VERSION | 408 // git log --format=format:%ct -n 1 SKP_VERSION |
| 409 // | 409 // |
| 410 // The output should be a single unix timestamp. | 410 // The output should be a single unix timestamp. |
| 411 cmd := exec.Command("git", "log", "--format=format:%ct", "-n", "1", "SKP
_VERSION") | 411 cmd := exec.Command("git", "log", "--format=format:%ct", "-n", "1", "SKP
_VERSION") |
| 412 cmd.Dir = g.dir | 412 cmd.Dir = g.dir |
| 413 b, err := cmd.Output() | 413 b, err := cmd.Output() |
| 414 if err != nil { | 414 if err != nil { |
| 415 glog.Error("Failed to read git log: ", err) | 415 glog.Error("Failed to read git log: ", err) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 441 } | 441 } |
| 442 return -1, -1, fmt.Errorf("Cannot find hash %s.\n", hash) | 442 return -1, -1, fmt.Errorf("Cannot find hash %s.\n", hash) |
| 443 } | 443 } |
| 444 | 444 |
| 445 // NumCommits returns the number of commits in the repo. | 445 // NumCommits returns the number of commits in the repo. |
| 446 func (g *GitInfo) NumCommits() int { | 446 func (g *GitInfo) NumCommits() int { |
| 447 g.mutex.Lock() | 447 g.mutex.Lock() |
| 448 defer g.mutex.Unlock() | 448 defer g.mutex.Unlock() |
| 449 return len(g.hashes) | 449 return len(g.hashes) |
| 450 } | 450 } |
| OLD | NEW |