[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 20d8217 44/92: Implemented directory copying
From: |
Alexey Veretennikov |
Subject: |
[elpa] master 20d8217 44/92: Implemented directory copying |
Date: |
Thu, 11 Jun 2015 19:48:04 +0000 |
branch: master
commit 20d821772b17e4b4d3809de63b2895bbed1f788f
Author: Alexey Veretennikov <address@hidden>
Commit: Alexey Veretennikov <address@hidden>
Implemented directory copying
---
ztree-diff-model.el | 34 +++++++++++++++++++
ztree-diff.el | 91 +++++++++++++++++++++++++++++++++++----------------
2 files changed, 97 insertions(+), 28 deletions(-)
diff --git a/ztree-diff-model.el b/ztree-diff-model.el
index 38cbac7..ab5a42c 100644
--- a/ztree-diff-model.el
+++ b/ztree-diff-model.el
@@ -66,6 +66,14 @@
(if (and left right) 'both
(if left 'left 'right))))
+(defun ztree-diff-node-equal (node1 node2)
+ (and (string-equal (ztree-diff-node-short-name node1)
+ (ztree-diff-node-short-name node2))
+ (string-equal (ztree-diff-node-left-path node1)
+ (ztree-diff-node-left-path node2))
+ (string-equal (ztree-diff-node-right-path node1)
+ (ztree-diff-node-right-path node1))))
+
(defun ztree-diff-model-files-equal (file1 file2)
"Compare files using external diff. Returns t if equal"
(let ((diff-output (shell-command-to-string (concat "diff -q" " " file1 " "
file2))))
@@ -105,6 +113,21 @@
result)))
result))
+(defun ztree-diff-node-update-diff-from-children (node)
+ (let ((children (ztree-diff-node-children node))
+ (diff nil))
+ (dolist (child children)
+ (setq diff
+ (ztree-diff-model-update-diff
+ diff
+ (ztree-diff-node-different child))))
+ (ztree-diff-node-set-different node diff)))
+
+(defun ztree-diff-node-update-all-parents-diff (node)
+ (let ((parent node))
+ (while (setq parent (ztree-diff-node-parent parent))
+ (ztree-diff-node-update-diff-from-children parent))))
+
(defun ztree-diff-model-update-diff (old new)
(if new
@@ -218,5 +241,16 @@ the rest is the combined list of nodes"
(message "Done.")
model))
+(defun ztree-diff-model-update-node (node)
+ (setq ztree-diff-model-wait-message
+ (concat "Updating " (ztree-diff-node-short-name node) " ..."))
+ (let ((traverse (ztree-diff-node-traverse node
+ (ztree-diff-node-left-path node)
+ (ztree-diff-node-right-path
node))))
+ (ztree-diff-node-set-children node (cdr traverse))
+ (ztree-diff-node-set-different node (car traverse))
+ (message "Done.")))
+
+
(provide 'ztree-diff-model)
diff --git a/ztree-diff.el b/ztree-diff.el
index 00e9067..ebc93d4 100644
--- a/ztree-diff.el
+++ b/ztree-diff.el
@@ -126,9 +126,60 @@ including . and ..")
" on left and right side are identical"))
(ediff left right)))))
- ;; (let ((parent (ztree-diff-node-parent node)))
- ;; (when parent
- ;; (message (ztree-diff-node-short-name parent)))))
+
+(defun ztree-diff-copy-file (node source-path destination-path copy-to-right)
+ (let ((target-path (concat
+ (file-name-as-directory destination-path)
+ (file-name-nondirectory
+ (directory-file-name source-path)))))
+ (let ((err (condition-case error-trap
+ (progn
+ ;; don't ask for overwrite
+ ;; keep time stamp
+ (copy-file source-path target-path t t)
+ nil)
+ (error error-trap))))
+ ;; error message if failed
+ (if err (message (concat "Error: " (nth 2 err)))
+ (progn ; otherwise:
+ ;; assuming all went ok when left and right nodes are the same
+ ;; set both as not different
+ (ztree-diff-node-set-different node nil)
+ ;; update left/right paths
+ (if copy-to-right
+ (ztree-diff-node-set-right-path node target-path)
+ (ztree-diff-node-set-left-path node target-path))
+ (ztree-diff-node-update-all-parents-diff node)
+ (ztree-refresh-buffer (line-number-at-pos)))))))
+
+
+(defun ztree-diff-copy-dir (node source-path destination-path copy-to-right)
+ (let* ((src-path (file-name-as-directory source-path))
+ (target-path (file-name-as-directory destination-path))
+ (target-full-path (concat
+ target-path
+ (file-name-nondirectory
+ (directory-file-name source-path)))))
+ (let ((err (condition-case error-trap
+ (progn
+ ;; keep time stamp
+ ;; ask for overwrite
+ (copy-directory src-path target-path t t)
+ nil)
+ (error error-trap))))
+ ;; error message if failed
+ (if err (message (concat "Error: " (nth 1 err)))
+ (progn
+ (message target-full-path)
+ (if copy-to-right
+ (ztree-diff-node-set-right-path node
+ target-full-path)
+ (ztree-diff-node-set-left-path node
+ target-full-path))
+ (ztree-diff-model-update-node node)
+ (ztree-diff-node-update-all-parents-diff node)
+ (ztree-refresh-buffer (line-number-at-pos)))))))
+
(defun ztree-diff-copy ()
(interactive)
@@ -166,30 +217,14 @@ including . and ..")
(if copy-to-right "RIGHT" "LEFT")
destination-path)))
(if (file-directory-p source-path)
- nil ; TODO: implement directory copy
- (let ((target-path (concat
- (file-name-as-directory destination-path)
- (file-name-nondirectory
- (directory-file-name source-path)))))
- (let ((err (condition-case error-trap
- (progn
- ;; ask for overwrite
- ;; keep time stamp
- (copy-file source-path target-path 1 t)
- nil)
- (error error-trap))))
- ;; error message if failed
- (if err (message (concat "Error: " (nth 2 err)))
- (progn ; otherwise:
- ;; assuming all went ok when left and right nodes are
the same
- ;; set both as not different
- (ztree-diff-node-set-different node nil)
- ;; update left/right paths
- (if copy-to-right
- (ztree-diff-node-set-right-path node target-path)
- (ztree-diff-node-set-left-path node target-path))
- (ztree-refresh-buffer (line-number-at-pos)))))))))))))
-
+ (ztree-diff-copy-dir node
+ source-path
+ destination-path
+ copy-to-right)
+ (ztree-diff-copy-file node
+ source-path
+ destination-path
+ copy-to-right))))))))
(defun ztree-diff (dir1 dir2)
"Creates an interactive buffer with the directory tree of the path given"
@@ -203,7 +238,7 @@ including . and ..")
'ztree-diff-insert-buffer-header
'ztree-diff-node-short-name
'ztree-diff-node-is-directory
- 'equal
+ 'ztree-diff-node-equal
'ztree-diff-node-children
'ztree-diff-node-face
'ztree-diff-node-action
- [elpa] master 291a115 32/92: Header is now customizable, (continued)
- [elpa] master 291a115 32/92: Header is now customizable, Alexey Veretennikov, 2015/06/11
- [elpa] master f9620df 34/92: Added action on modified files, Alexey Veretennikov, 2015/06/11
- [elpa] master 900c8fa 38/92: Refactored using defrecord macro, Alexey Veretennikov, 2015/06/11
- [elpa] master 6154ab8 21/92: Split view and models - for directory tree and for diff tree, Alexey Veretennikov, 2015/06/11
- [elpa] master 8335785 39/92: Added comment, Alexey Veretennikov, 2015/06/11
- [elpa] master 1ab3b48 43/92: Implemented file copying, Alexey Veretennikov, 2015/06/11
- [elpa] master af28a78 41/92: Started implementation of the copy functionality, Alexey Veretennikov, 2015/06/11
- [elpa] master 75b89a6 48/92: Fixed typo, Alexey Veretennikov, 2015/06/11
- [elpa] master 725f388 42/92: Preparation to copy implementation done, Alexey Veretennikov, 2015/06/11
- [elpa] master f78b859 47/92: Updated readme, Alexey Veretennikov, 2015/06/11
- [elpa] master 20d8217 44/92: Implemented directory copying,
Alexey Veretennikov <=
- [elpa] master d590f88 40/92: Added minor mode for ztree diff, to create custom keybindings, Alexey Veretennikov, 2015/06/11
- [elpa] master 81b6a4b 49/92: Added delete functionality, Alexey Veretennikov, 2015/06/11
- [elpa] master c3580db 46/92: Updated readme; renamed the ztree to ztree-dir, Alexey Veretennikov, 2015/06/11
- [elpa] master 3867ed3 45/92: Implemented support for hiding matched(equal) files, Alexey Veretennikov, 2015/06/11
- [elpa] master 15baed9 50/92: Repaired full rescan; added 'v' keybinding to quickly view files, Alexey Veretennikov, 2015/06/11
- [elpa] master 7f1ec58 53/92: Fixed topmost name in comparison tree, Alexey Veretennikov, 2015/06/11
- [elpa] master 56dce0e 51/92: Updated README, Alexey Veretennikov, 2015/06/11
- [elpa] master d791ebe 54/92: Readme is updated, Alexey Veretennikov, 2015/06/11
- [elpa] master 8ba9ca2 55/92: Added simple diff by using SPACE, Alexey Veretennikov, 2015/06/11
- [elpa] master c816a66 56/92: Updated readme, Alexey Veretennikov, 2015/06/11