source: cl-darcs/tags/0.2.0/get.lisp

Last change on this file was 101, checked in by Magnus Henoch, 17 years ago

Tag 0.2.0

File size: 5.1 KB
Line 
1;;; Copyright (C) 2006 Magnus Henoch
2;;;
3;;; This program is free software; you can redistribute it and/or
4;;; modify it under the terms of the GNU General Public License as
5;;; published by the Free Software Foundation; either version 2 of the
6;;; License, or (at your option) any later version.
7;;;
8;;; This program is distributed in the hope that it will be useful,
9;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11;;; General Public License for more details.
12;;;
13;;; You should have received a copy of the GNU General Public License
14;;; along with this program; if not, write to the Free Software
15;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16
17(in-package :darcs)
18
19(defun create-repo (repodir)
20  "Create an empty repository."
21  (setf repodir (fad:pathname-as-directory repodir))
22  (prepare-new-repo repodir)
23  (create-pristine-from-tree repodir))
24
25;; get_cmd in Get.lhs
26(defun get-repo (inrepodir outname &key (partial nil) (query nil))
27  (setf outname (fad:pathname-as-directory outname))
28  ;; other access methods later...
29  ;; XXX: checkpoints?
30  (let* ((repodir (make-upath inrepodir))
31         ;; Here we get a list of lists.  Each list represents a tag;
32         ;; the latest tag is at the head.  Each list contains patches
33         ;; in the order they are to be applied.
34         (patchinfo-list (read-repo-patch-list repodir))
35         ;; We should probably download checkpoint patches, btw...
36         (checkpoint (when partial
37                       (car (last (read-checkpoint-list repodir))))))
38    (let ((motd (get-preflist repodir "motd")))
39      (when motd
40        (format t "~{~&~A~}" motd)))
41
42    ;; Create directories...
43    (prepare-new-repo outname)
44    (set-default-repo outname inrepodir)
45
46    (when checkpoint
47      (format t "~&Copying checkpoint...")
48      (copy-checkpoint repodir outname checkpoint)
49      ;; After copying, we can read the checkpoint from OUTNAME.
50      (let ((checkpoint-patch (read-checkpoint-from-repo outname checkpoint)))
51        (apply-patch checkpoint-patch outname))
52      (format t "done"))
53
54
55    (let* ((all-patches (if checkpoint
56                            ;; XXX: patchinfo-list is a list of lists now
57                            (find-remaining-patches patchinfo-list checkpoint)
58                            (apply #'append (reverse patchinfo-list))))
59           (patches
60            (if (or (null query) (y-or-n-p "Apply all patches?"))
61                all-patches
62                (select-some-patches all-patches))))
63      ;; write-inventory wants patches ordered by tags, but we have
64      ;;them all in a list in all-patches and patches...
65      ;;(write-inventory outname patchinfo-list)
66      (copy-repo-patches repodir outname patches)
67     
68      (format t "~&Applying patches")
69      (dolist (patchinfo patches)
70        (let ((patch (read-patch-from-repo outname patchinfo)))
71          (apply-patch patch outname)
72          ;; XXX: this is where we write tags to inventory correctly
73          ;; Check how darcs handles tags - rotate inventory files?
74          ;; What happens when adding patches one by one?
75          (append-inventory outname patchinfo)
76          (format t ".")))
77      (format t "~&Creating pristine")
78      (create-pristine-from-tree outname)
79      (format t "~&All done"))))
80
81(defun select-some-patches (patchinfo-list)
82  "Interactively select some patches from PATCHINFO-LIST.
83Return a new list containing the selected patches."
84  (format t "~&Available patches:")
85  (loop for patchinfo in patchinfo-list
86     count patchinfo into i
87     do (format t "~&~3@A ~A" i patchinfo))
88  (format t "~&Specify inclusive start and end (NIL will do): ")
89  (let ((start (read)) (end (read)))
90    (if start
91        (decf start)
92        (setf start 0))
93    (subseq patchinfo-list start end)))
94
95(defun find-remaining-patches (patchinfo-list checkpoint)
96  "Find the patches remaining after getting to CHECKPOINT."
97  ;; XXX: this is incorrect; the checkpoint isn't among ordinary patches.
98  (loop for tail on patchinfo-list
99     when (equalp (car tail) checkpoint)
100     return (cdr tail)))
101
102(defun copy-repo-patches (from to patchinfo-list)
103  "Copy patches from repository FROM to repository TO.
104PATCHINFO-LIST is the list of patches in FROM to copy."
105  (format t "~&Copying ~A patches" (length patchinfo-list))
106  ;; Assume that TO/_darcs/patches is created
107  (dolist (patch patchinfo-list)
108    (let ((filename (patchinfo-make-filename patch)))
109      (with-open-file (out (merge-pathnames
110                            (make-pathname :directory (list :relative "_darcs" "patches")
111                                           :name filename)
112                            to)
113                           :direction :output :element-type '(unsigned-byte 8))
114        (with-open-stream (in (open-upath 
115                               (upath-subdir from '("_darcs" "patches") filename)
116                               :binary t))
117          (fad:copy-stream in out))))
118    (princ #\.)))
119
120(defun copy-checkpoint (from to checkpoint)
121  "Copy CHECKPOINT from repository FROM to repository TO.
122CHECKPOINT is a patchinfo naming the checkpoint."
123  (let ((filename (patchinfo-make-filename checkpoint)))
124    (with-open-file (out (merge-pathnames
125                          (make-pathname :directory '(:relative "_darcs" "checkpoints")
126                                         :name filename)
127                          to)
128                         :direction :output :element-type '(unsigned-byte 8))
129      (with-open-stream (in (open-upath
130                             (upath-subdir from '("_darcs" "checkpoints") filename)
131                             :binary t))
132        (fad:copy-stream in out)))))
133
Note: See TracBrowser for help on using the repository browser.