*/\r
package com.gitblit.wicket.panels;\r
\r
+import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Date;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashSet;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.Set;\r
\r
import org.apache.wicket.markup.html.basic.Label;\r
import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
import com.gitblit.models.PathModel;\r
+import com.gitblit.models.SubmoduleModel;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.utils.JGitUtils;\r
RevCommit commit = JGitUtils.getCommit(r, objectId);\r
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);\r
\r
+ Map<String, SubmoduleModel> submodules = new HashMap<String, SubmoduleModel>();\r
+ for (SubmoduleModel model : JGitUtils.getSubmodules(r, commit.getTree())) {\r
+ submodules.put(model.path, model);\r
+ }\r
+\r
PathModel matchingPath = null;\r
for (PathModel p : paths) {\r
if (p.path.equals(path)) {\r
}\r
\r
final boolean isTree = matchingPath == null ? true : matchingPath.isTree();\r
+ final boolean isSubmodule = matchingPath == null ? true : matchingPath.isSubmodule();\r
\r
+ // submodule\r
+ SubmoduleModel submodule = getSubmodule(submodules, repositoryName, matchingPath.path);\r
+ final String submodulePath;\r
+ final boolean hasSubmodule; \r
+ if (submodule != null) {\r
+ submodulePath = submodule.gitblitPath;\r
+ hasSubmodule = submodule.hasSubmodule;\r
+ } else {\r
+ submodulePath = "";\r
+ hasSubmodule = false;\r
+ }\r
+ \r
final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);\r
List<RevCommit> commits;\r
if (pageResults) {\r
WicketUtils.setHtmlTooltip(commitHash, entry.getName()); \r
item.add(commitHash);\r
\r
+ Fragment links = new Fragment("historyLinks", "treeLinks", this);\r
+ links.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,\r
+ WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
+ item.add(links);\r
+ } else if (isSubmodule) {\r
+ // submodule\r
+ item.add(new Label("hashLabel", submodulePath + "@"));\r
+ Repository repository = GitBlit.self().getRepository(repositoryName);\r
+ String submoduleId = JGitUtils.getSubmoduleCommitId(repository, path, entry);\r
+ repository.close();\r
+ LinkPanel commitHash = new LinkPanel("hashLink", null, submoduleId.substring(0, hashLen),\r
+ TreePage.class, WicketUtils.newObjectParameter(\r
+ submodulePath, submoduleId));\r
+ WicketUtils.setCssClass(commitHash, "shortsha1");\r
+ WicketUtils.setHtmlTooltip(commitHash, submoduleId); \r
+ item.add(commitHash.setEnabled(hasSubmodule));\r
+ \r
Fragment links = new Fragment("historyLinks", "treeLinks", this);\r
links.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,\r
WicketUtils.newObjectParameter(repositoryName, entry.getName())));\r
public boolean hasMore() {\r
return hasMore;\r
}\r
+ \r
+ protected SubmoduleModel getSubmodule(Map<String, SubmoduleModel> submodules, String repositoryName, String path) {\r
+ SubmoduleModel model = submodules.get(path);\r
+ if (model == null) {\r
+ // undefined submodule?!\r
+ model = new SubmoduleModel(path.substring(path.lastIndexOf('/') + 1), path, path);\r
+ model.hasSubmodule = false;\r
+ model.gitblitPath = model.name;\r
+ return model;\r
+ } else {\r
+ // extract the repository name from the clone url\r
+ List<String> patterns = GitBlit.getStrings(Keys.git.submoduleUrlPatterns);\r
+ String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0]));\r
+ \r
+ // determine the current path for constructing paths relative\r
+ // to the current repository\r
+ String currentPath = "";\r
+ if (repositoryName.indexOf('/') > -1) {\r
+ currentPath = repositoryName.substring(0, repositoryName.lastIndexOf('/') + 1);\r
+ }\r
+\r
+ // try to locate the submodule repository\r
+ // prefer bare to non-bare names\r
+ List<String> candidates = new ArrayList<String>();\r
+\r
+ // relative\r
+ candidates.add(currentPath + StringUtils.stripDotGit(submoduleName));\r
+ candidates.add(candidates.get(candidates.size() - 1) + ".git");\r
+\r
+ // relative, no subfolder\r
+ if (submoduleName.lastIndexOf('/') > -1) {\r
+ String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);\r
+ candidates.add(currentPath + StringUtils.stripDotGit(name));\r
+ candidates.add(currentPath + candidates.get(candidates.size() - 1) + ".git");\r
+ }\r
+\r
+ // absolute\r
+ candidates.add(StringUtils.stripDotGit(submoduleName));\r
+ candidates.add(candidates.get(candidates.size() - 1) + ".git");\r
+\r
+ // absolute, no subfolder\r
+ if (submoduleName.lastIndexOf('/') > -1) {\r
+ String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);\r
+ candidates.add(StringUtils.stripDotGit(name));\r
+ candidates.add(candidates.get(candidates.size() - 1) + ".git");\r
+ }\r
+\r
+ // create a unique, ordered set of candidate paths\r
+ Set<String> paths = new LinkedHashSet<String>(candidates);\r
+ for (String candidate : paths) {\r
+ if (GitBlit.self().hasRepository(candidate)) {\r
+ model.hasSubmodule = true;\r
+ model.gitblitPath = candidate;\r
+ return model;\r
+ }\r
+ }\r
+ \r
+ // we do not have a copy of the submodule, but we need a path\r
+ model.gitblitPath = candidates.get(0);\r
+ return model;\r
+ } \r
+ }\r
}\r