summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-04-01 08:09:29 -0400
committerJames Moger <james.moger@gitblit.com>2013-04-01 08:09:29 -0400
commit19c1af5650cd58228f78308d98a7c22f37e3dec3 (patch)
tree5d62736e3209a57d3ec5de9deac03df652253e10
parent2fe1e2d109fd84ec7a615c2d3d6740ff001dbf40 (diff)
parente0c37df7ca2fe51bb538bdfe2412f74d5880e17d (diff)
downloadgitblit-19c1af5650cd58228f78308d98a7c22f37e3dec3.tar.gz
gitblit-19c1af5650cd58228f78308d98a7c22f37e3dec3.zip
Merge branch 'autotagpush' of https://github.com/akquinet/gitblit into pushtags
-rw-r--r--src/main/java/com/gitblit/GitBlit.java2
-rw-r--r--src/main/java/com/gitblit/GitServlet.java30
-rw-r--r--src/main/java/com/gitblit/client/EditRepositoryDialog.java7
-rw-r--r--src/main/java/com/gitblit/models/RepositoryModel.java2
-rw-r--r--src/main/java/com/gitblit/utils/JGitUtils.java70
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.properties4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html1
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java1
8 files changed, 113 insertions, 4 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 12815e78..6d44f461 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -1676,6 +1676,7 @@ public class GitBlit implements ServletContextListener {
model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", "")));
model.useTickets = getConfig(config, "useTickets", false);
model.useDocs = getConfig(config, "useDocs", false);
+ model.useIncrementalRevisionNumbers = getConfig(config, "useIncrementalRevisionNumbers", false);
model.allowForks = getConfig(config, "allowForks", true);
model.accessRestriction = AccessRestrictionType.fromName(getConfig(config,
"accessRestriction", settings.getString(Keys.git.defaultAccessRestriction, null)));
@@ -2197,6 +2198,7 @@ public class GitBlit implements ServletContextListener {
config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners));
config.setBoolean(Constants.CONFIG_GITBLIT, null, "useTickets", repository.useTickets);
config.setBoolean(Constants.CONFIG_GITBLIT, null, "useDocs", repository.useDocs);
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "useIncrementalRevisionNumbers", repository.useIncrementalRevisionNumbers);
config.setBoolean(Constants.CONFIG_GITBLIT, null, "allowForks", repository.allowForks);
config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name());
config.setString(Constants.CONFIG_GITBLIT, null, "authorizationControl", repository.authorizationControl.name());
diff --git a/src/main/java/com/gitblit/GitServlet.java b/src/main/java/com/gitblit/GitServlet.java
index 77be963f..cb47b323 100644
--- a/src/main/java/com/gitblit/GitServlet.java
+++ b/src/main/java/com/gitblit/GitServlet.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -32,7 +33,9 @@ import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.http.server.resolver.DefaultReceivePackFactory;
import org.eclipse.jgit.http.server.resolver.DefaultUploadPackFactory;
import org.eclipse.jgit.lib.PersonIdent;
@@ -80,7 +83,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
private GroovyScriptEngine gse;
private File groovyDir;
-
+
@Override
public void init(ServletConfig config) throws ServletException {
groovyDir = GitBlit.getGroovyScriptsFolder();
@@ -100,7 +103,6 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
@Override
public ReceivePack create(HttpServletRequest req, Repository db)
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
-
// determine repository name from request
String repositoryName = req.getPathInfo().substring(1);
repositoryName = GitFilter.getRepositoryName(repositoryName);
@@ -163,6 +165,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
return up;
}
});
+
super.init(new GitblitServletConfig(config));
}
@@ -296,7 +299,28 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
UserModel user = getUserModel(rp);
RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);
-
+
+ if (repository.useIncrementalRevisionNumbers) {
+ List<ReceiveCommand> allCommands = rp.getAllCommands();
+ String cmds = "";
+ for (ReceiveCommand receiveCommand : allCommands) {
+ cmds += receiveCommand.getType() + "_"
+ + receiveCommand.getResult() + "_"
+ + receiveCommand.getMessage() + ", ";
+ if (receiveCommand.getType().equals(
+ ReceiveCommand.Type.UPDATE)
+ && receiveCommand.getResult().equals(
+ ReceiveCommand.Result.OK)) {
+ // if type=update and update was ok, autotag
+ String objectId = receiveCommand.getNewId().toString()
+ .replace("AnyObjectId[", "").replace("]", "");
+ boolean result = JGitUtils
+ .createIncrementalRevisionTag(
+ rp.getRepository(), objectId);
+ }
+ }
+ }
+
// log ref changes
for (ReceiveCommand cmd : commands) {
if (Result.OK.equals(cmd.getResult())) {
diff --git a/src/main/java/com/gitblit/client/EditRepositoryDialog.java b/src/main/java/com/gitblit/client/EditRepositoryDialog.java
index 8851de43..25f42f4a 100644
--- a/src/main/java/com/gitblit/client/EditRepositoryDialog.java
+++ b/src/main/java/com/gitblit/client/EditRepositoryDialog.java
@@ -92,6 +92,8 @@ public class EditRepositoryDialog extends JDialog {
private JCheckBox useDocs;
+ private JCheckBox useIncrementalRevisionNumbers;
+
private JCheckBox showRemoteBranches;
private JCheckBox showReadme;
@@ -212,6 +214,8 @@ public class EditRepositoryDialog extends JDialog {
anRepository.useTickets);
useDocs = new JCheckBox(Translation.get("gb.useDocsDescription"),
anRepository.useDocs);
+ useIncrementalRevisionNumbers = new JCheckBox(Translation.get("gb.useIncrementalRevisionNumbersDescription"),
+ anRepository.useIncrementalRevisionNumbers);
showRemoteBranches = new JCheckBox(
Translation.get("gb.showRemoteBranchesDescription"),
anRepository.showRemoteBranches);
@@ -309,6 +313,8 @@ public class EditRepositoryDialog extends JDialog {
useTickets));
fieldsPanel
.add(newFieldPanel(Translation.get("gb.enableDocs"), useDocs));
+ fieldsPanel
+ .add(newFieldPanel(Translation.get("gb.enableIncrementalRevisionNumbers"), useIncrementalRevisionNumbers));
fieldsPanel.add(newFieldPanel(Translation.get("gb.showRemoteBranches"),
showRemoteBranches));
fieldsPanel.add(newFieldPanel(Translation.get("gb.showReadme"),
@@ -563,6 +569,7 @@ public class EditRepositoryDialog extends JDialog {
repository.gcThreshold = gcThreshold.getText();
repository.useTickets = useTickets.isSelected();
repository.useDocs = useDocs.isSelected();
+ repository.useIncrementalRevisionNumbers = useIncrementalRevisionNumbers.isSelected();
repository.showRemoteBranches = showRemoteBranches.isSelected();
repository.showReadme = showReadme.isSelected();
repository.skipSizeCalculation = skipSizeCalculation.isSelected();
diff --git a/src/main/java/com/gitblit/models/RepositoryModel.java b/src/main/java/com/gitblit/models/RepositoryModel.java
index a2dab3c5..1f2ee2df 100644
--- a/src/main/java/com/gitblit/models/RepositoryModel.java
+++ b/src/main/java/com/gitblit/models/RepositoryModel.java
@@ -50,6 +50,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
public boolean showRemoteBranches;
public boolean useTickets;
public boolean useDocs;
+ public boolean useIncrementalRevisionNumbers;
public AccessRestrictionType accessRestriction;
public AuthorizationControl authorizationControl;
public boolean allowAuthenticated;
@@ -201,6 +202,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
clone.showRemoteBranches = false;
clone.allowForks = false;
clone.useDocs = useDocs;
+ clone.useIncrementalRevisionNumbers = useIncrementalRevisionNumbers;
clone.useTickets = useTickets;
clone.skipSizeCalculation = skipSizeCalculation;
clone.skipSummaryMetrics = skipSummaryMetrics;
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index 1f2ae943..4326700d 100644
--- a/src/main/java/com/gitblit/utils/JGitUtils.java
+++ b/src/main/java/com/gitblit/utils/JGitUtils.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -33,6 +34,7 @@ import java.util.regex.Pattern;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.FetchCommand;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.TagCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
@@ -80,6 +82,8 @@ import org.eclipse.jgit.util.io.DisabledOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.gitblit.GitBlit;
+import com.gitblit.Keys;
import com.gitblit.models.GitNote;
import com.gitblit.models.PathModel;
import com.gitblit.models.PathModel.PathChangeModel;
@@ -94,6 +98,7 @@ import com.gitblit.models.SubmoduleModel;
*/
public class JGitUtils {
+ private static final String REVISION_TAG_PREFIX = "rev_";
static final Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);
/**
@@ -1687,8 +1692,73 @@ public class JGitUtils {
}
return list;
}
+
+ /**
+ * this method creates an incremental revision number as a tag according to
+ * the amount of already existing tags, which start with a defined prefix {@link REVISION_TAG_PREFIX}
+ *
+ * @param repository
+ * @param objectId
+ * @return true if operation was successful, otherwise false
+ */
+ public static boolean createIncrementalRevisionTag(Repository repository, String objectId) {
+ boolean result = false;
+ Iterator<Entry<String, Ref>> iterator = repository.getTags().entrySet().iterator();
+ long revisionNumber = 1;
+ while (iterator.hasNext()) {
+ Entry<String, Ref> entry = iterator.next();
+ if (entry.getKey().startsWith(REVISION_TAG_PREFIX)) {
+ revisionNumber++;
+ }
+ }
+ result = createTag(repository,REVISION_TAG_PREFIX+revisionNumber,objectId);
+ return result;
+ }
/**
+ * creates a tag in a repository referring to the current head
+ *
+ * @param repository
+ * @param tag, the string label
+ * @return boolean, true if operation was successful, otherwise false
+ */
+ public static boolean createTag(Repository repository, String tag) {
+ return createTag(repository, tag, null);
+ }
+
+ /**
+ * creates a tag in a repository
+ *
+ * @param repository
+ * @param tag, the string label
+ * @param objectId, the ref the tag points towards
+ * @return boolean, true if operation was successful, otherwise false
+ */
+ public static boolean createTag(Repository repository, String tag,
+ String objectId) {
+ try {
+ PersonIdent author = new PersonIdent("GitblitAutoTagPush",
+ "gitblit@localhost");
+
+ LOGGER.debug("createTag in repo: "+repository.getDirectory().getAbsolutePath());
+ Git gitClient = Git.open(repository.getDirectory());
+ TagCommand tagCommand = gitClient.tag();
+ tagCommand.setTagger(author);
+ tagCommand.setMessage("autotag");
+ if (objectId != null) {
+ RevObject revObj = getCommit(repository, objectId);
+ tagCommand.setObjectId(revObj);
+ }
+ tagCommand.setName(tag);
+ Ref call = tagCommand.call();
+ return call != null ? true : false;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
* Create an orphaned branch in a repository.
*
* @param repository
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
index b0d559f6..81eecb2b 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
@@ -73,6 +73,7 @@ gb.accessRestriction = access restriction
gb.name = name
gb.enableTickets = enable tickets
gb.enableDocs = enable docs
+gb.enableIncrementalRevisionNumbers = enable incremental revision numbers
gb.save = save
gb.showRemoteBranches = show remote branches
gb.editUsers = edit users
@@ -85,6 +86,7 @@ gb.cloneRestricted = authenticated clone & push
gb.viewRestricted = authenticated view, clone, & push
gb.useTicketsDescription = readonly, distributed Ticgit issues
gb.useDocsDescription = enumerates Markdown documentation in repository
+gb.useIncrementalRevisionNumbersDescription = automatic tagging of each push with an incremental revision number
gb.showRemoteBranchesDescription = show remote branches
gb.canAdminDescription = can administer Gitblit server
gb.permittedUsers = permitted users
@@ -445,4 +447,4 @@ gb.isSparkleshared = repository is Sparkleshared
gb.owners = owners
gb.sessionEnded = Session has been closed
gb.closeBrowser = Please close the browser to properly end the session.
-gb.doesNotExistInTree = {0} does not exist in tree {1} \ No newline at end of file
+gb.doesNotExistInTree = {0} does not exist in tree {1}
diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html
index 7fc0de23..37ea0dd2 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html
+++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html
@@ -35,6 +35,7 @@
<tr><th colspan="2"><hr/></th></tr>
<tr><th><wicket:message key="gb.enableTickets"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="useTickets" tabindex="7" /> &nbsp;<span class="help-inline"><wicket:message key="gb.useTicketsDescription"></wicket:message></span></label></td></tr>
<tr><th><wicket:message key="gb.enableDocs"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="useDocs" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.useDocsDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.enableIncrementalRevisionNumbers"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="useIncrementalRevisionNumbers" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.useIncrementalRevisionNumbersDescription"></wicket:message></span></label></td></tr>
<tr><th><wicket:message key="gb.showRemoteBranches"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="showRemoteBranches" tabindex="9" /> &nbsp;<span class="help-inline"><wicket:message key="gb.showRemoteBranchesDescription"></wicket:message></span></label></td></tr>
<tr><th><wicket:message key="gb.showReadme"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="showReadme" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.showReadmeDescription"></wicket:message></span></label></td></tr>
<tr><th><wicket:message key="gb.skipSizeCalculation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="skipSizeCalculation" tabindex="11" /> &nbsp;<span class="help-inline"><wicket:message key="gb.skipSizeCalculationDescription"></wicket:message></span></label></td></tr>
diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
index d68d6550..2cbb88cc 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -422,6 +422,7 @@ public class EditRepositoryPage extends RootSubPage {
new FederationTypeRenderer()));
form.add(new CheckBox("useTickets"));
form.add(new CheckBox("useDocs"));
+ form.add(new CheckBox("useIncrementalRevisionNumbers"));
form.add(new CheckBox("showRemoteBranches"));
form.add(new CheckBox("showReadme"));
form.add(new CheckBox("skipSizeCalculation"));