sync: Track new/existing project count

New vs existing project may be a useful measure for analyzing
sync performance.

Bug: b/287105597
Change-Id: Ibea3e90c9fe3d16fd8b863bcae22b21963a6771a
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/377574
Tested-by: Jason Chang <jasonnc@google.com>
Reviewed-by: Joanna Wang <jojwang@google.com>
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 224d988..a2cc1f8 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1676,6 +1676,13 @@
         err_update_projects = False
         err_update_linkfiles = False
 
+        # Log the repo projects by existing and new.
+        existing = [x for x in all_projects if x.Exists]
+        mp.config.SetString("repo.existingprojectcount", str(len(existing)))
+        mp.config.SetString(
+            "repo.newprojectcount", str(len(all_projects) - len(existing))
+        )
+
         self._fetch_times = _FetchTimes(manifest)
         if not opt.local_only:
             with multiprocessing.Manager() as manager: