import java.text.MessageFormat;\r
import java.util.Collection;\r
import java.util.Enumeration;\r
+import java.util.Iterator;\r
import java.util.LinkedHashSet;\r
import java.util.List;\r
import java.util.Map;\r
import javax.servlet.ServletContext;\r
import javax.servlet.ServletException;\r
import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.Part;\r
\r
+import org.eclipse.jgit.api.Git;\r
import org.eclipse.jgit.http.server.resolver.DefaultReceivePackFactory;\r
import org.eclipse.jgit.http.server.resolver.DefaultUploadPackFactory;\r
import org.eclipse.jgit.lib.PersonIdent;\r
\r
private File groovyDir;\r
\r
+ @Override\r
+ public void destroy() {\r
+ super.destroy();\r
+ }\r
+ \r
@Override\r
public void init(ServletConfig config) throws ServletException {\r
groovyDir = GitBlit.getGroovyScriptsFolder();\r
@Override\r
public ReceivePack create(HttpServletRequest req, Repository db)\r
throws ServiceNotEnabledException, ServiceNotAuthorizedException {\r
- \r
// determine repository name from request\r
+ org.eclipse.jgit.http.server.glue.WrappedRequest wrreq = (org.eclipse.jgit.http.server.glue.WrappedRequest) req;\r
+ \r
String repositoryName = req.getPathInfo().substring(1);\r
repositoryName = GitFilter.getRepositoryName(repositoryName);\r
\r
return up;\r
}\r
});\r
+ \r
super.init(new GitblitServletConfig(config));\r
}\r
\r
\r
UserModel user = getUserModel(rp);\r
RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);\r
-\r
+ \r
+ if (repository.useIncrementalRevisionNumbers) {\r
+ List<ReceiveCommand> allCommands = rp.getAllCommands();\r
+ String cmds = "";\r
+ for (ReceiveCommand receiveCommand : allCommands) {\r
+ cmds += receiveCommand.getType() + "_"\r
+ + receiveCommand.getResult() + "_"\r
+ + receiveCommand.getMessage() + ", ";\r
+ if (receiveCommand.getType().equals(\r
+ ReceiveCommand.Type.UPDATE)\r
+ && receiveCommand.getResult().equals(\r
+ ReceiveCommand.Result.OK)) {\r
+ String objectId = receiveCommand.getNewId().toString()\r
+ .replace("AnyObjectId[", "").replace("]", "");\r
+ System.err.println("SHB id " + objectId);\r
+ System.err.println("SHB id "\r
+ + objectId.getBytes().length);\r
+ // if type=update and update was ok, autotag\r
+ boolean result = JGitUtils\r
+ .createIncrementalRevisionTag(\r
+ rp.getRepository(), objectId);\r
+ System.err.println("SHB res " + result);\r
+ }\r
+ }\r
+ System.err.println("SHB cmds: " + cmds);\r
+ }\r
+ \r
// log ref changes\r
for (ReceiveCommand cmd : commands) {\r
if (Result.OK.equals(cmd.getResult())) {\r
import java.util.Collections;\r
import java.util.Date;\r
import java.util.HashMap;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Map.Entry;\r
import org.eclipse.jgit.api.CloneCommand;\r
import org.eclipse.jgit.api.FetchCommand;\r
import org.eclipse.jgit.api.Git;\r
+import org.eclipse.jgit.api.TagCommand;\r
import org.eclipse.jgit.api.errors.GitAPIException;\r
import org.eclipse.jgit.diff.DiffEntry;\r
import org.eclipse.jgit.diff.DiffEntry.ChangeType;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
import com.gitblit.models.GitNote;\r
import com.gitblit.models.PathModel;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
*/\r
public class JGitUtils {\r
\r
+ private static final String REVISION_TAG_PREFIX = "rev_";\r
static final Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);\r
\r
/**\r
}\r
return list;\r
}\r
+ \r
+ /**\r
+ * this method creates an incremental revision number as a tag according to\r
+ * the amount of already existing tags, which start with a defined prefix {@link REVISION_TAG_PREFIX}\r
+ * \r
+ * @param repository\r
+ * @param objectId\r
+ * @return true if operation was successful, otherwise false\r
+ */\r
+ public static boolean createIncrementalRevisionTag(Repository repository, String objectId) {\r
+ boolean result = false;\r
+ Iterator<Entry<String, Ref>> iterator = repository.getTags().entrySet().iterator();\r
+ long revisionNumber = 1;\r
+ while (iterator.hasNext()) {\r
+ Entry<String, Ref> entry = iterator.next();\r
+ if (entry.getKey().startsWith(REVISION_TAG_PREFIX)) {\r
+ revisionNumber++;\r
+ }\r
+ }\r
+ result = createTag(repository,REVISION_TAG_PREFIX+revisionNumber,objectId);\r
+ return result;\r
+ }\r
\r
+ /**\r
+ * creates a tag in a repository referring to the current head\r
+ * \r
+ * @param repository\r
+ * @param tag, the string label\r
+ * @return boolean, true if operation was successful, otherwise false\r
+ */\r
+ public static boolean createTag(Repository repository, String tag) {\r
+ return createTag(repository, tag, null);\r
+ }\r
+ \r
+ /**\r
+ * creates a tag in a repository\r
+ * \r
+ * @param repository\r
+ * @param tag, the string label\r
+ * @param objectId, the ref the tag points towards\r
+ * @return boolean, true if operation was successful, otherwise false\r
+ */\r
+ public static boolean createTag(Repository repository, String tag,\r
+ String objectId) {\r
+ try { \r
+ PersonIdent author = new PersonIdent("GitblitAutoTagPush",\r
+ "gitblit@localhost");\r
+\r
+ LOGGER.debug("createTag in repo: "+repository.getDirectory().getAbsolutePath());\r
+ Git gitClient = Git.open(repository.getDirectory());\r
+ TagCommand tagCommand = gitClient.tag();\r
+ tagCommand.setTagger(author);\r
+ tagCommand.setMessage("autotag");\r
+ if (objectId != null) {\r
+ RevObject revObj = getCommit(repository, objectId);\r
+ tagCommand.setObjectId(revObj);\r
+ }\r
+ tagCommand.setName(tag);\r
+ Ref call = tagCommand.call(); \r
+ return call != null ? true : false;\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ return false;\r
+ }\r
+ \r
/**\r
* Create an orphaned branch in a repository.\r
* \r