mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
fix wrong changeset count for git push and pull commands
This commit is contained in:
@@ -697,6 +697,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 --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,7 @@ 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 ------------------------------------------------------------
|
||||
@@ -253,21 +254,24 @@ public abstract class AbstractGitPushOrPullCommand 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();
|
||||
|
||||
@@ -275,16 +279,17 @@ public abstract class AbstractGitPushOrPullCommand 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;
|
||||
|
||||
@@ -152,6 +152,8 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
counter += count(git, tru);
|
||||
}
|
||||
|
||||
logger.debug("received {} changesets by pull", counter);
|
||||
|
||||
return new PullResponse(counter);
|
||||
}
|
||||
|
||||
@@ -168,21 +170,25 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
{
|
||||
long counter = 0;
|
||||
|
||||
try
|
||||
if (GitUtil.isHead(tru.getLocalName()))
|
||||
{
|
||||
org.eclipse.jgit.api.LogCommand log = git.log();
|
||||
ObjectId oldId = tru.getOldObjectId();
|
||||
|
||||
if (oldId != null)
|
||||
try
|
||||
{
|
||||
log.not(oldId);
|
||||
}
|
||||
org.eclipse.jgit.api.LogCommand log = git.log();
|
||||
|
||||
ObjectId newId = tru.getNewObjectId();
|
||||
ObjectId oldId = tru.getOldObjectId();
|
||||
|
||||
if (newId != null)
|
||||
{
|
||||
log.add(newId);
|
||||
if (GitUtil.isValidObjectId(oldId))
|
||||
{
|
||||
log.not(oldId);
|
||||
}
|
||||
|
||||
ObjectId newId = tru.getNewObjectId();
|
||||
|
||||
if (GitUtil.isValidObjectId(newId))
|
||||
{
|
||||
log.add(newId);
|
||||
}
|
||||
|
||||
Iterable<RevCommit> commits = log.call();
|
||||
|
||||
@@ -190,16 +196,17 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
{
|
||||
counter += Iterables.size(commits);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("update without new object id");
|
||||
}
|
||||
|
||||
logger.trace("counting {} commits for ref update {}", counter, tru);
|
||||
}
|
||||
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 {}", tru);
|
||||
}
|
||||
|
||||
return counter;
|
||||
|
||||
Reference in New Issue
Block a user