diff options
Diffstat (limited to 'fit.py')
-rw-r--r-- | fit.py | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -1,4 +1,5 @@ import os, time +import collections from pygit2 import Repository, Signature from binascii import b2a_hex @@ -127,22 +128,35 @@ class Fit: def get_files_for_tags(self, tags): try: commit = self._get_last_commit() - tree = commit.tree['tags'].to_object() - entries = [ tree[x.encode('ascii')].to_object() for x in tags] - add = lambda x,y: x+y - return reduce(add, - map(lambda entry: [ (x.name, x.hex) for x in entry ],entries) - ) + root = commit.tree['tags'].to_object() + + def get_obj(x): + try: + return root[x.encode('ascii')].to_object() + except KeyError: + return [] + + entries = [get_obj(x) for x in tags] + + def merge(list_to_merge): + for sublist in list_to_merge: + for elem in sublist: + yield elem + + # return only entries which have all tags + search = collections.Counter([(x.name, x.hex) for x in merge(entries)]) + return [i for i in search if search[i]>=len(tags)] + except: return [] - def get_file_with_tags(self, oid): + def get_tags_for_file(self, oid): tags = [] - for name, tag_oid in fit.get_all_tags(): + for name, tag_oid in self.get_all_tags(): for entry in self.repo[tag_oid]: - if entry.oid == oid: - tags.append((name, tag_oid)) + if b2a_hex(entry.oid).decode('ascii') == oid: + tags.append(name) return tags |