git_cl: Add the ability to set the description. (reland)

BUG=607359

Review-Url: https://codereview.chromium.org/1935653002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@300366 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index bf94913..3fc685d 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -3279,6 +3279,8 @@
   """Brings up the editor for the current CL's description."""
   parser.add_option('-d', '--display', action='store_true',
                     help='Display the description instead of opening an editor')
+  parser.add_option('-n', '--new-description',
+                    help='New description to set for this issue (- for stdin)')
 
   _add_codereview_select_options(parser)
   auth.add_auth_options(parser)
@@ -3302,10 +3304,20 @@
   if not cl.GetIssue():
     DieWithError('This branch has no associated changelist.')
   description = ChangeDescription(cl.GetDescription())
+
   if options.display:
     print description.description
     return 0
-  description.prompt()
+
+  if options.new_description:
+    text = options.new_description
+    if text == '-':
+      text = '\n'.join(l.rstrip() for l in sys.stdin)
+
+    description.set_description(text)
+  else:
+    description.prompt()
+
   if cl.GetDescription() != description.description:
     cl.UpdateDescription(description.description)
   return 0