diff options
| author | Shawn Pearce <sop@google.com> | 2012-10-25 17:35:15 -0700 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-10-25 17:35:15 -0700 |
| commit | 2577cec0952899040cd8c6523f69ece4cdc005ac (patch) | |
| tree | 792f82c975d0d5d039ac3a6c6adc8404d87e8b2c /subcmds | |
| parent | e48d34659ebda45431512ab2478558f8e4cdd46c (diff) | |
| parent | d947858325ae70ff9c0b2f463a9e8c4ffd00002a (diff) | |
| download | git-repo-2577cec0952899040cd8c6523f69ece4cdc005ac.tar.gz | |
Merge "sync: Keep a moving average of last fetch times"
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/sync.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index 27dd877d..d565af7b 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -510,7 +510,6 @@ uncommitted changes are present' % project.relpath | |||
| 510 | to_fetch.append(rp) | 510 | to_fetch.append(rp) |
| 511 | to_fetch.extend(all_projects) | 511 | to_fetch.extend(all_projects) |
| 512 | to_fetch.sort(key=self._fetch_times.Get, reverse=True) | 512 | to_fetch.sort(key=self._fetch_times.Get, reverse=True) |
| 513 | self._fetch_times.Clear() | ||
| 514 | 513 | ||
| 515 | fetched = self._Fetch(to_fetch, opt) | 514 | fetched = self._Fetch(to_fetch, opt) |
| 516 | _PostRepoFetch(rp, opt.no_repo_verify) | 515 | _PostRepoFetch(rp, opt.no_repo_verify) |
| @@ -632,19 +631,24 @@ warning: Cannot automatically authenticate repo.""" | |||
| 632 | return True | 631 | return True |
| 633 | 632 | ||
| 634 | class _FetchTimes(object): | 633 | class _FetchTimes(object): |
| 634 | _ALPHA = 0.5 | ||
| 635 | |||
| 635 | def __init__(self, manifest): | 636 | def __init__(self, manifest): |
| 636 | self._path = os.path.join(manifest.repodir, '.repopickle_fetchtimes') | 637 | self._path = os.path.join(manifest.repodir, '.repopickle_fetchtimes') |
| 637 | self._times = None | 638 | self._times = None |
| 638 | 639 | self._seen = set() | |
| 639 | def Clear(self): | ||
| 640 | self._times = {} | ||
| 641 | 640 | ||
| 642 | def Get(self, project): | 641 | def Get(self, project): |
| 643 | self._Load() | 642 | self._Load() |
| 644 | return self._times.get(project.name, _ONE_DAY_S) | 643 | return self._times.get(project.name, _ONE_DAY_S) |
| 645 | 644 | ||
| 646 | def Set(self, project, t): | 645 | def Set(self, project, t): |
| 647 | self._times[project.name] = t | 646 | self._Load() |
| 647 | name = project.name | ||
| 648 | old = self._times.get(name, t) | ||
| 649 | self._seen.add(name) | ||
| 650 | a = self._ALPHA | ||
| 651 | self._times[name] = (a*t) + ((1-a) * old) | ||
| 648 | 652 | ||
| 649 | def _Load(self): | 653 | def _Load(self): |
| 650 | if self._times is None: | 654 | if self._times is None: |
| @@ -669,6 +673,14 @@ class _FetchTimes(object): | |||
| 669 | def Save(self): | 673 | def Save(self): |
| 670 | if self._times is None: | 674 | if self._times is None: |
| 671 | return | 675 | return |
| 676 | |||
| 677 | to_delete = [] | ||
| 678 | for name in self._times: | ||
| 679 | if name not in self._seen: | ||
| 680 | to_delete.append(name) | ||
| 681 | for name in to_delete: | ||
| 682 | del self._times[name] | ||
| 683 | |||
| 672 | try: | 684 | try: |
| 673 | f = open(self._path, 'wb') | 685 | f = open(self._path, 'wb') |
| 674 | try: | 686 | try: |
