From f6c5df64bb40f07e18309c7400a8f3d37fa97629 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 9 May 2007 00:15:56 +0200 Subject: [PATCH] Show tags in history view Put some content into the Tags field in the history browser. Besides tags we put matching branch names there too. Signed-off-by: Robin Rosenberg --- .../src/org/spearce/egit/ui/GitHistoryPage.java | 85 ++++++++++++++++++++-- .../src/org/spearce/jgit/lib/Repository.java | 2 +- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java index e5d92fed..8850405e 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java @@ -18,6 +18,7 @@ package org.spearce.egit.ui; import java.io.IOException; import java.util.Date; +import java.util.HashMap; import java.util.Map; import org.eclipse.compare.CompareConfiguration; @@ -78,6 +79,7 @@ import org.spearce.egit.core.project.RepositoryMapping; import org.spearce.egit.ui.internal.actions.GitCompareRevisionAction; import org.spearce.jgit.lib.Commit; import org.spearce.jgit.lib.ObjectId; +import org.spearce.jgit.lib.Tag; import org.spearce.jgit.lib.Repository.StGitPatch; public class GitHistoryPage extends HistoryPage implements IAdaptable, @@ -145,7 +147,7 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, if (item != null && item!=lastItem) { IFileRevision rev = (IFileRevision) item.getData(); String commitStr=null; - if (appliedPatches!=null) { + if (rev!=null && appliedPatches!=null) { String id = rev.getContentIdentifier(); if (!id.equals("Workspace")) { StGitPatch patch = (StGitPatch) appliedPatches.get(new ObjectId(id)); @@ -275,8 +277,34 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, return id + "@.." + rs; } - if (columnIndex == 2) - return ""; // TAGS + if (columnIndex == 2) { + String id = ((IFileRevision)element).getContentIdentifier(); + ObjectId oid = new ObjectId(id); + StringBuilder b=new StringBuilder(); + if (tags != null) { + Tag[] matching = tags.get(oid); + if (matching != null) { + for (Tag t : matching) { + if (b.length() > 0) + b.append(' '); + b.append(t.getTag()); + } + } + } + if (branches != null) { + if (b.length() >0) + b.append('\n'); + String[] matching = branches.get(oid); + if (matching != null) { + for (String t : matching) { + if (b.length() > 0) + b.append(' '); + b.append(t); + } + } + } + return b.toString(); + } if (columnIndex == 3) { Date d = new Date(((IFileRevision) element).getTimestamp()); @@ -352,6 +380,8 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, } private Map appliedPatches; + private Map tags; + private Map branches; class HistoryRefreshJob extends Job { @@ -373,6 +403,48 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, // TODO Auto-generated catch block e.printStackTrace(); } + Map newtags = new HashMap(); + try { + for (String name : repositoryMapping.getRepository().getTags()) { + Tag t = repositoryMapping.getRepository().mapTag(name); + Tag[] samecommit = newtags.get(t.getObjId()); + if (samecommit==null) { + samecommit = new Tag[] { t }; + } else { + Tag[] n=new Tag[samecommit.length+1]; + for (int j=0; j newBranches = new HashMap(); + try { + for (String branch : repositoryMapping.getRepository().getBranches()) { + ObjectId id = repositoryMapping.getRepository().resolve("refs/heads/"+branch); + String[] samecommit = newBranches.get(id); + if (samecommit == null) { + samecommit = new String[] { branch }; + } else { + String[] n=new String[samecommit.length + 1]; + for (int j=0; j ftags = newtags; + tree.getDisplay().asyncExec(new Runnable() { public void run() { @@ -389,8 +463,9 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, tree.setData(fileRevisions); tree.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true)); System.out.println("inputchanged, invoking refresh"); - viewer.refresh(); appliedPatches = fnewappliedPatches; + tags = ftags; + viewer.refresh(); done(Status.OK_STATUS); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 3b2a82cf..12beb880 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -470,7 +470,7 @@ public class Repository { return ref; } - public Collection getBranches() { + public Collection getBranches() { return listFilesRecursively(new File(refsDir, "heads"), null); } -- 2.11.4.GIT