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

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

Tag 0.2.0

File size: 3.8 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 record-patches (repo name author date log patches)
20  "Record PATCHES in REPO.
21NAME is the name of the patch, a description of one line.
22AUTHOR is the e-mail address (or other identifier) of the author.
23DATE is the date in YYYYMMDDHHMMSS format, or the keyword :NOW.
24LOG is either NIL or a possibly multi-line description of the patch.
25PATCHES is a list of patches that make up the change."
26  (let* ((patchinfo
27          (make-patchinfo
28           :name name :author author
29           :date (if (eql date :now)
30                     (multiple-value-bind
31                           (second minute hour date month year)
32                         (get-decoded-time)
33                       (format nil "~4,'0d~2,'0d~2,'0d~2,'0d~2,'0d~2,'0d"
34                               year month date hour minute second))
35                     date)
36           :log (when log
37                    (split-sequence:split-sequence #\Newline log))))
38         (patch (make-instance 'named-patch
39                               :patchinfo patchinfo
40                               :dependencies nil
41                               :patch
42                               (make-instance 'composite-patch
43                                              :patches patches))))
44    (write-patch-to-repo patch repo)
45    (apply-patch-to-pristine patch repo)
46    (append-inventory repo patchinfo)))
47
48(defun record-changes (repo name author date log)
49  "Record changes in REPO.
50Arguments as to `record-patches'."
51  (let ((patches (diff-repo repo)))
52    (unless patches
53      (error "Nothing to record."))
54
55    (record-patches repo name author date log (select-patches patches))))
56
57(defun select-patches (patches)
58  "Ask the user to select some of PATCHES.
59Do the necessary commutation and dependency elimination."
60  (let (patches-to-record)
61    (loop while (setf patches (remove nil patches))
62       do
63       ;; Should we include this patch?
64       (display-patch (car patches) *query-io*)
65       (if (y-or-n-p "Record patch ~A?" (car patches))
66           (progn
67             ;; Yes, just add it to the list and go on.
68             (push (car patches) patches-to-record)
69             (setf patches (cdr patches)))
70           ;; No, we need to commute it through the rest of the patches.
71           (loop for commute-patches on (cdr patches)
72              ;; Try to commute it with the next patch in line.
73              do (let ((commute-result (commute (car commute-patches) (car patches))))
74                   (if commute-result
75                       ;; Commutation succeeded; use the altered patches.
76                       (destructuring-bind (commuted-current commuted-future) commute-result
77                         (setf (car patches) commuted-current)
78                         (setf (car commute-patches) commuted-future))
79                       ;; Commutation failed; (car commute-patches) depends on (car patches).
80                       ;; Try to commute them together.
81                       (progn
82                         ;; Turn the patch we are commuting through
83                         ;; the list into a composite patch, unless it is
84                         ;; one already.  Append the dependency.
85                         (etypecase (car patches)
86                           (composite-patch
87                            (nconc (patches (car patches))
88                                   (list (car commute-patches))))
89                           (patch
90                            (setf (car patches)
91                                  (make-instance 'composite-patch
92                                                 :patches (list
93                                                           (car patches)
94                                                           (car commute-patches))))))
95                         ;; Drop the dependency from the list of
96                         ;; patches to consider.
97                         (setf (car commute-patches) nil))))
98              finally (setf patches (cdr patches)))))
99    (nreverse patches-to-record)))
Note: See TracBrowser for help on using the repository browser.