[Cl-darcs-cvs] r3 - cl-darcs/trunk
Author: mhenoch Date: Tue May 23 13:12:09 2006 New Revision: 3 Modified: cl-darcs/trunk/apply-patch.lisp Log: Handle the case of subsequent hunks changing the same line. Modified: cl-darcs/trunk/apply-patch.lisp ============================================================================== --- cl-darcs/trunk/apply-patch.lisp (original) +++ cl-darcs/trunk/apply-patch.lisp Tue May 23 13:12:09 2006 @@ -27,10 +27,13 @@ (,filename-gensym ,filename)) (restart-case ;; Open the file to patch for reading. - (with-open-file (,instreamvar ,filename-gensym - :direction :input - :if-does-not-exist :error - :element-type '(unsigned-byte 8)) + (with-open-stream (,instreamvar + (make-instance 'unreadable-stream + :base-stream + (open ,filename-gensym + :direction :input + :if-does-not-exist :error + :element-type '(unsigned-byte 8)))) ;; Open a temporary file for writing. (with-temp-file (,outstreamvar :element-type '(unsigned-byte 8)) (progn ,@body) @@ -40,7 +43,7 @@ (setf ,files-copied-gensym t) ;; Copy the temporary file over the original. - (fad:copy-file (pathname ,outstreamvar) (pathname ,instreamvar) :overwrite t))) + (fad:copy-file (pathname ,outstreamvar) ,filename :overwrite t))) ;; Until the temporary file is copied over the original, we can ;; retry as many times we want. @@ -292,12 +295,14 @@ ;; them to the temporary file. )))) - ;; Now, let's add lines, increasing the line counter as we - ;; go. - (dolist (new (hunk-new-lines hunk)) - (maybe-terpri) - (write-sequence new out) - (incf line-number))) + ;; Now, let's add lines. The obvious way to do it would + ;; be to print the lines to output, increasing the line + ;; counter for every line. However, in some circumstances + ;; there are two subsequent hunks modifying the same line + ;; (i.e. s/A/B/ and s/B/C/ are expected to have the same + ;; result as s/A/C/), so we unread the lines instead. + (dolist (new (reverse (hunk-new-lines hunk))) + (unread-line in new))) ;; And output the lines after all hunks (loop for line = (read-binary-line in nil :eof)
participants (1)
-
mhenoch@common-lisp.net