git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [EGIT PATCH] Show diffs for changed files under a new or deleted directory.
@ 2008-02-17 15:55 Roger C. Soares
  2008-02-17 15:05 ` Robin Rosenberg
  0 siblings, 1 reply; 4+ messages in thread
From: Roger C. Soares @ 2008-02-17 15:55 UTC (permalink / raw)
  To: git; +Cc: robin.rosenberg, Roger C. Soares

When a directory is added or removed in a commit the files under it 
were not being shown in the structure compare viewer. This fixes it by
adding diff nodes for all the files under this directory.

This patch also fixes some files showing as being removed in the
structure compare when they were actually being added.

Signed-off-by: Roger C. Soares <rogersoares@intelinet.com.br>
---
Hi Robin,

What is "TODO: Git ordering" supposed to change?

Please evaluate.

[]s,
Roger.


 .../GitCompareFileRevisionEditorInput.java         |   79 +++++++++++++++++---
 1 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java
index d3bc92a..d72093b 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/GitCompareFileRevisionEditorInput.java
@@ -122,30 +122,65 @@ public class GitCompareFileRevisionEditorInput extends CompareEditorInput {
 			while (li<lc.length && ri<rc.length) {
 				ITypedElement ln = lc[li];
 				ITypedElement rn = rc[ri];
+				int compareTo = ln.getName().compareTo(rn.getName());
 				// TODO: Git ordering!
-				if (ln.getName().compareTo(rn.getName()) < 0) {
-					diffNode.add(new DiffNode(Differencer.ADDITION,null, ln, null));
-					++li;
-				}
-				if (ln.getName().compareTo(rn.getName()) > 0) {
-					diffNode.add(new DiffNode(Differencer.DELETION,null, null, rn));
-					++ri;
-				}
-				if (ln.getName().compareTo(rn.getName()) == 0) {
+				if (compareTo == 0) {
 					if (!ln.equals(rn))
 						diffNode.add(compare(ln,rn));
 					++li;
 					++ri;
+				} else if (compareTo < 0) {
+					DiffNode childDiffNode = new DiffNode(Differencer.ADDITION, null, ln, null);
+					diffNode.add(childDiffNode);
+					if (ln.getType().equals(ITypedElement.FOLDER_TYPE)) {
+						ITypedElement[] children = (ITypedElement[])((IStructureComparator)ln).getChildren();
+						if(children != null && children.length > 0) {
+							for (ITypedElement child : children) {
+								childDiffNode.add(addDirectoryFiles(child, Differencer.ADDITION));
+							}
+						}
+					}
+					++li;
+				} else {
+					DiffNode childDiffNode = new DiffNode(Differencer.DELETION, null, null, rn);
+					diffNode.add(childDiffNode);
+					if (rn.getType().equals(ITypedElement.FOLDER_TYPE)) {
+						ITypedElement[] children = (ITypedElement[])((IStructureComparator)rn).getChildren();
+						if(children != null && children.length > 0) {
+							for (ITypedElement child : children) {
+								childDiffNode.add(addDirectoryFiles(child, Differencer.DELETION));
+							}
+						}
+					}
+					++ri;
 				}
 			}
 			while (li<lc.length) {
 				ITypedElement ln = lc[li];
-				diffNode.add(new DiffNode(Differencer.ADDITION,null, ln, null));
+				DiffNode childDiffNode = new DiffNode(Differencer.ADDITION, null, ln, null);
+				diffNode.add(childDiffNode);
+				if (ln.getType().equals(ITypedElement.FOLDER_TYPE)) {
+					ITypedElement[] children = (ITypedElement[])((IStructureComparator)ln).getChildren();
+					if(children != null && children.length > 0) {
+						for (ITypedElement child : children) {
+							childDiffNode.add(addDirectoryFiles(child, Differencer.ADDITION));
+						}
+					}
+				}
 				++li;
 			}
 			while (ri<rc.length) {
 				ITypedElement rn = rc[ri];
-				diffNode.add(new DiffNode(Differencer.ADDITION,null, null, rn));
+				DiffNode childDiffNode = new DiffNode(Differencer.DELETION, null, null, rn);
+				diffNode.add(childDiffNode);
+				if (rn.getType().equals(ITypedElement.FOLDER_TYPE)) {
+					ITypedElement[] children = (ITypedElement[])((IStructureComparator)rn).getChildren();
+					if(children != null && children.length > 0) {
+						for (ITypedElement child : children) {
+							childDiffNode.add(addDirectoryFiles(child, Differencer.DELETION));
+						}
+					}
+				}
 				++ri;
 			}
 			return diffNode;
@@ -154,6 +189,28 @@ public class GitCompareFileRevisionEditorInput extends CompareEditorInput {
 		}
 	}
 
+	private DiffNode addDirectoryFiles(ITypedElement elem, int diffType) {
+		ITypedElement l = null;
+		ITypedElement r = null;
+		if (diffType == Differencer.DELETION) {
+			r = elem;
+		} else {
+			l = elem;
+		}
+
+		if (elem.getType().equals(ITypedElement.FOLDER_TYPE)) {
+			DiffNode diffNode = null;
+			diffNode = new DiffNode(null,Differencer.CHANGE,null,l,r);
+			ITypedElement[] children = (ITypedElement[])((IStructureComparator)elem).getChildren();
+			for (ITypedElement child : children) {
+				diffNode.add(addDirectoryFiles(child, diffType));
+			}
+			return diffNode;
+		} else {
+			return new DiffNode(diffType, null, l, r);
+		}
+	}
+
 	private void initLabels(ICompareInput input) {
 		CompareConfiguration cc = getCompareConfiguration();
 		if(left != null && left instanceof GitResourceNode) {
-- 
1.5.3.8

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-18  6:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-17 15:55 [EGIT PATCH] Show diffs for changed files under a new or deleted directory Roger C. Soares
2008-02-17 15:05 ` Robin Rosenberg
2008-02-18  5:01   ` Roger C. Soares
2008-02-18  6:44     ` Robin Rosenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).