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

Contents of /meta-cvs/F-FFF16CA4956A36F19290AC9E1EBAFFD8

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sun Jan 20 07:12:03 2002 UTC (12 years, 2 months ago) by kaz
Branch: MAIN
Adding all existing source files.
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     (defun filemap-object-lookup (filemap object)
38     (find object filemap :test #'(lambda (o entry)
39     (string= o (first entry)))))
40    
41     (defun filemap-same-object-p (entry-one entry-two)
42     (string= (first entry-one) (first entry-two)))
43    
44     (defun filemap-same-path-p (entry-one entry-two)
45     (path-equal (second entry-one) (second entry-two)))
46    
47     (defun filemap-moved-p (entry-one entry-two)
48     (and (string= (first entry-one) (first entry-two))
49     (not (path-equal (second entry-one) (second entry-two)))))
50    
51     (defun mapping-sane-p (filemap)
52     "Performs various integrity checks on a MCVS file map. Checks that
53     it's a list of lists, that all paths and object names are unique.
54     Returns T if checks pass otherwise NIL."
55     (cond
56     ((not (block :structure-check
57     (dolist (item filemap)
58     (when (not (and (listp item) (= 2 (length item))))
59     (return-from :structure-check nil))))) nil)))
60    
61     (defun mapping-synchronize ()
62     "Synchronizes the contents of files in the sandbox, and their corresponding
63     CVS files in the MCVS directory. This must be done before any CVS operation
64     such as commit or update, so that the MCVS files have the correct contents
65     reflecting local changes. It must also be done after any CVS update operation,
66     to ensure that the newly incorporated changes are propagated to the sandbox"
67     (let (filemap)
68     (with-open-file (file *mcvs-map-local* :direction :input)
69     (setf filemap (read file)))
70    
71     (dolist (item filemap)
72     (can-restart-here ("Continue synchronizing files.")
73     (destructuring-bind (left right) item
74     (case (synchronize-files left right)
75     ((:left)
76     (chatter-info "synchronizing ~a -> ~a~%" left right))
77     ((:right)
78     (chatter-info "synchronizing ~a <- ~a~%" left right))
79     ((:same))
80     ((nil)
81     (error "mcvs-sync: neither ~a nor ~a exists."
82     left right))))))))
83    
84     (defun mapping-update ()
85     #.(format nil
86     "Reads the MCVS mapping files ~a and ~a, the local
87     mapping and repository mapping, respectively. It computes the difference
88     between them and then reorganizes the file structure of the sandbox as
89     necessary to make the mapping up to date. Then the local mapping file is
90     overwritten so it is identical to the repository one. This is necessary to
91     bring the local structure up to date after after CVS updates, adds or removes."
92     *mcvs-map-local* *mcvs-map*)
93     (let (old-filemap new-filemap)
94     (with-open-file (file *mcvs-map* :direction :input)
95     (setf new-filemap (read file)))
96    
97     (with-open-file (file *mcvs-map-local* :direction :input)
98     (setf old-filemap (read file)))
99    
100     (let ((added-files (set-difference new-filemap old-filemap
101     :test #'filemap-same-object-p))
102     (deleted-files (set-difference old-filemap new-filemap
103     :test #'filemap-same-object-p))
104     (moved-files (intersection new-filemap old-filemap
105     :test #'filemap-moved-p)))
106    
107     (dolist (item deleted-files)
108     (can-restart-here ("Continue updating file structure.")
109     (ensure-directories-gone (second item))
110     (chatter-info "deleting ~a~%" (second item))))
111    
112     (dolist (item moved-files)
113     (can-restart-here ("Continue updating file structure.")
114     (let ((old-item (filemap-object-lookup old-filemap (first item)))
115     (new-item (filemap-object-lookup new-filemap (first item))))
116     (ensure-directories-gone (second old-item))
117     (ensure-directories-exist (second new-item))
118     (synchronize-files (first new-item) (second new-item))
119     (chatter-info "moving ~a -> ~a~%" (second old-item)
120     (second new-item)))))
121    
122     (dolist (item added-files)
123     (can-restart-here ("Continue updating file structure.")
124     (synchronize-files (first item) (second item))
125     (chatter-info "adding ~a~%" (second item)))))
126    
127     (with-open-file (file *mcvs-map-local* :direction :output)
128     (let ((*print-right-margin* 1))
129     (prin1 new-filemap file)
130     (terpri file)))))

  ViewVC Help
Powered by ViewVC 1.1.5