[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ssh-deploy 8e2507b 085/133: Refactored remote changes f
From: |
Stefan Monnier |
Subject: |
[elpa] externals/ssh-deploy 8e2507b 085/133: Refactored remote changes function and made unit tests for it |
Date: |
Sat, 27 Mar 2021 14:48:49 -0400 (EDT) |
branch: externals/ssh-deploy
commit 8e2507bd3a9f8866b54b128f17e1b76107e77a82
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Refactored remote changes function and made unit tests for it
---
ssh-deploy-test.el | 90 +++++++++++++++++++++++++++++++++--
ssh-deploy.el | 135 ++++++++++-------------------------------------------
2 files changed, 110 insertions(+), 115 deletions(-)
diff --git a/ssh-deploy-test.el b/ssh-deploy-test.el
index 44c7a8b..0c12dab 100644
--- a/ssh-deploy-test.el
+++ b/ssh-deploy-test.el
@@ -44,6 +44,8 @@
(autoload 'ssh-deploy-add-after-save-hook "ssh-deploy")
(autoload 'ssh-deploy-add-after-save-hook "ssh-deploy")
(autoload 'ssh-deploy-upload-handler "ssh-deploy")
+(autoload 'ssh-deploy--remote-changes-data "ssh-deploy")
+(autoload 'ssh-deploy-download-handler "ssh-deploy")
(defun ssh-deploy-test--download (async async-with-threads)
"Test downloads asynchronously if ASYNC is above zero, with threads if
ASYNC-WITH-THREADS is above zero."
@@ -155,11 +157,11 @@
(when (> async 0)
(sleep-for 1))
- ;; Both old files should not exist anymore
+ ;; Both old files should not exist any more
(should (equal nil (file-exists-p file-a-old)))
(should (equal nil (file-exists-p file-b-old)))
- ;; Both new files should exist anymore
+ ;; Both new files should exist any more
(should (equal t (file-exists-p file-a-new)))
(should (equal t (file-exists-p file-b-new)))
@@ -248,6 +250,79 @@
(delete-directory directory-a t)
(delete-directory directory-b t)))
+(defun ssh-deploy-test--detect-remote-changes (async async-with-threads)
+ "Test uploads asynchronously if ASYNC is above zero, with threads if
ASYNC-WITH-THREADS is above zero."
+
+ (let ((directory-a (expand-file-name "test-a/"))
+ (directory-b (expand-file-name "test-b/")))
+
+ ;; Delete directories if they already exists
+ (when (file-directory-p directory-a)
+ (delete-directory directory-a t))
+ (when (file-directory-p directory-b)
+ (delete-directory directory-b t))
+
+ (make-directory-internal directory-a)
+ (make-directory-internal directory-b)
+
+ (let* ((file-a (expand-file-name "test.txt" directory-a))
+ (file-b (expand-file-name "test.txt" directory-b))
+ (file-a-contents "Random text")
+ (ssh-deploy-root-local directory-a)
+ (ssh-deploy-root-remote directory-b)
+ (ssh-deploy-on-explicit-save 1)
+ (ssh-deploy-debug 0)
+ (ssh-deploy-async async)
+ (ssh-deploy-async-with-threads async-with-threads))
+
+ ;; Just bypass the linter here
+ (when (and ssh-deploy-root-local
+ ssh-deploy-root-remote
+ ssh-deploy-on-explicit-save
+ ssh-deploy-debug
+ ssh-deploy-async
+ ssh-deploy-async-with-threads)
+
+ (ssh-deploy-add-after-save-hook)
+ (find-file file-a)
+ (insert file-a-contents)
+ (save-buffer) ;; NOTE Should trigger upload action
+ (when (> async 0)
+ (sleep-for 1))
+ (kill-buffer)
+
+ ;; Verify that both files have equal contents
+ (should (equal t (ediff-same-file-contents file-a file-b)))
+
+ ;; Update should not trigger upload
+ (find-file file-b)
+ (insert "Random blbob")
+ (save-buffer)
+ (kill-buffer)
+
+ ;; Verify that both files don't have equal contents
+ (should (equal nil (ediff-same-file-contents file-a file-b)))
+
+ ;; Remote file should signal change now
+ (should (equal 5 (nth 0 (ssh-deploy--remote-changes-data file-a))))
+
+ ;; Open file-a and download remote
+ (find-file file-a)
+ (ssh-deploy-download-handler)
+ (when (> async 0)
+ (sleep-for 1))
+ (kill-buffer)
+
+ ;; Remote file should not signal change now
+ (should (equal 4 (nth 0 (ssh-deploy--remote-changes-data file-a))))
+
+ ;; Delete both test files
+ (delete-file file-b)
+ (delete-file file-a)))
+
+ (delete-directory directory-a t)
+ (delete-directory directory-b t)))
+
(defun ssh-deploy-test--get-revision-path ()
"Test this function."
(should (string= (expand-file-name "./_mydirectory_random-file.txt")
(ssh-deploy--get-revision-path "/mydirectory/random-file.txt" (expand-file-name
".")))))
@@ -267,12 +342,14 @@
(defun ssh-deploy-test ()
"Run test for plug-in."
(let ((ssh-deploy-verbose 1)
- (ssh-deploy-debug 1))
+ (ssh-deploy-debug 1)
+ (debug-on-error t))
(when (and ssh-deploy-verbose
ssh-deploy-debug)
(if (fboundp 'async-start)
(message "\nNOTE: Running tests for async.el as well since it's
loaded\n")
(message "\nNOTE: Skipping tests for async.el since it's not
loaded\n"))
+
(ssh-deploy-test--get-revision-path)
(ssh-deploy-test--file-is-in-path)
(ssh-deploy-test--is-not-empty-string)
@@ -290,7 +367,12 @@
(ssh-deploy-test--rename-and-delete 0 0)
(when (fboundp 'async-start)
(ssh-deploy-test--rename-and-delete 1 0))
- (ssh-deploy-test--rename-and-delete 1 1))))
+ (ssh-deploy-test--rename-and-delete 1 1)
+
+ (ssh-deploy-test--detect-remote-changes 0 0)
+ (when (fboundp 'async-start)
+ (ssh-deploy-test--detect-remote-changes 1 0))
+ (ssh-deploy-test--detect-remote-changes 1 1))))
(ssh-deploy-test)
diff --git a/ssh-deploy.el b/ssh-deploy.el
index 988e3c7..4db8887 100644
--- a/ssh-deploy.el
+++ b/ssh-deploy.el
@@ -171,7 +171,6 @@
(put 'ssh-deploy-debug 'permanent-local t)
(put 'ssh-deploy-debug 'safe-local-variable 'integerp)
-;; TODO This flag needs to work better, you should not miss any useful
notifications when this is on
(defcustom ssh-deploy-verbose 1
"Boolean variable if debug messages should be shown, 1 by default."
:type 'integer)
@@ -324,7 +323,6 @@
(autoload 'ediff-same-file-contents "ediff-util")
(autoload 'string-remove-prefix "subr-x")
- ;; TODO Add all public functions as autoload here
(autoload 'ssh-deploy-download "ssh-deploy")
(autoload 'ssh-deploy-download-handler "ssh-deploy")
(autoload 'ssh-deploy-upload "ssh-deploy")
@@ -796,120 +794,35 @@
(list 1 (format "File '%s' is not in root or is excluded from it."
path-local) path-local))))
;;;###autoload
-(defun ssh-deploy-remote-changes (path-local &optional root-local root-remote
async revision-folder exclude-list async-with-threads)
- "Check if a local revision for PATH-LOCAL on ROOT-LOCAL and if remote file
has changed on ROOT-REMOTE, do it optionally asynchronously if ASYNC is true,
check for copies in REVISION-FOLDER and skip if path is in EXCLUDE-LIST. Use
multi-threading if ASYNC-WITH-THREADS is above zero."
+(defun ssh-deploy-remote-changes (path-local &optional root-local root-remote
async revision-folder exclude-list async-with-threads verbose)
+ "Check if a local revision for PATH-LOCAL on ROOT-LOCAL and if remote file
has changed on ROOT-REMOTE, do it optionally asynchronously if ASYNC is true,
check for copies in REVISION-FOLDER and skip if path is in EXCLUDE-LIST. Use
multi-threading if ASYNC-WITH-THREADS is above zero, VERBOSE if value above
zero."
(let ((root-local (or root-local ssh-deploy-root-local))
(root-remote (or root-remote ssh-deploy-root-remote))
- (exclude-list (or exclude-list ssh-deploy-exclude-list)))
-
+ (exclude-list (or exclude-list ssh-deploy-exclude-list))
+ (verbose (or verbose ssh-deploy-verbose))
+ (revision-folder (or revision-folder ssh-deploy-revision-folder)))
;; Is the file inside the local-root and should it not be excluded?
(if (and (ssh-deploy--file-is-in-path-p path-local root-local)
(ssh-deploy--file-is-included-p path-local exclude-list))
- (let* ((revision-folder (or revision-folder
ssh-deploy-revision-folder))
- (revision-path (ssh-deploy--get-revision-path path-local
revision-folder))
- (path-remote (expand-file-name (ssh-deploy--get-relative-path
root-local path-local) root-remote)))
-
- ;; Is the file a regular file?
- (if (not (file-directory-p path-local))
- (progn
-
- ;; Does a local revision of the file exist?
- (if (file-exists-p revision-path)
-
- ;; Local revision exist. Is async enabled?
- (if (> async 0)
- (progn
-
- ;; Update mode-line status
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-detecting-remote-changes)
-
- ;; Asynchronous logic here
- (ssh-deploy--async-process
- (lambda()
- (if (file-exists-p path-remote)
- (if (ediff-same-file-contents revision-path
path-remote)
- (list 0 (format "Remote file '%s' has not
changed. (asynchronously)" path-remote) path-local)
- (if (ediff-same-file-contents path-local
path-remote)
- (progn
- (copy-file path-local revision-path t
t t t)
- (list 0 (format "Remote file '%s' is
identical to local file '%s' but different to local revision. Updated local
revision. (asynchronously)" path-remote path-local) path-local))
- (list 1 (format "Remote file '%s' has
changed please download or diff. (asynchronously)" path-remote) path-local)))
- (list 0 (format "Remote file '%s' doesn't
exist. (asynchronously)" path-remote) path-local)))
- (lambda(return)
-
- ;; Update buffer status to idle
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-idle (nth 2 return))
-
- (if (= (nth 0 return) 0)
- (when (> ssh-deploy-verbose 0) (message (nth
1 return)))
- (display-warning 'ssh-deploy (nth 1 return)
:warning)))
- async-with-threads))
-
- ;; Async is not enabled - synchronous logic here
-
- ;; Update buffer status
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-detecting-remote-changes)
-
- ;; Does remote file exist?
- (if (file-exists-p path-remote)
- (if (ediff-same-file-contents revision-path
path-remote)
- (when (> ssh-deploy-verbose 0) (message "Remote
file '%s' has not changed. (synchronously)" path-remote))
- (display-warning 'ssh-deploy (format "Remote file
'%s' has changed, please download or diff. (synchronously)" path-remote)
:warning))
- (when (> ssh-deploy-verbose 0) (message "Remote file
'%s' doesn't exist. (synchronously)" path-remote)))
-
- ;; Update buffer status to idle
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-idle))
-
- ;; Does not have local revision. Is async enabled?
- (if (> async 0)
- (progn
-
- ;; Update buffer status
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-detecting-remote-changes)
-
- ;; Asynchronous logic here
- (ssh-deploy--async-process
- (lambda()
-
- ;; Does remote file exist?
- (if (file-exists-p path-remote)
- (if (ediff-same-file-contents path-local
path-remote)
- (progn
- (copy-file path-local revision-path t t t
t)
- (list 0 (format "Remote file '%s' has not
changed, created base revision. (asynchronously)" path-remote) path-local))
- (list 1 (format "Remote file '%s' has changed
please download or diff. (asynchronously)" path-remote) path-local))
- (list 0 (format "Remote file '%s' doesn't exist.
(asynchronously)" path-remote) path-local)))
- (lambda(return)
-
- ;; Update buffer status to idle
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-idle (nth 2 return))
-
- (if (= (nth 0 return) 0)
- (when (> ssh-deploy-verbose 0) (message (nth 1
return)))
- (display-warning 'ssh-deploy (nth 1 return)
:warning)))
- async-with-threads))
-
- ;; Async is not enabled - synchronous logic here
-
- ;; Update buffer status
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-detecting-remote-changes)
-
- ;; Does remote file exist?
- (if (file-exists-p path-remote)
- (if (ediff-same-file-contents path-local path-remote)
- (progn
- (copy-file path-local revision-path t t t t)
- (when (> ssh-deploy-verbose 0) (message "Remote
file '%s' has not changed, created base revision. (synchronously)"
path-remote)))
- (display-warning 'ssh-deploy (format "Remote file
'%s' has changed, please download or diff. (synchronously)" path-remote)
:warning))
- (when (> ssh-deploy-verbose 0) (message "Remote file
'%s' does not exist. (synchronously)" path-remote)))
-
- ;; Update buffer status to idle
- (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-idle))))
-
- ;; File is a directory
- (when (> ssh-deploy-debug 0) (message "File %s is a directory,
ignoring remote changes check." path-local))))
-
- ;; File is not inside root or is excluded from it
+ ;; Is the file a regular file?
+ (if (not (file-directory-p path-local))
+ (progn
+ ;; Update mode-line status to detecting remote changes
+ (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-detecting-remote-changes)
+ (if (> async 0)
+ (ssh-deploy--async-process
+ (lambda()
+ (ssh-deploy--remote-changes-data path-local root-local
root-remote revision-folder exclude-list))
+ (lambda(response)
+ ;; Update buffer status to idle
+ (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-idle (nth 2 response))
+ (ssh-deploy--remote-changes-post-executor response
verbose))
+ async-with-threads)
+ (let ((response (ssh-deploy--remote-changes-data path-local
root-local root-remote revision-folder exclude-list)))
+ ;; Update buffer status to idle
+ (ssh-deploy--mode-line-set-status-and-update
ssh-deploy--status-idle (nth 2 response))
+ (ssh-deploy--remote-changes-post-executor response
verbose))))
+ (when (> ssh-deploy-debug 0) (message "File %s is a directory,
ignoring remote changes check." path-local)))
(when (> ssh-deploy-debug 0) (message "File %s is not in root or is
excluded from it." path-local)))))
(defun ssh-deploy-delete (path &optional async async-with-threads)
- [elpa] externals/ssh-deploy e0bf686 054/133: More (if), (when) and (progn) optimizations, (continued)
- [elpa] externals/ssh-deploy e0bf686 054/133: More (if), (when) and (progn) optimizations, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy efc8be3 058/133: Added another example using plug-in functions from script, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 4044f78 064/133: Hydra compilation working, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy ae5354a 065/133: Fixed issue were remote paths with symlinks didn't work with recursive diff function, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 6e37aae 067/133: Added unit test for download, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 8107b9e 073/133: Added unit test for rename and delete, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy e895d6d 079/133: Replaced asynchronous (require) with (autoload), Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 5846974 082/133: Added instructions about how to trigger unit test with async.el integration, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 85a7c37 080/133: Added unit tests for asynchronous operations, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 6ddb12b 090/133: All unit tests for remote changes sync and async and compilation passing, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 8e2507b 085/133: Refactored remote changes function and made unit tests for it,
Stefan Monnier <=
- [elpa] externals/ssh-deploy 8c26f61 091/133: Updated version and change-date, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 6d20dae 109/133: Fixed issue were async directory diff would lock main thread for resolving file links when using the handler, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 9c73fef 110/133: Added support for asynchronous file difference check, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 045e463 095/133: Trying emacs version manager in travis, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 438c1b4 107/133: Do not allow failures on emacs snapshot, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 24fec85 096/133: Added Travis build status to README, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 316395c 089/133: Updated version and date, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy f462007 105/133: More work on directory difference unit test, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 2f6a36e 101/133: Improved instructions for hydra and use-package, Stefan Monnier, 2021/03/27
- [elpa] externals/ssh-deploy 567e1d5 120/133: Work on feature to automatically update revisions, Stefan Monnier, 2021/03/27