use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class Schema_123 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
ListMultimap<Account.Id, Change.Id> imports = MultimapBuilder.hashKeys().arrayListValues().build();
try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
ResultSet rs = stmt.executeQuery("SELECT account_id, change_id FROM starred_changes")) {
while (rs.next()) {
Account.Id accountId = new Account.Id(rs.getInt(1));
Change.Id changeId = new Change.Id(rs.getInt(2));
imports.put(accountId, changeId);
}
}
if (imports.isEmpty()) {
return;
}
try (Repository git = repoManager.openRepository(allUsersName);
RevWalk rw = new RevWalk(git)) {
BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
ObjectId id = StarredChangesUtil.writeLabels(git, StarredChangesUtil.DEFAULT_LABELS);
for (Map.Entry<Account.Id, Change.Id> e : imports.entries()) {
bru.addCommand(new ReceiveCommand(ObjectId.zeroId(), id, RefNames.refsStarredChanges(e.getValue(), e.getKey())));
}
bru.execute(rw, new TextProgressMonitor());
} catch (IOException ex) {
throw new OrmException(ex);
}
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class Schema_148 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
try (Repository repo = repoManager.openRepository(allUsersName);
RevWalk rw = new RevWalk(repo);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId rev = ExternalIdReader.readRevision(repo);
NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
boolean dirty = false;
for (Note note : noteMap) {
byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(ExternalIdReader.MAX_NOTE_SZ);
try {
ExternalId extId = ExternalId.parse(note.getName(), raw);
if (needsUpdate(extId)) {
ExternalIdsUpdate.upsert(rw, ins, noteMap, extId);
dirty = true;
}
} catch (ConfigInvalidException e) {
ui.message(String.format("Warning: Ignoring invalid external ID note %s", note.getName()));
}
}
if (dirty) {
ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, COMMIT_MSG, serverUser, serverUser);
}
} catch (IOException e) {
throw new OrmException("Failed to update external IDs", e);
}
}
use of org.eclipse.jgit.lib.ObjectId in project gitiles by GerritCodeReview.
the class DescribeServlet method describe.
private String describe(Repository repo, GitilesView view, HttpServletRequest req, HttpServletResponse res) throws IOException {
if (!getBooleanParam(view, CONTAINS_PARAM)) {
res.setStatus(SC_BAD_REQUEST);
return null;
}
ObjectId id = resolve(repo, view, req, res);
if (id == null) {
return null;
}
String name;
try (Git git = new Git(repo)) {
NameRevCommand cmd = nameRevCommand(git, id, req, res);
if (cmd == null) {
return null;
}
name = cmd.call().get(id);
} catch (GitAPIException e) {
throw new IOException(e);
}
if (name == null) {
res.setStatus(SC_NOT_FOUND);
return null;
}
return name;
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class UploadArchive method runImpl.
@Override
protected void runImpl() throws IOException, PermissionBackendException, Failure {
PacketLineOut packetOut = new PacketLineOut(out);
packetOut.setFlushOnEnd(true);
packetOut.writeString("ACK");
packetOut.end();
try {
// Parse Git arguments
readArguments();
ArchiveFormat f = allowedFormats.getExtensions().get("." + options.format);
if (f == null) {
throw new Failure(3, "fatal: upload-archive not permitted");
}
// Find out the object to get from the specified reference and paths
ObjectId treeId = repo.resolve(options.treeIsh);
if (treeId == null) {
throw new Failure(4, "fatal: reference not found");
}
// Verify the user has permissions to read the specified tree.
if (!canRead(treeId)) {
throw new Failure(5, "fatal: cannot perform upload-archive operation");
}
// The archive is sent in DATA sideband channel
try (SideBandOutputStream sidebandOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, SideBandOutputStream.MAX_BUF, out)) {
new ArchiveCommand(repo).setFormat(f.name()).setFormatOptions(getFormatOptions(f)).setTree(treeId).setPaths(options.path.toArray(new String[0])).setPrefix(options.prefix).setOutputStream(sidebandOut).call();
sidebandOut.flush();
} catch (GitAPIException e) {
throw new Failure(7, "fatal: git api exception, " + e);
}
} catch (Failure f) {
// Report the error in ERROR sideband channel
try (SideBandOutputStream sidebandError = new SideBandOutputStream(SideBandOutputStream.CH_ERROR, SideBandOutputStream.MAX_BUF, out)) {
sidebandError.write(f.getMessage().getBytes(UTF_8));
sidebandError.flush();
}
throw f;
} finally {
// In any case, cleanly close the packetOut channel
packetOut.end();
}
}
use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnMultipleChanges.
@Test
public void publishCommentsOnPushPublishesDraftsOnMultipleChanges() throws Exception {
ObjectId initialHead = testRepo.getRepository().resolve("HEAD");
List<RevCommit> commits = createChanges(2, "refs/for/master");
String id1 = byCommit(commits.get(0)).change().getKey().get();
String id2 = byCommit(commits.get(1)).change().getKey().get();
CommentInfo c1 = addDraft(id1, commits.get(0).name(), newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(id2, commits.get(1).name(), newDraft(FILE_NAME, 1, "comment2"));
assertThat(getPublishedComments(id1)).isEmpty();
assertThat(getPublishedComments(id2)).isEmpty();
amendChanges(initialHead, commits, "refs/for/master%publish-comments");
Collection<CommentInfo> cs1 = getPublishedComments(id1);
assertThat(cs1.stream().map(c -> c.message)).containsExactly("comment1");
assertThat(cs1.stream().map(c -> c.id)).containsExactly(c1.id);
assertThat(getLastMessage(id1)).isEqualTo("Uploaded patch set 2: Commit message was updated.\n\n(1 comment)");
Collection<CommentInfo> cs2 = getPublishedComments(id2);
assertThat(cs2.stream().map(c -> c.message)).containsExactly("comment2");
assertThat(cs2.stream().map(c -> c.id)).containsExactly(c2.id);
assertThat(getLastMessage(id2)).isEqualTo("Uploaded patch set 2: Commit message was updated.\n\n(1 comment)");
}
Aggregations