aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/branch.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-10-02 10:03:11 -0400
committerRuss Cox <rsc@golang.org>2017-11-10 03:13:48 +0000
commit69da225aa6e9f439011c7458bbbddd52b133aea9 (patch)
treefb3b060260b8dcba4a42e997114e5f82b43d207b /git-codereview/branch.go
parent0bdc7edde01a92e96255c6845b536d59706b9542 (diff)
downloadgo-x-review-69da225aa6e9f439011c7458bbbddd52b133aea9.tar.xz
git-codereview: overlap 'git fetch -q' with Gerrit queries in pending
Right now 'git fetch -q' takes about one second because of Gerrit advertising far too many refs. Overlap the fetch with all the other work, to at least reduce the overall time for 'git pending'. The Gerrit team is aware of the refs advertisement problem and a fix is planned for the next few months. That fix will speed things up even further. Change-Id: Iad57da9f1af1c6eae144fe28e5f96f79234bf3cd Reviewed-on: https://go-review.googlesource.com/67572 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'git-codereview/branch.go')
-rw-r--r--git-codereview/branch.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/git-codereview/branch.go b/git-codereview/branch.go
index 982c739..0a277ce 100644
--- a/git-codereview/branch.go
+++ b/git-codereview/branch.go
@@ -21,7 +21,6 @@ type Branch struct {
loadedPending bool // following fields are valid
originBranch string // upstream origin branch
commitsAhead int // number of commits ahead of origin branch
- commitsBehind int // number of commits behind origin branch
branchpoint string // latest commit hash shared with origin branch
pending []*Commit // pending commits, newest first (children before parents)
}
@@ -141,6 +140,12 @@ func (b *Branch) loadPending() {
return
}
+ // Note: This runs in parallel with "git fetch -q",
+ // so the commands may see a stale version of origin/master.
+ // The use of origin here is for identifying what the branch has
+ // in common with origin (what's old on the branch).
+ // Any new commits in origin do not affect that.
+
// Note: --topo-order means child first, then parent.
origin := b.OriginBranch()
const numField = 5
@@ -197,7 +202,12 @@ func (b *Branch) loadPending() {
}
}
b.commitsAhead = len(b.pending)
- b.commitsBehind = len(lines(cmdOutput("git", "log", "--format=format:x", b.FullName()+".."+b.OriginBranch(), "--")))
+}
+
+// CommitsBehind reports the number of commits present upstream
+// that are not present in the current branch.
+func (b *Branch) CommitsBehind() int {
+ return len(lines(cmdOutput("git", "log", "--format=format:x", b.FullName()+".."+b.OriginBranch(), "--")))
}
// Submitted reports whether some form of b's pending commit