[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c3144bd 16/36: Updated model - ignored files still not han
From: |
Alexey Veretennikov |
Subject: |
[elpa] master c3144bd 16/36: Updated model - ignored files still not handled |
Date: |
Wed, 27 Jan 2016 23:50:54 +0000 |
branch: master
commit c3144bdd8b87bf0ce8e8005b0509e37ea7a44e20
Author: Alexey Veretennikov <address@hidden>
Commit: Alexey Veretennikov <address@hidden>
Updated model - ignored files still not handled
---
ztree-diff-model.el | 75 ++++++++++++++++++++++++++++-----------------------
ztree-diff.el | 30 ++++++++++++--------
2 files changed, 59 insertions(+), 46 deletions(-)
diff --git a/ztree-diff-model.el b/ztree-diff-model.el
index 0801e55..a3711df 100644
--- a/ztree-diff-model.el
+++ b/ztree-diff-model.el
@@ -53,7 +53,7 @@
;; right-path is the full path of the right side,
;; short-name - is the file or directory name
;; children - list of nodes - files or directories if the node is a directory
-;; different = {nil, 'new, 'diff, 'ignore} - means comparison status
+;; different = {nil, 'same, 'new, 'diff, 'ignore} - means comparison status
(ztree-defrecord ztree-diff-node (parent left-path right-path short-name
right-short-name children different))
(defun ztree-diff-model-ignore-p (node)
@@ -63,17 +63,20 @@
(defun ztree-diff-node-to-string (node)
"Construct the string with contents of the NODE given."
- (let* ((string-or-nil #'(lambda (x) (if x
- (cond ((stringp x) x)
- ((eq x 'new) "new")
- ((eq x 'diff) "different")
- ((eq x 'ignore) "ignored")
- (t (ztree-diff-node-short-name
x)))
- "(empty)")))
- (children (ztree-diff-node-children node))
- (ch-str ""))
+ (let ((string-or-nil #'(lambda (x) (if x
+ (cond ((stringp x) x)
+ ((eq x 'new) "new")
+ ((eq x 'diff) "different")
+ ((eq x 'ignore) "ignored")
+ ((eq x 'same) "same")
+ (t (ztree-diff-node-short-name
x)))
+ "(empty)")))
+ (children (ztree-diff-node-children node))
+ (ch-str ""))
(dolist (x children)
- (setq ch-str (concat ch-str "\n * " (ztree-diff-node-short-name x))))
+ (setq ch-str (concat ch-str "\n * " (ztree-diff-node-short-name x)
+ ": "
+ (funcall string-or-nil (ztree-diff-node-different
x)))))
(concat "Node: " (ztree-diff-node-short-name node)
"\n"
;; " * Parent: " (let ((parent (ztree-diff-node-parent node)))
@@ -141,7 +144,7 @@ RIGHT if only on the right side."
Returns t if equal."
(let* ((file1-untrampified (ztree-diff-untrampify-filename
(ztree-diff-modef-quotify-string file1)))
(file2-untrampified (ztree-diff-untrampify-filename
(ztree-diff-modef-quotify-string file2)))
- (diff-command (concat diff-command "-q" " " file1-untrampified " "
file2-untrampified))
+ (diff-command (concat diff-command " -q" " " file1-untrampified " "
file2-untrampified))
(diff-output (shell-command-to-string diff-command)))
(not (> (length diff-output) 2))))
@@ -171,7 +174,7 @@ Filters out . and .."
(ztree-diff-node-set-different
node
(if (ztree-diff-model-files-equal left right)
- nil
+ 'same
'diff))))))
(defun ztree-diff-model-subtree (parent path side diff)
@@ -224,13 +227,21 @@ Argument SIDE either 'left or 'right side."
(defun ztree-diff-model-update-diff (old new)
- "Get the diff status depending if OLD or NEW is not nil."
- (if new
- (if (or (not old)
- (eq old 'new))
- new
- old)
- old))
+ "Get the diff status depending if OLD or NEW is not nil.
+If the OLD is 'ignore, do not change anything"
+ ;; if the old whole directory is ignored, ignore children's status
+ (cond ((eql old 'ignore) 'ignore)
+ ;; if the new status is ignored, use old
+ ((eql new 'ignore) old)
+ ;; if the old or new status is different, return different
+ ((or (eql old 'diff)
+ (eql new 'diff)) 'diff)
+ ;; if new is 'new, return new
+ ((eql new 'new) 'new)
+ ;; all other cases return old
+ (t old)))
+
+
(defun ztree-diff-node-traverse (parent)
"Traverse 2 paths creating the list nodes with PARENT defined and diff
status.
@@ -241,7 +252,8 @@ the rest is the combined list of nodes."
(path2 (ztree-diff-node-right-path parent))
(list1 (ztree-directory-files path1)) ;; left list of liles
(list2 (ztree-directory-files path2)) ;; right list of files
- (diff-parent (ztree-diff-node-different parent)) ;; status of this
node
+ (diff-parent (when parent (ztree-diff-node-different parent))) ;;
status of this node
+ (diff-status 'same) ;; status of this node
(children nil) ;; children
;; helper function to find if the same file exists
;; on the other side
@@ -274,16 +286,10 @@ the rest is the combined list of nodes."
;; if exists on both sides and it is a file, compare
((and file2 (not (file-directory-p file1)))
(ztree-diff-node-set-different node
- (if (ztree-diff-model-files-equal
file1 file2) nil 'diff)))
+ (if (ztree-diff-model-files-equal
file1 file2) 'same 'diff)))
;; if exists on both sides and it is a directory, traverse further
((and file2 (file-directory-p file1))
(ztree-diff-node-traverse node)))
- ;; update difference status for the whole comparison
- ;; depending if the node should participate in overall result
- (unless (ztree-diff-model-ignore-p node)
- (setq diff-parent
- (ztree-diff-model-update-diff diff-parent
- (ztree-diff-node-different
node))))
;; push the created node to the result list
(push node children)))
;; second - adding entries from the right directory which are not present
@@ -304,17 +310,19 @@ the rest is the combined list of nodes."
(when (file-directory-p file2)
(ztree-diff-node-set-children node
(ztree-diff-model-subtree node file2
'right 'new)))
- ;; update the different status for the whole comparison
- ;; depending if the node should participate in overall result
- (unless (ztree-diff-model-ignore-p node)
- (setq diff-parent (ztree-diff-model-update-diff diff-parent 'new)))
;; push the created node to the result list
(push node children))))
;; finally set different status based on all children
- (ztree-diff-node-set-different parent diff-parent)
+ ;; depending if the node should participate in overall result
+ (setq diff-status (cl-reduce 'ztree-diff-model-update-diff
+ children
+ :initial-value diff-status
+ :key 'ztree-diff-node-different))
+ (ztree-diff-node-set-different parent diff-status)
;; and set children
(ztree-diff-node-set-children parent children)))
+
(defun ztree-diff-model-create (dir1 dir2 &optional ignore-p)
"Create a node based on DIR1 and DIR2.
IGNORE-P is the optional filtering function, taking node as
@@ -333,7 +341,6 @@ from comparison."
nil
nil)))
(ztree-diff-node-traverse model)
- (message (ztree-diff-node-to-string model))
(message "Done.")
model))
diff --git a/ztree-diff.el b/ztree-diff.el
index c2ad76f..14c336e 100644
--- a/ztree-diff.el
+++ b/ztree-diff.el
@@ -120,7 +120,7 @@ By default paths starting with dot (like .git) are ignored")
(cond ((eq diff 'ignore) ztreep-diff-model-ignored-face)
((eq diff 'diff) ztreep-diff-model-diff-face)
((eq diff 'new) ztreep-diff-model-add-face)
- (t ztreep-diff-model-normal-face))))
+ ((eq diff 'same) ztreep-diff-model-normal-face))))
(defun ztree-diff-insert-buffer-header ()
"Insert the header to the ztree buffer."
@@ -235,7 +235,7 @@ Argument NODE node containing paths to files to call a diff
on."
(let ((split-width-threshold nil))
(view-file-other-window path))))))
(cond ((and left right)
- (if (not (ztree-diff-node-different node))
+ (if (eql (ztree-diff-node-different node) 'same)
(funcall open-f left)
(if hard
(ediff left right)
@@ -267,7 +267,7 @@ COPY-TO-RIGHT specifies which side of the NODE to update."
;; assuming all went ok when left and right nodes are the same
;; set both as not different if they were not ignored
(unless (eq (ztree-diff-node-different node) 'ignore)
- (ztree-diff-node-set-different node nil))
+ (ztree-diff-node-set-different node 'same))
;; update left/right paths
(if copy-to-right
(ztree-diff-node-set-right-path node target-path)
@@ -447,28 +447,34 @@ unless it is a parent node."
(defun ztree-node-is-visible (node)
"Determine if the NODE should be visible."
(let ((diff (ztree-diff-node-different node)))
+ t))
;; visible then
;; 1) either it is a parent
- (or (ztree-diff-node-parent node) ; parent is always visible
- ;; 2.1) or it is not in ignore list and
- (and (eq diff 'ignore)
- ztree-diff-show-filtered-files) ; show filtered files regardless
- ;; 2.2) it has different status
- (and ztree-diff-show-equal-files ; show equal files regardless
- (not diff))
- (or (eq diff 'new)
- (eq diff 'diff)))))
+ ;; (or (ztree-diff-node-parent node) ; parent is always visible
+ ;; nil)))
+ ;; ;; 2.1) or it is not in ignore list and
+ ;; (and (eql diff 'ignore)
+ ;; ztree-diff-show-filtered-files) ; show filtered files
regardless
+ ;; ;; 2.2) it has different status
+ ;; (and
+ ;; (not (eql diff 'same)))
+ ;; ;ztree-diff-show-equal-files) ; show equal files regardless
+
+ ;; (or (eql diff 'new)
+ ;; (eql diff 'diff)))))
(defun ztree-diff-toggle-show-equal-files ()
"Toggle visibility of the equal files."
(interactive)
(setq ztree-diff-show-equal-files (not ztree-diff-show-equal-files))
+ (message (concat (if ztree-diff-show-equal-files "Show" "Hide") " equal
files"))
(ztree-refresh-buffer))
(defun ztree-diff-toggle-show-filtered-files ()
"Toggle visibility of the filtered files."
(interactive)
(setq ztree-diff-show-filtered-files (not ztree-diff-show-filtered-files))
+ (message (concat (if ztree-diff-show-filtered-files "Show" "Hide") "
filtered files"))
(ztree-refresh-buffer))
- [elpa] master 6018029 11/36: Started updating diff logic to include ignored files, (continued)
- [elpa] master 6018029 11/36: Started updating diff logic to include ignored files, Alexey Veretennikov, 2016/01/27
- [elpa] master c227ed8 12/36: Added debug output and some other changes, Alexey Veretennikov, 2016/01/27
- [elpa] master 64d3960 13/36: Added face for ignored files, Alexey Veretennikov, 2016/01/27
- [elpa] master 45dda44 14/36: Started updating diff logic to include ignored files, Alexey Veretennikov, 2016/01/27
- [elpa] master 2dc412f 15/36: Added debug output and some other changes, Alexey Veretennikov, 2016/01/27
- [elpa] master 9408ca1 17/36: Fixed ztree-node-is-visible, Alexey Veretennikov, 2016/01/27
- [elpa] master eea3c2b 19/36: added comments, Alexey Veretennikov, 2016/01/27
- [elpa] master cef7d95 20/36: Functions with errors still:, Alexey Veretennikov, 2016/01/27
- [elpa] master 653a7f1 21/36: Fixed ignored files, Alexey Veretennikov, 2016/01/27
- [elpa] master a27dbbd 22/36: Started to fix issues with delete file, Alexey Veretennikov, 2016/01/27
- [elpa] master c3144bd 16/36: Updated model - ignored files still not handled,
Alexey Veretennikov <=
- [elpa] master bc6a12a 18/36: Traverse function now supports ignored, Alexey Veretennikov, 2016/01/27
- [elpa] master b021697 29/36: Added comment to not to forget to update copy procedure., Alexey Veretennikov, 2016/01/27
- [elpa] master da721ab 33/36: Fixed compile warnings, Alexey Veretennikov, 2016/01/27
- [elpa] master be4e000 24/36: Fix typo in value of Created header keyword, Alexey Veretennikov, 2016/01/27
- [elpa] master b5b2d02 32/36: removed test files, Alexey Veretennikov, 2016/01/27
- [elpa] master 74899aa 30/36: Merge branch 'master' of github.com:fourier/ztree, Alexey Veretennikov, 2016/01/27
- [elpa] master 6d7ce1f 28/36: Fixed Delete method, Alexey Veretennikov, 2016/01/27
- [elpa] master 3d70aef 25/36: Merge pull request #30 from tarsius/fix-typo, Alexey Veretennikov, 2016/01/27
- [elpa] master 159ddbd 26/36: Fixed partial update, Alexey Veretennikov, 2016/01/27
- [elpa] master a7c5489 35/36: Upgraded version number, Alexey Veretennikov, 2016/01/27