Merge "v.io/jiri/profiles: use runutil.Sequence."
diff --git a/cl.go b/cl.go
index 9460338..7ad11d6 100644
--- a/cl.go
+++ b/cl.go
@@ -825,7 +825,7 @@
 			return err
 		}
 	}
-	if err := gerrit.Push(review.jirix.Run(), review.CLOpts); err != nil {
+	if err := gerrit.Push(review.jirix.NewSeq(), review.CLOpts); err != nil {
 		return gerritError(err.Error())
 	}
 	return nil
diff --git a/gerrit/.api b/gerrit/.api
new file mode 100644
index 0000000..3ab044a
--- /dev/null
+++ b/gerrit/.api
@@ -0,0 +1,63 @@
+pkg gerrit, const PresubmitTestTypeAll PresubmitTestType
+pkg gerrit, const PresubmitTestTypeNone PresubmitTestType
+pkg gerrit, func New(*runutil.Sequence, string) *Gerrit
+pkg gerrit, func PresubmitTestTypes() []string
+pkg gerrit, func Push(*runutil.Sequence, CLOpts) error
+pkg gerrit, func Reference(CLOpts) string
+pkg gerrit, method (*Gerrit) PostReview(string, string, map[string]string) error
+pkg gerrit, method (*Gerrit) Query(string) ([]Change, error)
+pkg gerrit, method (*Gerrit) SetTopic(string, CLOpts) error
+pkg gerrit, method (*Gerrit) Submit(string) error
+pkg gerrit, method (Change) OwnerEmail() string
+pkg gerrit, method (Change) Reference() string
+pkg gerrit, type CLOpts struct
+pkg gerrit, type CLOpts struct, Autosubmit bool
+pkg gerrit, type CLOpts struct, Branch string
+pkg gerrit, type CLOpts struct, Ccs []string
+pkg gerrit, type CLOpts struct, Draft bool
+pkg gerrit, type CLOpts struct, Edit bool
+pkg gerrit, type CLOpts struct, Host string
+pkg gerrit, type CLOpts struct, Presubmit PresubmitTestType
+pkg gerrit, type CLOpts struct, Remote string
+pkg gerrit, type CLOpts struct, RemoteBranch string
+pkg gerrit, type CLOpts struct, Reviewers []string
+pkg gerrit, type CLOpts struct, Topic string
+pkg gerrit, type CLOpts struct, Verify bool
+pkg gerrit, type Change struct
+pkg gerrit, type Change struct, AutoSubmit bool
+pkg gerrit, type Change struct, Change_id string
+pkg gerrit, type Change struct, Current_revision string
+pkg gerrit, type Change struct, Labels map[string]map[string]interface{}
+pkg gerrit, type Change struct, MultiPart *MultiPartCLInfo
+pkg gerrit, type Change struct, Owner Owner
+pkg gerrit, type Change struct, PresubmitTest PresubmitTestType
+pkg gerrit, type Change struct, Project string
+pkg gerrit, type Change struct, Revisions Revisions
+pkg gerrit, type Change struct, Topic string
+pkg gerrit, type Comment struct
+pkg gerrit, type Comment struct, Line int
+pkg gerrit, type Comment struct, Message string
+pkg gerrit, type Commit struct
+pkg gerrit, type Commit struct, Message string
+pkg gerrit, type Fetch struct
+pkg gerrit, type Fetch struct, embedded Http
+pkg gerrit, type Gerrit struct
+pkg gerrit, type Http struct
+pkg gerrit, type Http struct, Ref string
+pkg gerrit, type MultiPartCLInfo struct
+pkg gerrit, type MultiPartCLInfo struct, Index int
+pkg gerrit, type MultiPartCLInfo struct, Topic string
+pkg gerrit, type MultiPartCLInfo struct, Total int
+pkg gerrit, type Owner struct
+pkg gerrit, type Owner struct, Email string
+pkg gerrit, type PresubmitTestType string
+pkg gerrit, type Review struct
+pkg gerrit, type Review struct, Comments map[string][]Comment
+pkg gerrit, type Review struct, Labels map[string]string
+pkg gerrit, type Review struct, Message string
+pkg gerrit, type Revision struct
+pkg gerrit, type Revision struct, embedded Commit
+pkg gerrit, type Revision struct, embedded Fetch
+pkg gerrit, type Revisions map[string]Revision
+pkg gerrit, type Topic struct
+pkg gerrit, type Topic struct, Topic string
diff --git a/gerrit/gerrit.go b/gerrit/gerrit.go
index 558df3f..6aee750 100644
--- a/gerrit/gerrit.go
+++ b/gerrit/gerrit.go
@@ -80,20 +80,20 @@
 // Gerrit records a hostname of a Gerrit instance.
 type Gerrit struct {
 	host string
-	r    *runutil.Run
+	s    *runutil.Sequence
 }
 
 // New is the Gerrit factory.
-func New(r *runutil.Run, host string) *Gerrit {
+func New(s *runutil.Sequence, host string) *Gerrit {
 	return &Gerrit{
 		host: host,
-		r:    r,
+		s:    s,
 	}
 }
 
 // PostReview posts a review to the given Gerrit reference.
 func (g *Gerrit) PostReview(ref string, message string, labels map[string]string) (e error) {
-	cred, err := hostCredentials(g.r, g.host)
+	cred, err := hostCredentials(g.s, g.host)
 	if err != nil {
 		return err
 	}
@@ -144,7 +144,7 @@
 
 // SetTopic sets the topic of the given Gerrit reference.
 func (g *Gerrit) SetTopic(cl string, opts CLOpts) (e error) {
-	cred, err := hostCredentials(g.r, g.host)
+	cred, err := hostCredentials(g.s, g.host)
 	if err != nil {
 		return err
 	}
@@ -317,7 +317,7 @@
 // - https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
 // - https://gerrit-review.googlesource.com/Documentation/user-search.html
 func (g *Gerrit) Query(query string) (_ []Change, e error) {
-	cred, err := hostCredentials(g.r, g.host)
+	cred, err := hostCredentials(g.s, g.host)
 	if err != nil {
 		return nil, err
 	}
@@ -345,7 +345,7 @@
 
 // Submit submits the given changelist through Gerrit.
 func (g *Gerrit) Submit(changeID string) (e error) {
-	cred, err := hostCredentials(g.r, g.host)
+	cred, err := hostCredentials(g.s, g.host)
 	if err != nil {
 		return err
 	}
@@ -427,13 +427,10 @@
 
 // getRemoteURL returns the URL of the Gerrit project with respect to the
 // project identified by the current working directory.
-func getRemoteURL(run *runutil.Run, clOpts CLOpts) (string, error) {
+func getRemoteURL(seq *runutil.Sequence, clOpts CLOpts) (string, error) {
 	args := []string{"config", "--get", "remote.origin.url"}
 	var stdout, stderr bytes.Buffer
-	opts := run.Opts()
-	opts.Stdout = &stdout
-	opts.Stderr = &stderr
-	if err := run.CommandWithOpts(opts, "git", args...); err != nil {
+	if err := seq.Capture(&stdout, &stderr).Last("git", args...); err != nil {
 		return "", gitutil.Error(stdout.String(), stderr.String(), args...)
 	}
 	baseUrl := clOpts.Host
@@ -444,11 +441,11 @@
 }
 
 // Push pushes the current branch to Gerrit.
-func Push(run *runutil.Run, clOpts CLOpts) error {
+func Push(seq *runutil.Sequence, clOpts CLOpts) error {
 	remote := clOpts.Remote
 	if remote == "" {
 		var err error
-		remote, err = getRemoteURL(run, clOpts)
+		remote, err = getRemoteURL(seq, clOpts)
 		if err != nil {
 			return err
 		}
@@ -464,10 +461,7 @@
 		args = append(args, "--no-verify")
 	}
 	var stdout, stderr bytes.Buffer
-	opts := run.Opts()
-	opts.Stdout = &stdout
-	opts.Stderr = &stderr
-	if err := run.CommandWithOpts(opts, "git", args...); err != nil {
+	if err := seq.Capture(&stdout, &stderr).Last("git", args...); err != nil {
 		return gitutil.Error(stdout.String(), stderr.String(), args...)
 	}
 	for _, line := range strings.Split(stderr.String(), "\n") {
@@ -486,7 +480,7 @@
 // hostCredentials returns credentials for the given Gerrit host. The
 // function uses best effort to scan common locations where the
 // credentials could exist.
-func hostCredentials(run *runutil.Run, host string) (_ *credentials, e error) {
+func hostCredentials(seq *runutil.Sequence, host string) (_ *credentials, e error) {
 	// Check the host URL is valid.
 	url, err := url.Parse(host)
 	if err != nil {
@@ -498,7 +492,7 @@
 
 	// Look for the host credentials in the .netrc file.
 	netrcPath := filepath.Join(os.Getenv("HOME"), ".netrc")
-	file, err := run.Open(netrcPath)
+	file, err := seq.Open(netrcPath)
 	if err != nil {
 		if !os.IsNotExist(err) {
 			return nil, err
@@ -518,12 +512,9 @@
 	// Look for the host credentials in the git cookie file.
 	args := []string{"config", "--get", "http.cookiefile"}
 	var stdout, stderr bytes.Buffer
-	opts := run.Opts()
-	opts.Stdout = &stdout
-	opts.Stderr = &stderr
-	if err := run.CommandWithOpts(opts, "git", args...); err == nil {
+	if err := seq.Capture(&stdout, &stderr).Last("git", args...); err == nil {
 		cookieFilePath := strings.TrimSpace(stdout.String())
-		file, err := run.Open(cookieFilePath)
+		file, err := seq.Open(cookieFilePath)
 		if err != nil {
 			if !os.IsNotExist(err) {
 				return nil, err
diff --git a/tool/context.go b/tool/context.go
index fed3577..b885130 100644
--- a/tool/context.go
+++ b/tool/context.go
@@ -140,7 +140,7 @@
 
 // Gerrit returns the Gerrit instance of the context.
 func (ctx Context) Gerrit(host string) *gerrit.Gerrit {
-	return gerrit.New(ctx.run, host)
+	return gerrit.New(ctx.NewSeq(), host)
 }
 
 type gitOpt interface {