From fe1a26b7c3fb9f68a243f8deb7f433f493447faf Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Fri, 5 Sep 2008 17:32:27 +0400 Subject: [PATCH] LocalHistory: memory optimization --- .../history/core/changes/ContentChange.java | 52 ++++++++++++---------- .../core/changes/ContentChangeAppliedState.java | 8 ++++ .../core/changes/ContentChangeNonAppliedState.java | 8 ++++ .../core/changes/CreateDirectoryChange.java | 13 +++--- .../history/core/changes/CreateEntryChange.java | 24 +++++++--- .../changes/CreateEntryChangeNonAppliedState.java | 5 +++ .../history/core/changes/CreateFileChange.java | 25 ++++++----- .../changes/CreateFileChangeNonAppliedState.java | 9 ++++ .../history/core/changes/DeleteChange.java | 39 +++++++++------- .../core/changes/DeleteChangeAppliedState.java | 7 +++ .../intellij/history/core/changes/MoveChange.java | 35 +++++++++------ .../core/changes/MoveChangeAppliedState.java | 7 +++ .../core/changes/MoveChangeNonAppliedState.java | 5 +++ .../history/core/changes/ROStatusChange.java | 38 +++++++++------- .../core/changes/ROStatusChangeAppliedState.java | 5 +++ .../changes/ROStatusChangeNonAppliedState.java | 5 +++ .../history/core/changes/RenameChange.java | 37 ++++++++------- .../core/changes/RenameChangeAppliedState.java | 5 +++ .../core/changes/RenameChangeNonAppliedState.java | 5 +++ .../history/core/changes/StructuralChange.java | 44 +++++++++++++----- .../core/changes/StructuralChangeAppliedState.java | 7 +++ .../changes/StructuralChangeNonAppliedState.java | 5 +++ .../core/changes/StructuralChangeState.java | 4 ++ .../history/core/changes/ChangeSetTest.java | 4 +- 24 files changed, 277 insertions(+), 119 deletions(-) create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/ContentChangeAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/ContentChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/CreateFileChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/DeleteChangeAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/MoveChangeAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/MoveChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/RenameChangeAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/RenameChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeNonAppliedState.java create mode 100644 lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeState.java diff --git a/lvcs/impl/src/com/intellij/history/core/changes/ContentChange.java b/lvcs/impl/src/com/intellij/history/core/changes/ContentChange.java index 1f8101ba1b..88f8451136 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/ContentChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/ContentChange.java @@ -1,67 +1,73 @@ package com.intellij.history.core.changes; -import com.intellij.history.core.IdPath; import com.intellij.history.core.storage.Content; import com.intellij.history.core.storage.Stream; import com.intellij.history.core.tree.Entry; +import com.intellij.history.core.IdPath; import java.io.IOException; import java.util.Collections; import java.util.List; -public class ContentChange extends StructuralChange { - private Content myNewContent; // transient - private long myNewTimestamp; // transient - private Content myOldContent; - private long myOldTimestamp; - +public class ContentChange extends StructuralChange { public ContentChange(String path, Content newContent, long timestamp) { super(path); - myNewContent = newContent; - myNewTimestamp = timestamp; + getNonAppliedState().myNewContent = newContent; + getNonAppliedState().myNewTimestamp = timestamp; } public ContentChange(Stream s) throws IOException { super(s); - myOldContent = s.readContent(); - myOldTimestamp = s.readLong(); + getAppliedState().myOldContent = s.readContent(); + getAppliedState().myOldTimestamp = s.readLong(); } @Override public void write(Stream s) throws IOException { super.write(s); - s.writeContent(myOldContent); - s.writeLong(myOldTimestamp); + s.writeContent(getAppliedState().myOldContent); + s.writeLong(getAppliedState().myOldTimestamp); + } + + @Override + protected ContentChangeAppliedState createAppliedState() { + return new ContentChangeAppliedState(); } + @Override + protected ContentChangeNonAppliedState createNonAppliedState() { + return new ContentChangeNonAppliedState(); + } + + public Content getOldContent() { - return myOldContent; + return getAppliedState().myOldContent; } public long getOldTimestamp() { - return myOldTimestamp; + return getAppliedState().myOldTimestamp; } @Override - protected IdPath doApplyTo(Entry root) { - Entry e = root.getEntry(myPath); + protected IdPath doApplyTo(Entry root, ContentChangeAppliedState newState) { + Entry e = root.getEntry(getPath()); - myOldContent = e.getContent(); - myOldTimestamp = e.getTimestamp(); + newState.myOldContent = e.getContent(); + newState.myOldTimestamp = e.getTimestamp(); - e.changeContent(myNewContent, myNewTimestamp); + e.changeContent(getNonAppliedState().myNewContent, getNonAppliedState().myNewTimestamp); return e.getIdPath(); } @Override public void revertOn(Entry root) { - Entry e = root.getEntry(myAffectedIdPath); - e.changeContent(myOldContent, myOldTimestamp); + Entry e = root.getEntry(getAffectedIdPath()); + e.changeContent(getAppliedState().myOldContent, getAppliedState().myOldTimestamp); } @Override public List getContentsToPurge() { - return Collections.singletonList(myOldContent); + return Collections.singletonList(getAppliedState().myOldContent); } @Override diff --git a/lvcs/impl/src/com/intellij/history/core/changes/ContentChangeAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/ContentChangeAppliedState.java new file mode 100644 index 0000000000..d413664625 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/ContentChangeAppliedState.java @@ -0,0 +1,8 @@ +package com.intellij.history.core.changes; + +import com.intellij.history.core.storage.Content; + +public class ContentChangeAppliedState extends StructuralChangeAppliedState { + public Content myOldContent; + public long myOldTimestamp; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/ContentChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/ContentChangeNonAppliedState.java new file mode 100644 index 0000000000..9cbac47403 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/ContentChangeNonAppliedState.java @@ -0,0 +1,8 @@ +package com.intellij.history.core.changes; + +import com.intellij.history.core.storage.Content; + +public class ContentChangeNonAppliedState extends StructuralChangeNonAppliedState { + public Content myNewContent; + public long myNewTimestamp; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/CreateDirectoryChange.java b/lvcs/impl/src/com/intellij/history/core/changes/CreateDirectoryChange.java index d71d43c4a6..e49dd00ae4 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/CreateDirectoryChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/CreateDirectoryChange.java @@ -1,18 +1,15 @@ package com.intellij.history.core.changes; -import com.intellij.history.core.IdPath; import com.intellij.history.core.storage.Stream; import com.intellij.history.core.tree.DirectoryEntry; import com.intellij.history.core.tree.Entry; +import com.intellij.history.core.IdPath; import java.io.IOException; -public class CreateDirectoryChange extends CreateEntryChange { - private int myId; // transient - +public class CreateDirectoryChange extends CreateEntryChange { public CreateDirectoryChange(int id, String path) { super(id, path); - myId = id; } public CreateDirectoryChange(Stream s) throws IOException { @@ -20,7 +17,7 @@ public class CreateDirectoryChange extends CreateEntryChange { } @Override - protected IdPath doApplyTo(Entry r) { + protected IdPath doApplyTo(Entry r, StructuralChangeAppliedState newState) { // todo messsssss!!!! should introduce createRoot method instead? // todo and simplify addEntry method too? String name = getEntryName(); @@ -28,10 +25,10 @@ public class CreateDirectoryChange extends CreateEntryChange { if (parentPath == null || !r.hasEntry(parentPath)) { // is it supposed to be a root? parentPath = null; - name = myPath; + name = getPath(); } - DirectoryEntry e = new DirectoryEntry(myId, name); + DirectoryEntry e = new DirectoryEntry(getNonAppliedState().myId, name); return addEntry(r, parentPath, e); } } diff --git a/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChange.java b/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChange.java index ab9077362a..95517ca49c 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChange.java @@ -7,26 +7,36 @@ import com.intellij.history.core.tree.Entry; import java.io.IOException; -public abstract class CreateEntryChange extends StructuralChange { - protected int myId; // transient +public abstract class CreateEntryChange + extends StructuralChange { public CreateEntryChange(int id, String path) { super(path); - myId = id; + getNonAppliedState().myId = id; } public CreateEntryChange(Stream s) throws IOException { super(s); } + @Override + protected NON_APPLIED_STATE_TYPE createNonAppliedState() { + return (NON_APPLIED_STATE_TYPE)new CreateEntryChangeNonAppliedState(); + } + + @Override + protected StructuralChangeAppliedState createAppliedState() { + return new StructuralChangeAppliedState(); + } + protected String getEntryParentPath() { - return Paths.getParentOf(myPath); + return Paths.getParentOf(getPath()); } protected String getEntryName() { // new String() is for trimming rest part of path to // minimaze memory usage after bulk updates and refreshes. - return new String(Paths.getNameOf(myPath)); + return new String(Paths.getNameOf(getPath())); } protected IdPath addEntry(Entry r, String parentPath, Entry e) { @@ -37,7 +47,7 @@ public abstract class CreateEntryChange extends StructuralChange { @Override public void revertOn(Entry root) { - Entry e = root.getEntry(myAffectedIdPath); + Entry e = root.getEntry(getAffectedIdPath()); removeEntry(e); } @@ -47,7 +57,7 @@ public abstract class CreateEntryChange extends StructuralChange { } public boolean isCreationalFor(IdPath p) { - return p.getId() == myAffectedIdPath.getId(); + return p.getId() == getAffectedIdPath().getId(); } @Override diff --git a/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChangeNonAppliedState.java new file mode 100644 index 0000000000..8ec250738b --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/CreateEntryChangeNonAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +class CreateEntryChangeNonAppliedState extends StructuralChangeNonAppliedState { + public int myId; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChange.java b/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChange.java index f69aaf04a5..955d7061a4 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChange.java @@ -8,16 +8,12 @@ import com.intellij.history.core.tree.FileEntry; import java.io.IOException; -public class CreateFileChange extends CreateEntryChange { - private Content myContent; // transient - private long myTimestamp; // transient - private boolean isReadOnly; // transient - +public class CreateFileChange extends CreateEntryChange { public CreateFileChange(int id, String path, Content content, long timestamp, boolean isReadOnly) { super(id, path); - myContent = content; - myTimestamp = timestamp; - this.isReadOnly = isReadOnly; + getNonAppliedState().myContent = content; + getNonAppliedState().myTimestamp = timestamp; + getNonAppliedState().isReadOnly = isReadOnly; } public CreateFileChange(Stream s) throws IOException { @@ -25,11 +21,20 @@ public class CreateFileChange extends CreateEntryChange { } @Override - protected IdPath doApplyTo(Entry r) { + protected CreateFileChangeNonAppliedState createNonAppliedState() { + return new CreateFileChangeNonAppliedState(); + } + + @Override + protected IdPath doApplyTo(Entry r, StructuralChangeAppliedState newState) { String name = getEntryName(); String parentPath = getEntryParentPath(); - Entry e = new FileEntry(myId, name, myContent, myTimestamp, isReadOnly); + Entry e = new FileEntry(getNonAppliedState().myId, + name, + getNonAppliedState().myContent, + getNonAppliedState().myTimestamp, + getNonAppliedState().isReadOnly); return addEntry(r, parentPath, e); } diff --git a/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChangeNonAppliedState.java new file mode 100644 index 0000000000..5fe40a1c0b --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/CreateFileChangeNonAppliedState.java @@ -0,0 +1,9 @@ +package com.intellij.history.core.changes; + +import com.intellij.history.core.storage.Content; + +public class CreateFileChangeNonAppliedState extends CreateEntryChangeNonAppliedState { + public Content myContent; + public long myTimestamp; + public boolean isReadOnly; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/DeleteChange.java b/lvcs/impl/src/com/intellij/history/core/changes/DeleteChange.java index 4bdf0a6032..e0da9840de 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/DeleteChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/DeleteChange.java @@ -9,34 +9,42 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class DeleteChange extends StructuralChange { - private Entry myAffectedEntry; - +public class DeleteChange extends StructuralChange { public DeleteChange(String path) { super(path); } public DeleteChange(Stream s) throws IOException { super(s); - myAffectedEntry = s.readEntry(); + getAppliedState().myAffectedEntry = s.readEntry(); } @Override public void write(Stream s) throws IOException { super.write(s); - s.writeEntry(myAffectedEntry); + s.writeEntry(getAppliedState().myAffectedEntry); + } + + @Override + protected StructuralChangeNonAppliedState createNonAppliedState() { + return new StructuralChangeNonAppliedState(); + } + + @Override + protected DeleteChangeAppliedState createAppliedState() { + return new DeleteChangeAppliedState(); } public Entry getAffectedEntry() { - return myAffectedEntry; + return getAppliedState().myAffectedEntry; } @Override - protected IdPath doApplyTo(Entry r) { - myAffectedEntry = r.getEntry(myPath); - IdPath idPath = myAffectedEntry.getIdPath(); + protected IdPath doApplyTo(Entry r, DeleteChangeAppliedState newState) { + newState.myAffectedEntry = r.getEntry(getPath()); + IdPath idPath = newState.myAffectedEntry.getIdPath(); - removeEntry(myAffectedEntry); + removeEntry(newState.myAffectedEntry); return idPath; } @@ -44,26 +52,26 @@ public class DeleteChange extends StructuralChange { @Override public void revertOn(Entry r) { Entry parent = getParent(r); - parent.addChild(myAffectedEntry.copy()); + parent.addChild(getAppliedState().myAffectedEntry.copy()); } @Override public boolean canRevertOn(Entry r) { - return hasNoSuchEntry(getParent(r), myAffectedEntry.getName()); + return hasNoSuchEntry(getParent(r), getAppliedState().myAffectedEntry.getName()); } private Entry getParent(Entry r) { - return r.getEntry(myAffectedIdPath.getParent()); + return r.getEntry(getAffectedIdPath().getParent()); } public boolean isDeletionOf(IdPath p) { - return p.startsWith(myAffectedIdPath); + return p.startsWith(getAffectedIdPath()); } @Override public List getContentsToPurge() { List result = new ArrayList(); - collectContentsRecursively(myAffectedEntry, result); + collectContentsRecursively(getAppliedState().myAffectedEntry, result); return result; } @@ -82,4 +90,5 @@ public class DeleteChange extends StructuralChange { public void accept(ChangeVisitor v) throws IOException, ChangeVisitor.StopVisitingException { v.visit(this); } + } diff --git a/lvcs/impl/src/com/intellij/history/core/changes/DeleteChangeAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/DeleteChangeAppliedState.java new file mode 100644 index 0000000000..97570ddc92 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/DeleteChangeAppliedState.java @@ -0,0 +1,7 @@ +package com.intellij.history.core.changes; + +import com.intellij.history.core.tree.Entry; + +class DeleteChangeAppliedState extends StructuralChangeAppliedState { + public Entry myAffectedEntry; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/MoveChange.java b/lvcs/impl/src/com/intellij/history/core/changes/MoveChange.java index 11b1b10655..8e0e3aa661 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/MoveChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/MoveChange.java @@ -6,37 +6,44 @@ import com.intellij.history.core.tree.Entry; import java.io.IOException; -public class MoveChange extends StructuralChange { - private String myNewParentPath; // transient - private IdPath myTargetIdPath; - +public class MoveChange extends StructuralChange { public MoveChange(String path, String newParentPath) { super(path); - myNewParentPath = newParentPath; + getNonAppliedState().myNewParentPath = newParentPath; } public MoveChange(Stream s) throws IOException { super(s); - myTargetIdPath = s.readIdPath(); + getAppliedState().myTargetIdPath = s.readIdPath(); } @Override public void write(Stream s) throws IOException { super.write(s); - s.writeIdPath(myTargetIdPath); + s.writeIdPath(getAppliedState().myTargetIdPath); + } + + @Override + protected MoveChangeAppliedState createAppliedState() { + return new MoveChangeAppliedState(); + } + + @Override + protected MoveChangeNonAppliedState createNonAppliedState() { + return new MoveChangeNonAppliedState(); } @Override - protected IdPath doApplyTo(Entry r) { - Entry e = r.getEntry(myPath); + protected IdPath doApplyTo(Entry r, MoveChangeAppliedState newState) { + Entry e = r.getEntry(getPath()); IdPath firstIdPath = e.getIdPath(); removeEntry(e); - Entry newParent = r.getEntry(myNewParentPath); + Entry newParent = r.getEntry(getNonAppliedState().myNewParentPath); newParent.addChild(e); - myTargetIdPath = e.getIdPath(); + newState.myTargetIdPath = e.getIdPath(); return firstIdPath; } @@ -56,16 +63,16 @@ public class MoveChange extends StructuralChange { } private Entry getEntry(Entry r) { - return r.getEntry(myTargetIdPath); + return r.getEntry(getAppliedState().myTargetIdPath); } private Entry getOldParent(Entry r) { - return r.getEntry(myAffectedIdPath.getParent()); + return r.getEntry(getAffectedIdPath().getParent()); } @Override public IdPath[] getAffectedIdPaths() { - return new IdPath[]{myAffectedIdPath, myTargetIdPath}; + return new IdPath[]{getAffectedIdPath(), getAppliedState().myTargetIdPath}; } @Override diff --git a/lvcs/impl/src/com/intellij/history/core/changes/MoveChangeAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/MoveChangeAppliedState.java new file mode 100644 index 0000000000..d8851d0012 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/MoveChangeAppliedState.java @@ -0,0 +1,7 @@ +package com.intellij.history.core.changes; + +import com.intellij.history.core.IdPath; + +public class MoveChangeAppliedState extends StructuralChangeAppliedState { + public IdPath myTargetIdPath; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/MoveChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/MoveChangeNonAppliedState.java new file mode 100644 index 0000000000..44af67f981 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/MoveChangeNonAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +public class MoveChangeNonAppliedState extends StructuralChangeNonAppliedState { + public String myNewParentPath; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChange.java b/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChange.java index fa62728c99..d0cc04644a 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChange.java @@ -1,50 +1,58 @@ package com.intellij.history.core.changes; -import com.intellij.history.core.IdPath; import com.intellij.history.core.storage.Stream; import com.intellij.history.core.tree.Entry; +import com.intellij.history.core.IdPath; import java.io.IOException; -public class ROStatusChange extends StructuralChange { - private boolean myOldStatus; - private boolean myNewStatus; // transient - +public class ROStatusChange extends StructuralChange { public ROStatusChange(String path, boolean isReadOnly) { super(path); - myNewStatus = isReadOnly; + getNonAppliedState().myNewStatus = isReadOnly; } public ROStatusChange(Stream s) throws IOException { super(s); - myOldStatus = s.readBoolean(); + getAppliedState().myOldStatus = s.readBoolean(); } @Override public void write(Stream s) throws IOException { super.write(s); - s.writeBoolean(myOldStatus); + s.writeBoolean(getAppliedState().myOldStatus); + } + + @Override + protected ROStatusChangeAppliedState createAppliedState() { + return new ROStatusChangeAppliedState(); + } + + @Override + protected ROStatusChangeNonAppliedState createNonAppliedState() { + return new ROStatusChangeNonAppliedState(); } public boolean getOldStatus() { - return myOldStatus; + return getAppliedState().myOldStatus; } @Override - protected IdPath doApplyTo(Entry r) { - Entry e = r.getEntry(myPath); - myOldStatus = e.isReadOnly(); - e.setReadOnly(myNewStatus); + protected IdPath doApplyTo(Entry r, ROStatusChangeAppliedState newState) { + Entry e = r.getEntry(getPath()); + newState.myOldStatus = e.isReadOnly(); + e.setReadOnly(getNonAppliedState().myNewStatus); + return e.getIdPath(); } @Override public void revertOn(Entry r) { - getEntry(r).setReadOnly(myOldStatus); + getEntry(r).setReadOnly(getAppliedState().myOldStatus); } private Entry getEntry(Entry r) { - return r.getEntry(myAffectedIdPath); + return r.getEntry(getAffectedIdPath()); } @Override diff --git a/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeAppliedState.java new file mode 100644 index 0000000000..bcaca35a22 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +public class ROStatusChangeAppliedState extends StructuralChangeAppliedState { + public boolean myOldStatus; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeNonAppliedState.java new file mode 100644 index 0000000000..7adbcf7ed5 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/ROStatusChangeNonAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +public class ROStatusChangeNonAppliedState extends StructuralChangeNonAppliedState { + public boolean myNewStatus; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/RenameChange.java b/lvcs/impl/src/com/intellij/history/core/changes/RenameChange.java index d7301f1cb0..fa68f07d5d 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/RenameChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/RenameChange.java @@ -7,54 +7,61 @@ import com.intellij.history.core.tree.Entry; import java.io.IOException; -public class RenameChange extends StructuralChange { - private String myOldName; - private String myNewName; // transient - +public class RenameChange extends StructuralChange { public RenameChange(String path, String newName) { super(path); - myNewName = newName; + getNonAppliedState().myNewName = newName; } public RenameChange(Stream s) throws IOException { super(s); - myOldName = s.readString(); + getAppliedState().myOldName = s.readString(); } @Override public void write(Stream s) throws IOException { super.write(s); - s.writeString(myOldName); + s.writeString(getAppliedState().myOldName); + } + + @Override + protected RenameChangeAppliedState createAppliedState() { + return new RenameChangeAppliedState(); + } + + @Override + protected RenameChangeNonAppliedState createNonAppliedState() { + return new RenameChangeNonAppliedState(); } public String getOldName() { - return myOldName; + return getAppliedState().myOldName; } @Override - protected IdPath doApplyTo(Entry r) { - Entry e = r.getEntry(myPath); + protected IdPath doApplyTo(Entry r, RenameChangeAppliedState newState) { + Entry e = r.getEntry(getPath()); // todo one more hack to support roots... // todo i defitilety have to do something with it... - myOldName = Paths.getNameOf(e.getName()); - rename(e, myNewName); + newState.myOldName = Paths.getNameOf(e.getName()); + rename(e, getNonAppliedState().myNewName); return e.getIdPath(); } @Override public void revertOn(Entry r) { - rename(getEntry(r), myOldName); + rename(getEntry(r), getAppliedState().myOldName); } @Override public boolean canRevertOn(Entry r) { - return hasNoSuchEntry(getEntry(r).getParent(), myOldName); + return hasNoSuchEntry(getEntry(r).getParent(), getAppliedState().myOldName); } private Entry getEntry(Entry r) { - return r.getEntry(myAffectedIdPath); + return r.getEntry(getAffectedIdPath()); } private void rename(Entry e, String newName) { diff --git a/lvcs/impl/src/com/intellij/history/core/changes/RenameChangeAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/RenameChangeAppliedState.java new file mode 100644 index 0000000000..db90a29ddd --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/RenameChangeAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +public class RenameChangeAppliedState extends StructuralChangeAppliedState { + public String myOldName; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/RenameChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/RenameChangeNonAppliedState.java new file mode 100644 index 0000000000..14082d26b9 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/RenameChangeNonAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +public class RenameChangeNonAppliedState extends StructuralChangeNonAppliedState { + public String myNewName; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/StructuralChange.java b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChange.java index 5fd51c8fd1..3f68a17adf 100644 --- a/lvcs/impl/src/com/intellij/history/core/changes/StructuralChange.java +++ b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChange.java @@ -9,29 +9,53 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -public abstract class StructuralChange extends Change { - protected String myPath; // transient - protected IdPath myAffectedIdPath; +public abstract class StructuralChange< + NON_APPLIED_STATE_TYPE extends StructuralChangeNonAppliedState, + APPLIED_STATE_TYPE extends StructuralChangeAppliedState> extends Change { + private StructuralChangeState myState; protected StructuralChange(String path) { - myPath = path; + myState = createNonAppliedState(); + getNonAppliedState().myPath = path; } protected StructuralChange(Stream s) throws IOException { - myAffectedIdPath = s.readIdPath(); + myState = createAppliedState(); + getAppliedState().myAffectedIdPath = s.readIdPath(); } public void write(Stream s) throws IOException { - s.writeIdPath(myAffectedIdPath); + s.writeIdPath(getAffectedIdPath()); + } + + protected String getPath() { + return getNonAppliedState().myPath; + } + + protected IdPath getAffectedIdPath() { + return getAppliedState().myAffectedIdPath; + } + + protected abstract NON_APPLIED_STATE_TYPE createNonAppliedState(); + + protected abstract APPLIED_STATE_TYPE createAppliedState(); + + protected NON_APPLIED_STATE_TYPE getNonAppliedState() { + return (NON_APPLIED_STATE_TYPE)myState; + } + + protected APPLIED_STATE_TYPE getAppliedState() { + return (APPLIED_STATE_TYPE)myState; } @Override public void applyTo(Entry r) { - myAffectedIdPath = doApplyTo(r); - myPath = null; + APPLIED_STATE_TYPE newState = createAppliedState(); + newState.myAffectedIdPath = doApplyTo(r, newState); + myState = newState; } - protected abstract IdPath doApplyTo(Entry r); + protected abstract IdPath doApplyTo(Entry r, APPLIED_STATE_TYPE newState); @Override public abstract void revertOn(Entry r); @@ -78,7 +102,7 @@ public abstract class StructuralChange extends Change { } public IdPath[] getAffectedIdPaths() { - return new IdPath[]{myAffectedIdPath}; + return new IdPath[]{getAffectedIdPath()}; } @Override diff --git a/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeAppliedState.java new file mode 100644 index 0000000000..4b7c14ef42 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeAppliedState.java @@ -0,0 +1,7 @@ +package com.intellij.history.core.changes; + +import com.intellij.history.core.IdPath; + +public class StructuralChangeAppliedState implements StructuralChangeState { + public IdPath myAffectedIdPath; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeNonAppliedState.java b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeNonAppliedState.java new file mode 100644 index 0000000000..c518b07609 --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeNonAppliedState.java @@ -0,0 +1,5 @@ +package com.intellij.history.core.changes; + +public class StructuralChangeNonAppliedState implements StructuralChangeState { + public String myPath; +} diff --git a/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeState.java b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeState.java new file mode 100644 index 0000000000..4e0b29be8b --- /dev/null +++ b/lvcs/impl/src/com/intellij/history/core/changes/StructuralChangeState.java @@ -0,0 +1,4 @@ +package com.intellij.history.core.changes; + +public interface StructuralChangeState { +} diff --git a/lvcs/impl/test/com/intellij/history/core/changes/ChangeSetTest.java b/lvcs/impl/test/com/intellij/history/core/changes/ChangeSetTest.java index a0f792eb30..33b5874a65 100644 --- a/lvcs/impl/test/com/intellij/history/core/changes/ChangeSetTest.java +++ b/lvcs/impl/test/com/intellij/history/core/changes/ChangeSetTest.java @@ -1,7 +1,7 @@ package com.intellij.history.core.changes; -import com.intellij.history.core.IdPath; import com.intellij.history.core.LocalVcsTestCase; +import com.intellij.history.core.IdPath; import com.intellij.history.core.tree.Entry; import com.intellij.history.core.tree.RootEntry; import org.junit.Test; @@ -91,7 +91,7 @@ public class ChangeSetTest extends LocalVcsTestCase { } @Override - protected IdPath doApplyTo(Entry root) { + protected IdPath doApplyTo(Entry root, StructuralChangeAppliedState newState) { log.add(myId); return null; } -- 2.11.4.GIT