[EGIT PATCH 6/9] Add branch and StGit patch to decorator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This makes it easier to see in what context you are working.

Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---

 .../internal/decorators/GitResourceDecorator.java  |   20 ++++++++++++++++----
 .../src/org/spearce/jgit/lib/Repository.java       |   22 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
index bde6182..da2e256 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
@@ -16,6 +16,8 @@
  */
 package org.spearce.egit.ui.internal.decorators;
 
+import java.io.IOException;
+
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
@@ -30,6 +32,7 @@ import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.UIIcons;
 import org.spearce.egit.ui.UIText;
 import org.spearce.jgit.lib.MergedTree;
+import org.spearce.jgit.lib.Repository;
 import org.spearce.jgit.lib.TreeEntry;
 
 /**
@@ -110,10 +113,19 @@ public class GitResourceDecorator extends LabelProvider implements
 			final MergedTree diff = mapped.getActiveDiff();
 			if (diff != null && diff.isModified())
 				decoration.addPrefix(">");
-			if (mapped.getRepository().isStGitMode())
-				decoration.addSuffix(" [StGit]");
-			else
-				decoration.addSuffix(" [Git]");
+			Repository repo = mapped.getRepository();
+			try {
+				String branch = repo.getBranch();
+				if (repo.isStGitMode()) {
+					String patch = repo.getPatch();
+					decoration.addSuffix(" [StGit " + patch + "@" + branch +"]");
+				} else {
+					decoration.addSuffix(" [Git @ "+ branch + "]");
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+				decoration.addSuffix(" [Git ?]");
+			}
 			decoration.addOverlay(UIIcons.OVR_SHARED);
 			return;
 		}
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 5e0e89a..d2943c3 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -342,6 +342,27 @@ public class Repository {
 		return "Repository[" + getDirectory() + "]";
 	}
 
+	public String getPatch() throws IOException {
+		final File ptr = new File(getDirectory(),"patches/"+getBranch()+"/current");
+		final BufferedReader br = new BufferedReader(new FileReader(ptr));
+		final String line = br.readLine();
+		return line;
+	}
+	public String getBranch() throws IOException {
+		final File ptr = new File(getDirectory(),"HEAD");
+		final BufferedReader br = new BufferedReader(new FileReader(ptr));
+		final String line = br.readLine();
+		
+		String ref;
+		if (line.startsWith("ref: "))
+			ref = line.substring(5);
+		else
+			ref = line; 
+		if (ref.startsWith("refs/heads/"))
+			ref = ref.substring(11);
+		return ref;
+	}
+
 	public Collection getBranches() {
 		return listFilesRecursively(new File(refsDir, "heads"), null);
 	}
@@ -391,4 +412,5 @@ public class Repository {
 		}
 		return ret;
 	}
+
 }
-
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]