فهرست منبع

babel hashing now handles more complex types in params

* lisp/ob.el (org-babel-sha1-hash): now handles more complex types in
  params
* testing/examples/babel.org: whitespace
* testing/lisp/test-ob.el (test-org-babel/sha1-hash): new test for
  babel hashing
Eric Schulte 14 سال پیش
والد
کامیت
e905dbe0f6
3فایلهای تغییر یافته به همراه23 افزوده شده و 8 حذف شده
  1. 15 8
      lisp/ob.el
  2. 2 0
      testing/examples/babel.org
  3. 6 0
      testing/lisp/test-ob.el

+ 15 - 8
lisp/ob.el

@@ -609,17 +609,24 @@ the current subtree."
 (defun org-babel-sha1-hash (&optional info)
   "Generate an sha1 hash based on the value of info."
   (interactive)
-  (let* ((info (or info (org-babel-get-src-block-info)))
+  (let* ((print-level nil)
+	 (info (or info (org-babel-get-src-block-info)))
          (hash (sha1
 		(format "%s-%s"
 			(mapconcat
-			 (lambda (arg)
-			   (if (stringp (cdr arg))
-			       (mapconcat
-				#'identity
-				(sort (split-string (cdr arg)) #'string<) " ")
-			     (cdr arg)))
-			 (nth 2 info) ":")
+			 #'identity
+			 (delq nil
+			       (mapcar
+				(lambda (arg)
+				  (let ((v (cdr arg)))
+				    (when (and v (not (and (sequencep v)
+							   (> (length v) 0))))
+				      (if (stringp v)
+					  (mapconcat #'identity
+						     (sort (split-string v)
+							   #'string<) " ")
+					(format "%S" v)))))
+				(nth 2 info))) ":")
 			(nth 1 info)))))
     (when (interactive-p) (message hash))
     hash))

+ 2 - 0
testing/examples/babel.org

@@ -129,6 +129,7 @@
 
   (pascals-triangle n)
 #+end_src
+
 * calling code blocks from inside table
   :PROPERTIES:
   :ID:       6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
@@ -138,6 +139,7 @@
 #+begin_src emacs-lisp :var n=9
   (sqrt n)
 #+end_src
+
 * executing an lob call line
   :PROPERTIES:
   :results:  silent

+ 6 - 0
testing/lisp/test-ob.el

@@ -64,6 +64,12 @@
       (should (equal 'a (cadr (assoc 1 results))))
       (should (equal 'd (cadr (assoc 4 results)))))))
 
+(ert-deftest test-org-babel/sha1-hash ()
+  (org-test-at-id "f68821bc-7f49-4389-85b5-914791ee3718"
+    (org-babel-next-src-block 2)
+    (should (string= "615946d1cd30c88c17ae6bf1d56a3f90232ddf78"
+		     (org-babel-sha1-hash)))))
+
 (provide 'test-ob)
 
 ;;; test-ob ends here