Mercurial > core / lisp/lib/vc/proto.lisp
changeset 388: |
dec30b6fd500 |
parent: |
45889d307d7f
|
child: |
95b861dff3d8 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 31 May 2024 18:18:12 -0400 |
permissions: |
-rw-r--r-- |
description: |
prelude/user packages init |
1 ;;; lib/vc/proto.lisp --- VC Protocol 9 (defgeneric vc-init (self) 10 (:documentation "Initialize a vc-repo - calls either 'git init' or 'hg init'")) 12 (defgeneric vc-run (self cmd &rest args) 13 (:documentation "Run a vc CMD with ARGS.")) 15 (defgeneric vc-id (self) 16 (:documentation "Get the ID of a vc object.")) 18 (defgeneric (setf vc-id) (self id) 19 (:documentation "Set the ID of a vc object.")) 21 (defgeneric vc-clone (self remote &key &allow-other-keys) 22 (:documentation "Clone repo REMOTE into spec SELF.")) 24 (defgeneric vc-push (self remote &key &allow-other-keys) 25 (:documentation "Push repo SELF to REMOTE.")) 27 (defgeneric vc-pull (self remote &key &allow-other-keys) 28 (:documentation "Pull repo REMOTE into spec SELF.")) 30 (defgeneric vc-commit (self msg &key &allow-other-keys) 31 (:documentation "Commit repo object SELF, supplied with message MSG.")) 33 (defgeneric vc-add (self &rest files) 34 (:documentation "Add FILES to repo SELF.")) 36 (defgeneric vc-remove (self &rest files) 37 (:documentation "Remove FILES from repo SELF.")) 39 (defgeneric vc-addremove (self &rest files) 40 (:documentation "Add any untracked files in the current directory and delete tracked files that 43 (defgeneric vc-branch (self) 44 (:documentation "Return the name of the current branch.")) 46 (defgeneric vc-status (self &key &allow-other-keys)) 48 ;; IDEA 2023-12-29: :ediff t 49 (defgeneric vc-diff (a b &key &allow-other-keys)) 54 ;; should be parsed from .hgrc and .gitconfig 55 (defclass vc-config (sxp cfg) ()) 59 ;; Basically we treat HG and GIT ignore files the same - just lines of string 60 ;; patterns. HG uses regexp and GIT is globs - an IGNOREFILE has a line parser 61 ;; slot for selecting the appropriate function. 63 (defun map-lines (fn path) 64 "Call FN on each line of file PATH and collect the result." 65 (with-open-file (file path) 66 (loop for line = (read-line file nil) 68 unless (or (= (length line) 0) (char= (aref line 0) #\#)) 69 collect (funcall fn line)))) 71 (defstruct vc-ignore path patterns) 73 (defgeneric vc-path-ignored-p (obj path) 74 (:documentation "Check PATH against the patterns in OBJ. If there is a match, return non-nil.") 75 (:method ((obj vc-ignore) (path t)) 76 (let ((len (length path))) 77 (loop for pat in (vc-ignore-patterns obj) 78 when (funcall pat path 0 len) 79 return (values path pat))))) 81 (defstruct vc-branch name rev) 83 (defstruct vc-commit id message) 85 (defstruct vc-tag name id) 87 (defstruct vc-remote name url) 89 (defstruct vc-rev num id) 92 ((path :initform nil :type (or null string pathname) :accessor vc-repo-path 94 :documentation "AKA working-directory or working-copy") 95 (head :initform nil :initarg :head :type (or null vc-rev) :accessor vc-repo-head) 96 (branches :initform (make-array 0 :element-type 'vc-branch :fill-pointer 0) :type (vector vc-branch)) 97 (tags :initform (make-array 0 :element-type 'vc-tag :fill-pointer 0) :type (vector vc-tag)) 98 (revisions :initform (make-array 0 :element-type 'vc-rev :fill-pointer 0) :type (vector vc-rev)) 99 (remotes :initform (make-array 0 :element-type 'vc-remote :fill-pointer 0) :type (vector vc-remote)) 100 (config :initform nil :type (or null vc-config))) 101 (:documentation "generic Repository object backed by one of VC-DESIGNATOR.")) 103 (defmethod vc-init ((self (eql t))) 104 (make-instance 'vc-repo))