Index: scripts/post-review
===================================================================
--- scripts/post-review	(revision 1900)
+++ scripts/post-review	(working copy)
@@ -1538,7 +1538,30 @@
         # XXX: This breaks on filenames with spaces.
         return last_line.split(' ')[2].rstrip()
 
+    def add_url_to_change(self, changenum, url):
+        """
+        Adds the review url to the change description if it doesn't exist
+        """
+        spec = execute(['p4', 'change', '-o', str(changenum)], ignore_errors=True)
+        regex = re.compile(r'^Description:(.*?)(Files|Jobs)', re.DOTALL | re.MULTILINE)
+        m = regex.search(spec)
 
+        if m:
+            desc = m.group(1)
+            next_section = m.group(2)
+
+            # If Review Url does not exist, add a new line. 
+            # If it already exists, update it.
+            if 'Review Url:' not in desc:
+                newdesc = regex.sub('Description: ' + desc + '\tReview Url: ' + url + '\n\n' + next_section, spec)
+            else:
+                newdesc = re.sub('Review Url:(.*)', 'Review Url: ' + url + '\n', spec)
+
+            execute(['p4', 'change', '-i'], ignore_errors=False, stdin = newdesc)
+
+
 class MercurialClient(SCMClient):
     """
     A wrapper around the hg Mercurial tool that fetches repository
@@ -1862,7 +1885,7 @@
 
 
 def execute(command, env=None, split_lines=False, ignore_errors=False,
-            extra_ignore_errors=()):
+            extra_ignore_errors=(), stdin=None):
     """
     Utility function to execute a command and return the output.
     """
@@ -1896,10 +1919,12 @@
                              close_fds=True,
                              universal_newlines=True,
                              env=env)
+
+    output = p.communicate(input = stdin)[0]
     if split_lines:
-        data = p.stdout.readlines()
+        data = output.splitlines()
     else:
-        data = p.stdout.read()
+        data = output
     rc = p.wait()
     if rc and not ignore_errors and rc not in extra_ignore_errors:
         die('Failed to execute command: %s\n%s' % (command, data))
@@ -2065,6 +2090,10 @@
                       default=False,
                       help="outputs a diff to the console and exits. "
                            "Does not post")
+    parser.add_option("-u", "--update-url",
+                      dest="update_url", action="store_true",
+                      default=False,
+                      help="update the changelist description with the review url generated")
     parser.add_option("--server",
                       dest="server", default=REVIEWBOARD_URL,
                       metavar="SERVER",
@@ -2294,6 +2323,10 @@
                             parent_diff_content=parent_diff,
                             submit_as=options.submit_as)
 
+    if options.update_url:
+        if tool.add_url_to_change:
+            tool.add_url_to_change(changenum, review_url)
+
     # Load the review up in the browser if requested to:
     if options.open_browser:
         try:
