Dissolve gerrit-server top-level directory
Change-Id: I538512dfe0f1bea774c01fdd45fa410a45634011
This commit is contained in:
committed by
Dave Borowitz
parent
472396c797
commit
376a7bbb64
100
javatests/com/google/gerrit/server/change/HashtagsTest.java
Normal file
100
javatests/com/google/gerrit/server/change/HashtagsTest.java
Normal file
@@ -0,0 +1,100 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HashtagsTest {
|
||||
@Test
|
||||
public void emptyCommitMessage() throws Exception {
|
||||
assertThat(HashtagsUtil.extractTags("")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullCommitMessage() throws Exception {
|
||||
assertThat(HashtagsUtil.extractTags((String) null)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noHashtags() throws Exception {
|
||||
String commitMessage = "Subject\n\nLine 1\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleHashtag() throws Exception {
|
||||
String commitMessage = "#Subject\n\nLine 1\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleHashtagNumeric() throws Exception {
|
||||
String commitMessage = "Subject\n\n#123\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleHashtags() throws Exception {
|
||||
String commitMessage = "#Subject\n\n#Hashtag\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject", "Hashtag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatedHashtag() throws Exception {
|
||||
String commitMessage = "#Subject\n\n#Hashtag1\n\n#Hashtag2\n\n#Hashtag1";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject", "Hashtag1", "Hashtag2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleHashtagsNoSpaces() throws Exception {
|
||||
String commitMessage = "Subject\n\n#Hashtag1#Hashtag2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Hashtag1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hyphenatedHashtag() throws Exception {
|
||||
String commitMessage = "Subject\n\n#Hyphenated-Hashtag";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Hyphenated-Hashtag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underscoredHashtag() throws Exception {
|
||||
String commitMessage = "Subject\n\n#Underscored_Hashtag";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Underscored_Hashtag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashtagsWithAccentedCharacters() throws Exception {
|
||||
String commitMessage = "Jag #måste #öva på min #Svenska!\n\nJag behöver en #läkare.";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("måste", "öva", "Svenska", "läkare"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashWithoutHashtag() throws Exception {
|
||||
String commitMessage = "Subject\n\n# Text";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage)).isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
|
||||
import org.eclipse.jgit.junit.RepositoryTestCase;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevTag;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IncludedInResolverTest extends RepositoryTestCase {
|
||||
|
||||
// Branch names
|
||||
private static final String BRANCH_MASTER = "master";
|
||||
private static final String BRANCH_1_0 = "rel-1.0";
|
||||
private static final String BRANCH_1_3 = "rel-1.3";
|
||||
private static final String BRANCH_2_0 = "rel-2.0";
|
||||
private static final String BRANCH_2_5 = "rel-2.5";
|
||||
|
||||
// Tag names
|
||||
private static final String TAG_1_0 = "1.0";
|
||||
private static final String TAG_1_0_1 = "1.0.1";
|
||||
private static final String TAG_1_3 = "1.3";
|
||||
private static final String TAG_2_0_1 = "2.0.1";
|
||||
private static final String TAG_2_0 = "2.0";
|
||||
private static final String TAG_2_5 = "2.5";
|
||||
private static final String TAG_2_5_ANNOTATED = "2.5-annotated";
|
||||
private static final String TAG_2_5_ANNOTATED_TWICE = "2.5-annotated_twice";
|
||||
|
||||
// Commits
|
||||
private RevCommit commit_initial;
|
||||
private RevCommit commit_v1_3;
|
||||
private RevCommit commit_v2_5;
|
||||
|
||||
private List<String> expTags = new ArrayList<>();
|
||||
private List<String> expBranches = new ArrayList<>();
|
||||
|
||||
private RevWalk revWalk;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
/*- The following graph will be created.
|
||||
|
||||
o tag 2.5, 2.5_annotated, 2.5_annotated_twice
|
||||
|\
|
||||
| o tag 2.0.1
|
||||
| o tag 2.0
|
||||
o | tag 1.3
|
||||
|/
|
||||
o c3
|
||||
|
||||
| o tag 1.0.1
|
||||
|/
|
||||
o tag 1.0
|
||||
o c2
|
||||
o c1
|
||||
|
||||
*/
|
||||
|
||||
// TODO(dborowitz): Use try/finally when this doesn't double-close the repo.
|
||||
@SuppressWarnings("resource")
|
||||
Git git = new Git(db);
|
||||
revWalk = new RevWalk(db);
|
||||
// Version 1.0
|
||||
commit_initial = git.commit().setMessage("c1").call();
|
||||
git.commit().setMessage("c2").call();
|
||||
RevCommit commit_v1_0 = git.commit().setMessage("version 1.0").call();
|
||||
git.tag().setName(TAG_1_0).setObjectId(commit_v1_0).call();
|
||||
RevCommit c3 = git.commit().setMessage("c3").call();
|
||||
// Version 1.01
|
||||
createAndCheckoutBranch(commit_v1_0, BRANCH_1_0);
|
||||
RevCommit commit_v1_0_1 = git.commit().setMessage("verREFS_HEADS_RELsion 1.0.1").call();
|
||||
git.tag().setName(TAG_1_0_1).setObjectId(commit_v1_0_1).call();
|
||||
// Version 1.3
|
||||
createAndCheckoutBranch(c3, BRANCH_1_3);
|
||||
commit_v1_3 = git.commit().setMessage("version 1.3").call();
|
||||
git.tag().setName(TAG_1_3).setObjectId(commit_v1_3).call();
|
||||
// Version 2.0
|
||||
createAndCheckoutBranch(c3, BRANCH_2_0);
|
||||
RevCommit commit_v2_0 = git.commit().setMessage("version 2.0").call();
|
||||
git.tag().setName(TAG_2_0).setObjectId(commit_v2_0).call();
|
||||
RevCommit commit_v2_0_1 = git.commit().setMessage("version 2.0.1").call();
|
||||
git.tag().setName(TAG_2_0_1).setObjectId(commit_v2_0_1).call();
|
||||
|
||||
// Version 2.5
|
||||
createAndCheckoutBranch(commit_v1_3, BRANCH_2_5);
|
||||
git.merge()
|
||||
.include(commit_v2_0_1)
|
||||
.setCommit(false)
|
||||
.setFastForward(FastForwardMode.NO_FF)
|
||||
.call();
|
||||
commit_v2_5 = git.commit().setMessage("version 2.5").call();
|
||||
git.tag().setName(TAG_2_5).setObjectId(commit_v2_5).setAnnotated(false).call();
|
||||
Ref ref_tag_2_5_annotated =
|
||||
git.tag().setName(TAG_2_5_ANNOTATED).setObjectId(commit_v2_5).setAnnotated(true).call();
|
||||
RevTag tag_2_5_annotated = revWalk.parseTag(ref_tag_2_5_annotated.getObjectId());
|
||||
git.tag()
|
||||
.setName(TAG_2_5_ANNOTATED_TWICE)
|
||||
.setObjectId(tag_2_5_annotated)
|
||||
.setAnnotated(true)
|
||||
.call();
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
revWalk.close();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveLatestCommit() throws Exception {
|
||||
// Check tip commit
|
||||
IncludedInResolver.Result detail = resolve(commit_v2_5);
|
||||
|
||||
// Check that only tags and branches which refer the tip are returned
|
||||
expTags.add(TAG_2_5);
|
||||
expTags.add(TAG_2_5_ANNOTATED);
|
||||
expTags.add(TAG_2_5_ANNOTATED_TWICE);
|
||||
assertEquals(expTags, detail.getTags());
|
||||
expBranches.add(BRANCH_2_5);
|
||||
assertEquals(expBranches, detail.getBranches());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveFirstCommit() throws Exception {
|
||||
// Check first commit
|
||||
IncludedInResolver.Result detail = resolve(commit_initial);
|
||||
|
||||
// Check whether all tags and branches are returned
|
||||
expTags.add(TAG_1_0);
|
||||
expTags.add(TAG_1_0_1);
|
||||
expTags.add(TAG_1_3);
|
||||
expTags.add(TAG_2_0);
|
||||
expTags.add(TAG_2_0_1);
|
||||
expTags.add(TAG_2_5);
|
||||
expTags.add(TAG_2_5_ANNOTATED);
|
||||
expTags.add(TAG_2_5_ANNOTATED_TWICE);
|
||||
assertEquals(expTags, detail.getTags());
|
||||
|
||||
expBranches.add(BRANCH_MASTER);
|
||||
expBranches.add(BRANCH_1_0);
|
||||
expBranches.add(BRANCH_1_3);
|
||||
expBranches.add(BRANCH_2_0);
|
||||
expBranches.add(BRANCH_2_5);
|
||||
assertEquals(expBranches, detail.getBranches());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveBetwixtCommit() throws Exception {
|
||||
// Check a commit somewhere in the middle
|
||||
IncludedInResolver.Result detail = resolve(commit_v1_3);
|
||||
|
||||
// Check whether all succeeding tags and branches are returned
|
||||
expTags.add(TAG_1_3);
|
||||
expTags.add(TAG_2_5);
|
||||
expTags.add(TAG_2_5_ANNOTATED);
|
||||
expTags.add(TAG_2_5_ANNOTATED_TWICE);
|
||||
assertEquals(expTags, detail.getTags());
|
||||
|
||||
expBranches.add(BRANCH_1_3);
|
||||
expBranches.add(BRANCH_2_5);
|
||||
assertEquals(expBranches, detail.getBranches());
|
||||
}
|
||||
|
||||
private IncludedInResolver.Result resolve(RevCommit commit) throws Exception {
|
||||
return IncludedInResolver.resolve(db, revWalk, commit);
|
||||
}
|
||||
|
||||
private void assertEquals(List<String> list1, List<String> list2) {
|
||||
Collections.sort(list1);
|
||||
Collections.sort(list2);
|
||||
Assert.assertEquals(list1, list2);
|
||||
}
|
||||
|
||||
private void createAndCheckoutBranch(ObjectId objectId, String branchName) throws IOException {
|
||||
String fullBranchName = "refs/heads/" + branchName;
|
||||
super.createBranch(objectId, fullBranchName);
|
||||
super.checkoutBranch(fullBranchName);
|
||||
}
|
||||
}
|
||||
374
javatests/com/google/gerrit/server/change/WalkSorterTest.java
Normal file
374
javatests/com/google/gerrit/server/change/WalkSorterTest.java
Normal file
@@ -0,0 +1,374 @@
|
||||
// Copyright (C) 2015 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.common.collect.Collections2.permutations;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.server.change.WalkSorter.PatchSetData;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.testing.GerritBaseTests;
|
||||
import com.google.gerrit.testing.InMemoryRepositoryManager;
|
||||
import com.google.gerrit.testing.InMemoryRepositoryManager.Repo;
|
||||
import com.google.gerrit.testing.TestChanges;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WalkSorterTest extends GerritBaseTests {
|
||||
private Account.Id userId;
|
||||
private InMemoryRepositoryManager repoManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
userId = new Account.Id(1);
|
||||
repoManager = new InMemoryRepositoryManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seriesOfChanges() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c1_1 = p.commit().create();
|
||||
RevCommit c2_1 = p.commit().parent(c1_1).create();
|
||||
RevCommit c3_1 = p.commit().parent(c2_1).create();
|
||||
|
||||
ChangeData cd1 = newChange(p, c1_1);
|
||||
ChangeData cd2 = newChange(p, c2_1);
|
||||
ChangeData cd3 = newChange(p, c3_1);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd3, c3_1), patchSetData(cd2, c2_1), patchSetData(cd1, c1_1)));
|
||||
|
||||
// Add new patch sets whose commits are in reverse order, so output is in
|
||||
// reverse order.
|
||||
RevCommit c3_2 = p.commit().create();
|
||||
RevCommit c2_2 = p.commit().parent(c3_2).create();
|
||||
RevCommit c1_2 = p.commit().parent(c2_2).create();
|
||||
|
||||
addPatchSet(cd1, c1_2);
|
||||
addPatchSet(cd2, c2_2);
|
||||
addPatchSet(cd3, c3_2);
|
||||
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd1, c1_2), patchSetData(cd2, c2_2), patchSetData(cd3, c3_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsetOfSeriesOfChanges() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c1_1 = p.commit().create();
|
||||
RevCommit c2_1 = p.commit().parent(c1_1).create();
|
||||
RevCommit c3_1 = p.commit().parent(c2_1).create();
|
||||
|
||||
ChangeData cd1 = newChange(p, c1_1);
|
||||
ChangeData cd3 = newChange(p, c3_1);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd3);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(
|
||||
sorter, changes, ImmutableList.of(patchSetData(cd3, c3_1), patchSetData(cd1, c1_1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seriesOfChangesAtSameTimestamp() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c0 = p.commit().tick(0).create();
|
||||
RevCommit c1 = p.commit().tick(0).parent(c0).create();
|
||||
RevCommit c2 = p.commit().tick(0).parent(c1).create();
|
||||
RevCommit c3 = p.commit().tick(0).parent(c2).create();
|
||||
RevCommit c4 = p.commit().tick(0).parent(c3).create();
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
ChangeData cd3 = newChange(p, c3);
|
||||
ChangeData cd4 = newChange(p, c4);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seriesOfChangesWithReverseTimestamps() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c0 = p.commit().tick(-1).create();
|
||||
RevCommit c1 = p.commit().tick(-1).parent(c0).create();
|
||||
RevCommit c2 = p.commit().tick(-1).parent(c1).create();
|
||||
RevCommit c3 = p.commit().tick(-1).parent(c2).create();
|
||||
RevCommit c4 = p.commit().tick(-1).parent(c3).create();
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isLessThan(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isLessThan(c2.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isLessThan(c3.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
ChangeData cd3 = newChange(p, c3);
|
||||
ChangeData cd4 = newChange(p, c4);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsetOfSeriesOfChangesWithReverseTimestamps() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c0 = p.commit().tick(-1).create();
|
||||
RevCommit c1 = p.commit().tick(-1).parent(c0).create();
|
||||
RevCommit c2 = p.commit().tick(-1).parent(c1).create();
|
||||
RevCommit c3 = p.commit().tick(-1).parent(c2).create();
|
||||
RevCommit c4 = p.commit().tick(-1).parent(c3).create();
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isLessThan(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isLessThan(c2.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isLessThan(c3.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
ChangeData cd4 = newChange(p, c4);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
List<PatchSetData> expected =
|
||||
ImmutableList.of(patchSetData(cd4, c4), patchSetData(cd2, c2), patchSetData(cd1, c1));
|
||||
|
||||
for (List<ChangeData> list : permutations(changes)) {
|
||||
// Not inOrder(); since child of c2 is missing, partial topo sort isn't
|
||||
// guaranteed to work.
|
||||
assertThat(sorter.sort(list)).containsExactlyElementsIn(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seriesOfChangesAtSameTimestampWithRootCommit() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c1 = p.commit().tick(0).create();
|
||||
RevCommit c2 = p.commit().tick(0).parent(c1).create();
|
||||
RevCommit c3 = p.commit().tick(0).parent(c2).create();
|
||||
RevCommit c4 = p.commit().tick(0).parent(c3).create();
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
ChangeData cd3 = newChange(p, c3);
|
||||
ChangeData cd4 = newChange(p, c4);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void projectsSortedByName() throws Exception {
|
||||
TestRepository<Repo> pa = newRepo("a");
|
||||
TestRepository<Repo> pb = newRepo("b");
|
||||
RevCommit c1 = pa.commit().create();
|
||||
RevCommit c2 = pb.commit().create();
|
||||
RevCommit c3 = pa.commit().parent(c1).create();
|
||||
RevCommit c4 = pb.commit().parent(c2).create();
|
||||
|
||||
ChangeData cd1 = newChange(pa, c1);
|
||||
ChangeData cd2 = newChange(pb, c2);
|
||||
ChangeData cd3 = newChange(pa, c3);
|
||||
ChangeData cd4 = newChange(pb, c4);
|
||||
|
||||
assertSorted(
|
||||
new WalkSorter(repoManager),
|
||||
ImmutableList.of(cd1, cd2, cd3, cd4),
|
||||
ImmutableList.of(
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd1, c1),
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd2, c2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restrictToPatchSets() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c1_1 = p.commit().create();
|
||||
RevCommit c2_1 = p.commit().parent(c1_1).create();
|
||||
|
||||
ChangeData cd1 = newChange(p, c1_1);
|
||||
ChangeData cd2 = newChange(p, c2_1);
|
||||
|
||||
// Add new patch sets whose commits are in reverse order.
|
||||
RevCommit c2_2 = p.commit().create();
|
||||
RevCommit c1_2 = p.commit().parent(c2_2).create();
|
||||
|
||||
addPatchSet(cd1, c1_2);
|
||||
addPatchSet(cd2, c2_2);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(
|
||||
sorter, changes, ImmutableList.of(patchSetData(cd1, c1_2), patchSetData(cd2, c2_2)));
|
||||
|
||||
// If we restrict to PS1 of each change, the sorter uses that commit.
|
||||
sorter.includePatchSets(
|
||||
ImmutableSet.of(new PatchSet.Id(cd1.getId(), 1), new PatchSet.Id(cd2.getId(), 1)));
|
||||
assertSorted(
|
||||
sorter, changes, ImmutableList.of(patchSetData(cd2, 1, c2_1), patchSetData(cd1, 1, c1_1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restrictToPatchSetsOmittingWholeProject() throws Exception {
|
||||
TestRepository<Repo> pa = newRepo("a");
|
||||
TestRepository<Repo> pb = newRepo("b");
|
||||
RevCommit c1 = pa.commit().create();
|
||||
RevCommit c2 = pa.commit().create();
|
||||
|
||||
ChangeData cd1 = newChange(pa, c1);
|
||||
ChangeData cd2 = newChange(pb, c2);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2);
|
||||
WalkSorter sorter =
|
||||
new WalkSorter(repoManager)
|
||||
.includePatchSets(ImmutableSet.of(cd1.currentPatchSet().getId()));
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retainBody() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c = p.commit().message("message").create();
|
||||
ChangeData cd = newChange(p, c);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd);
|
||||
RevCommit actual =
|
||||
new WalkSorter(repoManager).setRetainBody(true).sort(changes).iterator().next().commit();
|
||||
assertThat(actual.getRawBuffer()).isNotNull();
|
||||
assertThat(actual.getShortMessage()).isEqualTo("message");
|
||||
|
||||
actual =
|
||||
new WalkSorter(repoManager).setRetainBody(false).sort(changes).iterator().next().commit();
|
||||
assertThat(actual.getRawBuffer()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneChange() throws Exception {
|
||||
TestRepository<Repo> p = newRepo("p");
|
||||
RevCommit c = p.commit().create();
|
||||
ChangeData cd = newChange(p, c);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd, c)));
|
||||
}
|
||||
|
||||
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id) throws Exception {
|
||||
Project.NameKey project = tr.getRepository().getDescription().getProject();
|
||||
Change c = TestChanges.newChange(project, userId);
|
||||
ChangeData cd = ChangeData.createForTest(project, c.getId(), 1);
|
||||
cd.setChange(c);
|
||||
cd.currentPatchSet().setRevision(new RevId(id.name()));
|
||||
cd.setPatchSets(ImmutableList.of(cd.currentPatchSet()));
|
||||
return cd;
|
||||
}
|
||||
|
||||
private PatchSet addPatchSet(ChangeData cd, ObjectId id) throws Exception {
|
||||
TestChanges.incrementPatchSet(cd.change());
|
||||
PatchSet ps = new PatchSet(cd.change().currentPatchSetId());
|
||||
ps.setRevision(new RevId(id.name()));
|
||||
List<PatchSet> patchSets = new ArrayList<>(cd.patchSets());
|
||||
patchSets.add(ps);
|
||||
cd.setPatchSets(patchSets);
|
||||
return ps;
|
||||
}
|
||||
|
||||
private TestRepository<Repo> newRepo(String name) throws Exception {
|
||||
return new TestRepository<>(repoManager.createRepository(new Project.NameKey(name)));
|
||||
}
|
||||
|
||||
private static PatchSetData patchSetData(ChangeData cd, RevCommit commit) throws Exception {
|
||||
return PatchSetData.create(cd, cd.currentPatchSet(), commit);
|
||||
}
|
||||
|
||||
private static PatchSetData patchSetData(ChangeData cd, int psId, RevCommit commit)
|
||||
throws Exception {
|
||||
return PatchSetData.create(cd, cd.patchSet(new PatchSet.Id(cd.getId(), psId)), commit);
|
||||
}
|
||||
|
||||
private static void assertSorted(
|
||||
WalkSorter sorter, List<ChangeData> changes, List<PatchSetData> expected) throws Exception {
|
||||
for (List<ChangeData> list : permutations(changes)) {
|
||||
assertThat(sorter.sort(list)).containsExactlyElementsIn(expected).inOrder();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user