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

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

[elpa] externals/ebdb 40d71b9 222/350: Steal UUID generating function fr


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 40d71b9 222/350: Steal UUID generating function from Org
Date: Mon, 14 Aug 2017 11:46:41 -0400 (EDT)

branch: externals/ebdb
commit 40d71b97859b35f7d73ef57964e51591264e3122
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Steal UUID generating function from Org
    
    Fixes #38
    
    * ebdb.el (ebdb--make-uuid): Fallback in case there's no uuidgen
      program on the system.
      (ebdb-make-uuid): Use it.
---
 ebdb.el | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/ebdb.el b/ebdb.el
index 3053eea..4f2c466 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -2703,12 +2703,38 @@ executable.  When a symbol, assume an Elisp function."
           (shell-command-to-string
            (executable-find ebdb-uuid-function)))
          ((functionp ebdb-uuid-function)
-          (funcall ebdb-uuid-function)))))
+          (funcall ebdb-uuid-function))
+         (t (ebdb--make-uuid)))))
     (concat prefix-string
            (replace-regexp-in-string
             "[\n\t ]+" ""
             uid))))
 
+;; Stolen directly and with no shame from Org.
+(defun ebdb--make-uuid ()
+  "Return string with random (version 4) UUID."
+  (let ((rnd (md5 (format "%s%s%s%s%s%s%s"
+                         (random)
+                         (current-time)
+                         (user-uid)
+                         (emacs-pid)
+                         (user-full-name)
+                         user-mail-address
+                         (recent-keys)))))
+    (format "%s-%s-4%s-%s%s-%s"
+           (substring rnd 0 8)
+           (substring rnd 8 12)
+           (substring rnd 13 16)
+           (format "%x"
+                   (logior
+                    #b10000000
+                    (logand
+                     #b10111111
+                     (string-to-number
+                      (substring rnd 16 18) 16))))
+           (substring rnd 18 20)
+           (substring rnd 20 32))))
+
 ;;; The database class(es)
 
 (defclass ebdb-db (eieio-named eieio-persistent)



reply via email to

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