Procházet zdrojové kódy

Only fetch repo once-per-day under normal 'repo sync' usage

Its unlikely that a new version of repo will be delivered in any
given day, so we now check only once every 24 hours to see if repo
has been updated.  This reduces the sync cost, as we no longer need
to contact the repo distribution servers every time we do a sync.

repo selfupdate can still be used to force a check.

Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce před 17 roky
rodič
revize
f690687671
2 změnil soubory, kde provedl 19 přidání a 3 odebrání
  1. 8 0
      project.py
  2. 11 3
      subcmds/sync.py

+ 8 - 0
project.py

@@ -1349,6 +1349,14 @@ class MetaProject(Project):
         if base:
         if base:
           self.revision = base
           self.revision = base
 
 
+  @property
+  def LastFetch(self):
+    try:
+      fh = os.path.join(self.gitdir, 'FETCH_HEAD')
+      return os.path.getmtime(fh)
+    except OSError:
+      return 0
+
   @property
   @property
   def HasChanges(self):
   def HasChanges(self):
     """Has the remote received new commits not yet checked out?
     """Has the remote received new commits not yet checked out?

+ 11 - 3
subcmds/sync.py

@@ -18,6 +18,7 @@ import os
 import re
 import re
 import subprocess
 import subprocess
 import sys
 import sys
+import time
 
 
 from git_command import GIT
 from git_command import GIT
 from project import HEAD
 from project import HEAD
@@ -72,7 +73,7 @@ revision is temporarily needed.
                  dest='repo_upgraded', action='store_true',
                  dest='repo_upgraded', action='store_true',
                  help=SUPPRESS_HELP)
                  help=SUPPRESS_HELP)
 
 
-  def _Fetch(self, *projects):
+  def _Fetch(self, projects):
     fetched = set()
     fetched = set()
     pm = Progress('Fetching projects', len(projects))
     pm = Progress('Fetching projects', len(projects))
     for project in projects:
     for project in projects:
@@ -106,7 +107,14 @@ revision is temporarily needed.
     all = self.GetProjects(args, missing_ok=True)
     all = self.GetProjects(args, missing_ok=True)
 
 
     if not opt.local_only:
     if not opt.local_only:
-      fetched = self._Fetch(rp, mp, *all)
+      to_fetch = []
+      now = time.time()
+      if (24 * 60 * 60) <= (now - rp.LastFetch):
+        to_fetch.append(rp)
+      to_fetch.append(mp)
+      to_fetch.extend(all)
+
+      fetched = self._Fetch(to_fetch)
       _PostRepoFetch(rp, opt.no_repo_verify)
       _PostRepoFetch(rp, opt.no_repo_verify)
       if opt.network_only:
       if opt.network_only:
         # bail out now; the rest touches the working tree
         # bail out now; the rest touches the working tree
@@ -124,7 +132,7 @@ revision is temporarily needed.
         for project in all:
         for project in all:
           if project.gitdir not in fetched:
           if project.gitdir not in fetched:
             missing.append(project)
             missing.append(project)
-        self._Fetch(*missing)
+        self._Fetch(missing)
 
 
     syncbuf = SyncBuffer(mp.config,
     syncbuf = SyncBuffer(mp.config,
                          detach_head = opt.detach_head)
                          detach_head = opt.detach_head)