From cd89aef26451d533feab8e9f201b99c1996227b8 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 28 Dec 2024 13:57:50 -0800 Subject: [PATCH] Support COMMIT in treesit-language-source-alist * 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 0932f0fe67e..e62f1bfd36e 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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}" -- 2.39.5