~pkal/vc-backup

d777727173230330372ca71195c365f70b6958b5 — Alfred M. Szmidt 5 months ago 5ba724d
Prefix all internal functions and variables with 'vc-backup--'
1 files changed, 36 insertions(+), 36 deletions(-)

M vc-backup.el
M vc-backup.el => vc-backup.el +36 -36
@@ 117,13 117,13 @@

;; Internal Functions

(defconst vc-backup-current-tag "real"
(defconst vc-backup--current-tag "real"
  "Tag used for the actual file.")

(defconst vc-backup-previous-tag "prev"
(defconst vc-backup--previous-tag "prev"
  "Tag used for unversioned backup.")

(defun vc-backup-get-read (file-or-backup)
(defun vc-backup--get-read (file-or-backup)
  "Return the actual file behind FILE-OR-BACKUP."
  (if (backup-file-name-p file-or-backup)
      (replace-regexp-in-string


@@ 134,14 134,14 @@
	(file-name-sans-versions file-or-backup)))
    file-or-backup))

(defun vc-backup-list-backups (file-or-list)
(defun vc-backup--list-backups (file-or-list)
  "Generate a list of all backups for FILE-OR-LIST.
FILE-OR-LIST can either be a string or a list of strings.  This
function returns all backups for these files, in order of their
recency."
  (let (versions)
    (dolist (file (if (listp file-or-list) file-or-list (list file-or-list)))
      (let ((filename (thread-last (vc-backup-get-read file)
      (let ((filename (thread-last (vc-backup--get-read file)
			expand-file-name
			make-backup-file-name
			file-name-sans-versions)))


@@ 152,43 152,43 @@ recency."
	      versions)))
    (sort (apply #'nconc versions) #'file-newer-than-file-p)))

(defun vc-backup-extract-version (file-or-backup)
(defun vc-backup--extract-version (file-or-backup)
  "Return a revision string for FILE-OR-BACKUP.
If FILE-OR-BACKUP is the actual file, \"real\" is
returned.  Otherwise, it returns the version number as a string or
\"prev\" for unversioned backups."
  (cond ((not (backup-file-name-p file-or-backup)) vc-backup-current-tag)
  (cond ((not (backup-file-name-p file-or-backup)) vc-backup--current-tag)
	((string-match "\\.~\\([[:digit:]]+\\)~\\'" file-or-backup)
	 (match-string 1 file-or-backup))
	(t vc-backup-previous-tag)))
	(t vc-backup--previous-tag)))

(defun vc-backup-list-backup-versions (file)
(defun vc-backup--list-backup-versions (file)
  "Return an association list of backup files and versions for FILE.
Each element of the list has the form (VERS . BACKUP), where VERS
is the version string as generated by `vc-backup-extract-version'
is the version string as generated by `vc-backup--extract-version'
and BACKUP is the actual backup file."
  (let (files)
    (dolist (backup (vc-backup-list-backups file))
      (push (cons (vc-backup-extract-version backup) backup)
    (dolist (backup (vc-backup--list-backups file))
      (push (cons (vc-backup--extract-version backup) backup)
	    files))
    files))

(defun vc-backup-get-backup-file (file rev)
(defun vc-backup--get-backup-file (file rev)
  "Return backup file for FILE of the version REV."
  (cond ((string= rev vc-backup-current-tag) file)
	((string= rev vc-backup-previous-tag)
  (cond ((string= rev vc-backup--current-tag) file)
	((string= rev vc-backup--previous-tag)
	 (let ((prev (thread-last (expand-file-name file)
		       make-backup-file-name
		       file-name-sans-versions
		       (format "%~"))))
	   (and (file-exists-p prev) prev)))
	((cdr (assoc rev (vc-backup-list-backup-versions file))))))
	((cdr (assoc rev (vc-backup--list-backup-versions file))))))

(defun vc-backup-last-rev (file)
(defun vc-backup--last-rev (file)
  "Return the revision of the last backup for FILE."
  (thread-last (vc-backup-list-backups file)
  (thread-last (vc-backup--list-backups file)
    car
    vc-backup-extract-version))
    vc-backup--extract-version))

;; BACKEND PROPERTIES



@@ 220,7 220,7 @@ and BACKUP is the actual backup file."

(defun vc-backup-working-revision (file)
  "Check if FILE is the real file or a backup."
  (vc-backup-extract-version file))
  (vc-backup--extract-version file))

(defun vc-backup-checkout-model (_files)
  "Inform VC that files are not locked."


@@ 248,7 248,7 @@ and BACKUP is the actual backup file."
(defun vc-backup-find-revision (file rev buffer)
  "Open a backup of the version REV for FILE in BUFFER."
  (with-current-buffer buffer
    (insert-file-contents (vc-backup-get-backup-file file rev))))
    (insert-file-contents (vc-backup--get-backup-file file rev))))

(defun vc-backup-checkout (file &optional rev)
  "Before copying an old version of FILE, force a backup.


@@ 258,7 258,7 @@ If REV is non-nil, checkout that version."
	(make-backup-files t))
    (with-current-buffer (find-file-noselect file)
      (backup-buffer)))
  (copy-file (vc-backup-get-backup-file file rev)
  (copy-file (vc-backup--get-backup-file file rev)
	     file t))

;; * revert (file &optional contents-done)


@@ 293,7 293,7 @@ The results are written into BUFFER."
    (let ((inhibit-read-only t))
      (erase-buffer)
      (insert "Backups for " file "\n\n")
      (dolist (rev (nreverse (vc-backup-list-backup-versions file)))
      (dolist (rev (nreverse (vc-backup--list-backup-versions file)))
	(let* ((attr (file-attributes (cdr rev)))
	       (stime (file-attribute-modification-time attr))
	       (sdate (format-time-string "%c" stime)))


@@ 323,14 323,14 @@ The results are written into BUFFER."
  "Generate a diff for FILES between versions REV1 and REV2.
BUFFER and ASYNC as interpreted as specified in vc.el."
  (cl-assert (= (length files) 1))
  (setq rev2 (or rev2 (vc-backup-last-rev files)))
  (setq rev2 (or rev2 (vc-backup--last-rev files)))
  (save-window-excursion
    (let ((dirty nil))
      (dolist (file files)
	(let ((diff (diff-no-select
		     (vc-backup-get-backup-file file rev2)
		     (vc-backup-get-backup-file
		      file (or rev1 vc-backup-current-tag))
		     (vc-backup--get-backup-file file rev2)
		     (vc-backup--get-backup-file
		      file (or rev1 vc-backup--current-tag))
		     (vc-switches 'Backup 'diff)
		     (not async)
		     (get-buffer (or buffer "*vc-diff*")))))


@@ 343,7 343,7 @@ BUFFER and ASYNC as interpreted as specified in vc.el."
(defun vc-backup-revision-completion-table (files)
  "Return a list of revisions for FILES."
  (cl-assert (= (length files) 1))
  (mapcar #'car (vc-backup-list-backup-versions (car files))))
  (mapcar #'car (vc-backup--list-backup-versions (car files))))

;; - annotate-command (file buf &optional rev)



@@ 379,21 379,21 @@ BUFFER and ASYNC as interpreted as specified in vc.el."

(defun vc-backup-previous-revision (file rev)
  "Determine the revision before REV for FILE."
  (let* ((backups (vc-backup-list-backups file))
  (let* ((backups (vc-backup--list-backups file))
	 (index (cl-position rev backups :key #'car)))
    (cond ((string= rev vc-backup-current-tag) (car backups))
	  ((string= rev vc-backup-previous-tag) nil)
    (cond ((string= rev vc-backup--current-tag) (car backups))
	  ((string= rev vc-backup--previous-tag) nil)
	  ((and (natnump index) (> index 0))
	   (car (nth (1- index) backups))))))

(defun vc-backup-next-revision (file rev)
  "Determine the revision after REV for FILE."
  (let* ((backups (vc-backup-list-backups file))
  (let* ((backups (vc-backup--list-backups file))
	 (index (cl-position rev backups :key #'car)))
    (cond ((string= rev vc-backup-current-tag) nil)
    (cond ((string= rev vc-backup--current-tag) nil)
	  ((and (natnump index) (< index (length backups)))
	   (car (nth (1+ index) backups)))
	  (t vc-backup-current-tag))))
	  (t vc-backup--current-tag))))

;; - log-edit-mode ()



@@ 401,7 401,7 @@ BUFFER and ASYNC as interpreted as specified in vc.el."

(defun vc-backup-delete-file (file)
  "Delete FILE and all its backups."
  (dolist (backup (vc-backup-list-backups file))
  (dolist (backup (vc-backup--list-backups file))
    (delete-file backup))
  (delete-file file))



@@ 414,7 414,7 @@ BUFFER and ASYNC as interpreted as specified in vc.el."
	(old-part (thread-last (expand-file-name old-file)
		    make-backup-file-name
		    file-name-sans-versions)))
    (dolist (backup (vc-backup-list-backups old-file))
    (dolist (backup (vc-backup--list-backups old-file))
      (let ((new-backup (concat new-part (substring backup (length old-part)))))
	(rename-file backup new-backup t)))))