Merge "Improve performance of ReceiveCommits for repos with many refs" into stable-2.5
This commit is contained in:
@@ -249,7 +249,6 @@ public class ReceiveCommits {
|
|||||||
private final Map<RevCommit, ReplaceRequest> replaceByCommit =
|
private final Map<RevCommit, ReplaceRequest> replaceByCommit =
|
||||||
new HashMap<RevCommit, ReplaceRequest>();
|
new HashMap<RevCommit, ReplaceRequest>();
|
||||||
|
|
||||||
private Collection<ObjectId> existingObjects;
|
|
||||||
private Map<ObjectId, Ref> refsById;
|
private Map<ObjectId, Ref> refsById;
|
||||||
|
|
||||||
private String destTopicName;
|
private String destTopicName;
|
||||||
@@ -1116,22 +1115,7 @@ public class ReceiveCommits {
|
|||||||
try {
|
try {
|
||||||
Set<ObjectId> existing = Sets.newHashSet();
|
Set<ObjectId> existing = Sets.newHashSet();
|
||||||
walk.markStart(walk.parseCommit(newChange.getNewId()));
|
walk.markStart(walk.parseCommit(newChange.getNewId()));
|
||||||
for (Ref ref : repo.getAllRefs().values()) {
|
markHeadsAsUninteresting(walk, existing);
|
||||||
if (ref.getObjectId() == null) {
|
|
||||||
continue;
|
|
||||||
} else if (ref.getName().startsWith("refs/changes/")) {
|
|
||||||
existing.add(ref.getObjectId());
|
|
||||||
} else if (ref.getName().startsWith(R_HEADS)
|
|
||||||
|| ref.getName().equals(destBranchCtl.getRefName())) {
|
|
||||||
try {
|
|
||||||
walk.markUninteresting(walk.parseCommit(ref.getObjectId()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn(String.format("Invalid ref %s in %s",
|
|
||||||
ref.getName(), project.getName()), e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ChangeLookup> pending = Lists.newArrayList();
|
List<ChangeLookup> pending = Lists.newArrayList();
|
||||||
final Set<Change.Key> newChangeIds = new HashSet<Change.Key>();
|
final Set<Change.Key> newChangeIds = new HashSet<Change.Key>();
|
||||||
@@ -1229,6 +1213,26 @@ public class ReceiveCommits {
|
|||||||
return newChanges;
|
return newChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void markHeadsAsUninteresting(final RevWalk walk, Set<ObjectId> existing) {
|
||||||
|
for (Ref ref : repo.getAllRefs().values()) {
|
||||||
|
if (ref.getObjectId() == null) {
|
||||||
|
continue;
|
||||||
|
} else if (ref.getName().startsWith("refs/changes/")) {
|
||||||
|
existing.add(ref.getObjectId());
|
||||||
|
} else if (ref.getName().startsWith(R_HEADS)
|
||||||
|
|| (destBranchCtl != null && ref.getName().equals(destBranchCtl.getRefName()))) {
|
||||||
|
try {
|
||||||
|
walk.markUninteresting(walk.parseCommit(ref.getObjectId()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn(String.format("Invalid ref %s in %s",
|
||||||
|
ref.getName(), project.getName()), e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isValidChangeId(String idStr) {
|
private static boolean isValidChangeId(String idStr) {
|
||||||
return idStr.matches("^I[0-9a-fA-F]{40}$") && !idStr.matches("^I00*$");
|
return idStr.matches("^I[0-9a-fA-F]{40}$") && !idStr.matches("^I00*$");
|
||||||
}
|
}
|
||||||
@@ -1811,18 +1815,15 @@ public class ReceiveCommits {
|
|||||||
walk.reset();
|
walk.reset();
|
||||||
walk.sort(RevSort.NONE);
|
walk.sort(RevSort.NONE);
|
||||||
try {
|
try {
|
||||||
|
Set<ObjectId> existing = Sets.newHashSet();
|
||||||
walk.markStart(walk.parseCommit(cmd.getNewId()));
|
walk.markStart(walk.parseCommit(cmd.getNewId()));
|
||||||
for (ObjectId id : existingObjects()) {
|
markHeadsAsUninteresting(walk, existing);
|
||||||
try {
|
|
||||||
walk.markUninteresting(walk.parseCommit(id));
|
|
||||||
} catch (IOException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RevCommit c;
|
RevCommit c;
|
||||||
while ((c = walk.next()) != null) {
|
while ((c = walk.next()) != null) {
|
||||||
if (!validCommit(ctl, cmd, c)) {
|
if (existing.contains(c)) {
|
||||||
|
continue;
|
||||||
|
} else if (!validCommit(ctl, cmd, c)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1832,17 +1833,6 @@ public class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<ObjectId> existingObjects() {
|
|
||||||
if (existingObjects == null) {
|
|
||||||
Map<String, Ref> refs = repo.getAllRefs();
|
|
||||||
existingObjects = new ArrayList<ObjectId>(refs.size());
|
|
||||||
for (Ref r : refs.values()) {
|
|
||||||
existingObjects.add(r.getObjectId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return existingObjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validCommit(final RefControl ctl, final ReceiveCommand cmd,
|
private boolean validCommit(final RefControl ctl, final ReceiveCommand cmd,
|
||||||
final RevCommit c) throws MissingObjectException, IOException {
|
final RevCommit c) throws MissingObjectException, IOException {
|
||||||
rp.getRevWalk().parseBody(c);
|
rp.getRevWalk().parseBody(c);
|
||||||
|
Reference in New Issue
Block a user