def loadSnapshots(self, rewrite=False): self.newAssets = [] for snapshot in self.snapshots: if not rewrite and os.path.exists(snapshot.path): print "Loading snapshot", snapshot.path with open(snapshot.path) as f: assets = json.loads(f.read())['assets'] for xid in assets: info = assets[xid] name = info['name'] commit = info['commit'] sha = info['sha'] if name in self.assets: asset = self.assets[name] asset.addVersion(snapshot.commit.id, sha) else: # print "Adding %s as %s" % (name, xid) asset = Asset() asset.configure(commit, sha, xid, name, self.repoDir) self.assets[name] = asset # why are we adding asset to new here? #self.newAssets.append(asset) snapshot.add(asset) self.snapshotsLoaded += 1 else: print "Building snapshot", snapshot.xlink self.addTree(snapshot.commit.tree, '', snapshot) self.snapshotsCreated += 1
def addTree(self, tree, path, snapshot): """ Recursively traverses the git tree """ # todo: don't add metadir to assets for entry in tree: try: obj = self.repo[entry.id] except: print "bad id?", entry.id continue if obj.type == GIT_OBJ_TREE: self.addTree(obj, os.path.join(path, entry.name), snapshot) elif obj.type == GIT_OBJ_BLOB: name = os.path.join(path, entry.name) if name in self.assets: asset = self.assets[name] asset.addVersion(snapshot.commit.id, obj.id) else: xid = genxid(snapshot.commit.id, obj.id) asset = Asset() asset.configure(snapshot.commit.id, obj.id, xid, name, self.repoDir) self.assets[name] = asset snapshot.add(asset)