use of com.google.copybara.revision.Change in project copybara by google.
the class ChangeReader method parseChanges.
private ImmutableList<Change<HgRevision>> parseChanges(ImmutableList<HgLogEntry> logEntries) throws RepoException {
ImmutableList.Builder<Change<HgRevision>> result = ImmutableList.builder();
for (HgLogEntry entry : logEntries) {
HgRevision rev = new HgRevision(entry.getGlobalId());
if (NULL_GLOBAL_ID.equals(rev.getGlobalId())) {
continue;
}
Author user;
try {
user = AuthorParser.parse(entry.getUser());
} catch (InvalidAuthorException e) {
console.warn(String.format("Cannot parse commit user and email: %s", e.getMessage()));
user = authoring.orElseThrow(() -> new RepoException("No default author provided.")).getDefaultAuthor();
}
ImmutableList<HgRevision> parents = entry.getParents().stream().map(HgRevision::new).collect(ImmutableList.toImmutableList());
result.add(new Change<>(rev, user, entry.getDescription(), entry.getZonedDate(), ChangeMessage.parseAllAsLabels(entry.getDescription()).labelsAsMultimap(), ImmutableSet.copyOf(entry.getFiles()), parents.size() > 1, parents));
}
return result.build();
}
use of com.google.copybara.revision.Change in project copybara by google.
the class HgVisitorUtil method visitChanges.
/**
* Visits Hg changes, up to the termination point specified by the visitor.
*/
static void visitChanges(HgRevision start, ChangesVisitor visitor, ChangeReader.Builder queryChanges, GeneralOptions generalOptions, String type, int visitChangePageSize) throws RepoException {
Preconditions.checkNotNull(start);
int offset = 0;
boolean finished = false;
try (ProfilerTask ignore = generalOptions.profiler().start(type + "/visit_changes")) {
while (!finished) {
ImmutableList<Change<HgRevision>> result;
try (ProfilerTask ignore2 = generalOptions.profiler().start(String.format("hg_log_%d_%d", offset, visitChangePageSize))) {
try {
result = queryChanges.setSkip(offset).setLimit(visitChangePageSize).build().run(start.getGlobalId()).reverse();
} catch (ValidationException e) {
throw new RepoException(String.format("Error querying changes: %s", e.getMessage()), e.getCause());
}
}
if (result.isEmpty()) {
break;
}
offset += result.size();
for (Change<HgRevision> current : result) {
if (visitor.visit(current) == VisitResult.TERMINATE) {
finished = true;
break;
}
}
}
}
}
use of com.google.copybara.revision.Change in project copybara by google.
the class GitDestinationTest method testChangeDescriptionEmpty_setRevId.
@Test
public void testChangeDescriptionEmpty_setRevId() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().force().files("foo").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GitDestinationTest", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destination().newWriter(writerContext);
ValidationException e = assertThrows(ValidationException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("test.txt")), console));
assertThat(e).hasMessageThat().contains("Change description is empty");
}
use of com.google.copybara.revision.Change in project copybara by google.
the class GitDestinationTest method testChangeDescriptionEmpty_empty_commit.
@Test
public void testChangeDescriptionEmpty_empty_commit() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().force().files("foo").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GitDestinationTest", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destination().newWriter(writerContext);
ValidationException e = assertThrows(EmptyChangeException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("nothing_to_be_found"), ImmutableList.of("test.txt")), console));
assertThat(e).hasMessageThat().contains("Migration of the revision resulted in an empty change");
}
use of com.google.copybara.revision.Change in project copybara by google.
the class GitDestinationTest method testVisit.
@Test
public void testVisit() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
DummyRevision ref1 = new DummyRevision("origin_ref1");
DummyRevision ref2 = new DummyRevision("origin_ref2");
Files.write(workdir.resolve("test.txt"), "Visit me".getBytes(UTF_8));
process(firstCommitWriter(), ref1);
Files.write(workdir.resolve("test.txt"), "Visit me soon".getBytes(UTF_8));
process(newWriter(), ref2);
List<Change<?>> visited = new ArrayList<>();
newWriter().visitChanges(null, input -> {
visited.add(input);
return input.getLabels().get(DummyOrigin.LABEL_NAME).contains("origin_ref1") ? VisitResult.TERMINATE : VisitResult.CONTINUE;
});
assertThat(visited).hasSize(2);
assertThat(visited.get(0).getLabels().get(DummyOrigin.LABEL_NAME)).containsExactly("origin_ref2");
assertThat(visited.get(1).getLabels().get(DummyOrigin.LABEL_NAME)).containsExactly("origin_ref1");
}
Aggregations