Substitute commit id for patch name if a commit represents a patch state. Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> --- .../src/org/spearce/egit/ui/GitHistoryPage.java | 20 ++++++++++++ .../src/org/spearce/jgit/lib/Repository.java | 38 +++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 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 5655105..c72e1f1 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.Map; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.structuremergeviewer.ICompareInput; @@ -69,6 +70,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.Repository.StGitPatch; public class GitHistoryPage extends HistoryPage implements IAdaptable, IHistoryCompareAdapter { @@ -198,6 +200,11 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, String rss = ((IFileRevision) element).getURI().toString(); String rs = rss.substring(rss.length()-10); String id = ((IFileRevision) element).getContentIdentifier(); + if (appliedPatches!=null) { + StGitPatch patch = (StGitPatch) appliedPatches.get(new ObjectId(id)); + if (patch!=null) + return patch.getName(); + } if (id != null) if (id.length() > 9) // make sure "Workspace" is spelled out return id.substring(0, 7) + ".."; @@ -280,6 +287,8 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, viewer.setInput(getInput()); } + private Map appliedPatches; + class GitHistoryContentProvider implements ITreeContentProvider, ILazyTreeContentProvider { @@ -288,8 +297,17 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable, return; System.out.println("inputChanged(" + viewer + "," + oldInput + "," + newInput); + IProject project = ((IResource) getInput()).getProject(); RepositoryProvider provider = RepositoryProvider - .getProvider(((IResource) getInput()).getProject()); + .getProvider(project); + RepositoryMapping repositoryMapping = ((GitProvider)provider).getData().getRepositoryMapping(project); + try { + appliedPatches = null; + appliedPatches = repositoryMapping.getRepository().getAppliedPatches(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } IFileHistoryProvider fileHistoryProvider = provider .getFileHistoryProvider(); IFileHistory fileHistoryFor = fileHistoryProvider 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 5c31092..501dcc8 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -27,6 +27,7 @@ import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import java.util.WeakHashMap; @@ -477,6 +478,43 @@ public class Repository { } } + public static class StGitPatch { + public StGitPatch(String patchName, ObjectId id) { + name = patchName; + gitId = id; + } + public ObjectId getGitId() { + return gitId; + } + public String getName() { + return name; + } + private String name; + private ObjectId gitId; + } + + /** + * @return applied patches in a map indexed on current commit id + * @throws IOException + */ + public Map getAppliedPatches() throws IOException { + Map ret = new HashMap(); + if (isStGitMode()) { + File patchDir = new File(new File(getDirectory(),"patches"),getBranch()); + BufferedReader apr = new BufferedReader(new FileReader(new File(patchDir,"applied"))); + for (String patchName=apr.readLine(); patchName!=null; patchName=apr.readLine()) { + File topFile = new File(new File(new File(patchDir,"patches"), patchName), "top"); + BufferedReader tfr = new BufferedReader(new FileReader(topFile)); + String objectId = tfr.readLine(); + ObjectId id = new ObjectId(objectId); + ret.put(id, new StGitPatch(patchName, id)); + tfr.close(); + } + apr.close(); + } + return ret; + } + private Collection listFilesRecursively(File root, File start) { if (start == null) start = root; - 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