From 0301a9cb26c58124a44202b1adc50aa6a9f086d1 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Sat, 21 Jan 2012 19:30:53 +0100 Subject: [PATCH] Allow restoring orphan versions In order to support removing intermediate versions (on explicit user action or as part of automatic space reduction) we should not require the parent version to exist when restoring versions from backup. At least the Restore activity needs to be careful to never restore the child before the parent, otherwise we'd loose information in git (the parent commit id) that would have been recoverable. The previous check in restore() would have caught that, but also prevents restoring from backups which are missing intermediate versions (because they have been deleted). Alternatives: * Let gdatastore (and thus Backup) store "fake" intermediate versions on delete. --- gdatastore/datastore.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gdatastore/datastore.py b/gdatastore/datastore.py index e85cc4f..c0d59d8 100644 --- a/gdatastore/datastore.py +++ b/gdatastore/datastore.py @@ -190,7 +190,6 @@ class DBusApiNativeV1(dbus.service.Object): """ - add a new version with the given ids - there must be no existing entry with the same (tree_id, version_id) - - if parent_id != '' there must be an existing entry (tree_id, parent_id) - if parent_id = '', there must be no existing entry with the same tree_id and no parent_id """ if not tree_id: @@ -499,10 +498,6 @@ class InternalApi(object): raise ValueError('No parent_id given but tree_id already ' 'exists') - elif parent_id: - if not self._index.contains((tree_id, parent_id)): - raise ValueError('Given parent does not exist') - if not tree_id: tree_id = self._gen_uuid() @@ -593,8 +588,11 @@ class InternalApi(object): if not parent_id: return None - return self._git_call('rev-parse', - [_format_ref(tree_id, parent_id)]).strip() + try: + return self._git_call('rev-parse', + [_format_ref(tree_id, parent_id)]).strip() + except GitError: + return None def _format_commit_message(self, metadata): return pprint.pformat(to_native(metadata)) -- 1.7.9.5