# HG changeset patch # User Richard Westhaver # Date 1716929094 14400 # Node ID 45889d307d7fc9593ed69118456ee04dcea29254 # Parent 2ef83f2178f1bd06ab7f316690aa85ee242c32ad vc ignore stuff diff -r 2ef83f2178f1 -r 45889d307d7f .hgignore --- a/.hgignore Mon May 27 23:15:33 2024 -0400 +++ b/.hgignore Tue May 28 16:44:54 2024 -0400 @@ -1,3 +1,5 @@ +# test + ^x$ .*Cargo.lock$ .*target/.* diff -r 2ef83f2178f1 -r 45889d307d7f lisp/bin/skel.lisp --- a/lisp/bin/skel.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/bin/skel.lisp Tue May 28 16:44:54 2024 -0400 @@ -111,7 +111,7 @@ (defcmd skc-pull (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) (:git (run-git-command "pull" $args t)) - (:hg (run-hg-command "pull" (push "-u" $args) t)) + (:hg (run-hg-command "pull" (append "-u" $args) t)) (t (skel-error "unknown VC type")))) (defun hg-status () diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/skel/core/obj.lisp --- a/lisp/lib/skel/core/obj.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/skel/core/obj.lisp Tue May 28 16:44:54 2024 -0400 @@ -243,7 +243,6 @@ :kind (when-let ((ext (pathname-type script))) (keywordicate ext)))))) - (defmethod sk-run ((self sk-script)) (sb-ext:run-program (sk-path self) nil :output t)) @@ -420,16 +419,8 @@ :initform (make-array 0 :element-type 'sk-script :adjustable t) :accessor sk-scripts :type (vector sk-script)) - (snippets :initarg :snippets - :initform (make-array 0 :element-type 'sk-snippet :adjustable t) - :accessor sk-snippets - :type (vector sk-snippet)) (stash :initarg :stash :accessor sk-stash :type pathname) (store :initarg :store :accessor sk-store :type pathname) - (abbrevs :initarg :abbrevs - :initform (make-array 0 :element-type 'sk-abbrev :adjustable t) - :accessor sk-abbrevs - :type (vector sk-abbrevs)) (imports :initarg :imports :initform (make-array 0 :element-type 'pathname :adjustable t) :accessor sk-imports @@ -550,11 +541,11 @@ (defmethod sk-install-user-config ((self sk-project) (cfg sk-user-config)) (with-slots (vc store stash license author) (debug! cfg) ;; log-level, custom, fmt - (cas (sk-vc self) nil vc) - (cas (sk-stash self) nil stash) - (cas (sk-store self) nil store) - (cas (sk-license self) nil license) - (cas (sk-author self) nil author))) + (setf (sk-vc self) vc) + (setf (sk-stash self) stash) + (setf (sk-store self) store) + (setf (sk-license self) license) + (setf (sk-author self) author))) (defmethod sk-find-rule (name self) (find (string-upcase name) (sk-rules self) :test 'equalp :key #'sk-rule-target)) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/skel/pkg.lisp --- a/lisp/lib/skel/pkg.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/skel/pkg.lisp Tue May 28 16:44:54 2024 -0400 @@ -67,11 +67,9 @@ :*default-containerfile* ;; obj :*user-skelrc* :*system-skelrc* :*keep-ast* - :*skel-project* :*skel-user-config* :*default-skelrc* :*skel-registry* :*skel-cache* - :*default-skelfile* :*default-skel-user* :*default-skel-cache* :*default-user-skel-config* - :*default-user-skelrc* :*default-system-skel-config* :*skelfile-extension* :*skelfile-boundary* - :*default-skel-stash* - :*default-system-skelrc* + :*skel-project* :*skel-user-config* :*skel-system-config* :*default-skelrc* :*skel-registry* :*skel-cache* + :*default-skelfile* :*default-skel-user* :*default-skel-cache* + :*skelfile-extension* :*skelfile-boundary* :load-ast :sk-license :sk-author :sk-path :sk-stash :sk-cache :sk-registry :sk-user :sk-store :sk-push :sk-pull diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/git.lisp --- a/lisp/lib/vc/git.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/vc/git.lisp Tue May 28 16:44:54 2024 -0400 @@ -19,6 +19,9 @@ (:regex "^git@")) url-str))) +(defun gitignore (&optional (path ".gitignore")) + (make-vc-ignore :path path :patterns (map-lines #'glob-path-match path))) + (defclass git-repo (vc-repo) ((index))) ;; working-directory diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/hg.lisp --- a/lisp/lib/vc/hg.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/vc/hg.lisp Tue May 28 16:44:54 2024 -0400 @@ -55,6 +55,9 @@ (:regex "^hg@")) url-str))) +(defun hgignore (&optional (path ".hgignore")) + (make-vc-ignore :path path :patterns (map-lines #'ppcre:create-scanner path))) + ;; (describe (make-instance 'hg-repo)) ;; https://repo.mercurial-scm.org/hg/file/tip/mercurial/interfaces/repository.py (defclass hg-repo (vc-repo) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/ignore.lisp --- a/lisp/lib/vc/ignore.lisp Mon May 27 23:15:33 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -(in-package :vc) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/pkg.lisp --- a/lisp/lib/vc/pkg.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/vc/pkg.lisp Tue May 28 16:44:54 2024 -0400 @@ -1,5 +1,5 @@ (defpackage :vc - (:use :cl :std :cli :log :obj :sb-bsd-sockets :cl-ppcre) + (:use :cl :std :cli :log :obj :sb-bsd-sockets :cl-ppcre :parse/lex) (:import-from :uiop :with-current-directory) (:export :*default-vc* :vc-error :git-error :hg-error :vc-status @@ -10,8 +10,9 @@ :run-hg-command :repo :hg-repo :git-repo :vc-meta :hg-meta :git-meta :make-hg-client :hg-client :*repo-roots* :*repo-registry* :find-repo - :make-repo :register-repo)) + :make-repo :register-repo + :vc-ignore :hgignore :gitignore)) (in-package :vc) -(defvar *default-vc* :hg) +(defparameter *default-vc* :hg) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/proto.lisp --- a/lisp/lib/vc/proto.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/vc/proto.lisp Tue May 28 16:44:54 2024 -0400 @@ -41,8 +41,33 @@ ;;; Objects +;;;; Config ;; should be parsed from .hgrc and .gitconfig -(defclass vc-config (sxp) ()) +(defclass vc-config (sxp cfg) ()) + +;;;; Ignorefile + +;; Basically we treat HG and GIT ignore files the same - just lines of string +;; patterns. HG uses regexp and GIT is globs - an IGNOREFILE has a line parser +;; slot for selecting the appropriate function. + +(defun map-lines (fn path) + "Call FN on each line of file PATH and collect the result." + (with-open-file (file path) + (loop for line = (read-line file nil) + while line + unless (or (= (length line) 0) (char= (aref line 0) #\#)) + collect (funcall fn line)))) + +(defstruct vc-ignore path patterns) + +(defgeneric vc-path-ignored-p (obj path) + (:documentation "Check PATH against the patterns in OBJ. If there is a match, return non-nil.") + (:method ((obj vc-ignore) (path t)) + (let ((len (length path))) + (loop for pat in (vc-ignore-patterns obj) + when (funcall pat path 0 len) + return (values path pat))))) (defstruct vc-branch name rev) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/util.lisp --- a/lisp/lib/vc/util.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/vc/util.lisp Tue May 28 16:44:54 2024 -0400 @@ -4,3 +4,10 @@ (if (pathnamep obj) (namestring obj) obj)) + +(defun rel-pathname (path) + (pathname (string-left-trim '(#\/) path))) + +(defun glob-path-match (glob) + (lambda (p start end) + (member (subseq p start end) (directory (rel-pathname glob)) :test 'equal))) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lib/vc/vc.asd --- a/lisp/lib/vc/vc.asd Mon May 27 23:15:33 2024 -0400 +++ b/lisp/lib/vc/vc.asd Tue May 28 16:44:54 2024 -0400 @@ -1,9 +1,8 @@ (defsystem :vc - :depends-on (:std :cli :obj :net :log) + :depends-on (:std :cli :obj :net :log :parse) :components ((:file "pkg") (:file "util") (:file "err") - (:file "ignore") (:file "proto") (:file "hg") (:file "git")) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/lisp.sk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/lisp.sk Tue May 28 16:44:54 2024 -0400 @@ -0,0 +1,4 @@ +;;; lisp.sk --- lisp skelfile -*- mode: skel; -*- +:name "core/lisp" +:description "The CC Lisp Core" +:components ((:asd "prelude.asd")) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/skelfile --- a/lisp/skelfile Mon May 27 23:15:33 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -;;; lisp.sk --- lisp skelfile -*- mode: skel; -*- -:name "core/lisp" -:description "The CC Lisp Core" -:components ((:file "prelude.asd")) - diff -r 2ef83f2178f1 -r 45889d307d7f lisp/std/path.lisp --- a/lisp/std/path.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/std/path.lisp Tue May 28 16:44:54 2024 -0400 @@ -34,3 +34,5 @@ (defconstant +pathsep+ #+windows #\; #+unix #\: "Path separator for this OS.") + +(defconstant +wildfile+ (make-pathname :name :wild :type :wild :version :wild)) diff -r 2ef83f2178f1 -r 45889d307d7f lisp/std/pkg.lisp --- a/lisp/std/pkg.lisp Mon May 27 23:15:33 2024 -0400 +++ b/lisp/std/pkg.lisp Tue May 28 16:44:54 2024 -0400 @@ -332,7 +332,8 @@ :absolute-pathname :relative-pathname :directory-pathname - :absolute-directory-pathname)) + :absolute-directory-pathname + :+wildfile+ :+pathsep+)) (defpkg :std/os (:use :cl) @@ -354,7 +355,6 @@ :file= :file-size :file-size-in-octets - :+pathsep+ :octet-vector= :file-date :file-timestamp diff -r 2ef83f2178f1 -r 45889d307d7f rust/rust.sk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/rust.sk Tue May 28 16:44:54 2024 -0400 @@ -0,0 +1,8 @@ +;;; rust.sk --- core/rust skelfile -*- mode: skel; -*- +:name "core/rust" +:version "0.1.0" +:description "Rust Core" +:tags ("rust") +:components ((:toml "Cargo")) +:rules +(("clean" () #$cargo clean$#)) diff -r 2ef83f2178f1 -r 45889d307d7f rust/skelfile --- a/rust/skelfile Mon May 27 23:15:33 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -;;; rust.sk --- core/rust skelfile -*- mode: skel; -*- -:name "core/rust" -:version "0.1.0" -:description "Rust Core" -:tags ("rust") -:rules -(("clean" () #$cargo clean$#))