summaryrefslogtreecommitdiff
path: root/morphlib/cachedrepo.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-30 13:47:06 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-07-07 15:06:22 +0100
commitc029130068e3a08c51dd551fda88cc5302671d53 (patch)
tree185e204a874c085b625d2ca536593ceba3f26833 /morphlib/cachedrepo.py
parent770a6cb434ac31238eb2eee526e235728ce07aff (diff)
downloadmorph-c029130068e3a08c51dd551fda88cc5302671d53.tar.gz
Fix Morph failing to update some cached git repos
I was getting the following error when running the 'do-release.py' script: ERROR:root:Command failed: morph --quiet --trove-host=git.baserock.org list-artifacts baserock:baserock/definitions sam/auto-release minimal-system-x86_32-generic ERROR: Ref d67a0e110187abd560a1de63fa172894a52839d5 is an invalid reference for repo git://git.baserock.org/delta/linux The commit that it wants did actually exist in git.baserock.org and the logs show that Morph hadn't done a `git remote update` to get the commit locally. This turned out to be because it'd had already looked up a different ref in linux.git. It hadn't needed to run 'git remote update', but it *had* added linux.git to a "don't need to update this repo again" list. Oops! I've moved the code in question to the cachedrepo module so that the repo object keeps that of whether it should be updated. The bug is now fixed. As a side effect this patch fixes the spurious 'Updating repo file:///...' messages, which were printed even though repos with file:/// URLs are never updated.
Diffstat (limited to 'morphlib/cachedrepo.py')
-rw-r--r--morphlib/cachedrepo.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py
index e85b0059..996b42f7 100644
--- a/morphlib/cachedrepo.py
+++ b/morphlib/cachedrepo.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Codethink Limited
+# Copyright (C) 2012-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -103,6 +103,7 @@ class CachedRepo(object):
self.url = url
self.path = path
self.is_mirror = not url.startswith('file://')
+ self.already_updated = False
def ref_exists(self, ref):
'''Returns True if the given ref exists in the repo'''
@@ -221,6 +222,30 @@ class CachedRepo(object):
return self._ls_tree(sha1)
+ def requires_update_for_ref(self, ref):
+ '''Returns False if there's no need to update this cached repo.
+
+ If the ref points to a specific commit that's already available
+ locally, there's never any need to update. If it's a named ref and this
+ repo wasn't already updated in the lifetime of the current process,
+ it's necessary to update.
+
+ '''
+ if not self.is_mirror:
+ # Repos with file:/// URLs don't ever need updating.
+ return False
+
+ if self.already_updated:
+ return False
+
+ # Named refs that are valid SHA1s will confuse this code.
+ ref_can_change = not morphlib.git.is_valid_sha1(ref)
+
+ if ref_can_change or not self.ref_exists(ref):
+ return True
+ else:
+ return False
+
def update(self):
'''Updates the cached repository using its origin remote.
@@ -234,6 +259,7 @@ class CachedRepo(object):
try:
self._update()
+ self.already_updated = True
except cliapp.AppException, e:
raise UpdateError(self)