diff options
Diffstat (limited to 'src/main')
10 files changed, 99 insertions, 66 deletions
diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties index 8c90258b..c881f14f 100644 --- a/src/main/distrib/data/gitblit.properties +++ b/src/main/distrib/data/gitblit.properties @@ -146,6 +146,17 @@ git.defaultAccessRestriction = NONE # SINCE 1.1.0
git.defaultAuthorizationControl = NAMED
+# The default incremental push tag prefix. Tag prefix applied to a repository
+# that has automatic push tags enabled and does not specify a custom tag prefix.
+#
+# If incremental push tags are enabled, the tips of each branch in the push will
+# be tagged with an increasing revision integer.
+#
+# e.g. refs/tags/r2345 or refs/tags/rev_2345
+#
+# SINCE 1.3.0
+git.defaultIncrementalPushTagPrefix = r
+
# Enable JGit-based garbage collection. (!!EXPERIMENTAL!!)
#
# USE AT YOUR OWN RISK!
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 6d44f461..1a817ab7 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -1676,7 +1676,8 @@ 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.useIncrementalPushTags = getConfig(config, "useIncrementalPushTags", false);
+ model.incrementalPushTagPrefix = getConfig(config, "incrementalPushTagPrefix", null);
model.allowForks = getConfig(config, "allowForks", true);
model.accessRestriction = AccessRestrictionType.fromName(getConfig(config,
"accessRestriction", settings.getString(Keys.git.defaultAccessRestriction, null)));
@@ -2198,7 +2199,13 @@ 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, "useIncrementalPushTags", repository.useIncrementalPushTags);
+ if (StringUtils.isEmpty(repository.incrementalPushTagPrefix) ||
+ repository.incrementalPushTagPrefix.equals(settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r"))) {
+ config.unset(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix");
+ } else {
+ config.setString(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix", repository.incrementalPushTagPrefix);
+ }
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 cb47b323..b64e44e5 100644 --- a/src/main/java/com/gitblit/GitServlet.java +++ b/src/main/java/com/gitblit/GitServlet.java @@ -23,7 +23,6 @@ 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;
@@ -33,9 +32,7 @@ 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;
@@ -55,6 +52,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.client.Translation;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ClientLogger;
@@ -297,26 +295,41 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet { return;
}
- UserModel user = getUserModel(rp);
+ 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);
+ if (repository.useIncrementalPushTags) {
+ // tag each pushed branch tip
+ String emailAddress = user.emailAddress == null ? rp.getRefLogIdent().getEmailAddress() : user.emailAddress;
+ PersonIdent userIdent = new PersonIdent(user.getDisplayName(), emailAddress);
+
+ for (ReceiveCommand cmd : commands) {
+ if (!cmd.getRefName().startsWith("refs/heads/")) {
+ // only tag branch ref changes
+ continue;
+ }
+
+ if (!ReceiveCommand.Type.DELETE.equals(cmd.getType())
+ && ReceiveCommand.Result.OK.equals(cmd.getResult())) {
+ String objectId = cmd.getNewId().getName();
+ String branch = cmd.getRefName().substring("refs/heads/".length());
+ // get translation based on the server's locale setting
+ String template = Translation.get("gb.incrementalPushTagMessage");
+ String msg = MessageFormat.format(template, branch);
+ String prefix;
+ if (StringUtils.isEmpty(repository.incrementalPushTagPrefix)) {
+ prefix = GitBlit.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");
+ } else {
+ prefix = repository.incrementalPushTagPrefix;
+ }
+
+ JGitUtils.createIncrementalRevisionTag(
+ rp.getRepository(),
+ objectId,
+ userIdent,
+ prefix,
+ "0",
+ msg);
}
}
}
@@ -332,6 +345,9 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet { case CREATE:
logger.info(MessageFormat.format("{0} CREATED {1} in {2}", user.username, cmd.getRefName(), repository.name));
break;
+ case UPDATE:
+ logger.info(MessageFormat.format("{0} UPDATED {1} in {2} (from {3} to {4})", user.username, cmd.getRefName(), repository.name, cmd.getOldId().name(), cmd.getNewId().name()));
+ break;
case UPDATE_NONFASTFORWARD:
logger.info(MessageFormat.format("{0} UPDATED NON-FAST-FORWARD {1} in {2} (from {3} to {4})", user.username, cmd.getRefName(), repository.name, cmd.getOldId().name(), cmd.getNewId().name()));
break;
diff --git a/src/main/java/com/gitblit/client/EditRepositoryDialog.java b/src/main/java/com/gitblit/client/EditRepositoryDialog.java index 25f42f4a..118c5c82 100644 --- a/src/main/java/com/gitblit/client/EditRepositoryDialog.java +++ b/src/main/java/com/gitblit/client/EditRepositoryDialog.java @@ -92,7 +92,7 @@ public class EditRepositoryDialog extends JDialog { private JCheckBox useDocs;
- private JCheckBox useIncrementalRevisionNumbers;
+ private JCheckBox useIncrementalPushTags;
private JCheckBox showRemoteBranches;
@@ -214,8 +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);
+ useIncrementalPushTags = new JCheckBox(Translation.get("gb.useIncrementalPushTagsDescription"),
+ anRepository.useIncrementalPushTags);
showRemoteBranches = new JCheckBox(
Translation.get("gb.showRemoteBranchesDescription"),
anRepository.showRemoteBranches);
@@ -314,7 +314,7 @@ public class EditRepositoryDialog extends JDialog { fieldsPanel
.add(newFieldPanel(Translation.get("gb.enableDocs"), useDocs));
fieldsPanel
- .add(newFieldPanel(Translation.get("gb.enableIncrementalRevisionNumbers"), useIncrementalRevisionNumbers));
+ .add(newFieldPanel(Translation.get("gb.enableIncrementalPushTags"), useIncrementalPushTags));
fieldsPanel.add(newFieldPanel(Translation.get("gb.showRemoteBranches"),
showRemoteBranches));
fieldsPanel.add(newFieldPanel(Translation.get("gb.showReadme"),
@@ -569,7 +569,7 @@ public class EditRepositoryDialog extends JDialog { repository.gcThreshold = gcThreshold.getText();
repository.useTickets = useTickets.isSelected();
repository.useDocs = useDocs.isSelected();
- repository.useIncrementalRevisionNumbers = useIncrementalRevisionNumbers.isSelected();
+ repository.useIncrementalPushTags = useIncrementalPushTags.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 1f2ee2df..5c906e5e 100644 --- a/src/main/java/com/gitblit/models/RepositoryModel.java +++ b/src/main/java/com/gitblit/models/RepositoryModel.java @@ -50,7 +50,8 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel public boolean showRemoteBranches;
public boolean useTickets;
public boolean useDocs;
- public boolean useIncrementalRevisionNumbers;
+ public boolean useIncrementalPushTags;
+ public String incrementalPushTagPrefix;
public AccessRestrictionType accessRestriction;
public AuthorizationControl authorizationControl;
public boolean allowAuthenticated;
@@ -202,7 +203,6 @@ 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/DiffUtils.java b/src/main/java/com/gitblit/utils/DiffUtils.java index 04b5b0b1..67871d22 100644 --- a/src/main/java/com/gitblit/utils/DiffUtils.java +++ b/src/main/java/com/gitblit/utils/DiffUtils.java @@ -16,6 +16,7 @@ package com.gitblit.utils;
import java.io.ByteArrayOutputStream;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -274,7 +275,7 @@ public class DiffUtils { lines.add(line);
}
} catch (Throwable t) {
- LOGGER.error("failed to generate blame!", t);
+ LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
}
return lines;
}
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java index 4326700d..c3aae275 100644 --- a/src/main/java/com/gitblit/utils/JGitUtils.java +++ b/src/main/java/com/gitblit/utils/JGitUtils.java @@ -19,6 +19,7 @@ import java.io.ByteArrayOutputStream; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -82,8 +83,6 @@ 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;
@@ -98,7 +97,6 @@ import com.gitblit.models.SubmoduleModel; */
public class JGitUtils {
- private static final String REVISION_TAG_PREFIX = "rev_";
static final Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);
/**
@@ -1692,59 +1690,58 @@ 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}
+ * the amount of already existing tags, which start with a defined prefix.
*
* @param repository
* @param objectId
+ * @param tagger
+ * @param prefix
+ * @param intPattern
+ * @param message
* @return true if operation was successful, otherwise false
*/
- public static boolean createIncrementalRevisionTag(Repository repository, String objectId) {
+ public static boolean createIncrementalRevisionTag(Repository repository,
+ String objectId, PersonIdent tagger, String prefix, String intPattern, String message) {
boolean result = false;
Iterator<Entry<String, Ref>> iterator = repository.getTags().entrySet().iterator();
- long revisionNumber = 1;
+ long lastRev = 0;
while (iterator.hasNext()) {
Entry<String, Ref> entry = iterator.next();
- if (entry.getKey().startsWith(REVISION_TAG_PREFIX)) {
- revisionNumber++;
+ if (entry.getKey().startsWith(prefix)) {
+ try {
+ long val = Long.parseLong(entry.getKey().substring(prefix.length()));
+ if (val > lastRev) {
+ lastRev = val;
+ }
+ } catch (Exception e) {
+ // this tag is NOT an incremental revision tag
+ }
}
}
- result = createTag(repository,REVISION_TAG_PREFIX+revisionNumber,objectId);
+ DecimalFormat df = new DecimalFormat(intPattern);
+ result = createTag(repository, objectId, tagger, prefix + df.format((lastRev + 1)), message);
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
+ * @param tagger, the person tagging the object
+ * @param tag, the string label
+ * @param message, the string message
* @return boolean, true if operation was successful, otherwise false
*/
- public static boolean createTag(Repository repository, String tag,
- String objectId) {
+ public static boolean createTag(Repository repository, String objectId, PersonIdent tagger, String tag, String message) {
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");
+ tagCommand.setTagger(tagger);
+ tagCommand.setMessage(message);
if (objectId != null) {
RevObject revObj = getCommit(repository, objectId);
tagCommand.setObjectId(revObj);
@@ -1753,7 +1750,7 @@ public class JGitUtils { Ref call = tagCommand.call();
return call != null ? true : false;
} catch (Exception e) {
- e.printStackTrace();
+ error(e, repository, "Failed to create tag {1} in repository {0}", objectId, tag);
}
return false;
}
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index 81eecb2b..f2d4a36c 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -73,7 +73,6 @@ 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
@@ -86,7 +85,6 @@ 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
@@ -448,3 +446,6 @@ 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} +gb.enableIncrementalPushTags = enable incremental push tags
+gb.useIncrementalPushTagsDescription = on push, automatically tag each branch tip with an incremental revision number
+gb.incrementalPushTagMessage = Auto-tagged [{0}] branch on push
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html index 37ea0dd2..f8ecb992 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -35,7 +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" /> <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" /> <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" /> <span class="help-inline"><wicket:message key="gb.useIncrementalRevisionNumbersDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.enableIncrementalPushTags"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="useIncrementalPushTags" tabindex="8" /> <span class="help-inline"><wicket:message key="gb.useIncrementalPushTagsDescription"></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" /> <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" /> <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" /> <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 2cbb88cc..58d3390c 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -422,7 +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("useIncrementalPushTags"));
form.add(new CheckBox("showRemoteBranches"));
form.add(new CheckBox("showReadme"));
form.add(new CheckBox("skipSizeCalculation"));
|