Skip to content

The Unified and Autonomous Development Platform

fix the issue of incorrect commit graph

robin shine27f2b41fed77
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
index 238794f913..f61546a4ae 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
@@ -322,9 +322,7 @@ public class GitUtils {
List<RevCommit> commits = RevWalkUtils.find(revWalk, sourceCommit, targetCommit);
Collections.reverse(commits);
RevCommit headCommit = targetCommit;
- int count = 0;
for (RevCommit commit: commits) {
- count++;
ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE.newMerger(repository, true);
merger.setBase(commit.getParent(0));
if (merger.merge(headCommit, commit)) {
@@ -338,7 +336,6 @@ public class GitUtils {
headCommit = revWalk.parseCommit(inserter.insert(newCommit));
}
} else {
- System.out.println(count);
return null;
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
index f6b253d86d..18e28bbaa8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
@@ -796,7 +796,7 @@ public class Depot extends AbstractEntity implements AccountBelonging {
String refName = GitUtils.branch2ref(branch);
ObjectId commitId = getRevCommit(refName).getId();
try {
- git().branchDelete().setBranchNames(branch).call();
+ git().branchDelete().setForce(true).setBranchNames(branch).call();
} catch (Exception e) {
Throwables.propagate(e);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInfoManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInfoManager.java
index 3781c9a4e7..1a4ea1b2a4 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInfoManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInfoManager.java
@@ -16,23 +16,14 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
-import jetbrains.exodus.ArrayByteIterable;
-import jetbrains.exodus.ByteIterable;
-import jetbrains.exodus.env.Environment;
-import jetbrains.exodus.env.EnvironmentConfig;
-import jetbrains.exodus.env.Environments;
-import jetbrains.exodus.env.Store;
-import jetbrains.exodus.env.StoreConfig;
-import jetbrains.exodus.env.Transaction;
-import jetbrains.exodus.env.TransactionalComputable;
-import jetbrains.exodus.env.TransactionalExecutable;
-
import org.apache.commons.lang3.SerializationUtils;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.Sessional;
import com.pmease.commons.hibernate.UnitOfWork;
import com.pmease.commons.hibernate.dao.Dao;
@@ -51,6 +42,17 @@ import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.manager.support.BatchWorker;
+import jetbrains.exodus.ArrayByteIterable;
+import jetbrains.exodus.ByteIterable;
+import jetbrains.exodus.env.Environment;
+import jetbrains.exodus.env.EnvironmentConfig;
+import jetbrains.exodus.env.Environments;
+import jetbrains.exodus.env.Store;
+import jetbrains.exodus.env.StoreConfig;
+import jetbrains.exodus.env.Transaction;
+import jetbrains.exodus.env.TransactionalComputable;
+import jetbrains.exodus.env.TransactionalExecutable;
+
@Singleton
public class DefaultPullRequestInfoManager implements PullRequestInfoManager, DepotListener,
LifecycleListener, PullRequestUpdateListener {
@@ -191,32 +193,36 @@ public class DefaultPullRequestInfoManager implements PullRequestInfoManager, De
for (PullRequestUpdate update: pullRequestUpdateManager.queryAfter(depot, lastUpdate)) {
try (RevWalk revWalk = new RevWalk(depot.getRepository())) {
List<ObjectId> commits = new ArrayList<>();
- revWalk.markStart(revWalk.lookupCommit(ObjectId.fromString(update.getHeadCommitHash())));
- revWalk.markUninteresting(revWalk.lookupCommit(ObjectId.fromString(update.getBaseCommitHash())));
- revWalk.forEach(commit->commits.add(commit.getId().copy()));
- env.executeInTransaction(new TransactionalExecutable() {
+ RevCommit headCommit = GitUtils.parseCommit(revWalk, ObjectId.fromString(update.getHeadCommitHash()));
+ RevCommit baseCommit = GitUtils.parseCommit(revWalk, ObjectId.fromString(update.getBaseCommitHash()));
+ if (headCommit != null && baseCommit != null) {
+ revWalk.markStart(headCommit);
+ revWalk.markUninteresting(baseCommit);
+ revWalk.forEach(commit->commits.add(commit.getId().copy()));
+ env.executeInTransaction(new TransactionalExecutable() {
- @SuppressWarnings("unchecked")
- @Override
- public void execute(Transaction txn) {
- ByteIterable key = new StringByteIterable(update.getUUID());
- for (ObjectId commit: commits) {
- byte[] keyBytes = new byte[20];
- commit.copyRawTo(keyBytes, 0);
- ByteIterable commitKey = new ArrayByteIterable(keyBytes);
- byte[] valueBytes = getBytes(store.get(txn, commitKey));
- Collection<String> requests;
- if (valueBytes != null)
- requests = (Collection<String>) SerializationUtils.deserialize(valueBytes);
- else
- requests = new HashSet<>();
- requests.add(update.getRequest().getUUID());
- store.put(txn, commitKey, new ArrayByteIterable(SerializationUtils.serialize((Serializable) requests)));
+ @SuppressWarnings("unchecked")
+ @Override
+ public void execute(Transaction txn) {
+ ByteIterable key = new StringByteIterable(update.getUUID());
+ for (ObjectId commit: commits) {
+ byte[] keyBytes = new byte[20];
+ commit.copyRawTo(keyBytes, 0);
+ ByteIterable commitKey = new ArrayByteIterable(keyBytes);
+ byte[] valueBytes = getBytes(store.get(txn, commitKey));
+ Collection<String> requests;
+ if (valueBytes != null)
+ requests = (Collection<String>) SerializationUtils.deserialize(valueBytes);
+ else
+ requests = new HashSet<>();
+ requests.add(update.getRequest().getUUID());
+ store.put(txn, commitKey, new ArrayByteIterable(SerializationUtils.serialize((Serializable) requests)));
+ }
+ store.put(txn, LAST_UPDATE_KEY, key);
}
- store.put(txn, LAST_UPDATE_KEY, key);
- }
-
- });
+
+ });
+ }
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
index 74d3c0e4c3..571c7b7352 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
@@ -137,7 +137,7 @@ public class DepotCommitsPage extends DepotPage {
commits.last = new ArrayList<>();
for (int i=0; i<lastMaxCount; i++) {
- revWalk.parseCommit(ObjectId.fromString(commitHashes.get(i)));
+ commits.last.add(revWalk.parseCommit(ObjectId.fromString(commitHashes.get(i))));
}
CommitGraphUtils.sort(commits.last, 0);