Author: ericwa
Date: Thu Mar 27 20:30:21 2014
New Revision: 10655
URL: http://svn.gna.org/viewcvs/etoile?rev=10655&view=rev
Log:
Revert 'COUndoTrack: migrate -undoNode:,-redoNode: to use the new
-addToStoreTransaction: method in COCommandGroup instead of -applyToContext:,
and remove -applyToContext: because it is no longer used. This eliminates two
parallel implementations of the complex logic in
COCommandSetCurrentVersionForBranch.'. See comment inserted in -[TestUndo
testSelectiveUndoOfCommands2]
Modified:
trunk/Etoile/Frameworks/CoreObject/Tests/Undo/TestUndo.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.h
trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeleteBranch.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeletePersistentRoot.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.h
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetBranchMetadata.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentBranch.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentVersionForBranch.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetPersistentRootMetadata.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeleteBranch.m
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeletePersistentRoot.m
trunk/Etoile/Frameworks/CoreObject/Undo/COUndoTrack.m
Modified: trunk/Etoile/Frameworks/CoreObject/Tests/Undo/TestUndo.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Tests/Undo/TestUndo.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Tests/Undo/TestUndo.m (original)
+++ trunk/Etoile/Frameworks/CoreObject/Tests/Undo/TestUndo.m Thu Mar 27
20:30:21 2014
@@ -651,7 +651,12 @@
[self checkCommandIsEndOfTrack: _testTrack.nodes[0]];
[self checkCommand: _testTrack.nodes[1] isSetVersionFrom: r0 to: r1];
[self checkCommand: _testTrack.nodes[2] isSetVersionFrom: r1 to: r2];
- [self checkCommand: _testTrack.nodes[3] isSetVersionFrom: r1 to: r0];
+
+ // This is the undo track node generated by undoNode:.
+ // We've switched back and forth between recording the command as
r2->r3 and
+ // r1->r0. Recording it as r2->r3 is safer because if the selective
undo has
+ // undesirable results, you can undo it and be guarantee to be returned
to r2.
+ [self checkCommand: _testTrack.nodes[3] isSetVersionFrom: r2 to: r3];
// Check that the commit created by COUndoTrack has proper commit
metadata
// FIXME: This next line tests the undo track node metadata, not the
revision metadata.
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.h
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.h?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.h (original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.h Thu Mar 27 20:30:21 2014
@@ -92,6 +92,11 @@
- (BOOL) canApplyToContext: (COEditingContext *)aContext;
/**
* <override-subclass />
+ * Applies the receiver changes to the editing context.
+ */
+- (void) applyToContext: (COEditingContext *)aContext;
+/**
+ * <override-subclass />
* Applies the receiver changes directly to a store transaction.
*/
- (void) addToStoreTransaction: (COStoreTransaction *)txn
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.m (original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommand.m Thu Mar 27 20:30:21 2014
@@ -118,6 +118,11 @@
return NO;
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ [NSException raise: NSInvalidArgumentException format: @"override"];
+}
+
- (void) addToStoreTransaction: (COStoreTransaction *)txn
withRevisionMetadata: (NSDictionary *)metadata assumingEditingContextState:
(COEditingContext *)ctx
{
[NSException raise: NSInvalidArgumentException format: @"override"];
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeleteBranch.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeleteBranch.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeleteBranch.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeleteBranch.m Thu Mar
27 20:30:21 2014
@@ -54,6 +54,17 @@
[txn deleteBranch: _branchUUID ofPersistentRoot: _persistentRootUUID];
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ COPersistentRoot *proot = [aContext persistentRootForUUID:
_persistentRootUUID];
+ COBranch *branch = [proot branchForUUID: _branchUUID];
+ ETAssert(branch != nil);
+
+ [branch setDeleted: YES];
+}
+
- (NSString *)kind
{
return _(@"Branch Deletion");
Modified:
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeletePersistentRoot.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeletePersistentRoot.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeletePersistentRoot.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandDeletePersistentRoot.m
Thu Mar 27 20:30:21 2014
@@ -82,6 +82,12 @@
[txn deletePersistentRoot: _persistentRootUUID];
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+ [[aContext persistentRootForUUID: _persistentRootUUID] setDeleted: YES];
+}
+
- (NSString *)kind
{
return _(@"Persistent Root Deletion");
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.h
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.h?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.h (original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.h Thu Mar 27
20:30:21 2014
@@ -119,6 +119,10 @@
*/
- (BOOL) canApplyToContext: (COEditingContext *)aContext;
/**
+ * Applies the receiver changes to the editing context.
+ */
+- (void) applyToContext: (COEditingContext *)aContext;
+/**
* Applies the receiver changes directly to a store transaction.
*/
- (void) addToStoreTransaction: (COStoreTransaction *)txn
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.m (original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandGroup.m Thu Mar 27
20:30:21 2014
@@ -162,6 +162,16 @@
return YES;
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ for (COCommand *command in _contents)
+ {
+ [command applyToContext: aContext];
+ }
+}
+
- (void) addToStoreTransaction: (COStoreTransaction *)txn
withRevisionMetadata: (NSDictionary *)metadata assumingEditingContextState:
(COEditingContext *)ctx
{
NILARG_EXCEPTION_TEST(ctx);
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetBranchMetadata.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetBranchMetadata.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetBranchMetadata.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetBranchMetadata.m
Thu Mar 27 20:30:21 2014
@@ -69,6 +69,17 @@
[txn setMetadata: _newMetadata forBranch: _branchUUID ofPersistentRoot:
_persistentRootUUID];
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ COPersistentRoot *proot = [aContext persistentRootForUUID:
_persistentRootUUID];
+ COBranch *branch = [proot branchForUUID: _branchUUID];
+ ETAssert(branch != nil);
+
+ [branch setMetadata: _newMetadata];
+}
+
- (NSString *)kind
{
return _(@"Branch Metadata Update");
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentBranch.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentBranch.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentBranch.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentBranch.m Thu Mar
27 20:30:21 2014
@@ -59,6 +59,17 @@
[txn setCurrentBranch: _newBranchUUID forPersistentRoot:
_persistentRootUUID];
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ COPersistentRoot *proot = [aContext persistentRootForUUID:
_persistentRootUUID];
+ COBranch *branch = [proot branchForUUID: _newBranchUUID];
+ ETAssert(branch != nil);
+
+ [proot setCurrentBranch: branch];
+}
+
- (NSString *)kind
{
return _(@"Branch Switch");
Modified:
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentVersionForBranch.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentVersionForBranch.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
---
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentVersionForBranch.m
(original)
+++
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetCurrentVersionForBranch.m
Thu Mar 27 20:30:21 2014
@@ -128,6 +128,61 @@
// }
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ COPersistentRoot *proot = [aContext persistentRootForUUID:
_persistentRootUUID];
+ COBranch *branch = [proot branchForUUID: _branchUUID];
+ ETAssert(branch != nil);
+
+ if ([[[branch currentRevision] UUID] isEqual: _oldRevisionUUID]
+ && branch.supportsRevert)
+ {
+ [branch setCurrentRevision:
+ [aContext revisionForRevisionUUID: _newRevisionUUID
persistentRootUUID: _persistentRootUUID]];
+
+ if (![aContext isRevision: _newHeadRevisionUUID
+ equalToOrParentOfRevision: _oldHeadRevisionUUID
+ persistentRoot: _persistentRootUUID])
+ {
+ [branch setHeadRevision:
+ [aContext revisionForRevisionUUID:
_newHeadRevisionUUID persistentRootUUID: _persistentRootUUID]];
+ }
+ }
+ else
+ {
+ _currentRevisionBeforeSelectiveApply = [[branch
currentRevision] UUID];
+
+ CODiffManager *merged = [self
diffToSelectivelyApplyToBranchCurrentRevision:
_currentRevisionBeforeSelectiveApply
+
assumingEditingContext: aContext];
+ COItemGraph *oldGraph = [[proot store] itemGraphForRevisionUUID:
_oldRevisionUUID persistentRoot: _persistentRootUUID];
+
+ id<COItemGraph> result = [[COItemGraph alloc] initWithItemGraph:
oldGraph];
+ [merged applyTo: result];
+
+ // FIXME: Works, but an ugly API mismatch when setting object graph
context contents
+ NSMutableArray *items = [NSMutableArray array];
+ for (ETUUID *uuid in [result itemUUIDs])
+ {
+ COItem *replacementItem = [result itemForUUID: uuid];
+ COItem *existingItem = [[branch objectGraphContext]
itemForUUID: uuid];
+ if (existingItem == nil
+ || ![existingItem isEqual: replacementItem])
+ {
+ [items addObject: replacementItem];
+ }
+ }
+
+ // FIXME: Handle cross-persistent root relationship constraint
violations,
+ // if we introduce those
+ [[branch objectGraphContext] insertOrUpdateItems: items];
+
+ // N.B. newHeadRevisionID is intentionally ignored here, it
only applies
+ // if we were able to do a non-selective undo.
+ }
+}
+
+ (ETUUID *) currentRevisionUUIDForBranch: (COBranch *)branch
withChangesInStoreTransaction: (COStoreTransaction *)txn
{
NILARG_EXCEPTION_TEST(branch);
Modified:
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetPersistentRootMetadata.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetPersistentRootMetadata.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
---
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetPersistentRootMetadata.m
(original)
+++
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandSetPersistentRootMetadata.m
Thu Mar 27 20:30:21 2014
@@ -64,6 +64,16 @@
[txn setMetadata: _newMetadata forPersistentRoot: _persistentRootUUID];
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ COPersistentRoot *proot = [aContext persistentRootForUUID:
_persistentRootUUID];
+ ETAssert(proot != nil);
+
+ [proot setMetadata: _newMetadata];
+}
+
- (NSString *)kind
{
return _(@"Persistent Root Metadata Update");
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeleteBranch.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeleteBranch.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeleteBranch.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeleteBranch.m Thu Mar
27 20:30:21 2014
@@ -54,6 +54,17 @@
[txn undeleteBranch: _branchUUID ofPersistentRoot: _persistentRootUUID];
}
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+
+ COPersistentRoot *proot = [aContext persistentRootForUUID:
_persistentRootUUID];
+ COBranch *branch = [proot branchForUUID: _branchUUID];
+ ETAssert(branch != nil);
+
+ [branch setDeleted: NO];
+}
+
- (NSString *)kind
{
return _(@"Branch Undeletion");
Modified:
trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeletePersistentRoot.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeletePersistentRoot.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeletePersistentRoot.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COCommandUndeletePersistentRoot.m
Thu Mar 27 20:30:21 2014
@@ -35,6 +35,12 @@
return NO;
}
return YES;
+}
+
+- (void) applyToContext: (COEditingContext *)aContext
+{
+ NILARG_EXCEPTION_TEST(aContext);
+ [[aContext persistentRootForUUID: _persistentRootUUID] setDeleted: NO];
}
- (void) addToStoreTransaction: (COStoreTransaction *)txn
withRevisionMetadata: (NSDictionary *)metadata assumingEditingContextState:
(COEditingContext *)ctx
Modified: trunk/Etoile/Frameworks/CoreObject/Undo/COUndoTrack.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Undo/COUndoTrack.m?rev=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Undo/COUndoTrack.m (original)
+++ trunk/Etoile/Frameworks/CoreObject/Undo/COUndoTrack.m Thu Mar 27
20:30:21 2014
@@ -276,27 +276,23 @@
COUndoTrack *track = [COUndoTrack trackForName: ((COCommandGroup
*)aNode).trackName withEditingContext: _editingContext];
ETAssert(track != nil);
- COCommandGroup *command = [(COCommandGroup *)aNode inverse];
+ COCommand *command = [(COCommand *)aNode inverse];
+ [command applyToContext: _editingContext];
NSString *commitShortDescription = [aNode localizedShortDescription];
if (commitShortDescription == nil)
commitShortDescription = @"";
- NSMutableDictionary *md = [@{kCOCommitMetadataIdentifier :
@"org.etoile.CoreObject.selective-undo",
-
kCOCommitMetadataShortDescriptionArguments : @[commitShortDescription]}
mutableCopy];
-
+ NSMutableDictionary *md = [@{kCOCommitMetadataShortDescriptionArguments
: @[commitShortDescription]} mutableCopy];
if (self.customRevisionMetadata != nil)
{
[md addEntriesFromDictionary: self.customRevisionMetadata];
}
- command.metadata = md;
-
- COStoreTransaction *txn = [[COStoreTransaction alloc] init];
- [command addToStoreTransaction: txn withRevisionMetadata: md
assumingEditingContextState: _editingContext];
- [self commitStoreTransaction: txn];
-
- [self recordCommand: command];
+ [_editingContext commitWithIdentifier:
@"org.etoile.CoreObject.selective-undo"
+ metadata: md
+ undoTrack: track
+ error:
NULL];
}
- (void)redoNode: (id <COTrackNode>)aNode
@@ -304,27 +300,23 @@
COUndoTrack *track = [COUndoTrack trackForName: ((COCommandGroup
*)aNode).trackName withEditingContext: _editingContext];
ETAssert(track != nil);
- COCommandGroup *command = [(COCommandGroup *)aNode copy];
+ COCommand *command = (COCommand *)aNode;
+ [command applyToContext: _editingContext];
NSString *commitShortDescription = [aNode localizedShortDescription];
if (commitShortDescription == nil)
commitShortDescription = @"";
- NSMutableDictionary *md = [@{kCOCommitMetadataIdentifier :
@"org.etoile.CoreObject.selective-redo",
-
kCOCommitMetadataShortDescriptionArguments : @[commitShortDescription]}
mutableCopy];
-
+ NSMutableDictionary *md = [@{kCOCommitMetadataShortDescriptionArguments
: @[commitShortDescription]} mutableCopy];
if (self.customRevisionMetadata != nil)
{
[md addEntriesFromDictionary: self.customRevisionMetadata];
}
-
- command.metadata = md;
-
- COStoreTransaction *txn = [[COStoreTransaction alloc] init];
- [command addToStoreTransaction: txn withRevisionMetadata: md
assumingEditingContextState: _editingContext];
- [self commitStoreTransaction: txn];
-
- [self recordCommand: command];
+
+ [_editingContext commitWithIdentifier:
@"org.etoile.CoreObject.selective-redo"
+ metadata: md
+ undoTrack: track
+ error:
NULL];
}
#pragma mark - COUndoTrack - Other Public Methods
_______________________________________________
Etoile-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-cvs