{"thread":{"id":"12799","subject":"[EGIT PATCH 4/4] Show changed files in the revision detail viewer.","startedAt":"2008-03-21T22:08:31Z","lastAt":"2008-03-21T22:08:31Z","messageCount":1,"participants":["Roger C. Soares"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"72623","messageId":"1206137311-4097-1-git-send-email-rogersoares@intelinet.com.br","threadId":"12799","inReplyTo":null,"subject":"[EGIT PATCH 4/4] Show changed files in the revision detail viewer.","fromName":"Roger C. Soares","fromEmail":"rogersoares@intelinet.com.br","sentAt":"2008-03-21T22:08:31Z","receivedAt":"2008-03-21T22:08:31Z","isPatch":true,"sender":{"key":"rogersoares@intelinet.com.br","avatar":null},"body":"Shows files changed from the parent commits in the revision detail viewer.\nIt gives a better idea of the impact of a commit when browsing the\nhistory.\n\nSigned-off-by: Roger C. Soares <rogersoares@intelinet.com.br>\n---\n .../org/spearce/egit/ui/RevisionInfoThread.java    |  130 ++++++++++++++++++++\n 1 files changed, 130 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/RevisionInfoThread.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/RevisionInfoThread.java\nindex 27fd87f..f5d5754 100644\n--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/RevisionInfoThread.java\n+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/RevisionInfoThread.java\n@@ -16,6 +16,7 @@\n  */\n package org.spearce.egit.ui;\n \n+import java.io.IOException;\n import java.util.Set;\n import java.util.concurrent.CancellationException;\n \n@@ -29,6 +30,8 @@ import org.spearce.egit.core.util.CommitMetaInfo;\n import org.spearce.egit.core.util.RepositoryUtil;\n import org.spearce.jgit.lib.Commit;\n import org.spearce.jgit.lib.ObjectId;\n+import org.spearce.jgit.lib.Tree;\n+import org.spearce.jgit.lib.TreeEntry;\n \n /**\n  * This class prints info the revisionInfo viewer that may take some time to be\n@@ -132,6 +135,39 @@ public class RevisionInfoThread extends Thread implements IProgressMonitor {\n \t\t\t\t}\n \t\t\t\tmetaInfo.append(\"\\n\");\n \t\t\t}\n+\n+\t\t\tif (revThread.currentThreadIx < globalThreadIx) {\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t\tprint(revThread, metaInfo, null);\n+\n+\t\t\t// List changed files.\n+\t\t\tObjectId[] parentIds = commit.getParentIds();\n+\t\t\tif (parentIds.length > 0) {\n+\t\t\t\tCommit current = revThread.repositoryMapping.getRepository()\n+\t\t\t\t\t\t.mapCommit(revThread.rev.getCommitId());\n+\t\t\t\tint count = 0;\n+\t\t\t\tfor (ObjectId parentId : parentIds) {\n+\t\t\t\t\tCommit previous = revThread.repositoryMapping\n+\t\t\t\t\t\t\t.getRepository().mapCommit(parentId);\n+\n+\t\t\t\t\tStringBuilder changedFiles;\n+\t\t\t\t\tchangedFiles = compare(current.getTree(), previous\n+\t\t\t\t\t\t\t.getTree(), revThread);\n+\t\t\t\t\tmetaInfo.append(\"\\n\");\n+\t\t\t\t\tmetaInfo.append(\"Files changed from \");\n+\t\t\t\t\tmetaInfo.append(revThread.parentDescs[count]);\n+\t\t\t\t\tmetaInfo.append(\":\\n\");\n+\t\t\t\t\tmetaInfo.append(changedFiles);\n+\n+\t\t\t\t\tcount++;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tmetaInfo.append(\"\\n\");\n+\t\t\t\tmetaInfo.append(\"Initial commit\");\n+\t\t\t\tmetaInfo.append(\":\\n\");\n+\t\t\t\taddDirectoryFiles(metaInfo, revThread.rev.getTreeEntry(), true);\n+\t\t\t}\n \t\t} catch (CancellationException e) {\n \t\t\treturn;\n \t\t} catch (Exception e) {\n@@ -173,6 +209,100 @@ public class RevisionInfoThread extends Thread implements IProgressMonitor {\n \t\t});\n \t}\n \n+\tprivate static String ADDED_MARK = \"+\\t\";\n+\n+\tprivate static String DELETED_MARK = \"-\\t\";\n+\n+\tprivate static String MODIFIED_MARK = \"\\t\";\n+\n+\tprivate static StringBuilder compare(Tree current, Tree parent,\n+\t\t\tRevisionInfoThread revThread) throws IOException,\n+\t\t\tCancellationException {\n+\t\tStringBuilder sb = new StringBuilder();\n+\t\tTreeEntry[] c = current.members();\n+\t\tTreeEntry[] p = parent.members();\n+\t\tint cix = 0;\n+\t\tint pix = 0;\n+\n+\t\twhile (cix < c.length && pix < p.length) {\n+\t\t\tTreeEntry compC = c[cix];\n+\t\t\tTreeEntry compP = p[pix];\n+\t\t\tint compareTo = compC.getName().compareTo(compP.getName());\n+\t\t\tif (compareTo == 0) {\n+\t\t\t\tif (!compC.getId().equals(compP.getId())) {\n+\t\t\t\t\tif (compC instanceof Tree && compP instanceof Tree) {\n+\t\t\t\t\t\tsb\n+\t\t\t\t\t\t\t\t.append(compare((Tree) compC, (Tree) compP,\n+\t\t\t\t\t\t\t\t\t\trevThread));\n+\t\t\t\t\t} else if (compC instanceof Tree) {\n+\t\t\t\t\t\tsb.append(DELETED_MARK);\n+\t\t\t\t\t\tsb.append(compP.getFullName());\n+\t\t\t\t\t\tsb.append(\"\\n\");\n+\t\t\t\t\t\taddDirectoryFiles(sb, compC, true);\n+\t\t\t\t\t} else if (compP instanceof Tree) {\n+\t\t\t\t\t\taddDirectoryFiles(sb, compP, false);\n+\t\t\t\t\t\tsb.append(ADDED_MARK);\n+\t\t\t\t\t\tsb.append(compC.getFullName());\n+\t\t\t\t\t\tsb.append(\"\\n\");\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\tsb.append(MODIFIED_MARK);\n+\t\t\t\t\t\tsb.append(compC.getFullName());\n+\t\t\t\t\t\tsb.append(\"\\n\");\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tcix++;\n+\t\t\t\tpix++;\n+\t\t\t} else if (compareTo < 0) {\n+\t\t\t\taddDirectoryFiles(sb, compC, true);\n+\t\t\t\tcix++;\n+\t\t\t} else {\n+\t\t\t\taddDirectoryFiles(sb, compP, false);\n+\t\t\t\tpix++;\n+\t\t\t}\n+\t\t\tif (revThread.currentThreadIx < globalThreadIx) {\n+\t\t\t\tthrow new CancellationException(\"getCommitMetaInfo cancelled\");\n+\t\t\t}\n+\t\t}\n+\t\twhile (cix < c.length) {\n+\t\t\taddDirectoryFiles(sb, c[cix], true);\n+\t\t\tcix++;\n+\t\t}\n+\t\twhile (pix < p.length) {\n+\t\t\taddDirectoryFiles(sb, p[pix], false);\n+\t\t\tpix++;\n+\t\t}\n+\n+\t\treturn sb;\n+\t}\n+\n+\tprivate static void addDirectoryFiles(StringBuilder sb, TreeEntry te,\n+\t\t\tboolean isAdd) throws IOException {\n+\t\tif (te instanceof Tree) {\n+\t\t\tTreeEntry[] members = ((Tree) te).members();\n+\t\t\tfor (TreeEntry member : members) {\n+\t\t\t\tif (member instanceof Tree) {\n+\t\t\t\t\taddDirectoryFiles(sb, member, isAdd);\n+\t\t\t\t} else {\n+\t\t\t\t\tif (isAdd) {\n+\t\t\t\t\t\tsb.append(ADDED_MARK);\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\tsb.append(DELETED_MARK);\n+\t\t\t\t\t}\n+\t\t\t\t\tsb.append(member.getFullName());\n+\t\t\t\t\tsb.append(\"\\n\");\n+\t\t\t\t}\n+\t\t\t}\n+\t\t} else {\n+\t\t\tif (isAdd) {\n+\t\t\t\tsb.append(ADDED_MARK);\n+\t\t\t} else {\n+\t\t\t\tsb.append(DELETED_MARK);\n+\t\t\t}\n+\t\t\tsb.append(te.getFullName());\n+\t\t\tsb.append(\"\\n\");\n+\t\t}\n+\t}\n+\n \tstatic void updateGlobalThreadIx() {\n \t\t++globalThreadIx;\n \t}\n-- \n1.5.4.1\n"}]}