/[meta-cvs]/meta-cvs/F-FFF16CA4956A36F19290AC9E1EBAFFD8
ViewVC logotype

Contents of /meta-cvs/F-FFF16CA4956A36F19290AC9E1EBAFFD8

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Sat Jan 26 01:41:49 2002 UTC (12 years, 2 months ago) by kaz
Branch: MAIN
Changes since 1.6: +0 -1 lines
Oops, removed forgotten (break).
1 (require "dirwalk")
2 (require "system")
3 (require "sync")
4 (require "chatter")
5 (require "restart")
6 (provide "mapping")
7
8 (eval-when (:compile-toplevel :load-toplevel :execute)
9 (defconstant *mcvs-dir* #.(path-cat "MCVS")))
10
11 (eval-when (:compile-toplevel :load-toplevel :execute)
12 (defconstant *mcvs-map* #.(path-cat *mcvs-dir* "MAP"))
13 (defconstant *mcvs-map-local* #.(path-cat *mcvs-dir* "MAP-LOCAL")))
14
15 ;; TODO: use getcwd()
16 (defun mcvs-locate ()
17 "Search for MCVS directory by looking in the current directory, and
18 if it is not found there, by changing directory up through successive
19 parent directories. Returns the path from the new current directory
20 down to the original one, or the value nil if not found."
21 (if (ignore-errors (stat *mcvs-dir*))
22 "."
23 (let ((came-from (go-up)))
24 (if came-from
25 (let ((locate (mcvs-locate)))
26 (if locate
27 (path-cat locate came-from)))))))
28
29 (defmacro in-sandbox-root-dir (&body forms)
30 (let ((downpath-sym (gensym "DOWNPATH-")))
31 `(current-dir-restore
32 (let ((,downpath-sym (mcvs-locate)))
33 (when (not ,downpath-sym)
34 (error "mcvs: could not locate ~a directory." *mcvs-dir*))
35 (flet ((sandbox-translate-path (in-path)
36 (multiple-value-bind (out-path out-of-bounds)
37 (canonicalize-path
38 (path-cat ,downpath-sym in-path))
39 (if out-of-bounds
40 (error "mcvs: path ~a is not within sandbox." out-path)
41 out-path))))
42 (symbol-macrolet ((sandbox-down-path ',downpath-sym))
43 ,@forms))))))
44
45 (defun filemap-generate-name ()
46 (let ((name (format nil "F-~32,'0X" (guid-gen))))
47 (path-cat *mcvs-dir* name)))
48
49 (defun filemap-sort (filemap)
50 (sort filemap #'(lambda (i1 i2) (string-lessp (second i1) (second i2)))))
51
52 (defun filemap-extract-paths (filemap)
53 (mapcar #'second filemap))
54 (declaim (inline filemap-extract-paths))
55
56 (defun filemap-lookup (filemap path)
57 (find path filemap :test #'path-equal :key #'second))
58
59 (defun filemap-prefix-lookup (filemap prefix)
60 (if (path-equal *this-dir* prefix)
61 (first filemap)
62 (find prefix filemap :test #'path-prefix-equal :key #'second)))
63
64 (defun filemap-prefix-matches (filemap path)
65 (if (path-equal *this-dir* path)
66 filemap
67 (remove-if-not #'(lambda (entry)
68 (path-prefix-equal path (second entry))) filemap)))
69
70 (defun filemap-object-lookup (filemap object)
71 (find object filemap :test #'string= :key #'first))
72
73 (defun filemap-same-object-p (entry-one entry-two)
74 (string= (first entry-one) (first entry-two)))
75
76 (defun filemap-same-path-p (entry-one entry-two)
77 (path-equal (second entry-one) (second entry-two)))
78
79 (defun filemap-moved-p (entry-one entry-two)
80 (and (string= (first entry-one) (first entry-two))
81 (not (path-equal (second entry-one) (second entry-two)))))
82
83 (defun filemap-remove (filemap file-list)
84 "Returns a new filemap, with the specified files removed."
85 (mapcan #'(lambda (entry)
86 (if (member (second entry) file-list :test #'path-equal)
87 nil
88 entry))))
89
90 (defun filemap-rename-files (filemap file-list old-prefix new-prefix)
91 "Returns a new filemap, in which the pathames in the list file-list are edited
92 by replacing the old-prefix with the new-prefix. If any path thus created
93 matches an existing map entry, that map entry is removed. The sorting order
94 of the map is not preserved."
95 (flet ((combine (prefix path)
96 (if (string= path "")
97 prefix
98 (canonicalize-path (path-cat prefix path)))))
99 (let* ((op-len (length old-prefix))
100 (delete-map (mapcan #'(lambda (entry)
101 (destructuring-bind (object path) entry
102 (if (and (member path file-list
103 :test #'path-equal)
104 (path-prefix-equal old-prefix
105 path))
106 (list entry)))) filemap))
107 (replace-map (mapcan #'(lambda (entry)
108 (destructuring-bind (object path) entry
109 (list (list object
110 (combine new-prefix
111 (subseq path
112 op-len))))))
113 delete-map)))
114 (append
115 (set-difference
116 (set-difference filemap delete-map :test #'filemap-same-path-p)
117 replace-map :test #'filemap-same-path-p)
118 replace-map))))
119
120 (defun filemap-sane-p (filemap)
121 "Performs various integrity checks on a MCVS file map. Checks that
122 it's a list of lists, that all paths and object names are unique.
123 Returns T if checks pass otherwise NIL."
124 (cond
125 ((not (block :structure-check
126 (dolist (item filemap)
127 (when (not (and (listp item) (= 2 (length item))))
128 (return-from :structure-check nil))))) nil)))
129
130 (defun mapping-synchronize ()
131 "Synchronizes the contents of files in the sandbox, and their corresponding
132 CVS files in the MCVS directory. This must be done before any CVS operation
133 such as commit or update, so that the MCVS files have the correct contents
134 reflecting local changes. It must also be done after any CVS update operation,
135 to ensure that the newly incorporated changes are propagated to the sandbox"
136 (let (filemap)
137 (with-open-file (file *mcvs-map-local* :direction :input)
138 (setf filemap (read file)))
139
140 (dolist (item filemap)
141 (can-restart-here ("Continue synchronizing files.")
142 (destructuring-bind (left right) item
143 (case (synchronize-files left right)
144 ((:left)
145 (chatter-info "synchronizing ~a -> ~a~%" left right))
146 ((:right)
147 (chatter-info "synchronizing ~a <- ~a~%" left right))
148 ((:same))
149 ((nil)
150 (error "mcvs-sync: neither ~a nor ~a exists."
151 left right))))))))
152
153 (defun mapping-update ()
154 #.(format nil
155 "Reads the MCVS mapping files ~a and ~a, the local
156 mapping and repository mapping, respectively. It computes the difference
157 between them and then reorganizes the file structure of the sandbox as
158 necessary to make the mapping up to date. Then the local mapping file is
159 overwritten so it is identical to the repository one. This is necessary to
160 bring the local structure up to date after after CVS updates, adds or removes."
161 *mcvs-map-local* *mcvs-map*)
162 (let (old-filemap new-filemap)
163 (with-open-file (file *mcvs-map* :direction :input)
164 (setf new-filemap (read file)))
165
166 (with-open-file (file *mcvs-map-local* :direction :input)
167 (setf old-filemap (read file)))
168
169 (let ((added-files (set-difference new-filemap old-filemap
170 :test #'filemap-same-object-p))
171 (deleted-files (set-difference old-filemap new-filemap
172 :test #'filemap-same-object-p))
173 (moved-files (intersection new-filemap old-filemap
174 :test #'filemap-moved-p)))
175
176 (dolist (item deleted-files)
177 (can-restart-here ("Continue updating file structure.")
178 (ensure-directories-gone (second item))
179 (chatter-info "deleting ~a~%" (second item))))
180
181 (dolist (item moved-files)
182 (can-restart-here ("Continue updating file structure.")
183 (let ((old-item (filemap-object-lookup old-filemap (first item)))
184 (new-item (filemap-object-lookup new-filemap (first item))))
185 (ensure-directories-gone (second old-item))
186 (ensure-directories-exist (second new-item))
187 (synchronize-files (first new-item) (second new-item))
188 (chatter-info "moving ~a -> ~a~%" (second old-item)
189 (second new-item)))))
190
191 (dolist (item added-files)
192 (can-restart-here ("Continue updating file structure.")
193 (synchronize-files (first item) (second item))
194 (chatter-info "adding ~a~%" (second item)))))
195
196 (with-open-file (file *mcvs-map-local* :direction :output)
197 (let ((*print-right-margin* 1))
198 (prin1 new-filemap file)
199 (terpri file)))))

  ViewVC Help
Powered by ViewVC 1.1.5