Skip to content

The Unified and Autonomous Development Platform

Fix issue #783 - Auto suggested reviewer sometimes not corresponding to submitted changes

Robin Shen7681c050993c
diff --git a/server-core/src/main/java/io/onedev/server/infomanager/DefaultCommitInfoManager.java b/server-core/src/main/java/io/onedev/server/infomanager/DefaultCommitInfoManager.java
index 0c19528128..95b5f2a130 100644
--- a/server-core/src/main/java/io/onedev/server/infomanager/DefaultCommitInfoManager.java
+++ b/server-core/src/main/java/io/onedev/server/infomanager/DefaultCommitInfoManager.java
@@ -89,7 +89,7 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
private static final Logger logger = LoggerFactory.getLogger(DefaultCommitInfoManager.class);
- private static final int INFO_VERSION = 12;
+ private static final int INFO_VERSION = 13;
private static final long LOG_FILE_SIZE = 256*1024;
@@ -121,12 +121,16 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
private static final String INDEX_TO_USER_STORE = "indexToUser";
+ private static final String EMAIL_TO_INDEX_STORE = "emailToIndex";
+
private static final String DAILY_CONTRIBUTIONS_STORE = "dailyContributions";
private static final ByteIterable NEXT_PATH_INDEX_KEY = new StringByteIterable("nextPathIndex");
private static final ByteIterable NEXT_USER_INDEX_KEY = new StringByteIterable("nextUserIndex");
+ private static final ByteIterable NEXT_EMAIL_INDEX_KEY = new StringByteIterable("nextEmailIndex");
+
private static final ByteIterable LAST_COMMIT_KEY = new StringByteIterable("lastCommit");
private static final ByteIterable LAST_COMMIT_OF_LINE_STATS_KEY = new StringByteIterable("lastCommitOfLineStats");
@@ -191,6 +195,7 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
Store pathToIndexStore = getStore(env, PATH_TO_INDEX_STORE);
Store indexToPathStore = getStore(env, INDEX_TO_PATH_STORE);
Store userToIndexStore = getStore(env, USER_TO_INDEX_STORE);
+ Store emailToIndexStore = getStore(env, EMAIL_TO_INDEX_STORE);
Store indexToUserStore = getStore(env, INDEX_TO_USER_STORE);
Store fixCommitsStore = getStore(env, FIX_COMMITS_STORE);
@@ -235,6 +240,7 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
NextIndex nextIndex = new NextIndex();
nextIndex.user = readInt(defaultStore, txn, NEXT_USER_INDEX_KEY, 0);
+ nextIndex.email = readInt(defaultStore, txn, NEXT_EMAIL_INDEX_KEY, 0);
nextIndex.path = readInt(defaultStore, txn, NEXT_PATH_INDEX_KEY, 0);
Map<Long, Integer> commitCountCache = new HashMap<>();
@@ -351,20 +357,27 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
indexToUserStore.put(txn, new IntByteIterable(userIndex), authorKey);
}
+ ByteIterable emailKey = new StringByteIterable(nameAndEmail.getEmailAddress());
+ int emailIndex = readInt(emailToIndexStore, txn, emailKey, -1);
+ if (emailIndex == -1) {
+ emailIndex = nextIndex.email++;
+ writeInt(emailToIndexStore, txn, emailKey, emailIndex);
+ }
+
for (FileChange change: currentCommit.getFileChanges()) {
for (String path: change.getPaths()) {
int pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,
nextIndex, path);
- updateCommitCount(commitCountsStore, txn, commitCountCache, userIndex, pathIndex);
+ updateCommitCount(commitCountsStore, txn, commitCountCache, emailIndex, pathIndex);
while (path.contains("/")) {
path = StringUtils.substringBeforeLast(path, "/");
pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,
nextIndex, path);
- updateCommitCount(commitCountsStore, txn, commitCountCache, userIndex, pathIndex);
+ updateCommitCount(commitCountsStore, txn, commitCountCache, emailIndex, pathIndex);
}
pathIndex = getPathIndex(pathToIndexStore, indexToPathStore, txn,
nextIndex, "");
- updateCommitCount(commitCountsStore, txn, commitCountCache, userIndex, pathIndex);
+ updateCommitCount(commitCountsStore, txn, commitCountCache, emailIndex, pathIndex);
}
}
}
@@ -414,6 +427,7 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
totalCommitCountCache.remove(project.getId());
writeInt(defaultStore, txn, NEXT_USER_INDEX_KEY, nextIndex.user);
+ writeInt(defaultStore, txn, NEXT_EMAIL_INDEX_KEY, nextIndex.email);
writeInt(defaultStore, txn, NEXT_PATH_INDEX_KEY, nextIndex.path);
userBytes = SerializationUtils.serialize((Serializable) users);
@@ -761,14 +775,14 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
}
private void updateCommitCount(Store store, Transaction txn,
- Map<Long, Integer> commitCountCache, int userIndex, int pathIndex) {
- long commitCountKey = (userIndex<<32)|pathIndex;
+ Map<Long, Integer> commitCountCache, int emailIndex, int pathIndex) {
+ long commitCountKey = ((long)emailIndex<<32)|pathIndex;
- Integer commitCountOfPathByUser = commitCountCache.get(commitCountKey);
- if (commitCountOfPathByUser == null)
- commitCountOfPathByUser = readInt(store, txn, new LongByteIterable(commitCountKey), 0);
- commitCountOfPathByUser ++;
- commitCountCache.put(commitCountKey, commitCountOfPathByUser);
+ Integer commitCountOfPathByEmail = commitCountCache.get(commitCountKey);
+ if (commitCountOfPathByEmail == null)
+ commitCountOfPathByEmail = readInt(store, txn, new LongByteIterable(commitCountKey), 0);
+ commitCountOfPathByEmail ++;
+ commitCountCache.put(commitCountKey, commitCountOfPathByEmail);
}
public List<NameAndEmail> getUsers(Project project) {
@@ -879,7 +893,7 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
@Override
public int getCommitCount(Project project, User user, String path) {
Environment env = getEnv(project.getId().toString());
- Store emailToIndexStore = getStore(env, USER_TO_INDEX_STORE);
+ Store emailToIndexStore = getStore(env, EMAIL_TO_INDEX_STORE);
Store pathToIndexStore = getStore(env, PATH_TO_INDEX_STORE);
Store commitCountStore = getStore(env, COMMIT_COUNTS_STORE);
@@ -889,11 +903,11 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
public Integer compute(Transaction txn) {
AtomicInteger count = new AtomicInteger(0);
user.getEmailAddresses().stream().filter(it->it.isVerified()).forEach(it-> {
- int userIndex = readInt(emailToIndexStore, txn, new StringByteIterable(it.getValue()), -1);
- if (userIndex != -1) {
+ int emailIndex = readInt(emailToIndexStore, txn, new StringByteIterable(it.getValue()), -1);
+ if (emailIndex != -1) {
int pathIndex = readInt(pathToIndexStore, txn, new StringByteIterable(path), -1);
if (pathIndex != -1) {
- long commitCountKey = (userIndex<<32)|pathIndex;
+ long commitCountKey = ((long)emailIndex<<32)|pathIndex;
count.addAndGet(readInt(commitCountStore, txn, new LongByteIterable(commitCountKey), 0));
}
}
@@ -1428,6 +1442,8 @@ public class DefaultCommitInfoManager extends AbstractMultiEnvironmentManager im
private static class NextIndex {
int user;
+ int email;
+
int path;
}
diff --git a/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java b/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java
index c124723397..571094fa74 100644
--- a/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java
+++ b/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java
@@ -109,6 +109,7 @@ public class PullRequestUpdate extends AbstractEntity {
treeWalk.addTree(headCommit.getTree());
treeWalk.addTree(comparisonBaseCommit.getTree());
treeWalk.setFilter(TreeFilter.ANY_DIFF);
+ treeWalk.setRecursive(true);
while (treeWalk.next())
changedFiles.add(treeWalk.getPathString());
} catch (IOException e) {
diff --git a/server-core/src/main/java/io/onedev/server/util/NameAndEmail.java b/server-core/src/main/java/io/onedev/server/util/NameAndEmail.java
index 972fb454ab..392fff96a4 100644
--- a/server-core/src/main/java/io/onedev/server/util/NameAndEmail.java
+++ b/server-core/src/main/java/io/onedev/server/util/NameAndEmail.java
@@ -16,9 +16,9 @@ public class NameAndEmail implements Comparable<NameAndEmail>, Serializable {
private final String emailAddress;
- public NameAndEmail(@Nullable String name, String emailAddress) {
- this.name = name;
- this.emailAddress = emailAddress;
+ public NameAndEmail(@Nullable String name, @Nullable String emailAddress) {
+ this.name = name!=null?name:"";
+ this.emailAddress = emailAddress!=null?emailAddress:"";
}
public NameAndEmail(PersonIdent person) {
@@ -29,12 +29,10 @@ public class NameAndEmail implements Comparable<NameAndEmail>, Serializable {
return new PersonIdent(name, emailAddress);
}
- @Nullable
public String getName() {
return name;
}
- @Nullable
public String getEmailAddress() {
return emailAddress;
}
@@ -59,9 +57,10 @@ public class NameAndEmail implements Comparable<NameAndEmail>, Serializable {
@Override
public int compareTo(NameAndEmail nameAndEmail) {
- if (name != null && nameAndEmail.name != null)
- return name.compareTo(nameAndEmail.name);
- else
+ int result = name.compareTo(nameAndEmail.name);
+ if (result != 0)
+ return result;
+ else
return emailAddress.compareTo(nameAndEmail.emailAddress);
}