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@xxxxxxxxxxxxxxxx> --- 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 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html