use of com.gitblit.models.SubmoduleModel in project gitblit by gitblit.
the class HistoryPanel method getSubmodule.
protected SubmoduleModel getSubmodule(Map<String, SubmoduleModel> submodules, String repositoryName, String path) {
SubmoduleModel model = submodules.get(path);
if (model == null) {
// undefined submodule?!
model = new SubmoduleModel(path.substring(path.lastIndexOf('/') + 1), path, path);
model.hasSubmodule = false;
model.gitblitPath = model.name;
return model;
} else {
// extract the repository name from the clone url
List<String> patterns = app().settings().getStrings(Keys.git.submoduleUrlPatterns);
String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0]));
// determine the current path for constructing paths relative
// to the current repository
String currentPath = "";
if (repositoryName.indexOf('/') > -1) {
currentPath = repositoryName.substring(0, repositoryName.lastIndexOf('/') + 1);
}
// try to locate the submodule repository
// prefer bare to non-bare names
List<String> candidates = new ArrayList<String>();
// relative
candidates.add(currentPath + StringUtils.stripDotGit(submoduleName));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
// relative, no subfolder
if (submoduleName.lastIndexOf('/') > -1) {
String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
candidates.add(currentPath + StringUtils.stripDotGit(name));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
}
// absolute
candidates.add(StringUtils.stripDotGit(submoduleName));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
// absolute, no subfolder
if (submoduleName.lastIndexOf('/') > -1) {
String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
candidates.add(StringUtils.stripDotGit(name));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
}
// create a unique, ordered set of candidate paths
Set<String> paths = new LinkedHashSet<String>(candidates);
for (String candidate : paths) {
if (app().repositories().hasRepository(candidate)) {
model.hasSubmodule = true;
model.gitblitPath = candidate;
return model;
}
}
// we do not have a copy of the submodule, but we need a path
model.gitblitPath = candidates.get(0);
return model;
}
}
use of com.gitblit.models.SubmoduleModel in project gitblit by gitblit.
the class RepositoryPage method getSubmodule.
protected SubmoduleModel getSubmodule(String path) {
SubmoduleModel model = null;
if (submodules != null) {
model = submodules.get(path);
}
if (model == null) {
// undefined submodule?!
model = new SubmoduleModel(path.substring(path.lastIndexOf('/') + 1), path, path);
model.hasSubmodule = false;
model.gitblitPath = model.name;
return model;
} else {
// extract the repository name from the clone url
List<String> patterns = app().settings().getStrings(Keys.git.submoduleUrlPatterns);
String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0]));
// determine the current path for constructing paths relative
// to the current repository
String currentPath = "";
if (repositoryName.indexOf('/') > -1) {
currentPath = repositoryName.substring(0, repositoryName.lastIndexOf('/') + 1);
}
// try to locate the submodule repository
// prefer bare to non-bare names
List<String> candidates = new ArrayList<String>();
// relative
candidates.add(currentPath + StringUtils.stripDotGit(submoduleName));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
// relative, no subfolder
if (submoduleName.lastIndexOf('/') > -1) {
String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
candidates.add(currentPath + StringUtils.stripDotGit(name));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
}
// absolute
candidates.add(StringUtils.stripDotGit(submoduleName));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
// absolute, no subfolder
if (submoduleName.lastIndexOf('/') > -1) {
String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
candidates.add(StringUtils.stripDotGit(name));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
}
// create a unique, ordered set of candidate paths
Set<String> paths = new LinkedHashSet<String>(candidates);
for (String candidate : paths) {
if (app().repositories().hasRepository(candidate)) {
model.hasSubmodule = true;
model.gitblitPath = candidate;
return model;
}
}
// we do not have a copy of the submodule, but we need a path
model.gitblitPath = candidates.get(0);
return model;
}
}
use of com.gitblit.models.SubmoduleModel in project gitblit by gitblit.
the class TicketPage method createPatchsetPanel.
protected Fragment createPatchsetPanel(String wicketId, RepositoryModel repository, UserModel user) {
final Patchset currentPatchset = ticket.getCurrentPatchset();
List<Patchset> patchsets = new ArrayList<Patchset>(ticket.getPatchsetRevisions(currentPatchset.number));
patchsets.remove(currentPatchset);
Collections.reverse(patchsets);
Fragment panel = new Fragment(wicketId, "collapsiblePatchsetFragment", this);
// patchset header
String ps = "<b>" + currentPatchset.number + "</b>";
if (currentPatchset.rev == 1) {
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetN"), ps)).setEscapeModelStrings(false));
} else {
String rev = "<b>" + currentPatchset.rev + "</b>";
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetNRevisionN"), ps, rev)).setEscapeModelStrings(false));
}
panel.add(new LinkPanel("patchId", null, "rev " + currentPatchset.rev, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, currentPatchset.tip), true));
// compare menu
panel.add(new LinkPanel("compareMergeBase", null, getString("gb.compareToMergeBase"), ComparePage.class, WicketUtils.newRangeParameter(repositoryName, currentPatchset.base, currentPatchset.tip), true));
ListDataProvider<Patchset> compareMenuDp = new ListDataProvider<Patchset>(patchsets);
DataView<Patchset> compareMenu = new DataView<Patchset>("comparePatch", compareMenuDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Patchset> item) {
Patchset patchset = item.getModelObject();
LinkPanel link = new LinkPanel("compareLink", null, MessageFormat.format(getString("gb.compareToN"), patchset.number + "-" + patchset.rev), ComparePage.class, WicketUtils.newRangeParameter(getRepositoryModel().name, patchset.tip, currentPatchset.tip), true);
item.add(link);
}
};
panel.add(compareMenu);
// reviews
List<Change> reviews = ticket.getReviews(currentPatchset);
ListDataProvider<Change> reviewsDp = new ListDataProvider<Change>(reviews);
DataView<Change> reviewsView = new DataView<Change>("reviews", reviewsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Change> item) {
Change change = item.getModelObject();
final String username = change.author;
UserModel user = app().users().getUserModel(username);
if (user == null) {
item.add(new Label("reviewer", username));
} else {
item.add(new LinkPanel("reviewer", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(username)));
}
// indicate review score
Review review = change.review;
Label scoreLabel = new Label("score");
String scoreClass = getScoreClass(review.score);
String tooltip = getScoreDescription(review.score);
WicketUtils.setCssClass(scoreLabel, scoreClass);
if (!StringUtils.isEmpty(tooltip)) {
WicketUtils.setHtmlTooltip(scoreLabel, tooltip);
}
item.add(scoreLabel);
}
};
panel.add(reviewsView);
if (ticket.isOpen() && user.canReviewPatchset(repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
// can only review open tickets
Review myReview = null;
for (Change change : ticket.getReviews(currentPatchset)) {
if (change.author.equals(user.username)) {
myReview = change.review;
}
}
// user can review, add review controls
Fragment reviewControls = new Fragment("reviewControls", "reviewControlsFragment", this);
// show "approve" button if no review OR not current score
if (user.canApprovePatchset(repository) && (myReview == null || Score.approved != myReview.score)) {
reviewControls.add(createReviewLink("approveLink", Score.approved));
} else {
reviewControls.add(new Label("approveLink").setVisible(false));
}
// show "looks good" button if no review OR not current score
if (myReview == null || Score.looks_good != myReview.score) {
reviewControls.add(createReviewLink("looksGoodLink", Score.looks_good));
} else {
reviewControls.add(new Label("looksGoodLink").setVisible(false));
}
// show "needs improvement" button if no review OR not current score
if (myReview == null || Score.needs_improvement != myReview.score) {
reviewControls.add(createReviewLink("needsImprovementLink", Score.needs_improvement));
} else {
reviewControls.add(new Label("needsImprovementLink").setVisible(false));
}
// show "veto" button if no review OR not current score
if (user.canVetoPatchset(repository) && (myReview == null || Score.vetoed != myReview.score)) {
reviewControls.add(createReviewLink("vetoLink", Score.vetoed));
} else {
reviewControls.add(new Label("vetoLink").setVisible(false));
}
panel.add(reviewControls);
} else {
// user can not review
panel.add(new Label("reviewControls").setVisible(false));
}
String insertions = MessageFormat.format("<span style=\"color:darkGreen;font-weight:bold;\">+{0}</span>", ticket.insertions);
String deletions = MessageFormat.format("<span style=\"color:darkRed;font-weight:bold;\">-{0}</span>", ticket.deletions);
panel.add(new Label("patchsetStat", MessageFormat.format(StringUtils.escapeForHtml(getString("gb.diffStat"), false), insertions, deletions)).setEscapeModelStrings(false));
// changed paths list
List<PathChangeModel> paths = JGitUtils.getFilesInRange(getRepository(), currentPatchset.base, currentPatchset.tip);
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
private static final long serialVersionUID = 1L;
int counter;
@Override
public void populateItem(final Item<PathChangeModel> item) {
final PathChangeModel entry = item.getModelObject();
Label changeType = new Label("changeType", "");
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
setChangeTypeTooltip(changeType, entry.changeType);
item.add(changeType);
boolean hasSubmodule = false;
String submodulePath = null;
if (entry.isTree()) {
// tree
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path), true));
item.add(new Label("diffStat").setVisible(false));
} else if (entry.isSubmodule()) {
// submodule
String submoduleId = entry.objectId;
SubmoduleModel submodule = getSubmodule(entry.path);
submodulePath = submodule.gitblitPath;
hasSubmodule = submodule.hasSubmodule;
item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), TreePage.class, WicketUtils.newPathParameter(submodulePath, submoduleId, ""), true).setEnabled(hasSubmodule));
item.add(new Label("diffStat").setVisible(false));
} else {
// blob
String displayPath = entry.path;
String path = entry.path;
if (entry.isSymlink()) {
RevCommit commit = JGitUtils.getCommit(getRepository(), PatchsetCommand.getTicketBranch(ticket.number));
path = JGitUtils.getStringContent(getRepository(), commit.getTree(), path);
displayPath = entry.path + " -> " + path;
}
if (entry.changeType.equals(ChangeType.ADD)) {
// add show view
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
} else if (entry.changeType.equals(ChangeType.DELETE)) {
// delete, show label
item.add(new Label("pathName", displayPath));
} else {
// mod, show diff
item.add(new LinkPanel("pathName", "list", displayPath, BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
}
item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
}
// quick links
if (entry.isSubmodule()) {
// submodule
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD)));
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
} else {
// tree or blob
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newBlobDiffParameter(repositoryName, currentPatchset.base, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD) && !entry.changeType.equals(ChangeType.DELETE)));
item.add(setNewTarget(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
}
WicketUtils.setAlternatingBackground(item, counter);
counter++;
}
};
panel.add(pathsView);
addPtCheckoutInstructions(user, repository, panel);
addGitCheckoutInstructions(user, repository, panel);
return panel;
}
use of com.gitblit.models.SubmoduleModel in project gitblit by gitblit.
the class JGitUtils method getSubmodules.
/**
* Returns the list of submodules for this repository.
*
* @param repository
* @param commit
* @return list of submodules
*/
public static List<SubmoduleModel> getSubmodules(Repository repository, RevTree tree) {
List<SubmoduleModel> list = new ArrayList<SubmoduleModel>();
byte[] blob = getByteContent(repository, tree, ".gitmodules", false);
if (blob == null) {
return list;
}
try {
BlobBasedConfig config = new BlobBasedConfig(repository.getConfig(), blob);
for (String module : config.getSubsections("submodule")) {
String path = config.getString("submodule", module, "path");
String url = config.getString("submodule", module, "url");
list.add(new SubmoduleModel(module, path, url));
}
} catch (ConfigInvalidException e) {
LOGGER.error("Failed to load .gitmodules file for " + repository.getDirectory(), e);
}
return list;
}
Aggregations