Reland "git-cache: Add option to fetch commits."

This is a reland of 4c67f856f06693b39eecaa0efb86b2856c3532bb
Issues should have been fixed by crrev.com/c/2838026

Original change's description:
> git-cache: Add option to fetch commits.
>
> Add option to git cache to fetch commits.
> And use it in bot_update and gclient sync to make sure
> the needed commits are present on the checkout.
>
> Change-Id: I9e90da9e3be6e7bacf714b22bf0b735463e655b6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2829942
> Reviewed-by: Gavin Mak <gavinmak@google.com>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>

Change-Id: Ie5a29737f5a75d28bc7c5c2f6cb99ec7f87cd9e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2841046
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/git_cache.py b/git_cache.py
index 89f7f6d..37b6795 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -107,9 +107,10 @@
     regex = r'\+%s:.*' % src.replace('*', r'\*')
     return ('+%s:%s' % (src, dest), regex)
 
-  def __init__(self, url, refs=None, print_func=None):
+  def __init__(self, url, refs=None, commits=None, print_func=None):
     self.url = url
     self.fetch_specs = set([self.parse_fetch_spec(ref) for ref in (refs or [])])
+    self.fetch_commits = set(commits or [])
     self.basedir = self.UrlToCacheDir(url)
     self.mirror_path = os.path.join(self.GetCachePath(), self.basedir)
     if print_func:
@@ -448,6 +449,13 @@
         if spec == '+refs/heads/*:refs/heads/*':
           raise ClobberNeeded()  # Corrupted cache.
         logging.warning('Fetch of %s failed' % spec)
+    for commit in self.fetch_commits:
+      self.print('Fetching %s' % commit)
+      try:
+        with self.print_duration_of('fetch %s' % commit):
+          self.RunGit(['fetch', 'origin', commit], cwd=rundir, retry=True)
+      except subprocess.CalledProcessError:
+        logging.warning('Fetch of %s failed' % commit)
 
   def populate(self,
                depth=None,
@@ -635,6 +643,8 @@
                     help='Only cache 10000 commits of history')
   parser.add_option('--ref', action='append',
                     help='Specify additional refs to be fetched')
+  parser.add_option('--commit', action='append',
+                    help='Specify additional commits to be fetched')
   parser.add_option('--no_bootstrap', '--no-bootstrap',
                     action='store_true',
                     help='Don\'t bootstrap from Google Storage')
@@ -657,7 +667,7 @@
     print('break_locks is no longer used. Please remove its usage.')
   url = args[0]
 
-  mirror = Mirror(url, refs=options.ref)
+  mirror = Mirror(url, refs=options.ref, commits=options.commit)
   kwargs = {
       'no_fetch_tags': options.no_fetch_tags,
       'verbose': options.verbose,