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)
def genxid(self): """ The project xid is generated from the first commit and tree sha's """ walker = self.repo.walk(self.repo.head.target, GIT_SORT_TIME | GIT_SORT_REVERSE) commit = walker.next() xid = genxid(commit.id, commit.tree.id) return str(xid)