From 30f9d25d77ccb5cd978d4cf8fa389ec819e90e95 Mon Sep 17 00:00:00 2001 From: Philip L. McMahon <philip.l.mcmahon@gmail.com> Date: Fri, 27 Jan 2012 02:02:19 -0500 Subject: [PATCH] Correct update of HEAD symbolic reference when target is a tag. --- src/com/gitblit/wicket/pages/EditRepositoryPage.java | 95 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 90 insertions(+), 5 deletions(-) diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index 1a5ec3d..6c04249 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -19,9 +19,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.wicket.PageParameters; import org.apache.wicket.extensions.markup.html.form.palette.Palette; @@ -33,6 +35,8 @@ import org.apache.wicket.markup.html.form.IChoiceRenderer; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import org.apache.wicket.model.util.CollectionModel; import org.apache.wicket.model.util.ListModel; @@ -41,17 +45,22 @@ import com.gitblit.GitBlit; import com.gitblit.GitBlitException; import com.gitblit.Keys; +import com.gitblit.models.RefModel; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; +import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.panels.BulletListPanel; public class EditRepositoryPage extends RootSubPage { private final boolean isCreate; private boolean isAdmin; + + private IModel<String> mailingLists; public EditRepositoryPage() { // create constructor @@ -76,6 +85,9 @@ List<String> federationSets = new ArrayList<String>(); List<String> repositoryUsers = new ArrayList<String>(); List<String> repositoryTeams = new ArrayList<String>(); + List<String> preReceiveScripts = new ArrayList<String>(); + List<String> postReceiveScripts = new ArrayList<String>(); + if (isCreate) { super.setupPage(getString("gb.newRepository"), ""); } else { @@ -86,8 +98,7 @@ Collections.sort(repositoryUsers); } federationSets.addAll(repositoryModel.federationSets); - } - + } final String oldName = repositoryModel.name; // users palette @@ -98,13 +109,31 @@ // teams palette final Palette<String> teamsPalette = new Palette<String>("teams", new ListModel<String>( repositoryTeams), new CollectionModel<String>(GitBlit.self().getAllTeamnames()), - new ChoiceRenderer<String>("", ""), 10, false); + new ChoiceRenderer<String>("", ""), 5, false); // federation sets palette List<String> sets = GitBlit.getStrings(Keys.federation.sets); final Palette<String> federationSetsPalette = new Palette<String>("federationSets", new ListModel<String>(federationSets), new CollectionModel<String>(sets), - new ChoiceRenderer<String>("", ""), 10, false); + new ChoiceRenderer<String>("", ""), 5, false); + + // pre-receive palette + if (!ArrayUtils.isEmpty(repositoryModel.preReceiveScripts)) { + preReceiveScripts.addAll(repositoryModel.preReceiveScripts); + } + final Palette<String> preReceivePalette = new Palette<String>("preReceiveScripts", + new ListModel<String>(preReceiveScripts), new CollectionModel<String>(GitBlit + .self().getPreReceiveScriptsUnused(repositoryModel)), + new ChoiceRenderer<String>("", ""), 12, true); + + // post-receive palette + if (!ArrayUtils.isEmpty(repositoryModel.postReceiveScripts)) { + postReceiveScripts.addAll(repositoryModel.postReceiveScripts); + } + final Palette<String> postReceivePalette = new Palette<String>("postReceiveScripts", + new ListModel<String>(postReceiveScripts), new CollectionModel<String>(GitBlit + .self().getPostReceiveScriptsUnused(repositoryModel)), + new ChoiceRenderer<String>("", ""), 12, true); CompoundPropertyModel<RepositoryModel> model = new CompoundPropertyModel<RepositoryModel>( repositoryModel); @@ -169,6 +198,35 @@ } } + // set mailing lists + String ml = mailingLists.getObject(); + if (!StringUtils.isEmpty(ml)) { + Set<String> list = new HashSet<String>(); + for (String address : ml.split("(,|\\s)")) { + if (StringUtils.isEmpty(address)) { + continue; + } + list.add(address.toLowerCase()); + } + repositoryModel.mailingLists = new ArrayList<String>(list); + } + + // pre-receive scripts + List<String> preReceiveScripts = new ArrayList<String>(); + Iterator<String> pres = preReceivePalette.getSelectedChoices(); + while (pres.hasNext()) { + preReceiveScripts.add(pres.next()); + } + repositoryModel.preReceiveScripts = preReceiveScripts; + + // post-receive scripts + List<String> postReceiveScripts = new ArrayList<String>(); + Iterator<String> post = postReceivePalette.getSelectedChoices(); + while (post.hasNext()) { + postReceiveScripts.add(post.next()); + } + repositoryModel.postReceiveScripts = postReceiveScripts; + // save the repository GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate); @@ -186,7 +244,7 @@ repositoryUsers.add(repositoryModel.owner); } GitBlit.self().setRepositoryUsers(repositoryModel, repositoryUsers); - + // save the team access list Iterator<String> teams = teamsPalette.getSelectedChoices(); List<String> repositoryTeams = new ArrayList<String>(); @@ -214,6 +272,9 @@ form.add(new CheckBox("isFrozen")); // TODO enable origin definition form.add(new TextField<String>("origin").setEnabled(false/* isCreate */)); + // enable alteration of the default branch after clone + form.add(new DropDownChoice<RefModel>("defaultHead", repositoryModel.availableHeads, + new RefModelRenderer()).setEnabled(GitBlitWebSession.get().canAdmin())); // federation strategies - remove ORIGIN choice if this repository has // no origin. @@ -230,9 +291,18 @@ form.add(new CheckBox("showReadme")); form.add(new CheckBox("skipSizeCalculation")); form.add(new CheckBox("skipSummaryMetrics")); + mailingLists = new Model<String>(ArrayUtils.isEmpty(repositoryModel.mailingLists) ? "" + : StringUtils.flattenStrings(repositoryModel.mailingLists, " ")); + form.add(new TextField<String>("mailingLists", mailingLists)); form.add(usersPalette); form.add(teamsPalette); form.add(federationSetsPalette); + form.add(preReceivePalette); + form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self() + .getPreReceiveScriptsInherited(repositoryModel))); + form.add(postReceivePalette); + form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self() + .getPostReceiveScriptsInherited(repositoryModel))); form.add(new Button("save")); Button cancel = new Button("cancel") { @@ -295,6 +365,21 @@ } } + private class RefModelRenderer implements IChoiceRenderer<RefModel> { + + private static final long serialVersionUID = 1L; + + @Override + public String getDisplayValue(RefModel type) { + return type.displayName; + } + + @Override + public String getIdValue(RefModel type, int index) { + return type.getName(); + } + } + private class AccessRestrictionRenderer implements IChoiceRenderer<AccessRestrictionType> { private static final long serialVersionUID = 1L; -- Gitblit v1.9.1