Teach 'repo upload --replace' how to add replacement patch sets

Users are prompted with the list of known changes we are about
to upload, and they can fill out the current change numbers for
any changes which already exist in the data store.  For each of
those changes the change number and commit id is sent as part of
the upload request, so Gerrit can insert the new commit as a new
patch set of the existing change, rather than make a new change.

This facility permits developers to replace a patch so they can
address comments made on a prior version of the same change.

Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/project.py b/project.py
index 1e25c2c..3955033 100644
--- a/project.py
+++ b/project.py
@@ -104,6 +104,7 @@
     self.project = project
     self.branch = branch
     self.base = base
+    self.replace_changes = None
 
   @property
   def name(self):
@@ -124,6 +125,16 @@
     return self._commit_cache
 
   @property
+  def unabbrev_commits(self):
+    r = dict()
+    for commit in self.project.bare_git.rev_list(
+        not_rev(self.base),
+        R_HEADS + self.name,
+        '--'):
+      r[commit[0:8]] = commit
+    return r
+
+  @property
   def date(self):
     return self.project.bare_git.log(
       '--pretty=format:%cd',
@@ -132,7 +143,8 @@
       '--')
 
   def UploadForReview(self):
-    self.project.UploadForReview(self.name)
+    self.project.UploadForReview(self.name,
+                                 self.replace_changes)
 
   @property
   def tip_url(self):
@@ -444,7 +456,7 @@
         return rb
     return None
 
-  def UploadForReview(self, branch=None):
+  def UploadForReview(self, branch=None, replace_changes=None):
     """Uploads the named branch for code review.
     """
     if branch is None:
@@ -482,7 +494,8 @@
                    dest_project = branch.remote.projectname,
                    dest_branch = dest_branch,
                    src_branch = R_HEADS + branch.name,
-                   bases = base_list)
+                   bases = base_list,
+                   replace_changes = replace_changes)
     except proto_client.ClientLoginError:
       raise UploadError('Login failure')
     except urllib2.HTTPError, e: