emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
@ 2010-05-07 15:57 David Maus
  2010-05-08  5:03 ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: David Maus @ 2010-05-07 15:57 UTC (permalink / raw)
  To: org-mode


[-- Attachment #1.1.1: Type: text/plain, Size: 730 bytes --]

Attached patch for org-id adds a new function `org-id-uuid' that
returns a random (version 4) uuid following the format and suggestions
in RFC 4122:

  - it collects some random, system ans user specific data

  - creates a md5 hash for this data to obtain the require 32 octets

  - flips the correct bits to indicate a random uuid

Using the elisp method to create a random uuid can be customized by
setting `org-id-method' to 'uuid.

In addition `org-id-new' throws an error when the call to
`org-id-uuid-program' returns something that does not look like a
uuid.[1]

HTH
 -- David


[1] Sorry, this should have been a patch on its own.

--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #1.1.2: org-id-uuid-elisp.diff --]
[-- Type: application/octet-stream, Size: 3156 bytes --]

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 88d477e..171c222 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2010-05-07  David Maus  <dmaus@ictsoc.de>
+
+	* org-id.el (org-id-uuid-regexp): New constant.  Regexp that
+	matches a uuid.
+	(org-id-method): New customization value.
+	(org-id-new): Use lisp function to create uuid.
+	(org-id-uuid): New function.  Return random (version 4) uuid.
+
 2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-table.el (org-table-recalculate-buffer-tables)
diff --git a/lisp/org-id.el b/lisp/org-id.el
index 168a0c9..0442ee2 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -72,6 +72,10 @@
 
 (declare-function message-make-fqdn "message" ())
 
+(defconst org-id-uuid-regexp
+  "^[0-9a-fA-F]\\{8\\}\\(-[0-9a-fA-F]\\{4\\}\\)\\{3\\}-[0-9a-fA-F]\\{12\\}"
+  "Regular expression matching a uuid.")
+
 ;;; Customization
 
 (defgroup org-id nil
@@ -86,7 +90,7 @@
 
 (defcustom org-id-method
   (condition-case nil
-      (if (string-match "\\`[-0-9a-fA-F]\\{36\\}\\'"
+      (if (string-match org-id-uuid-regexp
 			(org-trim (shell-command-to-string
 				   org-id-uuid-program)))
 	  'uuidgen
@@ -105,10 +109,13 @@ org        Org's own internal method, using an encoding of the current time to
            microsecond accuracy, and optionally the current domain of the
            computer.  See the variable `org-id-include-domain'.
 
+uuid       Random \(version 4\) uuids.
+
 uuidgen    Call the external command uuidgen."
   :group 'org-id
   :type '(choice
 	  (const :tag "Org's internal method" org)
+	  (const :tag "random uuid" uuid)
 	  (const :tag "external: uuidgen" uuidgen)))
 
 (defcustom org-id-prefix nil
@@ -307,7 +314,11 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
     (if (equal prefix ":") (setq prefix ""))
     (cond
      ((eq org-id-method 'uuidgen)
-      (setq unique (org-trim (shell-command-to-string org-id-uuid-program))))
+      (setq unique (org-trim (shell-command-to-string org-id-uuid-program)))
+      (unless (string-match-p org-id-uuid-regexp unique)
+	(error "Invalid uuid: %s" unique)))
+     ((eq org-id-method 'uuid)
+      (setq unique (org-id-uuid)))
      ((eq org-id-method 'org)
       (let* ((etime (org-id-reverse-string (org-id-time-to-b36)))
 	     (postfix (if org-id-include-domain
@@ -318,6 +329,30 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
      (t (error "Invalid `org-id-method'")))
     (concat prefix unique)))
 
+(defun org-id-uuid ()
+  "Return string with random uuid."
+  (let ((rnd (md5 (format "%s%s%s%s%s%s%s"
+			  (random t)
+			  (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))))
+
 (defun org-id-reverse-string (s)
   (mapconcat 'char-to-string (nreverse (string-to-list s)) ""))
 

[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
  2010-05-07 15:57 [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid David Maus
@ 2010-05-08  5:03 ` Carsten Dominik
  2010-05-08 14:14   ` David Maus
  0 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2010-05-08  5:03 UTC (permalink / raw)
  To: David Maus; +Cc: org-mode

Hi David,

what is the difference/advantage of this idea over using uuidgen as  
Org does now?

Thanks.

- Carsten

On May 7, 2010, at 5:57 PM, David Maus wrote:

> Attached patch for org-id adds a new function `org-id-uuid' that
> returns a random (version 4) uuid following the format and suggestions
> in RFC 4122:
>
>  - it collects some random, system ans user specific data
>
>  - creates a md5 hash for this data to obtain the require 32 octets
>
>  - flips the correct bits to indicate a random uuid
>
> Using the elisp method to create a random uuid can be customized by
> setting `org-id-method' to 'uuid.
>
> In addition `org-id-new' throws an error when the call to
> `org-id-uuid-program' returns something that does not look like a
> uuid.[1]
>
> HTH
> -- David
>
>
> [1] Sorry, this should have been a patch on its own.
>
> --
> OpenPGP... 0x99ADB83B5A4478E6
> Jabber.... dmjena@jabber.org
> Email..... dmaus@ictsoc.de
> <org-id-uuid- 
> elisp.diff>_______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
  2010-05-08  5:03 ` Carsten Dominik
@ 2010-05-08 14:14   ` David Maus
  2010-05-15  7:02     ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: David Maus @ 2010-05-08 14:14 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode


[-- Attachment #1.1: Type: text/plain, Size: 955 bytes --]

Carsten Dominik wrote:
>what is the difference/advantage of this idea over using uuidgen as
>Org does now?

Well, it allows uuids without depending on the presence of the uuidgen
binary.  E.g. I happen to occasionally use computers I have no control
of and carry my Emacs/Org configuration with me.

Without the elisp function the ID properties of my headlines are in an
inconsistent format depending on whether uuidgen was present on the
machine I created the ID property or not.

It may be a little pedantic but I'd like to be specific in what format
the IDs have and like the idea of having IDs that follow an
established standard.

Maybe another usage of the function could be:

 - org-id-method can be 'org for Org's id mechanism or 'uuid for uuids

 - `org-id-new' uses uuidgen if present and falls back to the elisp
   function otherwise

Regards,
  -- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
  2010-05-08 14:14   ` David Maus
@ 2010-05-15  7:02     ` Carsten Dominik
  2010-05-16  9:14       ` David Maus
  0 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2010-05-15  7:02 UTC (permalink / raw)
  To: David Maus; +Cc: org-mode


On May 8, 2010, at 4:14 PM, David Maus wrote:

> Carsten Dominik wrote:
>> what is the difference/advantage of this idea over using uuidgen as
>> Org does now?
>
> Well, it allows uuids without depending on the presence of the uuidgen
> binary.  E.g. I happen to occasionally use computers I have no control
> of and carry my Emacs/Org configuration with me.
>
> Without the elisp function the ID properties of my headlines are in an
> inconsistent format depending on whether uuidgen was present on the
> machine I created the ID property or not.
>
> It may be a little pedantic but I'd like to be specific in what format
> the IDs have and like the idea of having IDs that follow an
> established standard.
>
> Maybe another usage of the function could be:
>
> - org-id-method can be 'org for Org's id mechanism or 'uuid for uuids

I think it should be either uuidgen (for backward compatibility) or  
uuid.

>
> - `org-id-new' uses uuidgen if present and falls back to the elisp
>   function otherwise

I like that.  WOuld you like to modify your patch accordingly?

- Carsten

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
  2010-05-15  7:02     ` Carsten Dominik
@ 2010-05-16  9:14       ` David Maus
  2010-05-16  9:39         ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: David Maus @ 2010-05-16  9:14 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode


[-- Attachment #1.1: Type: text/plain, Size: 760 bytes --]

Carsten Dominik wrote:
>>
>> - `org-id-new' uses uuidgen if present and falls back to the elisp
>>   function otherwise

>I like that.  WOuld you like to modify your patch accordingly?

Yes, I'll do that.  Just for the records: using the elisp function as
fall back for the external program changes the meaning of the
org-id-method uuidgen: It makes Org use UUIDs for the ID property and
the external program is the preferred method for doing this.  Hence
the symbol should better be 'uuid, not 'uuidgen.  So if there is a
list for backward incompatible changes for a further release (maybe
7.x) that are reasonable but not important this should go there.

HTH
 -- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
  2010-05-16  9:14       ` David Maus
@ 2010-05-16  9:39         ` Carsten Dominik
  2010-05-16 14:16           ` David Maus
  0 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2010-05-16  9:39 UTC (permalink / raw)
  To: David Maus; +Cc: org-mode


On May 16, 2010, at 11:14 AM, David Maus wrote:

> Carsten Dominik wrote:
>>>
>>> - `org-id-new' uses uuidgen if present and falls back to the elisp
>>>  function otherwise
>
>> I like that.  WOuld you like to modify your patch accordingly?
>
> Yes, I'll do that.  Just for the records: using the elisp function as
> fall back for the external program changes the meaning of the
> org-id-method uuidgen: It makes Org use UUIDs for the ID property and
> the external program is the preferred method for doing this.  Hence
> the symbol should better be 'uuid, not 'uuidgen.  So if there is a
> list for backward incompatible changes for a further release (maybe
> 7.x) that are reasonable but not important this should go there.

Yes.

But what I would like to to ask is this:

Make the change and tell people to use `uuid' as the setting.  But if  
a user has set it to uuidgen, be gentle and accept that setting as  
well, treat it like uuid.

Thanks!

- Carsten

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid
  2010-05-16  9:39         ` Carsten Dominik
@ 2010-05-16 14:16           ` David Maus
  0 siblings, 0 replies; 7+ messages in thread
From: David Maus @ 2010-05-16 14:16 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode


[-- Attachment #1.1: Type: text/plain, Size: 1142 bytes --]

Carsten Dominik wrote:

>On May 16, 2010, at 11:14 AM, David Maus wrote:

>> Carsten Dominik wrote:
>>>>
>>>> - `org-id-new' uses uuidgen if present and falls back to the elisp
>>>>  function otherwise
>>
>>> I like that.  WOuld you like to modify your patch accordingly?
>>
>> Yes, I'll do that.  Just for the records: using the elisp function as
>> fall back for the external program changes the meaning of the
>> org-id-method uuidgen: It makes Org use UUIDs for the ID property and
>> the external program is the preferred method for doing this.  Hence
>> the symbol should better be 'uuid, not 'uuidgen.  So if there is a
>> list for backward incompatible changes for a further release (maybe
>> 7.x) that are reasonable but not important this should go there.

>Yes.

>But what I would like to to ask is this:

>Make the change and tell people to use `uuid' as the setting.  But if
>a user has set it to uuidgen, be gentle and accept that setting as
>well, treat it like uuid.

Ah, yes, now I've got it.  Patch will be there, soon.

HTH
 -- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-05-16 14:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-07 15:57 [patch] org-id: New org-id-method 'uuid' w/ elisp function that creates random uuid David Maus
2010-05-08  5:03 ` Carsten Dominik
2010-05-08 14:14   ` David Maus
2010-05-15  7:02     ` Carsten Dominik
2010-05-16  9:14       ` David Maus
2010-05-16  9:39         ` Carsten Dominik
2010-05-16 14:16           ` David Maus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).