Skip to content

Commit 125cab4

Browse files
authored
Merge pull request #167 from AKSW/feature/fixInitialCommit
Fix initial commit
2 parents 1b2e349 + 11d1fe0 commit 125cab4

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

quit/core.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def changeset(self, commit):
355355
def getFilesForCommit(self, commit):
356356
"""Get all entry, oid tupples for a commit.
357357
358-
On Cache miss this method also updates teh commits cache.
358+
On Cache miss this method also updates the commits cache.
359359
"""
360360
uriFileMap = self.config.getgraphurifilemap()
361361

@@ -394,11 +394,11 @@ def getFileReferenceAndContext(self, blob, commit):
394394
return quitWorkingData
395395
return self._blobs.get(blob)
396396

397-
def commit(self, graph, delta, message, commit_id, ref, query=None, default_graph=[],
397+
def commit(self, graph, delta, message, parent_commit_ref, ref, query=None, default_graph=[],
398398
named_graph=[], **kwargs):
399399
"""Commit changes after applying deltas to the blobs.
400400
401-
This methods analyzes the delta an apllies the changes to the blobs of the repository.
401+
This methods analyzes the delta and applies the changes to the blobs of the repository.
402402
A commit message is built with help of message and if called from endpoint with query,
403403
default_graph and named_graph. **kwargs can be used to extend the commit message with
404404
custom key-value-pairs.
@@ -407,7 +407,7 @@ def commit(self, graph, delta, message, commit_id, ref, query=None, default_grap
407407
graph: the current graph instance
408408
delta: delta that will be applied
409409
message: commit message
410-
commit_id: the commit-id of preceeding commit
410+
parent_commit_ref: the commit-id of preceeding commit
411411
ref: a ref/branch were the commit will be applied to
412412
query: the query that lead to the commit
413413
default_graph: using-graph-uri values from SPARQL protocol
@@ -445,19 +445,25 @@ def _apply(f, changeset, identifier):
445445
if not delta:
446446
return
447447

448-
commit = self.repository.revision(commit_id)
449-
index = self.repository.index(commit.id)
450-
448+
parent_commit_id = None
449+
parent_commit = None
450+
blobs = []
451451
blobs_new = set()
452-
try:
453-
blobs = self.getFilesForCommit(commit)
454-
except KeyError:
455-
blobs = []
452+
453+
if parent_commit_ref:
454+
parent_commit = self.repository.revision(parent_commit_ref)
455+
if parent_commit:
456+
parent_commit_id = parent_commit.id
457+
try:
458+
blobs = self.getFilesForCommit(parent_commit)
459+
except KeyError:
460+
pass
461+
index = self.repository.index(parent_commit_id)
456462

457463
for blob in blobs:
458464
(fileName, oid) = blob
459465
try:
460-
file_reference, contexts = self.getFileReferenceAndContext(blob, commit)
466+
file_reference, contexts = self.getFileReferenceAndContext(blob, parent_commit)
461467
for context in contexts:
462468
for entry in delta:
463469
changeset = entry.get(context.identifier, None)

tests/test_app.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from helpers import TemporaryRepository, TemporaryRepositoryFactory
1111
import json
1212
from helpers import createCommit, assertResultBindingsEqual
13+
from tempfile import TemporaryDirectory
1314

1415

1516
class SparqlProtocolTests(unittest.TestCase):
@@ -1668,6 +1669,40 @@ def testInitAndSelectFromNonEmptyGraphGet(self):
16681669
"p": {'type': 'uri', 'value': 'http://ex.org/y'},
16691670
"o": {'type': 'uri', 'value': 'http://ex.org/z'}})
16701671

1672+
def testInsertDataIntoEmptyRepository(self):
1673+
"""Test inserting data and selecting it, starting with an empty directory.
1674+
1675+
1. Prepare an empty directory
1676+
2. Start Quit
1677+
3. execute INSERT DATA query
1678+
4. execute SELECT query
1679+
"""
1680+
# Prepate a git Repository
1681+
with TemporaryDirectory() as repo:
1682+
1683+
# Start Quit
1684+
args = quitApp.parseArgs(['-t', repo, '-cm', 'graphfiles'])
1685+
objects = quitApp.initialize(args)
1686+
config = objects['config']
1687+
app = create_app(config).test_client()
1688+
1689+
# execute INSERT DATA query
1690+
update = "INSERT DATA {graph <http://example.org/> {<http://ex.org/a> <http://ex.org/b> <http://ex.org/c> .}}"
1691+
app.post('/sparql', data=dict(update=update))
1692+
1693+
# execute SELECT query
1694+
select = "SELECT * WHERE {graph <http://example.org/> {?s ?p ?o .}} ORDER BY ?s ?p ?o"
1695+
select_resp = app.post('/sparql', data=dict(query=select), headers=dict(accept="application/sparql-results+json"))
1696+
1697+
obj = json.loads(select_resp.data.decode("utf-8"))
1698+
1699+
self.assertEqual(len(obj["results"]["bindings"]), 1)
1700+
1701+
self.assertDictEqual(obj["results"]["bindings"][0], {
1702+
"s": {'type': 'uri', 'value': 'http://ex.org/a'},
1703+
"p": {'type': 'uri', 'value': 'http://ex.org/b'},
1704+
"o": {'type': 'uri', 'value': 'http://ex.org/c'}})
1705+
16711706
def testInsertDataAndSelectFromEmptyGraph(self):
16721707
"""Test inserting data and selecting it, starting with an empty graph.
16731708

0 commit comments

Comments
 (0)