emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dtache c8a99aed35 123/158: Add version to the dtache da


From: ELPA Syncer
Subject: [elpa] externals/dtache c8a99aed35 123/158: Add version to the dtache database
Date: Wed, 19 Jan 2022 18:58:04 -0500 (EST)

branch: externals/dtache
commit c8a99aed35f3dc744fd9d3c9d1357a6b75946161
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Add version to the dtache database
    
    This patch adds a header to the dtache.db file. This header allows
    dtache to read the dtache-session version of the sessions stored in
    the database.
    
    If the version is not matching the databasee content is
    discarded. The version should be increase when an update has been made
    to the dtache-session object, which breaks backwards compatibility.
---
 CHANELOG.org |  1 +
 dtache.el    | 21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/CHANELOG.org b/CHANELOG.org
index 88e100b015..955f392015 100644
--- a/CHANELOG.org
+++ b/CHANELOG.org
@@ -4,6 +4,7 @@
 
 * Development
 
+- Add version for =dtache-session= objects. This makes dtache not break 
whenever non-backwards compatible changes are made to the dtache-session object.
 - The commands for launching sessions are now renamed to resemble the non 
dtache commands. The commands are =dtache-shell-command=, 
=dtache-shell-send-input=, =dtache-eshell-send-input=, =dtache-compile=.
 - Add action value to a session. This value is set to dtache-session-action 
which is a property list optionally specifying attach, view and run properties. 
These properties are then used in dwim commands to improve their functionality.
 - Add a generic detach command, =dtache-detach-dwim=. This command is supposed 
to be used to detach from sessions in all supported modes.
diff --git a/dtache.el b/dtache.el
index 15bbf3b73a..8f14c00054 100644
--- a/dtache.el
+++ b/dtache.el
@@ -143,6 +143,9 @@ Valid values are: create, new and attach")
 (defvar dtache-metadata-annotators-alist nil
   "An alist of annotators for metadata.")
 
+(defconst dtache-session-version 1
+  "The version of `dtache-session'.")
+
 (defvar dtache-action-map
   (let ((map (make-sparse-keymap)))
     (define-key map "c" #'dtache-post-compile-session)
@@ -941,13 +944,24 @@ Optionally make the path LOCAL to host."
 
 (defun dtache--db-initialize ()
   "Return all sessions stored in database."
-  (let ((db (expand-file-name "dtache.db" dtache-db-directory)))
+  (let ((db (expand-file-name "dtache.db" dtache-db-directory))
+        (session-version))
     (when (file-exists-p db)
       (with-temp-buffer
         (insert-file-contents db)
         (cl-assert (eq (point) (point-min)))
-        (setq dtache--sessions
-              (read (current-buffer)))))))
+        (goto-char (point-min))
+        (when (= (dtache--db-session-version) dtache-session-version)
+          (setq dtache--sessions
+                (read (current-buffer))))))))
+
+(defun dtache--db-session-version ()
+  "Return `dtache-session-version' from database."
+  (let ((header (thing-at-point 'line))
+        (regexp (rx "Dtache Session Version: " (group (one-or-more digit)))))
+    (string-match regexp header)
+    (string-to-number
+     (match-string 1 header))))
 
 (defun dtache--db-insert-entry (session)
   "Insert SESSION into `dtache--sessions' and update database."
@@ -981,6 +995,7 @@ Optionally make the path LOCAL to host."
   "Write `dtache--sessions' to database."
   (let ((db (expand-file-name "dtache.db" dtache-db-directory)))
     (with-temp-file db
+      (insert (format ";; Dtache Session Version: %d\n\n" 
dtache-session-version))
       (prin1 dtache--sessions (current-buffer)))))
 
 ;;;;; Other



reply via email to

[Prev in Thread] Current Thread [Next in Thread]