git-review: allow mail with multiple -r and -cc flags
They accumulate, like they do in other standard git commands.
Fixes golang/go#9241.
Change-Id: I48e72ff1561cd34c194ebf6dfbc5176a33f4a2d6
Reviewed-on: https://go-review.googlesource.com/1442
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/git-review/mail.go b/git-review/mail.go
index 2dd03e2..0d828b3 100644
--- a/git-review/mail.go
+++ b/git-review/mail.go
@@ -15,9 +15,12 @@
var (
diff = flags.Bool("diff", false, "show change commit diff and don't upload or mail")
force = flags.Bool("f", false, "mail even if there are staged changes")
- rList = flags.String("r", "", "comma-separated list of reviewers")
- ccList = flags.String("cc", "", "comma-separated list of people to CC:")
+ rList = new(stringList) // installed below
+ ccList = new(stringList) // installed below
)
+ flags.Var(rList, "r", "comma-separated list of reviewers")
+ flags.Var(ccList, "cc", "comma-separated list of people to CC:")
+
flags.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s mail %s [-r reviewer,...] [-cc mail,...]\n", os.Args[0], globalFlags)
}
@@ -45,11 +48,11 @@
refSpec := "HEAD:refs/for/master"
start := "%"
if *rList != "" {
- refSpec += mailList(start, "r", *rList)
+ refSpec += mailList(start, "r", string(*rList))
start = ","
}
if *ccList != "" {
- refSpec += mailList(start, "cc", *ccList)
+ refSpec += mailList(start, "cc", string(*ccList))
}
run("git", "push", "-q", "origin", refSpec)
}
@@ -74,3 +77,22 @@
}
return spec
}
+
+// stringList is a flag.Value that is like flag.String, but if repeated
+// keeps appending to the old value, inserting commas as separators.
+// This allows people to write -r rsc,adg (like the old hg command)
+// but also -r rsc -r adg (like standard git commands).
+// This does change the meaning of -r rsc -r adg (it used to mean just adg).
+type stringList string
+
+func (x *stringList) String() string {
+ return string(*x)
+}
+
+func (x *stringList) Set(s string) error {
+ if *x != "" && s != "" {
+ *x += ","
+ }
+ *x += stringList(s)
+ return nil
+}