Fixed.
[riece] / lisp / riece-log.el
index f9c9fe3..738b2a5 100644 (file)
@@ -119,29 +119,46 @@ If integer, flash back only this line numbers. t means all lines."
        (expand-file-name name (expand-file-name server riece-log-directory))
       (expand-file-name name riece-log-directory))))
 
+(defun riece-log-get-directory-1 (identity)
+  (let ((prefix (riece-identity-canonicalize-prefix
+                (riece-identity-prefix identity)))
+       (server (riece-identity-server identity))
+       (map (assoc (riece-format-identity identity) riece-log-directory-map))
+       name)
+    (if map
+       (setq name (cdr map))
+      (expand-file-name (riece-log-encode-file-name prefix)
+                       (expand-file-name
+                        (concat "." (riece-log-encode-file-name server))
+                        riece-log-directory)))))
+
 (defun riece-log-encode-file-name (file-name)
   (if riece-log-file-name-coding-system
       (setq file-name
            (encode-coding-string file-name
                                  riece-log-file-name-coding-system)))
-  (let ((index 0))
-    (while (string-match "[^-0-9A-Za-z=_\x80-\xFF]" file-name index)
-      (setq file-name (replace-match
-                      (format "=%02X"
-                              (aref file-name (match-beginning 0)))
-                      nil t file-name)
-           index (+ 3 index)))
+  (let ((index 0)
+       c)
+    (while (string-match "[^-0-9A-Za-z_\x80-\xFF]" file-name index)
+      (setq c (aref file-name (match-beginning 0)))
+      (if (eq c ?=)
+         (setq file-name (replace-match "==" nil t file-name)
+               index (1+ (match-end 0)))
+       (setq file-name (replace-match (format "=%02X" c) nil t file-name)
+             index (+ 2 (match-end 0)))))
     file-name))
 
 (defun riece-log-decode-file-name (file-name)
   (let ((index 0))
-    (while (string-match "=\\([0-7][0-9A-F]\\)" file-name index)
+    (while (string-match "==\\|=\\([0-7][0-9A-F]\\)" file-name index)
       (setq file-name (replace-match
-                      (char-to-string
-                       (car (read-from-string
-                             (concat "?\\x" (match-string 1 file-name)))))
+                      (if (eq (aref file-name (1- (match-end 0))) ?=)
+                          "="
+                        (char-to-string
+                         (car (read-from-string
+                               (concat "?\\x" (match-string 1 file-name))))))
                       nil t file-name)
-           index (1+ index)))
+           index (1+ (match-beginning 0))))
     file-name)
   (if riece-log-file-name-coding-system
       (setq file-name
@@ -149,48 +166,43 @@ If integer, flash back only this line numbers. t means all lines."
                                  riece-log-file-name-coding-system)))
   file-name)
 
-(defun riece-log-flashback-1 (identity)
-  (if (eq riece-log-flashback t)
+(defun riece-log-insert (identity lines)
+  "Insert logs for IDENTITY at most LINES.
+If LINES is t, insert today's logs entirely."
+  (if (eq lines t)
       (let ((file (riece-log-get-file identity)))
        (if (file-exists-p file)
            (insert-file-contents file)))
     (let ((files (riece-log-get-files identity))
-         (lines (- riece-log-flashback))
+         (lines (- lines))
          date point)
       (while (and (< lines 0) files)
        (if (and (file-exists-p (car files))
-                (string-match (concat "\\("
-                                      (riece-make-interval-regexp "[0-9]" 4)
-                                      "\\)\\("
-                                      (riece-make-interval-regexp "[0-9]" 2)
-                                      "\\)\\("
-                                      (riece-make-interval-regexp "[0-9]" 2)
-                                      "\\).log$")
+                (string-match (concat "\\([0-9][0-9][0-9][0-9]\\)"
+                                      "\\([0-9][0-9]\\)\\([0-9][0-9]\\).log$")
                               (car files)))
            (save-restriction
-             (narrow-to-region (point-min) (point-min))
+             (narrow-to-region (point) (point))
              (setq date (concat " (" (match-string 1 (car files)) "/"
                                 (match-string 2 (car files)) "/"
                                 (match-string 3 (car files)) ")"))
              (insert-file-contents (car files))
              (goto-char (point-max))
-             (setq lines (forward-line lines)
-                   point (point))
+             (setq lines (forward-line lines))
+             (delete-region (point-min) (point))
              (while (not (eobp))
                (end-of-line)
                (insert date)
                (forward-line))
-             (goto-char point)))
-       (setq files (cdr files)))
-      (if (zerop lines)
-         (delete-region (point-min) (point))))))
+             (goto-char (point-min))))
+       (setq files (cdr files))))))
 
 (defun riece-log-flashback (identity)
   (when riece-log-flashback
     (let (buffer-read-only
          (point (goto-char (point-max))))
       (insert (with-temp-buffer
-               (riece-log-flashback-1 identity)
+               (riece-log-insert identity riece-log-flashback)
                (buffer-string)))
       (goto-char point)
       (while (re-search-forward