git-review: save reference to mailed revision using tag

Git mail in the branch named work tags the revision that just got mailed
as work.mailed, overwriting the tag if one already exists. This will let you
run things like

	git diff work.mailed

to see what you've changed since the last time you did a git mail.

The reflog will store the tag history, so you can also diff against older
mailed copies:

	git diff work.mailed@{2}
	git diff work.mailed work.mailed@{2}

Fixes golang/go#9293.

Change-Id: Ifae4c4601c6c9641db88383d52a021087b806e74
Reviewed-on: https://go-review.googlesource.com/1444
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/git-review/mail.go b/git-review/mail.go
index 0d828b3..93867d4 100644
--- a/git-review/mail.go
+++ b/git-review/mail.go
@@ -55,6 +55,19 @@
 		refSpec += mailList(start, "cc", string(*ccList))
 	}
 	run("git", "push", "-q", "origin", refSpec)
+
+	// Create local tag for mailed change.
+	// If in the 'work' branch, this creates or updates work.mailed.
+	// Older mailings are in the reflog, so work.mailed is newest,
+	// work.mailed@{1} is the one before that, work.mailed@{2} before that,
+	// and so on.
+	// Git doesn't actually have a concept of a local tag,
+	// but Gerrit won't let people push tags to it, so the tag
+	// can't propagate out of the local client into the official repo.
+	// There is no conflict with the branch names people are using
+	// for work, because git change rejects any name containing a dot.
+	// The space of names with dots is ours (the Go team's) to define.
+	run("git", "tag", "-f", b.Name+".mailed")
 }
 
 // mailAddressRE matches the mail addresses we admit. It's restrictive but admits