Anonymous avatar Anonymous committed e660818

Initializing ChangeContent.old_contents only when do() is called

Comments (0)

Files changed (3)

rope/base/change.py

         # IDEA: Only saving diffs; possible problems when undo/redoing
         self.new_contents = new_contents
         self.old_contents = old_contents
-        if self.old_contents is None:
-            if self.resource.exists():
-                self.old_contents = self.resource.read()
         self.operations = self.resource.project.operations
 
     @_handle_job_set
 
     @_handle_job_set
     def undo(self):
+        if self.old_contents is None:
+            raise exceptions.HistoryError(
+                'Undoing a change that is not performed yet!')
         self.operations.write_file(self.resource, self.old_contents)
 
     def __str__(self):

rope/base/default_config.py

     # project is very large, you might consider 'shelve' or the
     # slower 'sqlite'.
     prefs['objectdb_type'] = 'persisted_memory'
-    prefs['compress_objectdb'] = False
+    prefs['compress_objectdb'] = True
 
     # Shows whether to save history across sessions.  Defaults to
     # `False`.
     prefs['save_history'] = True
-    prefs['max_history_items'] = 80
-    prefs['compress_history'] = False
+    prefs['max_history_items'] = 32
+    prefs['compress_history'] = True
 
     # If `False` when running modules or unit tests "Dynamic Object
     # Inference" is turned off.  This makes them much faster.  The

ropetest/historytest.py

         self.history.do(change)
         self.assertEquals(0, len(self.history.redo_list))
 
+    @testutils.assert_raises(exceptions.HistoryError)
+    def test_undoing_a_not_yet_performed_change(self):
+        change = ChangeContents(self.file1, '1')
+        change.undo()
+
 
 class SavingHistoryTest(unittest.TestCase):
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.