Skip to content

Commit

Permalink
Added max number versions limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jensbob committed Dec 17, 2012
1 parent e679100 commit 244c903
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
30 changes: 2 additions & 28 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Undo - Undo to the previous commit
Redo - Undo to the next commit
GotoCommit[n] - Go to the nth version

SetVersionLimit[n] - sets max number of saved versions to the last 5
------
NOTICE
------
Expand All @@ -46,7 +47,7 @@ Weather a commit needs to be made when running undo is checked with a system var
TODO's
------

* do some clean up
* do some cleaning up

----------------------------
Possible future improvements
Expand All @@ -62,33 +63,6 @@ Possible future improvements

* Make autocommits after text was entered - not only on evaluations

* Add a limitation for avaliable undo steps (in autocommit modes to save disk space)

--------------
Added features
--------------

(done) added croncommit, to make regular commits based on time

(done) added help entry

(done) multiple kernels lead to multiple menu entries. Fixed by reseting the menus before menu entries are created

(done) Add windows support (cp -> copy, rm -> del)


(done) If the notebook was not saved yet ask for filename to save it on the first commit.

(done) Check if the package was loaded already, to prevent multiple loads, to prevent creatation of multiple menu entries

(done) Skip the "Are you sure you want to revert message.

(done) Issue with manual commits and changes in the recent version

(done) Imporve Commits: If the notebook was not changed, do not make a new commit.

(done) Print commit info in dialog window

-----------------------------------------------------------------


Expand Down
15 changes: 9 additions & 6 deletions undo.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Alt+d : Show CommitInfo dialog
Functions Defined:
ManualCommit, AutoCommit, CronCommit[n], CommitInfo, CommitClean, CommitNow Undo, Redo, GotoCommit[n]
ManualCommit, AutoCommit, CronCommit[n], CommitInfo, CommitClean, CommitNow Undo, Redo, GotoCommit[n], SetVersionLimit[n]
";


Expand All @@ -29,11 +29,14 @@
Undo::usage="Moves back to the previous version. If you are currently working on the latest version (highest version number) the current changes are automaically commited. Otherwise data might be lost.";
Redo::usage="Moves forward in the commited versions.";
GotoCommit::usage="GotoCommit[n] loads version n.";
SetVersionLimit::usage="SetVersionLimit[n] sets the limit of saved commits to n."

Begin["`Private`"];

warning1 = "You need to save the notebook, in order \n to use the commiting and undo system.";
AutoCo"manual";
VersionLimit=1000;
SetVersionLimit[n_]:=(VersionLimit=n;);

(*Define copy and delete for different operating systmes*)
OSCopy=If[$OperatingSystem == "Windows","copy","cp"];
Expand All @@ -59,7 +62,7 @@
Column[{"Nothing Commited", "", "Commit mode: " <> ToString[AutoCo],"",Item[DefaultButton[], Alignment -> Right]}]
],
CreateDialog[
Column[{"Currently working on version: " <> ToString[RecentVersion], "", "Commit mode: " <> ToString[AutoCo], "", Row[{TableForm[Take[CommitList,Max[-30,-Length[CommitList]]]]}], "", Item[DefaultButton[], Alignment -> Right]}] (*open dialog with a list of the last 30 versions*)
Column[{"Currently working on version: " <> ToString[RecentVersion], "", "Backed up versions limited to the last: " <>ToString[VersionLimit],"","Commit mode: " <> ToString[AutoCo], "", Row[{TableForm[Take[CommitList,Max[-VersionLimit,-Length[CommitList]]]]}], "", Item[DefaultButton[], Alignment -> Right]}] (*open dialog with a list of the last 30 versions*)
];
];
];
Expand All @@ -83,7 +86,7 @@
(*Save the Notebook*)
NotebookSave[EvaluationNotebook[], nb];
(*Create Backup Copy*)
Import["!"<>ToString[OSCopy]<>" "<> ToString[nb] <> " " <> ToString[nb] <> ToString[RecentVersion] <> ".bak", "Table"];
Import["!"<>ToString[OSCopy]<>" "<> ToString[nb] <> " " <> ToString[nb] <> ToString[Mod[RecentVersion,VersionLimit,1]] <> ".bak", "Table"];
(*update undo file*)
Export[ToString[nb] <> ".undo.mx", {RecentVersion, MaxVersion, CommitList}];
];
Expand Down Expand Up @@ -116,7 +119,7 @@
{RecentVersion, MaxVersion, CommitList} = Import[ToString[nb] <> ".undo.mx"];
];

Import["!"<>ToString[OSCopy]<>" " <> ToString[nb] <> ToString[RecentVersion-1] <> ".bak" <> " " <> ToString[nb], "Table"]; (*copy last backup on notebook file*)
Import["!"<>ToString[OSCopy]<>" " <> ToString[nb] <> ToString[Mod[RecentVersion-1,VersionLimit,1]] <> ".bak" <> " " <> ToString[nb], "Table"]; (*copy last backup on notebook file*)
If[RecentVersion>1,
FrontEndExecute[FrontEndToken["Revert",False]];(*false - show no warning*)
RecentVersion -= 1;
Expand All @@ -135,7 +138,7 @@
];
If[RecentVersion < MaxVersion,
RecentVersion += 1;
Import["!"<>ToString[OSCopy]<>" " <> ToString[nb] <> ToString[RecentVersion] <> ".bak" <> " " <> ToString[nb], "Table"];
Import["!"<>ToString[OSCopy]<>" " <> ToString[nb] <> ToString[Mod[RecentVersion,VersionLimit,1]] <> ".bak" <> " " <> ToString[nb], "Table"];
FrontEndExecute[FrontEndToken["Revert",False]];
];
Export[ToString[nb] <> ".undo.mx", {RecentVersion, MaxVersion, CommitList}];
Expand All @@ -151,7 +154,7 @@
];
If[a>=1&&a<=MaxVersion&&RecentVersion!=0,
RecentVersion=a;
Import["!"<>ToString[OSCopy]<>" "<>ToString[nb]<>ToString[RecentVersion]<>".bak"<> " "<>ToString[nb],"Table"];
Import["!"<>ToString[OSCopy]<>" "<>ToString[nb]<>ToString[Mod[RecentVersion,VersionLimit,1]]<>".bak"<> " "<>ToString[nb],"Table"];
FrontEndExecute[FrontEndToken["Revert",False]];,Print["Invalid Version"]
];
] ;
Expand Down

0 comments on commit 244c903

Please sign in to comment.