import java.util.Date;\r
\r
import org.eclipse.jgit.lib.ObjectId;\r
+import org.eclipse.jgit.lib.PersonIdent;\r
import org.eclipse.jgit.lib.Ref;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
+import org.eclipse.jgit.revwalk.RevObject;\r
+import org.eclipse.jgit.revwalk.RevTag;\r
\r
public class RefModel implements Serializable, Comparable<RefModel> {\r
\r
private static final long serialVersionUID = 1L;\r
public final String displayName;\r
- public final RevCommit commit;\r
- public transient Ref ref;\r
+ public final RevObject referencedObject;\r
+ public transient Ref reference;\r
\r
- public RefModel(String displayName, Ref ref, RevCommit commit) {\r
+ public RefModel(String displayName, Ref ref, RevObject refObject) {\r
this.displayName = displayName;\r
- this.ref = ref;\r
- this.commit = commit;\r
+ this.reference = ref;\r
+ this.referencedObject = refObject;\r
}\r
\r
public Date getDate() {\r
- return new Date(commit.getCommitTime() * 1000L);\r
+ Date date = new Date(0);\r
+ if (referencedObject != null) {\r
+ if (referencedObject instanceof RevTag) {\r
+ date = ((RevTag) referencedObject).getTaggerIdent().getWhen();\r
+ } else if (referencedObject instanceof RevCommit) {\r
+ date = ((RevCommit) referencedObject).getCommitterIdent().getWhen();\r
+ }\r
+ }\r
+ return date;\r
}\r
\r
public String getName() {\r
- return ref.getName();\r
+ return reference.getName();\r
}\r
\r
- public ObjectId getCommitId() {\r
- return commit.getId();\r
+ public int getReferencedObjectType() {\r
+ int type = referencedObject.getType();\r
+ if (referencedObject instanceof RevTag) {\r
+ type = ((RevTag) referencedObject).getObject().getType();\r
+ }\r
+ return type;\r
}\r
\r
- public String getShortLog() {\r
- return commit.getShortMessage();\r
+ public ObjectId getReferencedObjectId() {\r
+ if (referencedObject instanceof RevTag) {\r
+ return ((RevTag) referencedObject).getObject().getId();\r
+ }\r
+ return referencedObject.getId();\r
+ }\r
+\r
+ public String getShortMessage() {\r
+ String message = "";\r
+ if (referencedObject instanceof RevTag) {\r
+ message = ((RevTag) referencedObject).getShortMessage();\r
+ } else if (referencedObject instanceof RevCommit) {\r
+ message = ((RevCommit) referencedObject).getShortMessage();\r
+ }\r
+ return message;\r
+ }\r
+\r
+ public String getFullMessage() {\r
+ String message = "";\r
+ if (referencedObject instanceof RevTag) {\r
+ message = ((RevTag) referencedObject).getFullMessage();\r
+ } else if (referencedObject instanceof RevCommit) {\r
+ message = ((RevCommit) referencedObject).getFullMessage();\r
+ }\r
+ return message;\r
+ }\r
+\r
+ public PersonIdent getAuthorIdent() {\r
+ if (referencedObject instanceof RevTag) {\r
+ return ((RevTag) referencedObject).getTaggerIdent();\r
+ } else if (referencedObject instanceof RevCommit) {\r
+ return ((RevCommit) referencedObject).getAuthorIdent();\r
+ }\r
+ return null;\r
}\r
\r
public ObjectId getObjectId() {\r
- return ref.getObjectId();\r
+ return reference.getObjectId();\r
}\r
\r
public boolean isAnnotatedTag() {\r
- // ref.isPeeled() ??\r
- return !getCommitId().equals(getObjectId());\r
+ if (referencedObject instanceof RevTag) {\r
+ return !getReferencedObjectId().equals(getObjectId());\r
+ }\r
+ return reference.getPeeledObjectId() != null;\r
}\r
\r
@Override\r
public int hashCode() {\r
- return getCommitId().hashCode() + getName().hashCode();\r
+ return getReferencedObjectId().hashCode() + getName().hashCode();\r
}\r
\r
@Override\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Map.Entry;\r
-import java.util.Set;\r
import java.util.zip.ZipEntry;\r
import java.util.zip.ZipOutputStream;\r
\r
import org.eclipse.jgit.errors.IncorrectObjectTypeException;\r
import org.eclipse.jgit.errors.MissingObjectException;\r
import org.eclipse.jgit.errors.StopWalkException;\r
-import org.eclipse.jgit.lib.AnyObjectId;\r
import org.eclipse.jgit.lib.Constants;\r
import org.eclipse.jgit.lib.FileMode;\r
import org.eclipse.jgit.lib.ObjectId;\r
return commit;\r
}\r
\r
- public static Map<ObjectId, List<String>> getAllRefs(Repository r) {\r
- Map<ObjectId, List<String>> refs = new HashMap<ObjectId, List<String>>();\r
- Map<AnyObjectId, Set<Ref>> allRefs = r.getAllRefsByPeeledObjectId();\r
- for (Entry<AnyObjectId, Set<Ref>> setRefs : allRefs.entrySet()) {\r
- List<String> list = new ArrayList<String>();\r
- for (Ref setRef : setRefs.getValue()) {\r
- String name = setRef.getName();\r
- list.add(name);\r
+ public static Map<ObjectId, List<RefModel>> getAllRefs(Repository r) {\r
+ List<RefModel> list = getRefs(r, org.eclipse.jgit.lib.RefDatabase.ALL, -1);\r
+ Map<ObjectId, List<RefModel>> refs = new HashMap<ObjectId, List<RefModel>>();\r
+ for (RefModel ref : list) {\r
+ ObjectId objectid = ref.getReferencedObjectId();\r
+ if (!refs.containsKey(objectid)) {\r
+ refs.put(objectid, new ArrayList<RefModel>());\r
}\r
- refs.put(setRefs.getKey().toObjectId(), list);\r
- }\r
+ refs.get(objectid).add(ref);\r
+ } \r
return refs;\r
}\r
\r
- /**\r
- * Lookup an entry stored in a tree, failing if not present.\r
- * \r
- * @param tree\r
- * the tree to search.\r
- * @param path\r
- * the path to find the entry of.\r
- * @return the parsed object entry at this path\r
- * @throws Exception\r
- */\r
- public static byte[] getRawContent(Repository r, RevCommit commit, final String path) {\r
+ public static byte[] getByteContent(Repository r, RevTree tree, final String path) {\r
RevWalk rw = new RevWalk(r);\r
TreeWalk tw = new TreeWalk(r);\r
tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));\r
byte[] content = null;\r
try {\r
- if (commit == null) {\r
+ if (tree == null) {\r
ObjectId object = r.resolve(Constants.HEAD);\r
- commit = rw.parseCommit(object);\r
+ RevCommit commit = rw.parseCommit(object);\r
+ tree = commit.getTree();\r
}\r
- tw.reset(commit.getTree());\r
+ tw.reset(tree);\r
while (tw.next()) {\r
if (tw.isSubtree() && !path.equals(tw.getPathString())) {\r
tw.enterSubtree();\r
content = os.toByteArray();\r
}\r
} catch (Throwable t) {\r
- LOGGER.error("Can't find " + path + " in tree " + commit.getTree().name(), t);\r
+ LOGGER.error("Can't find " + path + " in tree " + tree.name(), t);\r
} finally {\r
rw.dispose();\r
tw.release();\r
return content;\r
}\r
\r
- public static String getRawContentAsString(Repository r, RevCommit commit, String blobPath) {\r
- byte[] content = getRawContent(r, commit, blobPath);\r
+ public static String getStringContent(Repository r, RevTree tree, String blobPath) {\r
+ byte[] content = getByteContent(r, tree, blobPath);\r
+ if (content == null) {\r
+ return null;\r
+ }\r
+ return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));\r
+ }\r
+\r
+ public static byte[] getByteContent(Repository r, String objectId) {\r
+ RevWalk rw = new RevWalk(r);\r
+ byte[] content = null;\r
+ try {\r
+ RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId));\r
+ rw.parseBody(blob);\r
+ ByteArrayOutputStream os = new ByteArrayOutputStream();\r
+ ObjectLoader ldr = r.open(blob.getId(), Constants.OBJ_BLOB);\r
+ byte[] tmp = new byte[4096];\r
+ InputStream in = ldr.openStream();\r
+ int n;\r
+ while ((n = in.read(tmp)) > 0) {\r
+ os.write(tmp, 0, n);\r
+ }\r
+ in.close();\r
+ content = os.toByteArray();\r
+ } catch (Throwable t) {\r
+ LOGGER.error("Can't find blob " + objectId, t);\r
+ } finally {\r
+ rw.dispose();\r
+ }\r
+ return content;\r
+ }\r
+\r
+ public static String getStringContent(Repository r, String objectId) {\r
+ byte[] content = getByteContent(r, objectId);\r
if (content == null) {\r
return null;\r
}\r
return getRefs(r, Constants.R_REMOTES, maxCount);\r
}\r
\r
- public static List<RefModel> getNotes(Repository r, int maxCount) {\r
+ public static List<RefModel> getNotesRefs(Repository r, int maxCount) {\r
return getRefs(r, Constants.R_NOTES, maxCount);\r
}\r
\r
List<RefModel> list = new ArrayList<RefModel>();\r
try {\r
Map<String, Ref> map = r.getRefDatabase().getRefs(refs);\r
+ RevWalk rw = new RevWalk(r);\r
for (Entry<String, Ref> entry : map.entrySet()) {\r
Ref ref = entry.getValue();\r
- RevCommit commit = getCommit(r, ref.getObjectId().getName());\r
- list.add(new RefModel(entry.getKey(), ref, commit));\r
+ RevObject object = rw.parseAny(ref.getObjectId());\r
+ list.add(new RefModel(entry.getKey(), ref, object));\r
}\r
+ rw.dispose();\r
Collections.sort(list);\r
Collections.reverse(list);\r
if (maxCount > 0 && list.size() > maxCount) {\r
\r
public static List<GitNote> getNotesOnCommit(Repository repository, RevCommit commit) {\r
List<GitNote> list = new ArrayList<GitNote>();\r
- List<RefModel> notesRefs = getNotes(repository, -1);\r
+ List<RefModel> notesRefs = getNotesRefs(repository, -1);\r
for (RefModel notesRef : notesRefs) {\r
- RevCommit notes = JGitUtils.getCommit(repository, notesRef.getName());\r
+ RevTree notesTree = JGitUtils.getCommit(repository, notesRef.getName()).getTree();\r
StringBuilder sb = new StringBuilder(commit.getName());\r
sb.insert(2, '/');\r
- String text = getRawContentAsString(repository, notes, sb.toString());\r
+ String notePath = sb.toString();\r
+ String text = getStringContent(repository, notesTree, notePath);\r
if (!StringUtils.isEmpty(text)) {\r
- GitNote gitNote = new GitNote(notesRef, text);\r
+ List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1);\r
+ RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history\r
+ .size() - 1));\r
+ GitNote gitNote = new GitNote(noteRef, text);\r
list.add(gitNote);\r
}\r
}\r
final List<RefModel> tags = JGitUtils.getTags(r, -1);\r
final Map<ObjectId, RefModel> tagMap = new HashMap<ObjectId, RefModel>();\r
for (RefModel tag : tags) {\r
- tagMap.put(tag.getCommitId(), tag);\r
+ tagMap.put(tag.getReferencedObjectId(), tag);\r
}\r
try {\r
RevWalk walk = new RevWalk(r);\r
import java.util.List;\r
\r
import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.revwalk.RevCommit;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
if (ticgitBranch == null) {\r
return null;\r
}\r
- List<PathModel> paths = JGitUtils.getFilesInPath(r, null, ticgitBranch.commit);\r
+ RevCommit commit = (RevCommit) ticgitBranch.referencedObject;\r
+ List<PathModel> paths = JGitUtils.getFilesInPath(r, null, commit);\r
List<TicketModel> tickets = new ArrayList<TicketModel>();\r
for (PathModel ticketFolder : paths) {\r
if (ticketFolder.isTree()) {\r
}\r
\r
private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {\r
- List<PathModel> ticketFiles = JGitUtils\r
- .getFilesInPath(r, ticket.name, ticketsBranch.commit);\r
+ RevCommit commit = (RevCommit) ticketsBranch.referencedObject;\r
+ List<PathModel> ticketFiles = JGitUtils.getFilesInPath(r, ticket.name, commit);\r
for (PathModel file : ticketFiles) {\r
- String content = JGitUtils.getRawContentAsString(r, ticketsBranch.commit, file.path)\r
- .trim();\r
+ String content = JGitUtils.getStringContent(r, commit.getTree(), file.path).trim();\r
if (file.name.equals("TICKET_ID")) {\r
ticket.id = content;\r
} else if (file.name.equals("TITLE")) {\r
gb.showReadme = show readme\r
gb.showReadmeDescription = show a \"readme\" markdown file on the summary page\r
gb.nameDescription = use '/' to group repositories. e.g. libraries/mycoollib.git\r
-gb.ownerDescription = the owner may edit repository settings
\ No newline at end of file
+gb.ownerDescription = the owner may edit repository settings\r
+gb.blob = blob
\ No newline at end of file
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.CommitHeaderPanel;\r
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;\r
public BlobPage(PageParameters params) {\r
super(params);\r
\r
+ Repository r = getRepository();\r
final String blobPath = WicketUtils.getPath(params);\r
\r
- String extension = null;\r
- if (blobPath.lastIndexOf('.') > -1) {\r
- extension = blobPath.substring(blobPath.lastIndexOf('.') + 1).toLowerCase();\r
- }\r
+ if (StringUtils.isEmpty(blobPath)) {\r
+ // blob by objectid\r
\r
- // see if we should redirect to the markdown page\r
- for (String ext : GitBlit.getStrings(Keys.web.markdownExtensions)) {\r
- if (ext.equals(extension)) {\r
- setResponsePage(MarkdownPage.class, params);\r
- return;\r
+ add(new Label("blameLink", getString("gb.blame")).setEnabled(false));\r
+ add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class).setEnabled(false));\r
+ add(new BookmarkablePageLink<Void>("rawLink", RawPage.class,\r
+ WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
+ add(new BookmarkablePageLink<Void>("headLink", BlobPage.class).setEnabled(false));\r
+ add(new CommitHeaderPanel("commitHeader", objectId));\r
+ add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));\r
+ Component c = new Label("blobText", JGitUtils.getStringContent(r, objectId));\r
+ WicketUtils.setCssClass(c, "plainprint");\r
+ add(c);\r
+ } else {\r
+ // standard blob view\r
+ String extension = null;\r
+ if (blobPath.lastIndexOf('.') > -1) {\r
+ extension = blobPath.substring(blobPath.lastIndexOf('.') + 1).toLowerCase();\r
}\r
- }\r
\r
- // standard blob view\r
- Repository r = getRepository();\r
- RevCommit commit = getCommit();\r
+ // see if we should redirect to the markdown page\r
+ for (String ext : GitBlit.getStrings(Keys.web.markdownExtensions)) {\r
+ if (ext.equals(extension)) {\r
+ setResponsePage(MarkdownPage.class, params);\r
+ return;\r
+ }\r
+ }\r
\r
- // blob page links\r
- add(new Label("blameLink", getString("gb.blame")));\r
- add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,\r
- WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
- add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(\r
- repositoryName, objectId, blobPath)));\r
- add(new BookmarkablePageLink<Void>("headLink", BlobPage.class,\r
- WicketUtils.newPathParameter(repositoryName, Constants.HEAD, blobPath)));\r
+ // manually get commit because it can be null\r
+ RevCommit commit = JGitUtils.getCommit(r, objectId);\r
\r
- add(new CommitHeaderPanel("commitHeader", repositoryName, commit));\r
+ // blob page links\r
+ add(new Label("blameLink", getString("gb.blame")));\r
+ add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,\r
+ WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
+ add(new BookmarkablePageLink<Void>("rawLink", RawPage.class,\r
+ WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
+ add(new BookmarkablePageLink<Void>("headLink", BlobPage.class,\r
+ WicketUtils.newPathParameter(repositoryName, Constants.HEAD, blobPath)));\r
\r
- add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));\r
+ add(new CommitHeaderPanel("commitHeader", repositoryName, commit));\r
\r
- // Map the extensions to types\r
- Map<String, Integer> map = new HashMap<String, Integer>();\r
- for (String ext : GitBlit.getStrings(Keys.web.prettyPrintExtensions)) {\r
- map.put(ext.toLowerCase(), 1);\r
- }\r
- for (String ext : GitBlit.getStrings(Keys.web.imageExtensions)) {\r
- map.put(ext.toLowerCase(), 2);\r
- }\r
- for (String ext : GitBlit.getStrings(Keys.web.binaryExtensions)) {\r
- map.put(ext.toLowerCase(), 3);\r
- }\r
+ add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));\r
\r
- if (extension != null) {\r
- int type = 0;\r
- if (map.containsKey(extension)) {\r
- type = map.get(extension);\r
+ // Map the extensions to types\r
+ Map<String, Integer> map = new HashMap<String, Integer>();\r
+ for (String ext : GitBlit.getStrings(Keys.web.prettyPrintExtensions)) {\r
+ map.put(ext.toLowerCase(), 1);\r
+ }\r
+ for (String ext : GitBlit.getStrings(Keys.web.imageExtensions)) {\r
+ map.put(ext.toLowerCase(), 2);\r
+ }\r
+ for (String ext : GitBlit.getStrings(Keys.web.binaryExtensions)) {\r
+ map.put(ext.toLowerCase(), 3);\r
}\r
- Component c = null;\r
- switch (type) {\r
- case 1:\r
- // PrettyPrint blob text\r
- c = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));\r
- WicketUtils.setCssClass(c, "prettyprint linenums");\r
- break;\r
- case 2:\r
- // TODO image blobs\r
- c = new Label("blobText", "Image File");\r
- break;\r
- case 3:\r
- // TODO binary blobs\r
- c = new Label("blobText", "Binary File");\r
- break;\r
- default:\r
+\r
+ if (extension != null) {\r
+ int type = 0;\r
+ if (map.containsKey(extension)) {\r
+ type = map.get(extension);\r
+ }\r
+ Component c = null;\r
+ switch (type) {\r
+ case 1:\r
+ // PrettyPrint blob text\r
+ c = new Label("blobText", JGitUtils.getStringContent(r, commit.getTree(),\r
+ blobPath));\r
+ WicketUtils.setCssClass(c, "prettyprint linenums");\r
+ break;\r
+ case 2:\r
+ // TODO image blobs\r
+ c = new Label("blobText", "Image File");\r
+ break;\r
+ case 3:\r
+ // TODO binary blobs\r
+ c = new Label("blobText", "Binary File");\r
+ break;\r
+ default:\r
+ // plain text\r
+ c = new Label("blobText", JGitUtils.getStringContent(r, commit.getTree(),\r
+ blobPath));\r
+ WicketUtils.setCssClass(c, "plainprint");\r
+ }\r
+ add(c);\r
+ } else {\r
// plain text\r
- c = new Label("blobText", JGitUtils.getRawContentAsString(r, commit, blobPath));\r
- WicketUtils.setCssClass(c, "plainprint");\r
+ Label blobLabel = new Label("blobText", JGitUtils.getStringContent(r,\r
+ commit.getTree(), blobPath));\r
+ WicketUtils.setCssClass(blobLabel, "plainprint");\r
+ add(blobLabel);\r
}\r
- add(c);\r
- } else {\r
- // plain text\r
- Label blobLabel = new Label("blobText", JGitUtils.getRawContentAsString(r, commit,\r
- blobPath));\r
- WicketUtils.setCssClass(blobLabel, "plainprint");\r
- add(blobLabel);\r
}\r
}\r
\r
<div class="commit_message" wicket:id="fullMessage">[commit message]</div>\r
\r
<!-- git notes -->\r
- <table style="padding-bottom:5px;">\r
+ <table class="gitnotes">\r
<tr wicket:id="notes">\r
- <td style="vertical-align:top;"><span class="headRef" wicket:id="refName"></span><br/><span wicket:id="authorName"></span><br/><span wicket:id="authorDate"></span></td>\r
- <td><span wicket:id="noteContent"></span></td>\r
+ <td class="info">\r
+ <table>\r
+ <tr><td><span wicket:id="refName"></span></td></tr>\r
+ <tr><td><span class="sha1" wicket:id="authorName"></span></td></tr>\r
+ <tr><td><span class="sha1" wicket:id="authorDate"></span></td></tr>\r
+ </table>\r
+ </td>\r
+ <td class="message"><span class="sha1" wicket:id="noteContent"></span></td>\r
</tr>\r
</table>\r
\r
package com.gitblit.wicket.pages;\r
\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.List;\r
\r
-import org.apache.wicket.Component;\r
import org.apache.wicket.PageParameters;\r
import org.apache.wicket.markup.html.basic.Label;\r
import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
import com.gitblit.models.GitNote;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.utils.StringUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
+import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.CommitHeaderPanel;\r
import com.gitblit.wicket.panels.CommitLegendPanel;\r
import com.gitblit.wicket.panels.LinkPanel;\r
+import com.gitblit.wicket.panels.RefsPanel;\r
\r
public class CommitPage extends RepositoryPage {\r
\r
\r
public void populateItem(final Item<GitNote> item) {\r
GitNote entry = item.getModelObject();\r
- Component c = new LinkPanel("refName", null, entry.notesRef.displayName,\r
- CommitPage.class, newCommitParameter(entry.notesRef.commit.getName()));\r
- WicketUtils.setCssClass(c, "headRef");\r
- item.add(c);\r
- item.add(createPersonPanel("authorName", entry.notesRef.commit.getAuthorIdent(), SearchType.AUTHOR));\r
+ item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));\r
+ item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(), SearchType.AUTHOR));\r
item.add(WicketUtils.createTimestampLabel("authorDate",\r
- entry.notesRef.commit.getAuthorIdent().getWhen(), getTimeZone()));\r
+ entry.notesRef.getAuthorIdent().getWhen(), getTimeZone()));\r
item.add(new Label("noteContent", StringUtils.breakLinesForHtml(entry.content)).setEscapeModelStrings(false));\r
}\r
};\r
WicketUtils.newPathParameter(repositoryName, Constants.HEAD, markdownPath)));\r
\r
// Read raw markdown content and transform it to html\r
- String markdownText = JGitUtils.getRawContentAsString(r, commit, markdownPath);\r
+ String markdownText = JGitUtils.getStringContent(r, commit.getTree(), markdownPath);\r
String htmlText;\r
try {\r
htmlText = MarkdownUtils.transformMarkdown(markdownText);\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.WicketUtils;\r
\r
public class RawPage extends WebPage {\r
return;\r
}\r
\r
- RevCommit commit = JGitUtils.getCommit(r, objectId);\r
-\r
- String extension = null;\r
- if (blobPath.lastIndexOf('.') > -1) {\r
- extension = blobPath.substring(blobPath.lastIndexOf('.') + 1);\r
- }\r
+ if (StringUtils.isEmpty(blobPath)) {\r
+ // objectid referenced raw view\r
+ Label blobLabel = new Label("rawText", JGitUtils.getStringContent(r, objectId));\r
+ WicketUtils.setCssClass(blobLabel, "plainprint");\r
+ add(blobLabel);\r
+ } else {\r
+ // standard raw blob view\r
+ RevCommit commit = JGitUtils.getCommit(r, objectId);\r
\r
- // Map the extensions to types\r
- Map<String, Integer> map = new HashMap<String, Integer>();\r
- for (String ext : GitBlit.getStrings(Keys.web.imageExtensions)) {\r
- map.put(ext.toLowerCase(), 2);\r
- }\r
- for (String ext : GitBlit.getStrings(Keys.web.binaryExtensions)) {\r
- map.put(ext.toLowerCase(), 3);\r
- }\r
+ String extension = null;\r
+ if (blobPath.lastIndexOf('.') > -1) {\r
+ extension = blobPath.substring(blobPath.lastIndexOf('.') + 1);\r
+ }\r
\r
- if (extension != null) {\r
- int type = 0;\r
- if (map.containsKey(extension)) {\r
- type = map.get(extension);\r
+ // Map the extensions to types\r
+ Map<String, Integer> map = new HashMap<String, Integer>();\r
+ for (String ext : GitBlit.getStrings(Keys.web.imageExtensions)) {\r
+ map.put(ext.toLowerCase(), 2);\r
+ }\r
+ for (String ext : GitBlit.getStrings(Keys.web.binaryExtensions)) {\r
+ map.put(ext.toLowerCase(), 3);\r
}\r
- Component c = null;\r
- switch (type) {\r
- case 2:\r
- // TODO image blobs\r
- c = new Label("rawText", "Image File");\r
- break;\r
- case 3:\r
- // TODO binary blobs\r
- c = new Label("rawText", "Binary File");\r
- break;\r
- default:\r
+\r
+ if (extension != null) {\r
+ int type = 0;\r
+ if (map.containsKey(extension)) {\r
+ type = map.get(extension);\r
+ }\r
+ Component c = null;\r
+ switch (type) {\r
+ case 2:\r
+ // TODO image blobs\r
+ c = new Label("rawText", "Image File");\r
+ break;\r
+ case 3:\r
+ // TODO binary blobs\r
+ c = new Label("rawText", "Binary File");\r
+ break;\r
+ default:\r
+ // plain text\r
+ c = new Label("rawText", JGitUtils.getStringContent(r, commit.getTree(),\r
+ blobPath));\r
+ WicketUtils.setCssClass(c, "plainprint");\r
+ }\r
+ add(c);\r
+ } else {\r
// plain text\r
- c = new Label("rawText", JGitUtils.getRawContentAsString(r, commit, blobPath));\r
- WicketUtils.setCssClass(c, "plainprint");\r
+ Label blobLabel = new Label("rawText", JGitUtils.getStringContent(r,\r
+ commit.getTree(), blobPath));\r
+ WicketUtils.setCssClass(blobLabel, "plainprint");\r
+ add(blobLabel);\r
}\r
- add(c);\r
- } else {\r
- // plain text\r
- Label blobLabel = new Label("rawText", JGitUtils.getRawContentAsString(r, commit,\r
- blobPath));\r
- WicketUtils.setCssClass(blobLabel, "plainprint");\r
- add(blobLabel);\r
}\r
r.close();\r
}\r
}\r
}\r
if (!StringUtils.isEmpty(readme)) {\r
- String markdownText = JGitUtils.getRawContentAsString(r, head, readme);\r
+ String markdownText = JGitUtils.getStringContent(r, head.getTree(), readme);\r
htmlText = MarkdownUtils.transformMarkdown(markdownText);\r
}\r
} catch (ParseException p) {\r
\r
<!-- commit info -->\r
<table class="plain">\r
- <tr><th><wicket:message key="gb.object">[object]</wicket:message></th><td><span class="sha1" wicket:id="tagId">[tag id]</span></td></tr>\r
- <tr><th><wicket:message key="gb.tagger">[tagger]</wicket:message></th><td><span class="sha1" wicket:id="tagAuthor">[tag author]</span></td></tr>\r
+ <tr><th><wicket:message key="gb.name">[name]</wicket:message></th><td><span class="tagRef" wicket:id="tagName">[tag name]</span></td></tr>\r
+ <tr><th><wicket:message key="gb.tag">[tag]</wicket:message></th><td><span class="sha1" wicket:id="tagId">[tag id]</span></td></tr>\r
+ <tr><th><wicket:message key="gb.object">[object]</wicket:message></th><td><span class="sha1" wicket:id="taggedObject">[tagged object]</span> <span class="link" wicket:id="taggedObjectType"></span></td></tr>\r
+ <tr><th><wicket:message key="gb.tagger">[tagger]</wicket:message></th><td><span class="sha1" wicket:id="tagger">[tagger]</span></td></tr>\r
<tr><th></th><td><span class="sha1" wicket:id="tagDate">[tag date]</span></td></tr>\r
</table>\r
\r
*/\r
package com.gitblit.wicket.pages;\r
\r
+import java.text.MessageFormat;\r
+import java.util.Arrays;\r
import java.util.List;\r
\r
import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.eclipse.jgit.lib.Constants;\r
import org.eclipse.jgit.lib.Repository;\r
-import org.eclipse.jgit.revwalk.RevCommit;\r
\r
import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.LinkPanel;\r
+import com.gitblit.wicket.panels.RefsPanel;\r
\r
public class TagPage extends RepositoryPage {\r
\r
super(params);\r
\r
Repository r = getRepository();\r
- RevCommit c = getCommit();\r
- List<RefModel> tags = JGitUtils.getTags(r, -1);\r
\r
+ // Find tag in repository\r
+ List<RefModel> tags = JGitUtils.getTags(r, -1);\r
RefModel tagRef = null;\r
- // determine tag\r
for (RefModel tag : tags) {\r
if (tag.getName().equals(objectId) || tag.getObjectId().getName().equals(objectId)) {\r
tagRef = tag;\r
}\r
}\r
\r
+ // Failed to find tag!\r
if (tagRef == null) {\r
- // point to commit\r
- add(new LinkPanel("commit", "title", c.getShortMessage(), CommitPage.class,\r
- newCommitParameter()));\r
- add(new LinkPanel("tagId", "list", c.getName(), CommitPage.class,\r
- newCommitParameter(c.getName())));\r
- } else {\r
- // TODO commit or tree or blob?\r
- add(new LinkPanel("commit", "title", tagRef.displayName, CommitPage.class,\r
- newCommitParameter()));\r
- add(new LinkPanel("tagId", "list", c.getName(), CommitPage.class,\r
- newCommitParameter(c.getName())));\r
+ error(MessageFormat.format("Could not find tag {0}", objectId), true);\r
+ }\r
+\r
+ // Display tag.\r
+ Class<? extends RepositoryPage> linkClass;\r
+ PageParameters linkParameters = newCommitParameter(tagRef.getReferencedObjectId().getName());\r
+ String typeKey;\r
+ switch (tagRef.getReferencedObjectType()) {\r
+ case Constants.OBJ_BLOB:\r
+ typeKey = "gb.blob";\r
+ linkClass = BlobPage.class;\r
+ break;\r
+ case Constants.OBJ_TREE:\r
+ typeKey = "gb.tree";\r
+ linkClass = TreePage.class;\r
+ break;\r
+ case Constants.OBJ_COMMIT:\r
+ default:\r
+ typeKey = "gb.commit";\r
+ linkClass = CommitPage.class;\r
+ break;\r
}\r
+ add(new LinkPanel("commit", "title", tagRef.displayName, linkClass, linkParameters));\r
+ add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));\r
+ add(new Label("tagId", tagRef.getObjectId().getName()));\r
+ add(new LinkPanel("taggedObject", "list", tagRef.getReferencedObjectId().getName(),\r
+ linkClass, linkParameters));\r
+ add(new Label("taggedObjectType", getString(typeKey)));\r
\r
- add(createPersonPanel("tagAuthor", c.getAuthorIdent(), SearchType.AUTHOR));\r
- add(WicketUtils\r
- .createTimestampLabel("tagDate", c.getAuthorIdent().getWhen(), getTimeZone()));\r
+ add(createPersonPanel("tagger", tagRef.getAuthorIdent(), SearchType.AUTHOR));\r
+ add(WicketUtils.createTimestampLabel("tagDate", tagRef.getAuthorIdent().getWhen(),\r
+ getTimeZone()));\r
\r
- addFullText("fullMessage", c.getFullMessage(), true);\r
+ addFullText("fullMessage", tagRef.getFullMessage(), true);\r
}\r
\r
@Override\r
\r
private static final long serialVersionUID = 1L;\r
\r
+ public CommitHeaderPanel(String id, String title) {\r
+ super(id);\r
+ add(new Label("shortmessage", title));\r
+ add(new Label("commitid"));\r
+ add(new Label("author"));\r
+ add(new Label("date"));\r
+ }\r
+ \r
public CommitHeaderPanel(String id, String repositoryName, RevCommit c) {\r
super(id);\r
add(new LinkPanel("shortmessage", "title", c.getShortMessage(), CommitPage.class,\r
import com.gitblit.Keys;\r
import com.gitblit.models.PathModel;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
import com.gitblit.utils.StringUtils;\r
}\r
final boolean isTree = matchingPath == null ? true : matchingPath.isTree();\r
\r
- final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);\r
+ final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r);\r
List<RevCommit> commits;\r
if (pageResults) {\r
// Paging result set\r
\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
import com.gitblit.utils.StringUtils;\r
itemsPerPage = 50;\r
}\r
\r
- final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);\r
+ final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r);\r
List<RevCommit> commits;\r
if (pageResults) {\r
// Paging result set\r
import org.eclipse.jgit.lib.ObjectId;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.pages.CommitPage;\r
import com.gitblit.wicket.pages.LogPage;\r
private static final long serialVersionUID = 1L;\r
\r
public RefsPanel(String id, final String repositoryName, RevCommit c,\r
- Map<ObjectId, List<String>> refs) {\r
+ Map<ObjectId, List<RefModel>> refs) {\r
+ this(id, repositoryName, refs.get(c.getId()));\r
+ }\r
+\r
+ public RefsPanel(String id, final String repositoryName, List<RefModel> refs) {\r
super(id);\r
- List<String> refNames = refs.get(c.getId());\r
- if (refNames == null) {\r
- refNames = new ArrayList<String>();\r
+ if (refs == null) {\r
+ refs = new ArrayList<RefModel>();\r
}\r
- Collections.sort(refNames);\r
+ Collections.sort(refs);\r
// refNames.remove(Constants.HEAD);\r
\r
- ListDataProvider<String> refsDp = new ListDataProvider<String>(refNames);\r
- DataView<String> refsView = new DataView<String>("ref", refsDp) {\r
+ ListDataProvider<RefModel> refsDp = new ListDataProvider<RefModel>(refs);\r
+ DataView<RefModel> refsView = new DataView<RefModel>("ref", refsDp) {\r
private static final long serialVersionUID = 1L;\r
\r
- public void populateItem(final Item<String> item) {\r
- String entry = item.getModelObject();\r
+ public void populateItem(final Item<RefModel> item) {\r
+ RefModel entry = item.getModelObject();\r
+ String name = entry.displayName;\r
+ String objectid = entry.getReferencedObjectId().getName();\r
Component c = null;\r
- if (entry.startsWith(Constants.R_HEADS)) {\r
+ if (name.startsWith(Constants.R_HEADS)) {\r
+ // local head\r
+ c = new LinkPanel("refName", null, name.substring(Constants.R_HEADS.length()),\r
+ LogPage.class, WicketUtils.newObjectParameter(repositoryName, objectid));\r
+ WicketUtils.setCssClass(c, "headRef");\r
+ } else if (name.equals(Constants.HEAD)) {\r
// local head\r
- c = new LinkPanel("refName", null, entry.substring(Constants.R_HEADS.length()),\r
- LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry));\r
+ c = new LinkPanel("refName", null, name, LogPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, objectid));\r
WicketUtils.setCssClass(c, "headRef");\r
- } else if (entry.startsWith(Constants.R_REMOTES)) {\r
+ } else if (name.startsWith(Constants.R_REMOTES)) {\r
// remote head\r
c = new LinkPanel("refName", null,\r
- entry.substring(Constants.R_REMOTES.length()), LogPage.class,\r
- WicketUtils.newObjectParameter(repositoryName, entry));\r
+ name.substring(Constants.R_REMOTES.length()), LogPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, objectid));\r
WicketUtils.setCssClass(c, "remoteRef");\r
- } else if (entry.startsWith(Constants.R_TAGS)) {\r
+ } else if (name.startsWith(Constants.R_TAGS)) {\r
// tag\r
- c = new LinkPanel("refName", null, entry.substring(Constants.R_TAGS.length()),\r
- TagPage.class, WicketUtils.newObjectParameter(repositoryName, entry));\r
+ c = new LinkPanel("refName", null, name.substring(Constants.R_TAGS.length()),\r
+ TagPage.class, WicketUtils.newObjectParameter(repositoryName, objectid));\r
WicketUtils.setCssClass(c, "tagRef");\r
} else {\r
// other\r
- c = new LinkPanel("refName", null, entry, CommitPage.class,\r
- WicketUtils.newObjectParameter(repositoryName, entry));\r
+ c = new LinkPanel("refName", null, name, CommitPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, objectid));\r
WicketUtils.setCssClass(c, "otherRef");\r
}\r
- WicketUtils.setHtmlTooltip(c, entry);\r
+ WicketUtils.setHtmlTooltip(c, name);\r
item.add(c);\r
}\r
};\r
\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
import com.gitblit.utils.StringUtils;\r
\r
RevCommit commit = JGitUtils.getCommit(r, objectId);\r
\r
- final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);\r
+ final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r);\r
List<RevCommit> commits;\r
if (pageResults) {\r
// Paging result set\r
<!-- annotated tag links -->\r
<wicket:fragment wicket:id="annotatedLinks">\r
<span class="link">\r
- <a wicket:id="view"><wicket:message key="gb.view"></wicket:message></a> | <a wicket:id="commit"><wicket:message key="gb.commit"></wicket:message></a> | <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a>\r
+ <a wicket:id="tag"><wicket:message key="gb.tag"></wicket:message></a> | <a wicket:id="commit"><wicket:message key="gb.commit"></wicket:message></a> | <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a>\r
</span>\r
</wicket:fragment>\r
\r
<a wicket:id="commit"><wicket:message key="gb.commit"></wicket:message></a> | <a wicket:id="log"><wicket:message key="gb.log"></wicket:message></a>\r
</span>\r
</wicket:fragment>\r
+\r
+ <!-- blob tag links -->\r
+ <wicket:fragment wicket:id="blobLinks">\r
+ <span class="link">\r
+ <a wicket:id="tag"><wicket:message key="gb.tag"></wicket:message></a> | <a wicket:id="blob"><wicket:message key="gb.blob"></wicket:message></a> | <a wicket:id="raw"><wicket:message key="gb.raw"></wicket:message></a>\r
+ </span>\r
+ </wicket:fragment>\r
\r
</wicket:panel>\r
</body>\r
import org.apache.wicket.markup.repeater.data.DataView;\r
import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
import org.apache.wicket.model.StringResourceModel;\r
+import org.eclipse.jgit.lib.Constants;\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.pages.BlobPage;\r
import com.gitblit.wicket.pages.CommitPage;\r
import com.gitblit.wicket.pages.LogPage;\r
+import com.gitblit.wicket.pages.RawPage;\r
+import com.gitblit.wicket.pages.RepositoryPage;\r
import com.gitblit.wicket.pages.SummaryPage;\r
import com.gitblit.wicket.pages.TagPage;\r
import com.gitblit.wicket.pages.TagsPage;\r
+import com.gitblit.wicket.pages.TreePage;\r
\r
public class TagsPanel extends BasePanel {\r
\r
\r
item.add(WicketUtils.createDateLabel("tagDate", entry.getDate(), getTimeZone()));\r
\r
- // tag icon\r
- if (entry.isAnnotatedTag()) {\r
- item.add(WicketUtils.newImage("tagIcon", "tag_16x16.png"));\r
- } else {\r
- item.add(WicketUtils.newBlankImage("tagIcon"));\r
+ Class<? extends RepositoryPage> linkClass;\r
+ switch (entry.getReferencedObjectType()) {\r
+ case Constants.OBJ_BLOB:\r
+ linkClass = BlobPage.class;\r
+ break;\r
+ case Constants.OBJ_TREE:\r
+ linkClass = TreePage.class;\r
+ break;\r
+ case Constants.OBJ_COMMIT:\r
+ default:\r
+ linkClass = CommitPage.class;\r
+ break;\r
}\r
-\r
- item.add(new LinkPanel("tagName", "list name", entry.displayName, CommitPage.class,\r
- WicketUtils.newObjectParameter(repositoryName, entry.getCommitId()\r
- .getName())));\r
+ item.add(new LinkPanel("tagName", "list name", entry.displayName, linkClass,\r
+ WicketUtils.newObjectParameter(repositoryName, entry\r
+ .getReferencedObjectId().getName())));\r
String message;\r
if (maxCount > 0) {\r
- message = StringUtils.trimString(entry.getShortLog(), 40);\r
+ message = StringUtils.trimString(entry.getShortMessage(), 40);\r
} else {\r
- message = entry.getShortLog();\r
+ // workaround for RevTag returning a lengthy shortlog. :(\r
+ message = StringUtils.trimShortLog(entry.getShortMessage());\r
}\r
- if (entry.isAnnotatedTag()) {\r
+ if (linkClass.equals(BlobPage.class)) {\r
+ // Blob Tag Object\r
+ item.add(WicketUtils.newImage("tagIcon", "file_16x16.png"));\r
item.add(new LinkPanel("tagDescription", "list", message, TagPage.class,\r
WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()\r
.getName())));\r
- Fragment fragment = new Fragment("tagLinks", "annotatedLinks", this);\r
- fragment.add(new BookmarkablePageLink<Void>("view", TagPage.class, WicketUtils\r
+\r
+ Fragment fragment = new Fragment("tagLinks", "blobLinks", this);\r
+ fragment.add(new BookmarkablePageLink<Void>("tag", TagPage.class, WicketUtils\r
.newObjectParameter(repositoryName, entry.getObjectId().getName()))\r
.setEnabled(entry.isAnnotatedTag()));\r
- fragment.add(new BookmarkablePageLink<Void>("commit", CommitPage.class,\r
- WicketUtils.newObjectParameter(repositoryName, entry.getCommitId()\r
- .getName())));\r
- fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
- .newObjectParameter(repositoryName, entry.getName())));\r
- item.add(fragment);\r
- } else {\r
- item.add(new LinkPanel("tagDescription", "list", message, CommitPage.class,\r
- WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()\r
+\r
+ fragment.add(new BookmarkablePageLink<Void>("blob", linkClass, WicketUtils\r
+ .newObjectParameter(repositoryName, entry.getReferencedObjectId()\r
.getName())));\r
- Fragment fragment = new Fragment("tagLinks", "lightweightLinks", this);\r
- fragment.add(new BookmarkablePageLink<Void>("commit", CommitPage.class,\r
- WicketUtils.newObjectParameter(repositoryName, entry.getCommitId()\r
+\r
+ fragment.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils\r
+ .newObjectParameter(repositoryName, entry.getReferencedObjectId()\r
.getName())));\r
- fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils\r
- .newObjectParameter(repositoryName, entry.getName())));\r
item.add(fragment);\r
+ } else {\r
+ // TODO Tree Tag Object\r
+ // Standard Tag Object\r
+ if (entry.isAnnotatedTag()) {\r
+ item.add(WicketUtils.newImage("tagIcon", "tag_16x16.png"));\r
+ item.add(new LinkPanel("tagDescription", "list", message, TagPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()\r
+ .getName())));\r
+\r
+ Fragment fragment = new Fragment("tagLinks", "annotatedLinks", this);\r
+ fragment.add(new BookmarkablePageLink<Void>("tag", TagPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()\r
+ .getName())).setEnabled(entry.isAnnotatedTag()));\r
+\r
+ fragment.add(new BookmarkablePageLink<Void>("commit", linkClass,\r
+ WicketUtils.newObjectParameter(repositoryName, entry\r
+ .getReferencedObjectId().getName())));\r
+\r
+ fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
+ item.add(fragment);\r
+ } else {\r
+ item.add(WicketUtils.newBlankImage("tagIcon"));\r
+ item.add(new LinkPanel("tagDescription", "list", message, CommitPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()\r
+ .getName())));\r
+ Fragment fragment = new Fragment("tagLinks", "lightweightLinks", this);\r
+ fragment.add(new BookmarkablePageLink<Void>("commit", CommitPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry\r
+ .getReferencedObjectId().getName())));\r
+ fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
+ item.add(fragment);\r
+ }\r
}\r
\r
WicketUtils.setAlternatingBackground(item, counter);\r
}\r
\r
div.commit_message {\r
+ font-family: monospace;\r
padding: 8px;\r
border: solid #bbb;\r
border-width: 1px 0px 0px;\r
border-right: 1px solid #bbb; \r
}\r
\r
-table.pretty, table.comments, table.repositories {\r
+table.pretty, table.comments, table.repositories, table.gitnotes {\r
width:100%;\r
}\r
\r
}\r
table.palette td.pane {\r
padding: 0px; \r
-} \r
+}\r
+\r
+table.gitnotes { \r
+ padding-bottom: 5px;\r
+}\r
+table.gitnotes td {\r
+ border-top: 1px solid #ccc;\r
+ padding-top: 3px;\r
+ vertical-align:top;\r
+}\r
+\r
+table.gitnotes td table td {\r
+ border: none;\r
+ padding-top: 0px;\r
+}\r
+\r
+table.gitnotes td.info {\r
+}\r
+\r
+table.gitnotes td.message {\r
+ width: 65%;\r
+ border-left: 1px solid #ccc;\r
+}\r
\r
tr th a { padding-right: 15px; background-position: right; background-repeat:no-repeat; }\r
tr th.wicket_orderDown a {background-image: url(arrow_down.png); }\r
package com.gitblit.tests;\r
\r
import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
\r
import junit.extensions.TestSetup;\r
import junit.framework.Test;\r
import junit.framework.TestSuite;\r
\r
import org.eclipse.jgit.api.CloneCommand;\r
+import org.eclipse.jgit.api.FetchCommand;\r
import org.eclipse.jgit.api.Git;\r
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.storage.file.FileRepository;\r
+import org.eclipse.jgit.transport.RefSpec;\r
\r
import com.gitblit.FileSettings;\r
import com.gitblit.GitBlit;\r
return new FileRepository(new File(REPOSITORIES, "ticgit.git"));\r
}\r
\r
+ public static Repository getJGitRepository() throws Exception {\r
+ return new FileRepository(new File(REPOSITORIES, "nested/jgit.git"));\r
+ }\r
+\r
+ public static Repository getBluezGnomeRepository() throws Exception {\r
+ return new FileRepository(new File(REPOSITORIES, "nested/bluez-gnome.git"));\r
+ }\r
+\r
@Override\r
protected void setUp() throws Exception {\r
FileSettings settings = new FileSettings("distrib/gitblit.properties");\r
\r
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {\r
cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git", true);\r
- cloneOrFetch("nested/helloworld.git", "https://github.com/git/hello-world.git", true);\r
cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git", true);\r
+ cloneOrFetch("nested/bluez-gnome.git", "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git", true);\r
+ cloneOrFetch("nested/jgit.git", "https://github.com/eclipse/jgit.git", true);\r
+ cloneOrFetch("nested/helloworld.git", "https://github.com/git/hello-world.git", true);\r
\r
enableTickets("ticgit.git");\r
enableDocs("ticgit.git");\r
showRemoteBranches("ticgit.git");\r
+ showRemoteBranches("nested/jgit.git");\r
}\r
}\r
\r
File folder = new File(REPOSITORIES, toFolder + (bare ? "" : "/.git"));\r
if (folder.exists()) {\r
System.out.print("Updating " + (bare ? "bare " : " ") + toFolder + "... ");\r
- FileRepository repository = new FileRepository(new File(REPOSITORIES, toFolder));\r
- Git git = new Git(repository);\r
- git.fetch().call();\r
- repository.close();\r
+ fetch(toFolder);\r
System.out.println("done.");\r
} else {\r
System.out.println("Cloning " + (bare ? "bare " : " ") + toFolder + "... ");\r
CloneCommand clone = new CloneCommand();\r
clone.setBare(bare);\r
- clone.setCloneAllBranches(true);\r
+ clone.setCloneAllBranches(true); \r
clone.setURI(fromUrl);\r
clone.setDirectory(folder);\r
clone.call();\r
+ // Now we have to fetch because CloneCommand doesn't fetch\r
+ // Notes nor does it allow manual RefSpec.\r
+ fetch(toFolder);\r
System.out.println("done.");\r
}\r
}\r
+ \r
+ private void fetch(String toFolder) throws Exception {\r
+ FileRepository repository = new FileRepository(new File(REPOSITORIES, toFolder));\r
+ Git git = new Git(repository);\r
+ FetchCommand fetch = git.fetch();\r
+ List<RefSpec> specs = new ArrayList<RefSpec>();\r
+ specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));\r
+ specs.add(new RefSpec("+refs/tags/*:refs/tags/*"));\r
+ specs.add(new RefSpec("+refs/notes/*:refs/notes/*"));\r
+ fetch.setRefSpecs(specs);\r
+ fetch.call();\r
+ repository.close();\r
+ }\r
\r
private void enableTickets(String repositoryName) {\r
try {\r
\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.GitNote;\r
import com.gitblit.models.PathModel;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
+import com.gitblit.utils.StringUtils;\r
\r
public class JGitUtilsTest extends TestCase {\r
\r
}\r
\r
public void testRefs() throws Exception {\r
- Repository repository = GitBlitSuite.getTicgitRepository();\r
- Map<ObjectId, List<String>> map = JGitUtils.getAllRefs(repository);\r
+ Repository repository = GitBlitSuite.getJGitRepository();\r
+ Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);\r
repository.close();\r
assertTrue(map.size() > 0);\r
+ for (Map.Entry<ObjectId, List<RefModel>> entry : map.entrySet()) {\r
+ List<RefModel> list = entry.getValue();\r
+ for (RefModel ref : list) {\r
+ if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {\r
+ assertTrue(ref.getObjectId().getName().equals("8bbde7aacf771a9afb6992434f1ae413e010c6d8"));\r
+ assertTrue(ref.getAuthorIdent().getEmailAddress().equals("spearce@spearce.org"));\r
+ assertTrue(ref.getShortMessage().startsWith("GPG key"));\r
+ assertTrue(ref.getFullMessage().startsWith("GPG key")); \r
+ assertTrue(ref.getReferencedObjectType() == Constants.OBJ_BLOB);\r
+ } else if (ref.displayName.equals("refs/tags/v0.12.1")) {\r
+ assertTrue(ref.isAnnotatedTag());\r
+ }\r
+ }\r
+ }\r
}\r
\r
public void testBranches() throws Exception {\r
assertTrue(model.getName().startsWith(Constants.R_HEADS));\r
assertTrue(model.equals(model));\r
assertFalse(model.equals(""));\r
- assertTrue(model.hashCode() == model.getCommitId().hashCode()\r
+ assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()\r
+ model.getName().hashCode());\r
- assertTrue(model.getShortLog().equals(model.commit.getShortMessage()));\r
+ assertTrue(model.getShortMessage().equals(model.getShortMessage()));\r
}\r
for (RefModel model : JGitUtils.getRemoteBranches(repository, -1)) {\r
assertTrue(model.getName().startsWith(Constants.R_REMOTES));\r
assertTrue(model.equals(model));\r
assertFalse(model.equals(""));\r
- assertTrue(model.hashCode() == model.getCommitId().hashCode()\r
+ assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()\r
+ model.getName().hashCode());\r
- assertTrue(model.getShortLog().equals(model.commit.getShortMessage()));\r
+ assertTrue(model.getShortMessage().equals(model.getShortMessage()));\r
}\r
assertTrue(JGitUtils.getRemoteBranches(repository, 10).size() == 10);\r
repository.close();\r
assertTrue(model.getName().startsWith(Constants.R_TAGS));\r
assertTrue(model.equals(model));\r
assertFalse(model.equals(""));\r
- assertTrue(model.hashCode() == model.getCommitId().hashCode()\r
+ assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()\r
+ model.getName().hashCode());\r
- assertTrue(model.getShortLog().equals(model.commit.getShortMessage()));\r
+ }\r
+ repository.close();\r
+ \r
+ repository = GitBlitSuite.getBluezGnomeRepository();\r
+ for (RefModel model : JGitUtils.getTags(repository, -1)) {\r
+ if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) {\r
+ assertFalse(model.isAnnotatedTag());\r
+ assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org"));\r
+ assertTrue(model.getFullMessage().equals("Update changelog and bump version number\n"));\r
+ }\r
}\r
repository.close();\r
}\r
\r
public void testCommitNotes() throws Exception {\r
-// Repository repository = new FileRepository(new File("c:/projects/git/jgit.git/.git"));\r
-// RevCommit commit = JGitUtils.getCommit(repository,\r
-// "ada903085d1b4ef8c79e3e2d91f49fee7e188f53");\r
-// List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);\r
-// repository.close();\r
-// assertTrue(list.size() > 0);\r
+ Repository repository = GitBlitSuite.getJGitRepository();\r
+ RevCommit commit = JGitUtils.getCommit(repository,\r
+ "690c268c793bfc218982130fbfc25870f292295e");\r
+ List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);\r
+ repository.close();\r
+ assertTrue(list.size() > 0);\r
+ assertTrue(list.get(0).notesRef.getReferencedObjectId().getName()\r
+ .equals("183474d554e6f68478a02d9d7888b67a9338cdff"));\r
}\r
\r
public void testStringContent() throws Exception {\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
- String contentA = JGitUtils.getRawContentAsString(repository, null, "java.java");\r
+ String contentA = JGitUtils.getStringContent(repository, null, "java.java");\r
RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);\r
- String contentB = JGitUtils.getRawContentAsString(repository, commit, "java.java");\r
- String contentC = JGitUtils.getRawContentAsString(repository, commit, "missing.txt");\r
+ String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");\r
+ String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");\r
+\r
+ // manually construct a blob, calculate the hash, lookup the hash in git\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("blob ").append(contentA.length()).append('\0');\r
+ sb.append(contentA);\r
+ String sha1 = StringUtils.getSHA1(sb.toString());\r
+ String contentD = JGitUtils.getStringContent(repository, sha1);\r
repository.close();\r
assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);\r
assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);\r
assertTrue(contentA.equals(contentB));\r
assertTrue(contentC == null);\r
+ assertTrue(contentA.equals(contentD));\r
}\r
\r
public void testFilesInCommit() throws Exception {\r