aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/gofmt.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-01-14 10:16:36 -0500
committerRuss Cox <rsc@golang.org>2015-01-19 15:21:59 +0000
commitb7c368d48daa966e82150f307f53ef15aa84a195 (patch)
tree077a06c9d16c021a5620a4fe3e398592bd96e5e7 /git-codereview/gofmt.go
parent3f0e294d12887a79b32d25a71cd90747084b34d5 (diff)
downloadgo-x-review-b7c368d48daa966e82150f307f53ef15aa84a195.tar.xz
git-codereview: refactor getOutput/getLines into cmdOutput, trim, lines, nonBlankLines
This CL separates the "run the command and gather output" from the "process output" operations. Doing so makes the desired processing clearer, makes the processing available for use on other text sources. Also, add cmdOutputDir, for running a command in a different directory. This is needed by the gofmt command to work around a bug in Git, and it's made much easier by the above separation. Change-Id: I2addd8b79dab2d4aa8a24c94a8d7b3a16a8e3484 Reviewed-on: https://go-review.googlesource.com/2906 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'git-codereview/gofmt.go')
-rw-r--r--git-codereview/gofmt.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/git-codereview/gofmt.go b/git-codereview/gofmt.go
index 28edf5d..937fbd6 100644
--- a/git-codereview/gofmt.go
+++ b/git-codereview/gofmt.go
@@ -120,15 +120,15 @@ func runGofmt(flags int) (files []string, stderrText string) {
// Find files modified in the index compared to the branchpoint.
branchpt := b.Branchpoint()
- if strings.Contains(getOutput("git", "branch", "-r", "--contains", b.Name), "origin/") {
+ if strings.Contains(cmdOutput("git", "branch", "-r", "--contains", b.Name), "origin/") {
// This is a branch tag move, not an actual change.
// Use HEAD as branch point, so nothing will appear changed.
// We don't want to think about gofmt on already published
// commits.
branchpt = "HEAD"
}
- indexFiles := addRoot(repo, filter(gofmtRequired, getLines("git", "diff", "--name-only", "--diff-filter=ACM", "--cached", branchpt, "--")))
- localFiles := addRoot(repo, filter(gofmtRequired, getLines("git", "diff", "--name-only", "--diff-filter=ACM")))
+ indexFiles := addRoot(repo, filter(gofmtRequired, nonBlankLines(cmdOutput("git", "diff", "--name-only", "--diff-filter=ACM", "--cached", branchpt, "--"))))
+ localFiles := addRoot(repo, filter(gofmtRequired, nonBlankLines(cmdOutput("git", "diff", "--name-only", "--diff-filter=ACM"))))
localFilesMap := stringMap(localFiles)
isUnstaged := func(file string) bool {
return localFilesMap[file]
@@ -203,7 +203,7 @@ func runGofmt(flags int) (files []string, stderrText string) {
}
args := []string{"checkout-index", "--temp", "--"}
args = append(args, needTemp[:n]...)
- for _, line := range getLines("git", args...) {
+ for _, line := range nonBlankLines(cmdOutput("git", args...)) {
i := strings.Index(line, "\t")
if i < 0 {
continue
@@ -266,10 +266,7 @@ func runGofmt(flags int) (files []string, stderrText string) {
}
// Build file list.
- files = strings.Split(stdout.String(), "\n")
- if len(files) > 0 && files[len(files)-1] == "" {
- files = files[:len(files)-1]
- }
+ files = lines(stdout.String())
// Restage files that need to be restaged.
if flags&gofmtWrite != 0 {
@@ -288,7 +285,7 @@ func runGofmt(flags int) (files []string, stderrText string) {
run("git", add...)
}
if len(updateIndex) > 0 {
- hashes := getLines("git", write...)
+ hashes := nonBlankLines(cmdOutput("git", write...))
if len(hashes) != len(write)-3 {
dief("git hash-object -w did not write expected number of objects")
}