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 <sop@google.com>
diff --git a/project.py b/project.py
index 09a768f..9f4512f 100644
--- a/project.py
+++ b/project.py
@@ -1353,7 +1353,25 @@
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