cros_mark_as_stable: Commit changes as one big batch instead of individually.

This speeds up the uprev stage by about 15 seconds (from 2m9s to 1m53s).

BUG=chromium:232960
TEST=trybot

Change-Id: If40f938956429db769ce439868400de7e893004b
Reviewed-on: https://gerrit.chromium.org/gerrit/48432
Commit-Queue: David James <davidjames@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
diff --git a/scripts/cros_mark_as_stable.py b/scripts/cros_mark_as_stable.py
index 78c9388..c67419b 100644
--- a/scripts/cros_mark_as_stable.py
+++ b/scripts/cros_mark_as_stable.py
@@ -18,6 +18,9 @@
 from chromite.lib import parallel
 
 
+# Commit message for uprevving Portage packages.
+_GIT_COMMIT_MESSAGE = 'Marking 9999 ebuild for %s as stable.'
+
 # Dictionary of valid commands with usage information.
 COMMAND_DICTIONARY = {
                         'commit':
@@ -295,6 +298,7 @@
           cros_build_lib.RunCommand(['git', 'rebase', existing_branch],
                                     print_cmd=False, cwd=overlay)
 
+        messages = []
         for ebuild in ebuilds:
           if options.verbose:
             cros_build_lib.Info('Working on %s', ebuild.package)
@@ -303,12 +307,16 @@
             if new_package:
               revved_packages.append(ebuild.package)
               new_package_atoms.append('=%s' % new_package)
+              messages.append(_GIT_COMMIT_MESSAGE % ebuild.package)
           except (OSError, IOError):
             cros_build_lib.Warning('Cannot rev %s\n' % ebuild.package +
                     'Note you will have to go into %s '
                     'and reset the git repo yourself.' % overlay)
             raise
 
+        if messages:
+          portage_utilities.EBuild.CommitChange('\n\n'.join(messages), overlay)
+
         if cros_build_lib.IsInsideChroot():
           # Regenerate caches if need be.  We do this all the time to
           # catch when users make changes without updating cache files.