This is the first of two patches that allows patcher to handle removed
files. This patch makes changes to patch-to-change-log in add-log.el.
patch-to-change-log has three difficulties with removed files:
1. It uses /dev/null as the file name. This is because it uses the
second file name as the name of the changed file. This is fixed by
looking on the line above for the correct filename.
2. It looks in the file's directory for the ChangeLog, however the
directory containing the file may have also been removed. This is
fixed by searching up the directory path for a directory that does
3. It reads the file before generating the ChangeLog entry. This is
fixed by generating a 'Removed' entry for any zero sized buffer.
One problem that isn't fixed is consolidating ChangeLog entries.
patch-to-change-log generates a new entry whenever the directory part of
the ChangeLog path changes. For CVS, which sorts the files in the
patch, this results in one ChangeLog entry per ChangeLog. Mercurial
always sorts the files by type (modified, added, removed) and then by
filename. If a patch contains files of more than one type in a
directory, multiple ChangeLog entries are produced.
Suggestions on how to fix this are welcome.
2008-04-29 Malcolm Purvis <malcolmp(a)xemacs.org>
* add-log.el (patch-to-change-log): Understand hunks in which
files and directories have been removed.
lisp-xemacs-base source patch:
Diff command: cvs -q diff -u
Files affected: add-log.el
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/xemacs-base/add-log.el,v
retrieving revision 1.25
diff -u -r1.25 add-log.el
--- add-log.el 2004/12/18 16:31:29 1.25
+++ add-log.el 2008/04/29 12:41:37
＠＠ -1097,6 +1097,7 ＠＠
(file-re1 "^Index: \\([^\n]*\\)")
(file-re2 "^\\+\\+\\+ \\([^\t]*\\)")
+ (removed-file-re "^--- \\(\\S-*\\)")
(hunk-re "^＠＠ -[0-9]+,[0-9]+ \\+\\([0-9]+\\),\\([0-9]+\\) ＠＠")
(lisp-defun-re "(def[a-z-]* \\([^ \n]+\\)")
＠＠ -1167,6 +1168,12 ＠＠
(setq first-file-re-p t))
(prog1 (re-search-forward file-re2 nil t)
(setq first-file-re-p nil)))
+ ;; If a file has been removed then the first match will be
+ ;; /dev/null. Go back one line and find the real file.
+ (if (string= (match-string 1) "/dev/null")
+ (forward-line -1)
+ (re-search-forward removed-file-re max t)))
(setq file (match-string 1))
(if (string-match basename-re file)
(setq dirname (match-string 1 file)
＠＠ -1178,6 +1185,9 ＠＠
(if first-file-re-p file-re1 file-re2)
+ ;; If the directory doesn't exist then search for the parent that does.
+ (while (not (file-exists-p dirname))
+ (setq dirname (directory-file-name (concat (file-name-directory dirname)))))
(when (not (equal dirname previous-dirname))
＠＠ -1327,22 +1337,25 ＠＠
(setq trylines (nreverse trylines))
(let ((already-visiting-p (get-file-buffer absfile)))
- (set-buffer (find-file-noselect absfile))
+ (set-buffer (find-file-noselect absfile t))
(mapc #'(lambda (n)
- (goto-line n)
- (setq current-defun (add-log-current-defun))
+ (if (> (buffer-size) 0)
+ (progn (goto-line n)
+ (setq current-defun (add-log-current-defun))
+ (if current-defun n 0)
+ (format (if current-defun
+ "\t* %s (%s):\n" "\t* %s:\n")
+ basename current-defun)))
- (if current-defun n 0)
- (format (if current-defun
- "\t* %s (%s):\n" "\t* %s:\n")
- basename current-defun)))
+ basename 0 nil (format "\t* %s: Removed\n" basename))))
(unless (or already-visiting-p cl-keep-source-files)
;; the patch might be totally blank.
Malcolm Purvis <malcolmp(a)xemacs.org>
XEmacs-Patches mailing list