aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/branch.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-10-02 09:42:13 -0400
committerRuss Cox <rsc@golang.org>2017-11-10 03:12:52 +0000
commit0bdc7edde01a92e96255c6845b536d59706b9542 (patch)
tree38e33d499a8dff245b9d3d7618c967260132a2fd /git-codereview/branch.go
parentc4baf783371a7c2b30b95ab528a38f6b12e7b6c1 (diff)
downloadgo-x-review-0bdc7edde01a92e96255c6845b536d59706b9542.tar.xz
git-codereview: batch GerritChange info fetches during pending
This speeds pending a bit by reducing the number of round trips to the Gerrit server when you have a stack of CLs. Change-Id: I456e1a8739b9b6586f4e05c1a5442f402e440a79 Reviewed-on: https://go-review.googlesource.com/67571 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'git-codereview/branch.go')
-rw-r--r--git-codereview/branch.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/git-codereview/branch.go b/git-codereview/branch.go
index 13193ff..982c739 100644
--- a/git-codereview/branch.go
+++ b/git-codereview/branch.go
@@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
+ "net/url"
"os"
"os/exec"
"regexp"
@@ -322,6 +323,33 @@ func (b *Branch) GerritChange(c *Commit, extra ...string) (*GerritChange, error)
return readGerritChange(id)
}
+// GerritChange returns the change metadata from the Gerrit server
+// for the given changes, which each be be the result of fullChangeID(b, c) for some c.
+// The extra strings are passed to the Gerrit API request as o= parameters,
+// to enable additional information. Typical values include "LABELS" and "CURRENT_REVISION".
+// See https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html for details.
+func (b *Branch) GerritChanges(ids []string, extra ...string) ([][]*GerritChange, error) {
+ q := ""
+ for _, id := range ids {
+ if q != "" {
+ q += "&"
+ }
+ if strings.HasSuffix(id, "~") {
+ // result of fullChangeID(b, c) with missing Change-Id; don't send
+ q += "q=is:closed+is:open" // cannot match anything
+ continue
+ }
+ q += "q=change:" + url.QueryEscape(id)
+ }
+ if q == "" {
+ return nil, fmt.Errorf("no changes found")
+ }
+ for _, x := range extra {
+ q += "&o=" + url.QueryEscape(x)
+ }
+ return readGerritChanges(q)
+}
+
// CommitByRev finds a unique pending commit by its git <rev>.
// It dies if rev cannot be resolved to a commit or that commit is not
// pending on b using the action ("mail", "submit") in the failure message.