* src/eval.c (struct backtrace): Don't cheat with negative numbers, but do
[bpt/emacs.git] / lisp / vc / add-log.el
index 88277e6..d75fcb5 100644 (file)
@@ -1,11 +1,10 @@
 ;;; add-log.el --- change log maintenance commands for Emacs
 
-;; Copyright (C) 1985, 1986, 1988, 1993, 1994, 1997, 1998, 2000, 2001,
-;;   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;; Copyright (C) 1985-1986, 1988, 1993-1994, 1997-1998, 2000-2011
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
-;; Keywords: tools
+;; Keywords: vc tools
 
 ;; This file is part of GNU Emacs.
 
@@ -37,9 +36,6 @@
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'timezone))
-
 (defgroup change-log nil
   "Change log maintenance."
   :group 'tools
@@ -701,7 +697,7 @@ current buffer to the complete file name.
 Optional arg BUFFER-FILE overrides `buffer-file-name'."
   ;; If we are called from a diff, first switch to the source buffer;
   ;; in order to respect buffer-local settings of change-log-default-name, etc.
-  (with-current-buffer (let ((buff (if (eq major-mode 'diff-mode)
+  (with-current-buffer (let ((buff (if (derived-mode-p 'diff-mode)
                                       (car (ignore-errors
                                             (diff-find-source-location))))))
                         (if (buffer-live-p buff) buff
@@ -755,7 +751,17 @@ Optional arg BUFFER-FILE overrides `buffer-file-name'."
     (if add-log-file-name-function
        (funcall add-log-file-name-function buffer-file)
       (setq buffer-file
-            (file-relative-name buffer-file (file-name-directory log-file)))
+            (let* ((dir (file-name-directory log-file))
+                   (rel (file-relative-name buffer-file dir)))
+              ;; Sometimes with symlinks, the two buffers may have names that
+              ;; appear to belong to different directory trees.  So check the
+              ;; file-truenames, to see if we get a better result.
+              (if (not (string-match "\\`\\.\\./" rel))
+                  rel
+                (let ((new (file-relative-name (file-truename buffer-file)
+                                               (file-truename dir))))
+                  (if (< (length new) (length rel))
+                      new rel)))))
       ;; If we have a backup file, it's presumably because we're
       ;; comparing old and new versions (e.g. for deleted
       ;; functions) and we'll want to use the original name.
@@ -1173,7 +1179,7 @@ Has a preference of looking backwards."
                ((apply 'derived-mode-p add-log-c-like-modes)
                 (or (c-cpp-define-name)
                     (c-defun-name)))
-               ((memq major-mode add-log-tex-like-modes)
+               ((apply #'derived-mode-p add-log-tex-like-modes)
                 (if (re-search-backward
                      "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
                      nil t)
@@ -1242,19 +1248,18 @@ Has a preference of looking backwards."
          (change-log-get-method-definition-1 ""))
        (concat change-log-get-method-definition-md "]"))))))
 \f
+(autoload 'timezone-make-date-sortable "timezone")
+
 (defun change-log-sortable-date-at ()
   "Return date of log entry in a consistent form for sorting.
 Point is assumed to be at the start of the entry."
-  (require 'timezone)
   (if (looking-at change-log-start-entry-re)
       (let ((date (match-string-no-properties 0)))
        (if date
            (if (string-match "\\(....\\)-\\(..\\)-\\(..\\)\\s-+" date)
                (concat (match-string 1 date) (match-string 2 date)
                        (match-string 3 date))
-             (condition-case nil
-                 (timezone-make-date-sortable date)
-               (error nil)))))
+             (ignore-errors (timezone-make-date-sortable date)))))
     (error "Bad date")))
 
 (defun change-log-resolve-conflict ()
@@ -1361,5 +1366,4 @@ old-style time formats for entries are supported."
 
 (provide 'add-log)
 
-;; arch-tag: 81eee6fc-088f-4372-a37f-80ad9620e762
 ;;; add-log.el ends here