From: Jean Louis <bugs@gnu.support>
To: Eli Zaretskii <eliz@gnu.org>, help-gnu-emacs@gnu.org
Subject: Re: Reviewing versioned backups
Date: Wed, 24 Mar 2021 14:05:11 +0300 [thread overview]
Message-ID: <YFsc5wiepTH6qeOt@protected.localdomain> (raw)
In-Reply-To: <YFr8rd5wSieknf3Y@protected.localdomain>
To add on the database backed backing of files or recording files as
specific revisions, for myself personally I find it handy for text
files and programming sources or letters. Database can be
automatically locally backed up, encrypted and remotely backed
up. Specific file revisions can be easily extracted, accessed, or
differentiated.
For now I work with functions below related to files. For database
entries it is automatic.
- C-r r - personal key binding to invoke `rcd-vc-revision' and
inserting the revision into the database. This is similar as
registration of a file in versioning system if the file was not
there, otherwise new version is inserted. Nothing much to think
about.
Interesting is that if I delete the whole file, revisions are still
there, even if I delete whole directory as database is
separate. With a function in future, it could be possible to convert
the revision system from a database into RCS or Git or some other
system. But this way, personally, I need not have file based
versioning system.
Those `backup.~1~' files are useful, but not as handy to browse or
review, I will switch that back to this database based backing up,
it is revision system.
- C-x k - has the hook `rcd-vc-insert-revision-on-kill-buffer' which
verifies if the file by its file path belonging to the buffer exists
in the database or not, if it does exists, the file is automatically
backed up, new revision by its ID is automatically creted -- I could
as well add versioning of a buffer without file name
I am sure this can be implemented with SQLite for single user, but
when it is implemented with the database user could even have the
database online, or on remote computers and files would get backed
up. Reminders could be sent to associated people, and collaboration
and review of changes and review of files becomes available to a team
including available from any kind of devices, provided there is
software to fetch such entries.
(defvar rcd-vc-ask-for-revision t
"Global decision to ask user for revision number or use
automatically assigned database ID numbers.")
(defun rcd-vc-insert-revision (filename title &optional description revision)
"Insert the revised FILENAME with TITLE into the
database. Optional DESCRIPTION and REVISION may be provided."
(if (or (file-directory-p filename)
(not (file-exists-p filename))
(not (file-readable-p filename)))
(message "Cannot read or access file: %s" filename)
(let* ((file (expand-file-name filename))
(original-file file)
(file (sql-escape-string file))
(title (sql-escape-string title))
(description (if description
(sql-escape-string description)
"NULL"))
(revision (if revision
(sql-escape-string revision)
"NULL"))
(file-body (file-to-string original-file))
(file-body (sql-escape-string file-body))
(sql (format "INSERT INTO vcfiles (vcfiles_filename, vcfiles_title, vcfiles_description, vcfiles_filebody, vcfiles_revision) VALUES (%s, %s, %s, %s, %s) RETURNING vcfiles_id" file title description file-body revision)))
(let ((id (rcd-sql-first sql *cf*)))
(if id
(message "File revision ID: %s for %s recorded" id original-file)
(error "Could not record revision for: %s" original-file))))))
(defun rcd-vc-previous-revision (filename)
"Returns previous available revision number if any by using
FILENAME."
(let* ((filename (expand-file-name filename))
(filename (sql-escape-string filename))
(sql (format "SELECT vcfiles_revision FROM vcfiles WHERE vcfiles_filename = %s ORDER BY vcfiles_id DESC LIMIT 1" filename)))
(rcd-sql-first sql *cf*)))
(defun rcd-vc-previous-revisions-exist-p (filename)
"Returns T if previous revisions for FILENAME exist in the
`vcfiles' database table."
(let* ((filename (expand-file-name filename))
(filename (sql-escape-string filename))
(sql (format "SELECT vcfiles_id FROM vcfiles WHERE vcfiles_filename = %s ORDER BY vcfiles_id DESC LIMIT 1" filename)))
(rcd-sql-first sql *cf*)))
(defun rcd-vc-revision ()
"Record RCD Version Control for the current file of the current
buffer into the database."
(interactive)
(when (buffer-modified-p)
(when (y-or-n-p (format "Save %s?" (expand-file-name (buffer-file-name))))
(save-buffer)))
(let ((title (read-from-minibuffer "Title: "))
(description (if (y-or-n-p "Edit description?")
(read-from-buffer "" (concat "Description of changes for: "
filename))
nil))
(revision (when rcd-vc-ask-for-revision
(when (y-or-n-p "Enter revision designation?")
(read-from-minibuffer "Revision designation: " (rcd-vc-previous-revision filename)))))
(filename (expand-file-name (buffer-file-name))))
(rcd-vc-insert-revision filename title description revision)))
;; TODO if user enters revision same as one of previous, need to get a
;; warning that it is same
(defun rcd-vc-insert-revision-on-kill-buffer ()
(when (buffer-file-name)
(let* ((filename (expand-file-name (buffer-file-name)))
(timestamp (rcd-timestamp))
(title (concat "Automatic revision: " timestamp)))
(when filename
(when (rcd-vc-previous-revisions-exist-p filename)
(rcd-vc-insert-revision filename title))))))
;; This may be added to automatically insert revision on killing of
;; the buffer if the buffer file name already exists in the database.
;; (add-hook 'kill-buffer-hook 'rcd-vc-insert-revision-on-kill-buffer)
next prev parent reply other threads:[~2021-03-24 11:05 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 19:21 Reviewing versioned backups Philip Kaludercic
2021-03-22 20:25 ` Jean Louis
2021-03-23 8:38 ` Eric S Fraga
2021-03-23 9:31 ` Jean Louis
2021-03-23 9:44 ` Eli Zaretskii
2021-03-23 10:19 ` Jean Louis
2021-03-23 11:12 ` Eli Zaretskii
2021-03-23 15:49 ` [External] : " Drew Adams
2021-03-23 9:56 ` Thibaut Verron
2021-03-23 11:55 ` Philip Kaludercic
2021-03-23 12:36 ` John Yates
2021-03-23 12:38 ` Eli Zaretskii
2021-03-24 8:47 ` Jean Louis
2021-03-24 11:05 ` Jean Louis [this message]
2021-03-24 16:53 ` Eli Zaretskii
2021-03-26 5:50 ` Robert Thorpe
2021-03-28 0:38 ` Michael Heerdegen
2021-03-28 9:23 ` Philip Kaludercic
2021-03-30 0:36 ` Michael Heerdegen
2021-03-30 9:29 ` Philip Kaludercic
2021-03-30 9:39 ` Eli Zaretskii
2021-03-30 10:03 ` Philip Kaludercic
2021-03-30 10:16 ` Jean Louis
2021-03-30 23:41 ` Michael Heerdegen
2021-03-31 1:56 ` Stefan Monnier
2021-03-31 6:24 ` Eli Zaretskii
2021-03-31 13:29 ` Philip Kaludercic
2021-03-31 14:00 ` Jean Louis
2021-04-01 15:52 ` Stefan Monnier
2021-04-01 19:44 ` Philip Kaludercic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YFsc5wiepTH6qeOt@protected.localdomain \
--to=bugs@gnu.support \
--cc=eliz@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.