Generate patchset name from commit subject

This is a reland of 947f2ee80883852e73fbe6fb2b624f354cebd800,
which was reverted in a5a1eea537ca2d82a0296dd703e038af7eee2fde

BUG=672332

Change-Id: If33c54e500fbeac11f60d81a19549880506c63d8
Reviewed-on: https://chromium-review.googlesource.com/419737
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 312fa32..23f8d48 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2934,16 +2934,24 @@
       print('Adding self-LGTM (Code-Review +1) because of TBRs')
       refspec_opts.append('l=Code-Review+1')
 
-    if options.title:
-      if not re.match(r'^[\w ]+$', options.title):
-        options.title = re.sub(r'[^\w ]', '', options.title)
+    title = options.title
+    if not title:
+      if self.GetIssue():
+        # We already have an issue, so we should ask for a title for new patch.
+        default = RunGit(['show', '-s', '--format=%s', 'HEAD']).strip()
+        title = ask_for_data('Title for patchset [%s]: ' % default) or default
+      else:
+        title = 'Initial upload'
+    if title:
+      if not re.match(r'^[\w ]+$', title):
+        title = re.sub(r'[^\w ]', '', title)
         print('WARNING: Patchset title may only contain alphanumeric chars '
-              'and spaces. Cleaned up title:\n%s' % options.title)
+              'and spaces. Cleaned up title:\n%s' % title)
         if not options.force:
           ask_for_data('Press enter to continue, Ctrl+C to abort')
       # Per doc, spaces must be converted to underscores, and Gerrit will do the
       # reverse on its side.
-      refspec_opts.append('m=' + options.title.replace(' ', '_'))
+      refspec_opts.append('m=' + title.replace(' ', '_'))
 
     if options.send_mail:
       if not change_desc.get_reviewers():