From fbd7bd8d36535c9ff93e5b2f4850b6c2727b9062 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Thu, 22 May 2014 20:32:53 +0000 Subject: 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). --- 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/*/*'] -- cgit v0.9.1