mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 03:55:51 +01:00
merge with branch 1.x
This commit is contained in:
@@ -37,8 +37,8 @@ package sonia.scm.repository;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevSort;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
@@ -52,8 +52,9 @@ import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -109,76 +110,27 @@ public class GitHookChangesetCollector
|
||||
|
||||
for (ReceiveCommand rc : receiveCommands)
|
||||
{
|
||||
//J-
|
||||
logger.trace("handle receive command, type={}, ref={}, result={}",
|
||||
new Object[] {
|
||||
rc.getType(),
|
||||
rc.getRefName(),
|
||||
rc.getResult()
|
||||
}
|
||||
);
|
||||
//J+
|
||||
|
||||
ObjectId newId = rc.getNewId();
|
||||
|
||||
String branch = GitUtil.getBranch(rc.getRefName());
|
||||
|
||||
walk.reset();
|
||||
walk.sort(RevSort.TOPO);
|
||||
walk.sort(RevSort.REVERSE, true);
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
if (rc.getType() != ReceiveCommand.Type.DELETE)
|
||||
{
|
||||
logger.trace("mark {} as start for rev walk", newId.getName());
|
||||
}
|
||||
|
||||
walk.markStart(walk.parseCommit(newId));
|
||||
|
||||
ObjectId oldId = rc.getOldId();
|
||||
|
||||
if ((oldId != null) &&!oldId.equals(ObjectId.zeroId()))
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
try
|
||||
{
|
||||
logger.trace("mark {} as uninteresting for rev walk",
|
||||
oldId.getName());
|
||||
collectChangesets(changesets, converter, walk, rc);
|
||||
}
|
||||
|
||||
walk.markUninteresting(walk.parseCommit(oldId));
|
||||
}
|
||||
|
||||
for (ObjectId id : getExistingObjects(rpack))
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.trace("mark {} as uninteresting for rev walk", id.getName());
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("could not handle receive command, type=");
|
||||
builder.append(rc.getType()).append(", ref=");
|
||||
builder.append(rc.getRefName()).append(", result=");
|
||||
builder.append(rc.getResult());
|
||||
logger.error(builder.toString(), ex);
|
||||
}
|
||||
|
||||
walk.markUninteresting(walk.parseCommit(id));
|
||||
}
|
||||
|
||||
RevCommit commit = walk.next();
|
||||
|
||||
List<String> branches = Lists.newArrayList(branch);
|
||||
|
||||
while (commit != null)
|
||||
else
|
||||
{
|
||||
|
||||
// parse commit body to avoid npe
|
||||
walk.parseBody(commit);
|
||||
|
||||
Changeset changeset = converter.createChangeset(commit, branches);
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("retrive commit {} for hook", changeset.getId());
|
||||
}
|
||||
|
||||
changesets.add(changeset);
|
||||
|
||||
commit = walk.next();
|
||||
logger.debug("skip delete of branch {}", rc.getRefName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -195,38 +147,78 @@ public class GitHookChangesetCollector
|
||||
return changesets;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param rpack
|
||||
* @param changesets
|
||||
* @param converter
|
||||
* @param walk
|
||||
* @param rc
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws IncorrectObjectTypeException
|
||||
*/
|
||||
private List<ObjectId> getExistingObjects(ReceivePack rpack)
|
||||
private void collectChangesets(List<Changeset> changesets,
|
||||
GitChangesetConverter converter, RevWalk walk, ReceiveCommand rc)
|
||||
throws IncorrectObjectTypeException, IOException
|
||||
{
|
||||
List<ObjectId> existingObjects = Lists.newArrayList();
|
||||
|
||||
if (existingObjects == null)
|
||||
{
|
||||
Map<String, Ref> refs = rpack.getRepository().getAllRefs();
|
||||
|
||||
for (Ref r : refs.values())
|
||||
{
|
||||
existingObjects.add(r.getObjectId());
|
||||
//J-
|
||||
logger.trace("handle receive command, type={}, ref={}, result={}",
|
||||
new Object[] {
|
||||
rc.getType(),
|
||||
rc.getRefName(),
|
||||
rc.getResult()
|
||||
}
|
||||
);
|
||||
//J+
|
||||
|
||||
ObjectId newId = rc.getNewId();
|
||||
|
||||
String branch = GitUtil.getBranch(rc.getRefName());
|
||||
|
||||
walk.reset();
|
||||
walk.sort(RevSort.TOPO);
|
||||
walk.sort(RevSort.REVERSE, true);
|
||||
|
||||
logger.trace("mark {} as start for rev walk", newId.getName());
|
||||
|
||||
walk.markStart(walk.parseCommit(newId));
|
||||
|
||||
ObjectId oldId = rc.getOldId();
|
||||
|
||||
if ((oldId != null) &&!oldId.equals(ObjectId.zeroId()))
|
||||
{
|
||||
logger.trace("mark {} as uninteresting for rev walk", oldId.getName());
|
||||
|
||||
walk.markUninteresting(walk.parseCommit(oldId));
|
||||
}
|
||||
|
||||
return existingObjects;
|
||||
RevCommit commit = walk.next();
|
||||
|
||||
List<String> branches = Lists.newArrayList(branch);
|
||||
|
||||
while (commit != null)
|
||||
{
|
||||
|
||||
// parse commit body to avoid npe
|
||||
walk.parseBody(commit);
|
||||
|
||||
Changeset changeset = converter.createChangeset(commit, branches);
|
||||
|
||||
logger.trace("retrive commit {} for hook", changeset.getId());
|
||||
|
||||
changesets.add(changeset);
|
||||
|
||||
commit = walk.next();
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private List<ReceiveCommand> receiveCommands;
|
||||
private final List<ReceiveCommand> receiveCommands;
|
||||
|
||||
/** Field description */
|
||||
private ReceivePack rpack;
|
||||
private final ReceivePack rpack;
|
||||
}
|
||||
|
||||
@@ -695,6 +695,32 @@ public final class GitUtil
|
||||
//J+
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param ref
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isHead(String ref)
|
||||
{
|
||||
return ref.startsWith(REF_HEAD_PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidObjectId(ObjectId id)
|
||||
{
|
||||
return (id != null) &&!id.equals(ObjectId.zeroId());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,8 @@ import org.eclipse.jgit.transport.RemoteRefUpdate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -61,17 +63,17 @@ import java.util.Collection;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class AbstractPushOrPullCommand extends AbstractGitCommand
|
||||
public abstract class AbstractGitPushOrPullCommand extends AbstractGitCommand
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String SCHEME = "scm://";
|
||||
|
||||
/**
|
||||
* the logger for AbstractPushOrPullCommand
|
||||
* the logger for AbstractGitPushOrPullCommand
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(AbstractPushOrPullCommand.class);
|
||||
LoggerFactory.getLogger(AbstractGitPushOrPullCommand.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
@@ -79,36 +81,38 @@ public abstract class AbstractPushOrPullCommand extends AbstractGitCommand
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param context
|
||||
* @param repository
|
||||
*/
|
||||
public AbstractPushOrPullCommand(GitContext context,
|
||||
sonia.scm.repository.Repository repository)
|
||||
protected AbstractGitPushOrPullCommand(GitRepositoryHandler handler,
|
||||
GitContext context, sonia.scm.repository.Repository repository)
|
||||
{
|
||||
super(context, repository);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @param target
|
||||
* @param remoteUrl
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
protected long push(Repository source, File target)
|
||||
protected long push(Repository source, String remoteUrl)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
Git git = Git.wrap(source);
|
||||
org.eclipse.jgit.api.PushCommand push = git.push();
|
||||
|
||||
push.setPushAll().setPushTags();
|
||||
push.setRemote(SCHEME.concat(target.getAbsolutePath()));
|
||||
push.setRemote(remoteUrl);
|
||||
|
||||
long counter = -1;
|
||||
|
||||
@@ -158,6 +162,61 @@ public abstract class AbstractPushOrPullCommand extends AbstractGitCommand
|
||||
return remoteRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getRemoteUrl(RemoteCommandRequest request)
|
||||
{
|
||||
String url;
|
||||
sonia.scm.repository.Repository remRepo = request.getRemoteRepository();
|
||||
|
||||
if (remRepo != null)
|
||||
{
|
||||
url = getRemoteUrl(remRepo);
|
||||
}
|
||||
else if (request.getRemoteUrl() != null)
|
||||
{
|
||||
url = request.getRemoteUrl().toExternalForm();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("repository or url is requiered");
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getRemoteUrl(File directory)
|
||||
{
|
||||
return SCHEME.concat(directory.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getRemoteUrl(sonia.scm.repository.Repository repository)
|
||||
{
|
||||
return getRemoteUrl(handler.getDirectory(repository));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -195,21 +254,24 @@ public abstract class AbstractPushOrPullCommand extends AbstractGitCommand
|
||||
{
|
||||
long counter = 0;
|
||||
|
||||
try
|
||||
if (GitUtil.isHead(update.getRemoteName()))
|
||||
{
|
||||
org.eclipse.jgit.api.LogCommand log = git.log();
|
||||
ObjectId oldId = update.getExpectedOldObjectId();
|
||||
|
||||
if (oldId != null)
|
||||
try
|
||||
{
|
||||
log.not(oldId);
|
||||
}
|
||||
org.eclipse.jgit.api.LogCommand log = git.log();
|
||||
ObjectId oldId = update.getExpectedOldObjectId();
|
||||
|
||||
ObjectId newId = update.getNewObjectId();
|
||||
if (GitUtil.isValidObjectId(oldId))
|
||||
{
|
||||
log.not(oldId);
|
||||
}
|
||||
|
||||
if (newId != null)
|
||||
{
|
||||
log.add(newId);
|
||||
ObjectId newId = update.getNewObjectId();
|
||||
|
||||
if (GitUtil.isValidObjectId(newId))
|
||||
{
|
||||
log.add(newId);
|
||||
}
|
||||
|
||||
Iterable<RevCommit> commits = log.call();
|
||||
|
||||
@@ -217,18 +279,24 @@ public abstract class AbstractPushOrPullCommand extends AbstractGitCommand
|
||||
{
|
||||
counter += Iterables.size(commits);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("update without new object id");
|
||||
}
|
||||
|
||||
logger.trace("counting {} commits for ref update {}", counter, update);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("could not count pushed/pulled changesets", ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
logger.error("could not count pushed/pulled changesets", ex);
|
||||
logger.debug("do not count non branch ref update {}", update);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected GitRepositoryHandler handler;
|
||||
}
|
||||
@@ -36,8 +36,19 @@ package sonia.scm.repository.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.FetchResult;
|
||||
import org.eclipse.jgit.transport.RefSpec;
|
||||
import org.eclipse.jgit.transport.TagOpt;
|
||||
import org.eclipse.jgit.transport.TrackingRefUpdate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
@@ -50,27 +61,37 @@ import sonia.scm.repository.api.PullResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitPullCommand extends AbstractPushOrPullCommand
|
||||
public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
implements PullCommand
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String REF_SPEC = "refs/heads/*:refs/heads/*";
|
||||
|
||||
/** Field description */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(GitPullCommand.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param repositoryHandler
|
||||
* @param handler
|
||||
* @param context
|
||||
* @param repository
|
||||
*/
|
||||
public GitPullCommand(GitRepositoryHandler repositoryHandler,
|
||||
GitContext context, Repository repository)
|
||||
public GitPullCommand(GitRepositoryHandler handler, GitContext context,
|
||||
Repository repository)
|
||||
{
|
||||
super(context, repository);
|
||||
this.repositoryHandler = repositoryHandler;
|
||||
super(handler, context, repository);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -90,18 +111,134 @@ public class GitPullCommand extends AbstractPushOrPullCommand
|
||||
public PullResponse pull(PullCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
Repository sourceRepository = getRemoteRepository(request);
|
||||
PullResponse response;
|
||||
Repository sourceRepository = request.getRemoteRepository();
|
||||
|
||||
File sourceDirectory = repositoryHandler.getDirectory(sourceRepository);
|
||||
if (sourceRepository != null)
|
||||
{
|
||||
response = pullFromScmRepository(sourceRepository);
|
||||
}
|
||||
else if (request.getRemoteUrl() != null)
|
||||
{
|
||||
response = pullFromUrl(request.getRemoteUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("repository or url is required");
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param git
|
||||
* @param result
|
||||
* @param fetch
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private PullResponse convert(Git git, FetchResult fetch)
|
||||
throws RepositoryException
|
||||
{
|
||||
long counter = 0l;
|
||||
|
||||
for (TrackingRefUpdate tru : fetch.getTrackingRefUpdates())
|
||||
{
|
||||
counter += count(git, tru);
|
||||
}
|
||||
|
||||
logger.debug("received {} changesets by pull", counter);
|
||||
|
||||
return new PullResponse(counter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param git
|
||||
* @param tru
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private long count(Git git, TrackingRefUpdate tru)
|
||||
{
|
||||
long counter = 0;
|
||||
|
||||
if (GitUtil.isHead(tru.getLocalName()))
|
||||
{
|
||||
try
|
||||
{
|
||||
org.eclipse.jgit.api.LogCommand log = git.log();
|
||||
|
||||
ObjectId oldId = tru.getOldObjectId();
|
||||
|
||||
if (GitUtil.isValidObjectId(oldId))
|
||||
{
|
||||
log.not(oldId);
|
||||
}
|
||||
|
||||
ObjectId newId = tru.getNewObjectId();
|
||||
|
||||
if (GitUtil.isValidObjectId(newId))
|
||||
{
|
||||
log.add(newId);
|
||||
}
|
||||
|
||||
Iterable<RevCommit> commits = log.call();
|
||||
|
||||
if (commits != null)
|
||||
{
|
||||
counter += Iterables.size(commits);
|
||||
}
|
||||
|
||||
logger.trace("counting {} commits for ref update {}", counter, tru);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("could not count pushed/pulled changesets", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("do not count non branch ref update {}", tru);
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param sourceRepository
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private PullResponse pullFromScmRepository(Repository sourceRepository)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
File sourceDirectory = handler.getDirectory(sourceRepository);
|
||||
|
||||
Preconditions.checkArgument(sourceDirectory.exists(),
|
||||
"source repository directory does not exists");
|
||||
|
||||
File targetDirectory = repositoryHandler.getDirectory(repository);
|
||||
File targetDirectory = handler.getDirectory(repository);
|
||||
|
||||
Preconditions.checkArgument(sourceDirectory.exists(),
|
||||
"target repository directory does not exists");
|
||||
|
||||
logger.debug("pull changes from {} to {}",
|
||||
sourceDirectory.getAbsolutePath(), repository.getId());
|
||||
|
||||
PullResponse response = null;
|
||||
|
||||
org.eclipse.jgit.lib.Repository source = null;
|
||||
@@ -109,7 +246,7 @@ public class GitPullCommand extends AbstractPushOrPullCommand
|
||||
try
|
||||
{
|
||||
source = Git.open(sourceDirectory).getRepository();
|
||||
response = new PullResponse(push(source, targetDirectory));
|
||||
response = new PullResponse(push(source, getRemoteUrl(targetDirectory)));
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -119,8 +256,42 @@ public class GitPullCommand extends AbstractPushOrPullCommand
|
||||
return response;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private PullResponse pullFromUrl(URL url)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
logger.debug("pull changes from {} to {}", url, repository.getId());
|
||||
|
||||
/** Field description */
|
||||
private GitRepositoryHandler repositoryHandler;
|
||||
PullResponse response;
|
||||
Git git = Git.wrap(open());
|
||||
|
||||
try
|
||||
{
|
||||
//J-
|
||||
FetchResult result = git.fetch()
|
||||
.setRefSpecs(new RefSpec(REF_SPEC))
|
||||
.setRemote(url.toExternalForm())
|
||||
.setTagOpt(TagOpt.FETCH_TAGS)
|
||||
.call();
|
||||
//J+
|
||||
|
||||
response = convert(git, result);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("error durring pull", ex);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -43,17 +45,22 @@ import sonia.scm.repository.api.PushResponse;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitPushCommand extends AbstractPushOrPullCommand
|
||||
public class GitPushCommand extends AbstractGitPushOrPullCommand
|
||||
implements PushCommand
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(GitPushCommand.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -65,7 +72,7 @@ public class GitPushCommand extends AbstractPushOrPullCommand
|
||||
public GitPushCommand(GitRepositoryHandler handler, GitContext context,
|
||||
Repository repository)
|
||||
{
|
||||
super(context, repository);
|
||||
super(handler, context, repository);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@@ -86,17 +93,10 @@ public class GitPushCommand extends AbstractPushOrPullCommand
|
||||
public PushResponse push(PushCommandRequest request)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
Repository target = getRemoteRepository(request);
|
||||
File targetDirectory = handler.getDirectory(target);
|
||||
String remoteUrl = getRemoteUrl(request);
|
||||
|
||||
Preconditions.checkArgument(targetDirectory.exists(),
|
||||
"target repository directory does not exists");
|
||||
logger.debug("push changes from {} to {}", repository.getId(), remoteUrl);
|
||||
|
||||
return new PushResponse(push(open(), targetDirectory));
|
||||
return new PushResponse(push(open(), remoteUrl));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private GitRepositoryHandler handler;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ import com.google.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Branches;
|
||||
import sonia.scm.repository.Changeset;
|
||||
@@ -60,6 +59,7 @@ import sonia.scm.template.TemplateEngineFactory;
|
||||
import sonia.scm.url.RepositoryUrlProvider;
|
||||
import sonia.scm.url.UrlProvider;
|
||||
import sonia.scm.url.UrlProviderFactory;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -85,7 +85,8 @@ public class GitRepositoryViewer
|
||||
public static final String MIMETYPE_HTML = "text/html";
|
||||
|
||||
/** Field description */
|
||||
public static final String RESOURCE_GITINDEX = "/sonia/scm/git.index.mustache";
|
||||
public static final String RESOURCE_GITINDEX =
|
||||
"/sonia/scm/git.index.mustache";
|
||||
|
||||
/** Field description */
|
||||
private static final int CHANGESET_PER_BRANCH = 10;
|
||||
@@ -104,16 +105,13 @@ public class GitRepositoryViewer
|
||||
*
|
||||
* @param templateEngineFactory
|
||||
* @param repositoryServiceFactory
|
||||
* @param configuration
|
||||
*/
|
||||
@Inject
|
||||
public GitRepositoryViewer(TemplateEngineFactory templateEngineFactory,
|
||||
RepositoryServiceFactory repositoryServiceFactory,
|
||||
ScmConfiguration configuration)
|
||||
RepositoryServiceFactory repositoryServiceFactory)
|
||||
{
|
||||
this.templateEngineFactory = templateEngineFactory;
|
||||
this.repositoryServiceFactory = repositoryServiceFactory;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -135,7 +133,9 @@ public class GitRepositoryViewer
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
|
||||
String baseUrl = configuration.getBaseUrl();
|
||||
String baseUrl = HttpUtil.getCompleteUrl(request);
|
||||
|
||||
logger.trace("render git repository quick view with base url {}", baseUrl);
|
||||
|
||||
UrlProvider urlProvider = UrlProviderFactory.createUrlProvider(baseUrl,
|
||||
UrlProviderFactory.TYPE_WUI);
|
||||
@@ -159,6 +159,7 @@ public class GitRepositoryViewer
|
||||
|
||||
try
|
||||
{
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
writer = response.getWriter();
|
||||
template.execute(writer, env);
|
||||
}
|
||||
@@ -453,9 +454,6 @@ public class GitRepositoryViewer
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private final ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private final RepositoryServiceFactory repositoryServiceFactory;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user