From 336f7bd0ed70f5ee2595463b6bd8dd277e90c833 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 18 Apr 2009 10:39:28 -0700 Subject: [PATCH] Avoid git fork on the common case of repo not changing Usually repo is upgraded only once a week, if that often. Most of the time we invoke HasChanges on the repo project (or even on the manifest project) the current HEAD will resolve to the same SHA-1 as the remote tracking ref, and there are therefore no changes. Signed-off-by: Shawn O. Pearce --- project.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/project.py b/project.py index 09a768fb..9f4512f6 100644 --- a/project.py +++ b/project.py @@ -1353,7 +1353,25 @@ class MetaProject(Project): def HasChanges(self): """Has the remote received new commits not yet checked out? """ + if not self.remote or not self.revision: + return False + + all = self.bare_ref.all rev = self.GetRemote(self.remote.name).ToLocal(self.revision) - if self._revlist(not_rev(HEAD), rev): + if rev in all: + revid = all[rev] + else: + revid = rev + + head = self.work_git.GetHead() + if head.startswith(R_HEADS): + try: + head = all[head] + except KeyError: + head = None + + if revid == head: + return False + elif self._revlist(not_rev(HEAD), rev): return True return False