From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Reviewing versioned backups Date: Wed, 24 Mar 2021 14:05:11 +0300 Message-ID: References: <87a6qvat9v.fsf@posteo.net> <87v99i9j9u.fsf@posteo.net> <8335wm82ps.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4203"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) To: Eli Zaretskii , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 24 12:09:14 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lP1Ny-0000zX-B5 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 24 Mar 2021 12:09:14 +0100 Original-Received: from localhost ([::1]:40446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lP1Nx-0006yv-DY for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 24 Mar 2021 07:09:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lP1Nd-0006yo-QA for help-gnu-emacs@gnu.org; Wed, 24 Mar 2021 07:08:53 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:55295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lP1Nb-00066k-Bt; Wed, 24 Mar 2021 07:08:53 -0400 Original-Received: from localhost ([::ffff:41.202.241.53]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000001E1C3.00000000605B1DBF.00004FAC; Wed, 24 Mar 2021 04:08:47 -0700 Mail-Followup-To: Eli Zaretskii , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128538 Archived-At: 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)