Back to index

texmacs  1.0.7.15
tmfs_versioning.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tmfs_versioning.cpp
00004 * DESCRIPTION: versioning for the TeXmacs file system
00005 * COPYRIGHT  : (C) 2007  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "tmfs.hpp"
00013 #include "scheme.hpp"
00014 
00015 /******************************************************************************
00016 * Versioning
00017 ******************************************************************************/
00018 
00019 string
00020 tmfs_create_identifier () {
00021   return as_string (call ("create-unique-id"));
00022 }
00023 
00024 string
00025 tmfs_create_ressource () {
00026   return tmfs_create_identifier ();
00027 }
00028 
00029 string
00030 tmfs_create_version (string ressource) {
00031   string id  = tmfs_create_identifier ();
00032   string head= tmfs_get_head (ressource);
00033   tmfs_set_property (seq ("version", id, ressource));
00034   if (head != "") tmfs_set_property (seq ("next", head, id));
00035   return id;
00036 }
00037 
00038 void
00039 tmfs_save_version_file (string version, string contents) {
00040   if (contents != "") tmfs_save (version, contents);
00041 }
00042 
00043 void
00044 tmfs_save_version_properties (string version, properties props) {
00045   tmfs_save (version * "!", properties_encode (props));
00046 }
00047 
00048 string
00049 tmfs_load_version_file (string version) {
00050   return tmfs_load (version);
00051 }
00052 
00053 properties
00054 tmfs_load_version_properties (string version) {
00055   return properties_decode (tmfs_load (version * "!"));
00056 }
00057 
00058 void
00059 tmfs_set_head (string ressource, string version) {
00060   string head= tmfs_get_head (ressource);
00061   if (ressource == head) return;
00062   if (head != "") {
00063     tmfs_reset_property (seq ("head", ressource, head));
00064     properties props= tmfs_load_version_properties (head);
00065     tmfs_reset_properties (props);
00066   }
00067   if (version != "") {
00068     tmfs_set_property (seq ("head", ressource, version));
00069     properties props= tmfs_load_version_properties (version);
00070     tmfs_set_properties (props);
00071   }
00072 }
00073 
00074 void
00075 tmfs_reset_head (string ressource) {
00076   tmfs_set_head (ressource, "");
00077 }
00078 
00079 string
00080 tmfs_get_head (string ressource) {
00081   solutions sols= tmfs_get_solutions (seq ("head", ressource, "?v"));
00082   collection c= as_collection (sols, "?v");
00083   if (N(c) == 0) return "";
00084   return first (c);
00085 }
00086 
00087 collection
00088 tmfs_get_versions (string ressource) {
00089   solutions sols= tmfs_get_solutions (seq ("version", "?v", ressource));
00090   return as_collection (sols, "?v");
00091 }
00092 
00093 void
00094 tmfs_save_ressource (string ressource, string contents, properties ps) {
00095   string version= tmfs_create_version (ressource);
00096   tmfs_save_version_file (version, contents);
00097   tmfs_save_version_properties (version, ps);
00098   tmfs_set_head (ressource, version);
00099 }
00100 
00101 string
00102 tmfs_load_ressource_file (string ressource) {
00103   string version= tmfs_get_head (ressource);
00104   if (version == "") return "";
00105   return tmfs_load_version_file (version);
00106 }
00107 
00108 properties
00109 tmfs_load_ressource_properties (string ressource) {
00110   string version= tmfs_get_head (ressource);
00111   if (version == "") return properties ();
00112   return tmfs_load_version_properties (version);
00113 }