threads / patch / 11731

patchshowing commiter and parent commit(s) on the revision detail viewer

Subject: [EGIT PATCH] showing commiter and parent commit(s) on the revision detail viewer

## tl;dr

2 messages between Jan 25, 2008 and Jan 27, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Roger C. Soares· Jan 25, 2008, 12:02 UTC · lore
---
 .../src/org/spearce/egit/ui/GitHistoryPage.java    |   57 +++++++++++++++++---
 1 files changed, 49 insertions(+), 8 deletions(-)
Show changes to org.spearce.egit.ui/src/org/spearce/egit/ui/GitHistoryPage.java +49 −8
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 649df3f..cc11b97 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
@@ -88,7 +88,9 @@ import org.spearce.egit.core.internal.mapping.GitFileHistoryProvider;
 import org.spearce.egit.core.internal.mapping.GitFileRevision;
 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.PersonIdent;
 import org.spearce.jgit.lib.Tag;
 import org.spearce.jgit.lib.TopologicalSorter;
 import org.spearce.jgit.lib.Repository.StGitPatch;
@@ -221,14 +223,16 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 				if(selection2.length == 1) {
 					// if the table item is not visible in the UI and it's selected via keyboard
 					// this listener is called before the listener that sets the item data.
-					if(selection2[0] == null) {
+					GitCommitFileRevision revision = (GitCommitFileRevision) selection2[0];
+					if(revision == null) {
 						int ix = table.getSelectionIndex();
-						GitFileRevision revision = (GitFileRevision) fileRevisions.get(ix);
+						revision = (GitCommitFileRevision) fileRevisions.get(ix);
 						selection2[0] = revision;
 					}
-					setRevisionInfoTextViewers(selection2[0]);
+					setRevisionInfoTextViewers(revision);
 				}
 
+
 				compareAction.setCurrentFileRevision(fileRevisions.get(0));
 				compareAction.selectionChanged(new StructuredSelection(
 						selection2));
@@ -554,7 +558,7 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 		revCommentTextViewer = new TextViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
 	}
 
-	/* private */void setRevisionInfoTextViewers(IFileRevision rev) {
+	/* private */void setRevisionInfoTextViewers(GitCommitFileRevision rev) {
 		StringBuilder revisionInfo = new StringBuilder();
 		if (appliedPatches != null) {
 			String id = rev.getContentIdentifier();
@@ -570,7 +574,7 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 			}
 		}
 		if (revisionInfo.length() == 0) {
-			revisionInfo.append("Commit: ");
+			revisionInfo.append("Commit ID: ");
 			revisionInfo.append(rev.getContentIdentifier());
 		}
 
@@ -673,10 +677,30 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 			e.printStackTrace();
 		}
 
+		Commit commit = rev.getCommit();
 		revisionInfo.append("\nAuthor: ");
-		revisionInfo.append(rev.getAuthor());
-		revisionInfo.append("\nDate: ");
-		revisionInfo.append(DATETIMETZ_FORMAT.format(new Date(rev.getTimestamp())));
+		revisionInfo.append(formatPersonIdentForRevInfo(commit.getAuthor()));
+		revisionInfo.append("\nCommiter: ");
+		revisionInfo.append(formatPersonIdentForRevInfo(commit.getCommitter()));
+		if(commit.getParentIds() != null) {
+			for(ObjectId pid : commit.getParentIds()) {
+				revisionInfo.append("\nParent: ");
+				revisionInfo.append(pid.toString());
+				try {
+					Commit pc = repositoryMapping.getRepository().mapCommit(pid);
+					revisionInfo.append(" (");
+					String cmesg = pc.getMessage();
+					int enterIndex = cmesg.indexOf("\n");
+					if(enterIndex > 0) {
+						cmesg = cmesg.substring(0, enterIndex);
+					}
+					revisionInfo.append(cmesg);
+					revisionInfo.append(" )");
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
 
 		String comment = rev.getComment();
 		revDetailTextViewer.setDocument(new Document(revisionInfo.toString()));
@@ -691,6 +715,23 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
 		if (workbenchPageSite != null) {
 			workbenchPageSite.getActionBars().getStatusLineManager().setMessage(comment);
 		}
+
+	}
+
+	private String formatPersonIdentForRevInfo(PersonIdent p) {
+		StringBuilder sb = new StringBuilder();
+		sb.append(p.getName());
+		if(p.getEmailAddress() != null) {
+			sb.append(" <");
+			sb.append(p.getEmailAddress());
+			sb.append(">");
+		}
+		if(p.getWhen() != null) {
+			sb.append(" ");
+			sb.append(DATETIMETZ_FORMAT.format(p.getWhen()));
+		}
+
+		return sb.toString();
 	}
 
 	/* private */void cleanRevisionInfoTextViewers() {
-- 
1.5.3.7
Robin Rosenberg· Jan 27, 2008, 00:34 UTC · re: Roger C. Soares · lore

Re: [EGIT PATCH] showing commiter and parent commit(s) on the revision detail viewer

Hi Roger,
The general idea is ok. Some minor coments though.
>Re: [EGIT PATCH] showing commiter and parent commit(s) on the revision detail viewer
"Show" and final period.
fredagen den 25 januari 2008 skrev Roger C. Soares:
Show 14 quoted lines
> @@ -221,14 +223,16 @@ public class GitHistoryPage extends HistoryPage implements IAdaptable,
>  				if(selection2.length == 1) {
>  					// if the table item is not visible in the UI and it's selected via keyboard
>  					// this listener is called before the listener that sets the item data.
> -					if(selection2[0] == null) {
> +					GitCommitFileRevision revision = (GitCommitFileRevision) selection2[0];
> +					if(revision == null) {
>  						int ix = table.getSelectionIndex();
> -						GitFileRevision revision = (GitFileRevision) fileRevisions.get(ix);
> +						revision = (GitCommitFileRevision) fileRevisions.get(ix);
>  						selection2[0] = revision;
>  					}
> -					setRevisionInfoTextViewers(selection2[0]);
> +					setRevisionInfoTextViewers(revision);
I'm rather allergic to casts, so if we could have only one I'd feel better. Something like
					IFileRevision revision = selection2[0];
					if(revision == null) {
 						int ix = table.getSelectionIndex();
						revision = fileRevisions.get(ix);
 						selection2[0] = revision;
 					}
					setRevisionInfoTextViewers((GitCommitFileRevision)revision);
>  				}
>  
> +
two lines of whitepspace
>  		if (revisionInfo.length() == 0) {
> -			revisionInfo.append("Commit: ");
> +			revisionInfo.append("Commit ID: ");
I prefer just commit. It's shorter and that it is the id is obvious.
> +		revisionInfo.append(formatPersonIdentForRevInfo(commit.getAuthor()));
> +		revisionInfo.append("\nCommiter: ");
Two t's in "Committer"
> +				} catch (IOException e) {
> +					e.printStackTrace();

We should start doing error handling better. But that's a separate chapter. Add a // TODO for now. I'll address them one all one one go later, unless someone does it for me.

-- robin

← back to recent threads