From 071c79f6fbb757ada49b92dd91c36412076229e7 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 4 Jul 2014 19:13:27 +1200 Subject: [PATCH] Create local refs to prevent pruning By default git will prune dangling commits more than 2 weeks old. All the unmerged versions of reviews pushed up more than 2 weeks ago count as such commits, so we're downloading all the history again and again each time git-gc --auto ends up being invoked (which is triggered amongst other things by loose object counts. This leads to random stalls in gertty when it has to redownload those objects - and this is obviously worse when offline. This commit adds refs to prevent this behaviour, but doesn't remove them at any point. We probably want to facilitate gc of merged/abandoned/ignored commits at some point. I'm not sure if that needs to happen in this commit or if it could be added later. Change-Id: I01c61fd65207fe0dc99208241eefd5d6432c2ad0 --- gertty/sync.py | 4 ++-- gertty/view/change.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gertty/sync.py b/gertty/sync.py index 0352d46..a75b319 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -255,7 +255,7 @@ class SyncChangeTask(Task): sync.app.config.password, url[1]) url = urlparse.urlunsplit(url) if (not revision) or self.force_fetch: - fetches[url].append(ref) + fetches[url].append('+%(ref)s:%(ref)s' % dict(ref=ref)) if not revision: revision = change.createRevision(remote_revision['_number'], remote_revision['commit']['message'], remote_commit, @@ -435,7 +435,7 @@ class FetchRefTask(Task): url = urlparse.urlunsplit(url) self.log.debug("git fetch %s %s" % (url, self.refs)) repo = sync.app.getRepo(self.project_name) - refs = self.refs + refs = ['+%(ref)s:%(ref)s' % dict(ref=ref) for ref in self.refs] try: repo.fetch(url, refs) except Exception: diff --git a/gertty/view/change.py b/gertty/view/change.py index 66b9e96..443563a 100644 --- a/gertty/view/change.py +++ b/gertty/view/change.py @@ -359,7 +359,7 @@ This Screen self.refresh() def checkGitRepo(self): - missing_revisions = False + missing_revisions = set() change_number = None change_id = None with self.app.db.getSession() as session: @@ -368,12 +368,15 @@ This Screen change_id = change.id repo = self.app.getRepo(change.project.name) for revision in change.revisions: - if not (repo.hasCommit(revision.parent) and - repo.hasCommit(revision.commit)): - missing_revisions = True + if not repo.hasCommit(revision.parent): + missing_revisions.add(revision.parent) + if not repo.hasCommit(revision.commit): + missing_revisions.add(revision.commit) + if missing_revisions: break if missing_revisions: - self.app.log.warning("Missing some commits for change %s" % change_number) + self.app.log.warning("Missing some commits for change %s %s", + change_number, missing_revisions) task = sync.SyncChangeTask(change_id, force_fetch=True, priority=sync.HIGH_PRIORITY) self.app.sync.submitTask(task)