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

Contents of /meta-cvs/F-FFF16CA4956A36F19290AC9E1EBAFFD8

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5