[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 0f062bc 1/8: Simplify use of structs in migration
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 0f062bc 1/8: Simplify use of structs in migration |
Date: |
Mon, 6 Jan 2020 14:39:41 -0500 (EST) |
branch: externals/ebdb
commit 0f062bcd4d78330056a53372525985009ade777b
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Simplify use of structs in migration
* ebdb-migrate.el (ebdb-defstruct): Remove this macro, there's no need
to preserve all this stuff just for the purpose of migration.
(ebdb-migration-spec, ebdb-migrate-record-lambda): Simplify.
---
ebdb-migrate.el | 103 +++++++++++++++++---------------------------------------
1 file changed, 31 insertions(+), 72 deletions(-)
diff --git a/ebdb-migrate.el b/ebdb-migrate.el
index 585e578..4f241fe 100644
--- a/ebdb-migrate.el
+++ b/ebdb-migrate.el
@@ -25,6 +25,7 @@
;;; Code:
(require 'ebdb)
+(require 'cl-lib)
(require 'subr-x)
(autoload 'calendar-absolute-from-gregorian "calendar")
(autoload 'calendar-gregorian-from-absolute "calendar")
@@ -61,57 +62,24 @@ Format ((VERSION . DIFFERENCES) ... ).")
;; Quiet compiler
(defvar bbdb-file)
-;;; These struct functions and definitions are here only to enable
-;;; multi-step upgrades from earlier versions of the database.
-
-(defmacro ebdb-defstruct (name &rest elts)
- "Define two functions to operate on vector NAME for each symbol ELT in ELTS.
-The function ebdb-NAME-ELT returns the element ELT in vector NAME.
-The function ebdb-NAME-set-ELT sets ELT.
-Also define a constant ebdb-NAME-length that holds the number of ELTS
-in vector NAME."
- (declare (indent 1))
- (let* ((count 0)
- (sname (symbol-name name))
- (uname (upcase sname))
- (cname (concat "ebdb-" sname "-"))
- body)
- (dolist (elt elts)
- (let* ((selt (symbol-name elt))
- (setname (intern (concat cname "set-" selt))))
- (push (list 'defsubst (intern (concat cname selt)) `(,name)
- (format "For EBDB %s read element %i `%s'."
- uname count selt)
- ;; Use `elt' instead of `aref' so that these functions
- ;; also work for the `ebdb-record-type' pseudo-code.
- `(elt ,name ,count)) body)
- (push (list 'defsubst setname `(,name value)
- (format "For EBDB %s set element %i `%s' to VALUE. \
-Return VALUE.
-Do not call this function directly. Call instead `ebdb-record-set-field'
-which ensures the integrity of the database. Also, this makes your code
-more robust with respect to possible future changes of EBDB's innermost
-internals."
- uname count selt)
- `(aset ,name ,count value)) body))
- (setq count (1+ count)))
- (push (list 'defconst (intern (concat cname "length")) count
- (concat "Length of EBDB `" sname "'.")) body)
- (cons 'progn body)))
-
;; Define structs so that the getters/setters used elsewhere in the
;; file operate normally. These functions are used nowhere else in
;; EBDB, and the "v" prefix has been added to prevent function name
;; clashes.
-(ebdb-defstruct
- vrecord
+(cl-defstruct (ebdb-vrecord
+ (:type vector)
+ (:constructor nil))
firstname lastname affix aka organization phone address mail xfields
uuid creation-date timestamp cache)
-(ebdb-defstruct vphone
+(cl-defstruct (ebdb-vphone
+ (:type vector)
+ (:constructor nil))
label area exchange suffix extension)
-(ebdb-defstruct vaddress
+(cl-defstruct (ebdb-vaddress
+ (:type vector)
+ (:constructor nil))
label streets city state postcode country)
(defun ebdb-peel-the-onion (lis)
@@ -170,22 +138,14 @@ slightly munged old EBDB files."
records)
(defconst ebdb-migration-spec
- '((2 (ebdb-vrecord-xfields ebdb-vrecord-set-xfields
- ebdb-migrate-change-dates))
- (3 (ebdb-vrecord-address ebdb-vrecord-set-address
- ebdb-migrate-add-country-field))
- (4 (ebdb-vrecord-address ebdb-vrecord-set-address
- ebdb-migrate-streets-to-list))
- (5 (ebdb-vrecord-address ebdb-vrecord-set-address
- ebdb-migrate-postcodes-to-strings))
- (6 (ebdb-vrecord-xfields ebdb-vrecord-set-xfields
- ebdb-migrate-xfields-to-list)
- (ebdb-vrecord-organization ebdb-vrecord-set-organization
- ebdb-migrate-organization-to-list))
- (7 (bbdb-record-xfields bbdb-record-set-xfields
- bbdb-migrate-xfields-to-list)
- (bbdb-record-organization bbdb-record-set-organization
- bbdb-migrate-organization-to-list)))
+ '((2 (ebdb-vrecord-xfields ebdb-migrate-change-dates))
+ (3 (ebdb-vrecord-address ebdb-migrate-add-country-field))
+ (4 (ebdb-vrecord-address ebdb-migrate-streets-to-list))
+ (5 (ebdb-vrecord-address ebdb-migrate-postcodes-to-strings))
+ (6 (ebdb-vrecord-xfields ebdb-migrate-xfields-to-list)
+ (ebdb-vrecord-organization ebdb-migrate-organization-to-list))
+ (7 (bbdb-record-xfields bbdb-migrate-xfields-to-list)
+ (bbdb-record-organization bbdb-migrate-organization-to-list)))
"The alist of (version . migration-spec-list).
See `ebdb-migrate-record-lambda' for details.")
@@ -200,12 +160,11 @@ modified, and SET is the function to be used to set the
field to be
modified. FUNCTION will be applied to the result of GET, and its
results will be saved with SET."
(byte-compile `(lambda (record)
- ,@(mapcar (lambda (ch)
- `(,(cadr ch) record
- (,(car (cddr ch))
- (,(car ch) record))))
- changes)
- record)))
+ ,@(mapcar (lambda (ch)
+ `(cl-callf ,(cadr ch)
+ (,(car ch) record)))
+ changes)
+ record)))
(defun ebdb-migrate-versions-lambda (v0)
"Return the function to migrate from V0 to `ebdb-file-format'."
@@ -264,7 +223,7 @@ This uses the code that used to be in
`ebdb-address-postcode'."
;; else a number, could be 3 to 5 digits
(possible error: assuming
;; no leading zeroes in postcodes)
(format "%d" (ebdb-vaddress-postcode
address)))))))
- (ebdb-vaddress-set-postcode address postcode))
+ (setf (ebdb-vaddress-postcode address) postcode))
address)
addresses))
@@ -367,13 +326,13 @@ Formats are changed in timestamp and creation-date fields
from
(ebdb-split 'organization organization)
organization))
-;;; These defcustoms are now obsolete, but they're here so that,
-;;; during the migration/upgrade process, we know which xfields to
-;;; handle specially, and turn into specific field types. In the case
-;;; of `bbdb/gnus-split-public-field', this should signal to us that
-;;; the record should actually be changed into a
-;;; `ebdb-record-mailing-list'. But that hasn't been implemented yet,
-;;; so...
+;; These defcustoms are now obsolete, but they're here so that,
+;; during the migration/upgrade process, we know which xfields to
+;; handle specially, and turn into specific field types. In the case
+;; of `bbdb/gnus-split-public-field', this should signal to us that
+;; the record should actually be changed into a
+;; `ebdb-record-mailing-list'. But that hasn't been implemented yet,
+;; so...
(defcustom bbdb/gnus-split-private-field 'gnus-private
"This variable is used to determine the xfield to reference to find the
- [elpa] externals/ebdb updated (4fb5fc9 -> 50c8ee4), Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb 8b952a4 2/8: First draft of EBDB support for Notmuch, Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb 0f062bc 1/8: Simplify use of structs in migration,
Eric Abrahamsen <=
- [elpa] externals/ebdb 04c207d 7/8: Shift location of auto update hook for wl, Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb e169e58 4/8: Add guards against fields failing to produce strings, Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb c0e7c2d 5/8: Neglected to add a ebdb-read method for ebdb-field-tags, Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb 311775a 3/8: Bump copyright years to 2020, Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb 50c8ee4 8/8: Bump to version 0.6.12, Eric Abrahamsen, 2020/01/06
- [elpa] externals/ebdb 606d49a 6/8: Fix logic of singleton fields, Eric Abrahamsen, 2020/01/06