summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-18 10:49:00 -0700
committerShawn O. Pearce <sop@google.com>2009-04-18 10:49:00 -0700
commitf6906876719a665819c603604603570363389d0d (patch)
treea309fe795eff059f5f464fd522fff74af148415b
parent336f7bd0ed70f5ee2595463b6bd8dd277e90c833 (diff)
downloadgit-repo-f6906876719a665819c603604603570363389d0d.tar.gz
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>
-rw-r--r--project.py8
-rw-r--r--subcmds/sync.py14
2 files changed, 19 insertions, 3 deletions
diff --git a/project.py b/project.py
index 9f4512f6..f2825028 100644
--- a/project.py
+++ b/project.py
@@ -1350,6 +1350,14 @@ class MetaProject(Project):
1350 self.revision = base 1350 self.revision = base
1351 1351
1352 @property 1352 @property
1353 def LastFetch(self):
1354 try:
1355 fh = os.path.join(self.gitdir, 'FETCH_HEAD')
1356 return os.path.getmtime(fh)
1357 except OSError:
1358 return 0
1359
1360 @property
1353 def HasChanges(self): 1361 def HasChanges(self):
1354 """Has the remote received new commits not yet checked out? 1362 """Has the remote received new commits not yet checked out?
1355 """ 1363 """
diff --git a/subcmds/sync.py b/subcmds/sync.py
index ec5ada21..55ffca3e 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -18,6 +18,7 @@ import os
18import re 18import re
19import subprocess 19import subprocess
20import sys 20import sys
21import time
21 22
22from git_command import GIT 23from git_command import GIT
23from project import HEAD 24from project import HEAD
@@ -72,7 +73,7 @@ revision is temporarily needed.
72 dest='repo_upgraded', action='store_true', 73 dest='repo_upgraded', action='store_true',
73 help=SUPPRESS_HELP) 74 help=SUPPRESS_HELP)
74 75
75 def _Fetch(self, *projects): 76 def _Fetch(self, projects):
76 fetched = set() 77 fetched = set()
77 pm = Progress('Fetching projects', len(projects)) 78 pm = Progress('Fetching projects', len(projects))
78 for project in projects: 79 for project in projects:
@@ -106,7 +107,14 @@ revision is temporarily needed.
106 all = self.GetProjects(args, missing_ok=True) 107 all = self.GetProjects(args, missing_ok=True)
107 108
108 if not opt.local_only: 109 if not opt.local_only:
109 fetched = self._Fetch(rp, mp, *all) 110 to_fetch = []
111 now = time.time()
112 if (24 * 60 * 60) <= (now - rp.LastFetch):
113 to_fetch.append(rp)
114 to_fetch.append(mp)
115 to_fetch.extend(all)
116
117 fetched = self._Fetch(to_fetch)
110 _PostRepoFetch(rp, opt.no_repo_verify) 118 _PostRepoFetch(rp, opt.no_repo_verify)
111 if opt.network_only: 119 if opt.network_only:
112 # bail out now; the rest touches the working tree 120 # bail out now; the rest touches the working tree
@@ -124,7 +132,7 @@ revision is temporarily needed.
124 for project in all: 132 for project in all:
125 if project.gitdir not in fetched: 133 if project.gitdir not in fetched:
126 missing.append(project) 134 missing.append(project)
127 self._Fetch(*missing) 135 self._Fetch(missing)
128 136
129 syncbuf = SyncBuffer(mp.config, 137 syncbuf = SyncBuffer(mp.config,
130 detach_head = opt.detach_head) 138 detach_head = opt.detach_head)