Add pick_operation to sync with client
This commit is contained in:
@@ -9,7 +9,7 @@ from .operation import ChangeSet
|
||||
from .operation import get_current_operation
|
||||
from .operation import execute_undo, execute_redo
|
||||
from .operation import have_snapshot, take_snapshot, pick_snapshot
|
||||
from .operation import sync_with_server
|
||||
from .operation import pick_operation, sync_with_server
|
||||
|
||||
from .command import execute_batch_commands
|
||||
|
||||
|
||||
@@ -141,12 +141,8 @@ def _get_parents(name: str, id: int) -> list[int]:
|
||||
return ids
|
||||
|
||||
|
||||
def pick_snapshot(name: str, tag: str, discard: bool) -> ChangeSet:
|
||||
if not have_snapshot(name, tag):
|
||||
return ChangeSet()
|
||||
|
||||
target = int(read(name, f"select id from snapshot_operation where tag = '{tag}'")['id'])
|
||||
|
||||
def pick_operation(name: str, operation: int, discard: bool) -> ChangeSet:
|
||||
target = operation
|
||||
curr = get_current_operation(name)
|
||||
|
||||
curr_parents = _get_parents(name, curr)
|
||||
@@ -183,6 +179,14 @@ def pick_snapshot(name: str, tag: str, discard: bool) -> ChangeSet:
|
||||
return change.compress()
|
||||
|
||||
|
||||
def pick_snapshot(name: str, tag: str, discard: bool) -> ChangeSet:
|
||||
if not have_snapshot(name, tag):
|
||||
return ChangeSet()
|
||||
|
||||
target = int(read(name, f"select id from snapshot_operation where tag = '{tag}'")['id'])
|
||||
return pick_operation(name, target, discard)
|
||||
|
||||
|
||||
def _get_change_set(name: str, operation: int, undo: bool) -> dict[str, Any]:
|
||||
row = read(name, f'select * from operation where id = {operation}')
|
||||
return eval(row['undo_cs']) if undo else eval(row['redo_cs'])
|
||||
|
||||
@@ -131,6 +131,9 @@ def take_snapshot(name: str, tag: str) -> int | None:
|
||||
def pick_snapshot(name: str, tag: str, discard: bool = False) -> ChangeSet:
|
||||
return api.pick_snapshot(name, tag, discard)
|
||||
|
||||
def pick_operation(name: str, operation: int, discard: bool = False) -> ChangeSet:
|
||||
return api.pick_operation(name, operation, discard)
|
||||
|
||||
def sync_with_server(name: str, operation: int) -> ChangeSet:
|
||||
return api.sync_with_server(name, operation)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user