Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/gdatastore/datastore.py
diff options
context:
space:
mode:
authorSascha Silbe <sascha-pgp@silbe.org>2014-05-22 20:32:53 (GMT)
committer Sascha Silbe <sascha-pgp@silbe.org>2014-05-22 20:32:53 (GMT)
commitfbd7bd8d36535c9ff93e5b2f4850b6c2727b9062 (patch)
tree70783c2e09ae481bb3ad01c5112e7daa278ba49a /gdatastore/datastore.py
parent6df7daa653812f39d5a2f20d01be37fd654e476d (diff)
Persist changed metadata in git
When only the metadata of an entry got changed, gdatastore only updated the Xapian index but neglected git. This caused the change not to persist across an index rebuild and not to propagate across gdatastore instances. We now store the updated metadata in a new commit with the same ref name and having the previous ref as parent. This should be enough for the index rebuild case. It will also propagate nicely through git, though we don't have code in place yet to notice updated entries (rather than completely new ones).
Diffstat (limited to 'gdatastore/datastore.py')
-rw-r--r--gdatastore/datastore.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/gdatastore/datastore.py b/gdatastore/datastore.py
index 6dd2170..a33aca8 100644
--- a/gdatastore/datastore.py
+++ b/gdatastore/datastore.py
@@ -542,6 +542,7 @@ class InternalApi(object):
old_metadata = self._index.retrieve(object_id)['metadata']
metadata['creation_time'] = old_metadata['creation_time']
+ self._update_metadata_in_git(object_id, metadata)
self._index.store(object_id, metadata)
self._invoke_callbacks('change_metadata', object_id, metadata)
@@ -815,6 +816,19 @@ class InternalApi(object):
finally:
shutil.rmtree(index_dir)
+ def _update_metadata_in_git(self, object_id, metadata):
+ commit_message = self._format_commit_message(metadata)
+ tree_hash = self._get_tree_hash(object_id)
+ ref = _format_ref(*object_id)
+ commit_hash = self._git_call('commit-tree', ['-p', ref, tree_hash],
+ input=commit_message).strip()
+ self._git_call('update-ref', [ref, commit_hash])
+
+ def _get_tree_hash(self, object_id):
+ args = ['commit', _format_ref(*object_id)]
+ # First line of output contains tree hash
+ return self._git_call('cat-file', args).split('\n', 1)[0].split(' ')[1]
+
def _get_object_ids_from_git(self):
args = ['--sort=committerdate', '--format=%(refname)',
'refs/gdatastore/*/*']