summaryrefslogtreecommitdiffstats
path: root/fit.py
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-05-14 11:52:42 +0200
committerNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-05-14 11:52:42 +0200
commit0a2ed52efaf75405928644b04093f34dc5fff9d8 (patch)
tree151adc2d088adebe5d4c8d4935c70ca813d30623 /fit.py
parent84424f7955c0108b6e69b893a427fb1136ff3728 (diff)
downloadklausuren-0a2ed52efaf75405928644b04093f34dc5fff9d8.tar.gz
klausuren-0a2ed52efaf75405928644b04093f34dc5fff9d8.tar.bz2
klausuren-0a2ed52efaf75405928644b04093f34dc5fff9d8.zip
search rewritten and refactoring
* search result are only files which are in all search tags * javascript refactoring
Diffstat (limited to 'fit.py')
-rw-r--r--fit.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/fit.py b/fit.py
index 529b787..28e818d 100644
--- a/fit.py
+++ b/fit.py
@@ -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