/[meta-cvs]/meta-cvs/F-94BF952D29F3DC3FFD457EFFCE570DB2
ViewVC logotype

Contents of /meta-cvs/F-94BF952D29F3DC3FFD457EFFCE570DB2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Sat Aug 17 18:58:50 2002 UTC (11 years, 8 months ago) by kaz
Branch: MAIN
CVS Tags: symlink-branch~branch-point
Branch point for: symlink-branch
Changes since 1.7: +1 -1 lines
* posix.lisp (edit-file): Function renamed to invoke-file-on,
because this name clashes with a standard Common Lisp symbol.
* types.lisp (types-let-user-edit): Updated to use new name.
1 ;;; This source file is part of the Meta-CVS program,
2 ;;; which is distributed under the GNU license.
3 ;;; Copyright 2002 Kaz Kylheku
4
5 (require "mapping")
6 (require "system")
7 (require "print")
8 (require "seqfuncs")
9 (provide "types")
10
11 (eval-when (:compile-toplevel :load-toplevel :execute)
12 (defconstant *mcvs-types-name* "TYPES"))
13
14 (eval-when (:compile-toplevel :load-toplevel :execute)
15 (defconstant *mcvs-types* #.(path-cat *mcvs-dir* *mcvs-types-name*))
16 (defconstant *mcvs-new-types* #.(path-cat *mcvs-dir* "TYPES-NEW")))
17
18 (defconstant *types-comments*
19 ";;; For each file suffix that appears in the file set, you can specify
20 ;;; the CVS keyword expansion mode, or you can specify that the files having
21 ;;; that suffix should not be imported. This is done by editing the list below.
22 ;;; Here are the symbols you can specify next to each suffix.
23 ;;;
24 ;;; :default Expand keyword using default form. (CVS -kkv)
25 ;;; :name-only Expand only the keyword name on checkout. (CVS -kk)
26 ;;; :keep-old Do not expand keywords, and keep any CVS or RCS keywords
27 ;;; that are already present in the files. (CVS -ko)
28 ;;; :binary Like :keep-old except that the file is treated as
29 ;;; binary. Not only are keywords not expanded, but line ending
30 ;;; conversions are not performed either. (CVS -kb)
31 ;;; :value-only Expand only the keyword value, no dollar signs. (CVS -kv)
32 ;;; :ignore Do not import or add these files.
33 ")
34
35
36 (defun types-read (filename)
37 (with-open-file (file filename :direction :input)
38 (read file)))
39
40 (defun types-write (types filename &key comments)
41 (with-open-file (file filename :direction :output)
42 (let ((sorted-types (sort (copy-list types)
43 #'string-lessp :key #'first)))
44 (when comments
45 (write-string comments file)
46 (terpri file))
47 (print-assoc-list sorted-types file)
48 (terpri file))))
49
50 (defun types-sanity-check (types)
51 (cond
52 ((null types)
53 (values))
54 ((consp types)
55 (let ((type-spec (first types)))
56 (when (or (not (stringp (first type-spec)))
57 (not (symbolp (second type-spec))))
58 (error "bad syntax in file type treatment specification: ~s" type-spec))
59 (when (not (member (second type-spec)
60 '(:name-only :keep-old :default :value-only
61 :binary :ignore)))
62 (error "unrecognized keyword: ~s" type-spec)))
63 (types-sanity-check (rest types)))
64 (t (error "bad syntax in file type treatment specification: ~s" types))))
65
66 (defun types-to-import-wrapper-args (types)
67 (mapcan #'(lambda (type-spec)
68 (destructuring-bind (suffix treatment) type-spec
69 (flet ((gen-option (suf opt)
70 (list "-W" (format nil "*.~a -k '~a'" suf opt))))
71 (ecase treatment
72 ((:name-only) (gen-option suffix "k"))
73 ((:keep-old) (gen-option suffix "o"))
74 ((:binary) (gen-option suffix "b"))
75 ((:value-only) (gen-option suffix "kv"))
76 ((:ignore) nil)
77 ((:default) nil)))))
78 types))
79
80 (defun types-remove-ignores (types mapping)
81 (let ((ignores (mapcan #'(lambda (type-spec)
82 (if (eq (second type-spec) :ignore)
83 (list (first type-spec))))
84 types)))
85 (remove-if #'(lambda (name)
86 (member (suffix name) ignores :test #'path-equal))
87 mapping :key #'first)))
88
89 (defun types-make-cvs-adds (types mapping)
90 (let (cvs-adds matching files)
91 (dolist (type-entry types)
92 (multiple-value-setq
93 (matching mapping)
94 (separate-if #'(lambda (x)
95 (and x (path-equal (first type-entry) x)))
96 mapping
97 :key #'(lambda (x) (suffix (first x)))))
98 (setf files (mapcar #'basename (mapcar #'first matching)))
99 (when files
100 (ecase (second type-entry)
101 ((:name-only) (setf files (list* "-kk" files)))
102 ((:keep-old) (setf files (list* "-ko" files)))
103 ((:binary) (setf files (list* "-kb" files)))
104 ((:value-only) (setf files (list* "-kv" files)))
105 ((:ignore) (setf files nil))
106 ((:default)))
107 (when files (push files cvs-adds))))
108 (setf files (mapcar #'basename (mapcar #'first mapping)))
109 (when files (push files cvs-adds))
110 cvs-adds))
111
112 (defun types-let-user-edit (types filename)
113 (when types
114 (types-write types filename :comments *types-comments*)
115 (loop
116 (restart-case
117 (progn
118 (chatter-debug "Editing types.~%")
119 (invoke-editor-on filename)
120 (let ((edited-types (types-read filename)))
121 (types-sanity-check edited-types)
122 (types-write edited-types filename)
123 (return edited-types)))
124 (retry ()
125 :report "Correct file type treatment, try again.")
126 (restore-types ()
127 :report "Revert to original file treatment and edit again."
128 (types-write types filename :comments *types-comments*))))))

  ViewVC Help
Powered by ViewVC 1.1.5