Disable print for git for-each-ref in git_cache

The command is used for verification purposes when git index is fetched
from GS. The output is verbose for chromium/src and not useful at all.

R=gavinmak@google.com

Bug: 1255228
Change-Id: Ie95963a23ef397e9fd6ce7bcf959ec9964d21ba7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3227145
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
diff --git a/git_cache.py b/git_cache.py
index 786546c..1240f2f 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -231,11 +231,12 @@
         name='rename [%s] => [%s]' % (src, dst),
         printerr=self.print)
 
-  def RunGit(self, cmd, **kwargs):
+  def RunGit(self, cmd, print_stdout=True, **kwargs):
     """Run git in a subprocess."""
     cwd = kwargs.setdefault('cwd', self.mirror_path)
     kwargs.setdefault('print_stdout', False)
-    kwargs.setdefault('filter_fn', self.print)
+    if print_stdout:
+      kwargs.setdefault('filter_fn', self.print)
     env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy())
     env.setdefault('GIT_ASKPASS', 'true')
     env.setdefault('SSH_ASKPASS', 'true')
@@ -320,7 +321,7 @@
       # Set HEAD to main.
       self.RunGit(['symbolic-ref', 'HEAD', 'refs/heads/main'], cwd=tempdir)
       # A quick validation that all references are valid.
-      self.RunGit(['for-each-ref'], cwd=tempdir)
+      self.RunGit(['for-each-ref'], print_stdout=False, cwd=tempdir)
     except Exception as e:
       self.print('Encountered error: %s' % str(e), file=sys.stderr)
       gclient_utils.rmtree(tempdir)