]> git.eshelyaron.com Git - emacs.git/commitdiff
Support COMMIT in treesit-language-source-alist
authorYuan Fu <casouri@gmail.com>
Sat, 28 Dec 2024 21:57:50 +0000 (13:57 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 4 Jan 2025 20:25:29 +0000 (21:25 +0100)
* lisp/treesit.el (treesit-language-source-alist): Add COMMIT
field.
(treesit--install-language-grammar-1): Support COMMIT.

(cherry picked from commit a22730f4d788d6476d5f3c6717ba8a3d4046e819)

lisp/treesit.el

index 0932f0fe67eaec913973f5bbe68bb361791b76ca..e62f1bfd36ef5408795881b23637ac08381630dc 100644 (file)
@@ -4082,14 +4082,16 @@ window."
 
 The value should be an alist where each element has the form
 
-    (LANG . (URL REVISION SOURCE-DIR CC C++))
+    (LANG . (URL REVISION SOURCE-DIR CC C++ COMMIT))
 
 Only LANG and URL are mandatory.  LANG is the language symbol.
 URL is the URL of the grammar's Git repository or a directory
 where the repository has been cloned.
 
-REVISION is the Git tag or branch of the desired version,
-defaulting to the latest default branch.
+REVISION is the Git tag or branch of the desired version, defaulting to
+the latest default branch.  If COMMIT is non-nil, checkout this commit
+hash after cloning the repo.  COMMIT has precedence over REVISION if
+both are non-nil.
 
 SOURCE-DIR is the relative subdirectory in the repository in which
 the grammar's parser.c file resides, defaulting to \"src\".
@@ -4257,7 +4259,8 @@ REVISION may be nil, in which case the cloned repo will be at its
 default branch.
 
 Use shallow clone by default.  Do a full clone when
-`treesit--install-language-grammar-full-clone' is t."
+`treesit--install-language-grammar-full-clone' is t.  Do a blobless
+clone if `treesit--install-language-grammar-blobless' is t."
   (message "Cloning repository")
   ;; git clone xxx --depth 1 --quiet [-b yyy] workdir
   (let ((args (list "git" nil t nil "clone" url "--quiet")))
@@ -4271,7 +4274,7 @@ Use shallow clone by default.  Do a full clone when
     (apply #'treesit--call-process-signal args)))
 
 (defun treesit--install-language-grammar-1
-    (out-dir lang url &optional revision source-dir cc c++)
+    (out-dir lang url &optional revision source-dir cc c++ commit)
   "Install and compile a tree-sitter language grammar library.
 
 OUT-DIR is the directory to put the compiled library file.  If it
@@ -4279,9 +4282,9 @@ is nil, the \"tree-sitter\" directory under user's Emacs
 configuration directory is used (and automatically created if it
 does not exist).
 
-For LANG, URL, REVISION, SOURCE-DIR, GRAMMAR-DIR, CC, C++, see
-`treesit-language-source-alist'.  If anything goes wrong, this
-function signals an error.
+For LANG, URL, REVISION, SOURCE-DIR, GRAMMAR-DIR, CC, C++, COMMIT, see
+`treesit-language-source-alist'.  If anything goes wrong, this function
+signals an error.
 
 Return the git revision of the installed grammar.  The revision is
 generated by \"git describe\".  It only works when
@@ -4312,6 +4315,8 @@ generated by \"git describe\".  It only works when
               (when revision
                 (treesit--git-checkout-branch workdir revision))
             (treesit--git-clone-repo url revision workdir))
+          (when commit
+            (treesit--git-checkout-branch workdir commit))
           ;; We need to go into the source directory because some
           ;; header files use relative path (#include "../xxx").
           ;; cd "${sourcedir}"