Permalink
Browse files

pulling dulwich objects out of cassandra now

  • Loading branch information...
1 parent c3ba14c commit d6c90df5cee70aafe2752493bfbd3f3efbcae55b @schacon committed Aug 7, 2009
Showing with 60 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +59 −12 dulwich/agitmemnon.py
View
@@ -0,0 +1 @@
+*.pyc
View
@@ -2,6 +2,9 @@
import sys
import pprint
+import zlib
+import base64
+
from urlparse import urlparse
from thrift.transport import TTransport
@@ -15,9 +18,18 @@
from dulwich.server import (
Backend,
)
-
-class Agitmemnon:
-
+from dulwich.object_store import *
+from dulwich.objects import *
+
+type_num_map = {
+ BLOB_ID: 3,
+ TREE_ID : 2,
+ COMMIT_ID : 1,
+ TAG_ID: 4,
+}
+
+class Agitmemnon(BaseObjectStore):
+ """Object store that keeps all objects in cassandra."""
def __init__(self):
host = '127.0.0.1'
port = 9160
@@ -47,18 +59,53 @@ def get_super(self, column, key, count=100, consistency_level=1):
count, consistency_level)
return result
-
def get_object(self, sha):
return self.get('Objects', sha)
- def fetch_objects(self, determine_wants, graph_walker, progress):
- """
- Yield the objects required for a list of commits.
+ def __contains__(self, sha):
+ """Check if the object with a particular SHA is present."""
+ if len(self.get_object(sha)) > 0:
+ return True
+ else:
+ return False
+
+ def __getitem__(self, name):
+ o = self.get_object(name)
+ data = ''
+ otype = ''
+ for col in o:
+ if col.name == 'data':
+ data = col.value
+ if col.name == 'type':
+ otype = col.value
+ data = zlib.decompress(base64.b64decode(data))
+ shafile = ShaFile.from_raw_string(type_num_map[otype], data)
+ return shafile
+
+
+ def find_common_revisions(self, graphwalker):
+ """Find which revisions this store has in common using graphwalker."""
+ haves = []
+ sha = graphwalker.next()
+ while sha:
+ if sha in self:
+ haves.append(sha)
+ graphwalker.ack(sha)
+ sha = graphwalker.next()
+ return haves
+
+ def find_missing_objects(self, haves, wants, progress=None):
+ return iter(MissingObjectFinder(self, haves, wants, progress).next, None)
+
+ def iter_shas(self, shas):
+ """Iterate over the objects for the specified shas."""
+ return ObjectStoreIterator(self, shas)
- :param progress: is a callback to send progress messages to the client
- """
- print 'fetch'
+ def fetch_objects(self, determine_wants, graph_walker, progress):
+ wants = determine_wants(self.get_refs())
+ haves = self.find_common_revisions(graph_walker)
+ return self.iter_shas(self.find_missing_objects(haves, wants, progress))
def get_refs(self):
"""Get dictionary with all refs."""
@@ -80,6 +127,6 @@ def __init__(self):
a = Agitmemnon()
-print a.get_refs()
-
+#print a.get_object('7486f4075d2b9307d02e3905c69e28e456a51a32')[0].value
+print a['7486f4075d2b9307d02e3905c69e28e456a51a32'].get_parents()
#print a.get_object('7486f4075d2b9307d02e3905c69e28e456a51a32')

0 comments on commit d6c90df

Please sign in to comment.