changelog shortlog graph tags branches changeset files revisions annotate raw help

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
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :vc)
7 
8 ;;; Functions
9 (defgeneric vc-init (self)
10  (:documentation "Initialize a vc-repo - calls either 'git init' or 'hg init'"))
11 
12 (defgeneric vc-run (self cmd &rest args)
13  (:documentation "Run a vc CMD with ARGS."))
14 
15 (defgeneric vc-id (self)
16  (:documentation "Get the ID of a vc object."))
17 
18 (defgeneric (setf vc-id) (self id)
19  (:documentation "Set the ID of a vc object."))
20 
21 (defgeneric vc-clone (self remote &key &allow-other-keys)
22  (:documentation "Clone repo REMOTE into spec SELF."))
23 
24 (defgeneric vc-push (self remote &key &allow-other-keys)
25  (:documentation "Push repo SELF to REMOTE."))
26 
27 (defgeneric vc-pull (self remote &key &allow-other-keys)
28  (:documentation "Pull repo REMOTE into spec SELF."))
29 
30 (defgeneric vc-commit (self msg &key &allow-other-keys)
31  (:documentation "Commit repo object SELF, supplied with message MSG."))
32 
33 (defgeneric vc-add (self &rest files)
34  (:documentation "Add FILES to repo SELF."))
35 
36 (defgeneric vc-remove (self &rest files)
37  (:documentation "Remove FILES from repo SELF."))
38 
39 (defgeneric vc-addremove (self &rest files)
40  (:documentation "Add any untracked files in the current directory and delete tracked files that
41 are missing."))
42 
43 (defgeneric vc-branch (self)
44  (:documentation "Return the name of the current branch."))
45 
46 (defgeneric vc-status (self &key &allow-other-keys))
47 
48 ;; IDEA 2023-12-29: :ediff t
49 (defgeneric vc-diff (a b &key &allow-other-keys))
50 
51 ;;; Objects
52 
53 ;;;; Config
54 ;; should be parsed from .hgrc and .gitconfig
55 (defclass vc-config (sxp cfg) ())
56 
57 ;;;; Ignorefile
58 
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.
62 
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)
67  while line
68  unless (or (= (length line) 0) (char= (aref line 0) #\#))
69  collect (funcall fn line))))
70 
71 (defstruct vc-ignore path patterns)
72 
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)))))
80 
81 (defstruct vc-branch name rev)
82 
83 (defstruct vc-commit id message)
84 
85 (defstruct vc-tag name id)
86 
87 (defstruct vc-remote name url)
88 
89 (defstruct vc-rev num id)
90 
91 (defclass vc-repo ()
92  ((path :initform nil :type (or null string pathname) :accessor vc-repo-path
93  :initarg :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."))
102 
103 (defmethod vc-init ((self (eql t)))
104  (make-instance 'vc-repo))