List of usage examples for org.eclipse.jgit.lib Constants OBJ_BLOB
int OBJ_BLOB
To view the source code for org.eclipse.jgit.lib Constants OBJ_BLOB.
Click Source Link
From source file:com.google.gerrit.rules.RulesCache.java
License:Apache License
private String read(Project.NameKey project, ObjectId rulesId) throws CompileException { try (Repository git = gitMgr.openRepository(project)) { try {//from www . jav a2 s . c om ObjectLoader ldr = git.open(rulesId, Constants.OBJ_BLOB); byte[] raw = ldr.getCachedBytes(SRC_LIMIT); return RawParseUtils.decode(raw); } catch (LargeObjectException e) { throw new CompileException("rules of " + project + " are too large", e); } catch (RuntimeException | IOException e) { throw new CompileException("Cannot load rules of " + project, e); } } catch (IOException e) { throw new CompileException("Cannot open repository " + project, e); } }
From source file:com.google.gerrit.server.change.FileContentUtil.java
License:Apache License
public BinaryResult downloadContent(ProjectState project, ObjectId revstr, String path, @Nullable String suffix) throws ResourceNotFoundException, IOException { suffix = Strings.emptyToNull(CharMatcher.inRange('a', 'z').retainFrom(Strings.nullToEmpty(suffix))); try (Repository repo = openRepository(project); RevWalk rw = new RevWalk(repo)) { RevCommit commit = rw.parseCommit(revstr); ObjectReader reader = rw.getObjectReader(); TreeWalk tw = TreeWalk.forPath(reader, path, commit.getTree()); if (tw == null) { throw new ResourceNotFoundException(); }//from w w w. j ava 2 s.c o m int mode = tw.getFileMode(0).getObjectType(); if (mode != Constants.OBJ_BLOB) { throw new ResourceNotFoundException(); } ObjectId id = tw.getObjectId(0); ObjectLoader obj = repo.open(id, OBJ_BLOB); byte[] raw; try { raw = obj.getCachedBytes(MAX_SIZE); } catch (LargeObjectException e) { raw = null; } MimeType contentType = registry.getMimeType(path, raw); return registry.isSafeInline(contentType) ? wrapBlob(path, obj, raw, contentType, suffix) : zipBlob(path, obj, commit, suffix); } }
From source file:com.google.gerrit.server.git.BanCommit.java
License:Apache License
private ObjectId createNoteContent(String reason, ObjectInserter inserter) throws UnsupportedEncodingException, IOException { String noteContent = reason != null ? reason : ""; if (noteContent.length() > 0 && !noteContent.endsWith("\n")) { noteContent = noteContent + "\n"; }//from w w w. j ava 2s . c om return inserter.insert(Constants.OBJ_BLOB, noteContent.getBytes("UTF-8")); }
From source file:com.google.gerrit.server.git.CreateCodeReviewNotes.java
License:Apache License
private ObjectId createNoteContent(Change change, RevCommit commit) throws CodeReviewNoteCreationException, IOException { try {//from w w w . jav a 2s.co m ReviewNoteHeaderFormatter formatter = new ReviewNoteHeaderFormatter(author.getTimeZone()); final List<String> idList = commit.getFooterLines(CHANGE_ID); if (idList.isEmpty()) formatter.appendChangeId(change.getKey()); ResultSet<PatchSetApproval> approvals = schema.patchSetApprovals() .byPatchSet(change.currentPatchSetId()); PatchSetApproval submit = null; for (PatchSetApproval a : approvals) { if (a.getValue() == 0) { // Ignore 0 values. } else if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) { submit = a; } else { ApprovalType type = approvalTypes.byId(a.getCategoryId()); if (type != null) { formatter.appendApproval(type.getCategory(), a.getValue(), accountCache.get(a.getAccountId()).getAccount()); } } } if (submit != null) { formatter.appendSubmittedBy(accountCache.get(submit.getAccountId()).getAccount()); formatter.appendSubmittedAt(submit.getGranted()); } if (canonicalWebUrl != null) { formatter.appendReviewedOn(canonicalWebUrl, change.getId()); } formatter.appendProject(change.getProject().get()); formatter.appendBranch(change.getDest()); return inserter.insert(Constants.OBJ_BLOB, formatter.toString().getBytes("UTF-8")); } catch (OrmException e) { throw new CodeReviewNoteCreationException(commit, e); } }
From source file:com.google.gerrit.server.git.ReviewNoteMerger.java
License:Eclipse Distribution License
@Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) { return theirs; }//from w ww . ja v a2 s . com if (theirs == null) { return ours; } if (ours.getData().equals(theirs.getData())) { return ours; } ObjectLoader lo = reader.open(ours.getData()); byte[] sep = new byte[] { '\n' }; ObjectLoader lt = reader.open(theirs.getData()); try (ObjectStream os = lo.openStream(); ByteArrayInputStream b = new ByteArrayInputStream(sep); ObjectStream ts = lt.openStream(); UnionInputStream union = new UnionInputStream(os, b, ts)) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union); return new Note(ours, noteData); } }
From source file:com.google.gerrit.server.git.SubmoduleOpTest.java
License:Apache License
/** * It creates and adds a regular file to git index of a repository. * * @param fileName The file name.// www . j a v a 2 s . c om * @param content File content. * @param repository The Repository instance. * @throws IOException If an I/O exception occurs. */ private void addRegularFileToIndex(final String fileName, final String content, final Repository repository) throws IOException { final ObjectInserter oi = repository.newObjectInserter(); AnyObjectId objectId = oi.insert(Constants.OBJ_BLOB, Constants.encode(content)); oi.flush(); addEntryToIndex(fileName, FileMode.REGULAR_FILE, objectId, repository); }
From source file:com.google.gerrit.server.git.VersionedMetaData.java
License:Apache License
protected byte[] readFile(String fileName) throws IOException { if (revision == null) { return new byte[] {}; }/*from ww w . j av a 2 s . co m*/ TreeWalk tw = TreeWalk.forPath(reader, fileName, revision.getTree()); if (tw != null) { ObjectLoader obj = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB); return obj.getCachedBytes(Integer.MAX_VALUE); } else { return new byte[] {}; } }
From source file:com.google.gerrit.server.git.VersionedMetaData.java
License:Apache License
protected void saveFile(String fileName, byte[] raw) throws IOException { DirCacheEditor editor = newTree.editor(); if (raw != null && 0 < raw.length) { final ObjectId blobId = inserter.insert(Constants.OBJ_BLOB, raw); editor.add(new PathEdit(fileName) { @Override// w w w . j av a2s. c om public void apply(DirCacheEntry ent) { ent.setFileMode(FileMode.REGULAR_FILE); ent.setObjectId(blobId); } }); } else { editor.add(new DeletePath(fileName)); } editor.finish(); }
From source file:com.google.gerrit.server.notedb.ChangeNotesTest.java
License:Apache License
@Test public void patchLineCommentNotesFormatSide1() throws Exception { Change c = newChange();//from w w w. ja va 2 s . c o m ChangeUpdate update = newUpdate(c, otherUser); String uuid1 = "uuid1"; String uuid2 = "uuid2"; String uuid3 = "uuid3"; String message1 = "comment 1"; String message2 = "comment 2"; String message3 = "comment 3"; CommentRange range1 = new CommentRange(1, 1, 2, 1); Timestamp time1 = TimeUtil.nowTs(); Timestamp time2 = TimeUtil.nowTs(); Timestamp time3 = TimeUtil.nowTs(); PatchSet.Id psId = c.currentPatchSetId(); PatchLineComment comment1 = newPublishedComment(psId, "file1", uuid1, range1, range1.getEndLine(), otherUser, null, time1, message1, (short) 1, "abcd1234abcd1234abcd1234abcd1234abcd1234"); update.setPatchSetId(psId); update.upsertComment(comment1); update.commit(); update = newUpdate(c, otherUser); CommentRange range2 = new CommentRange(2, 1, 3, 1); PatchLineComment comment2 = newPublishedComment(psId, "file1", uuid2, range2, range2.getEndLine(), otherUser, null, time2, message2, (short) 1, "abcd1234abcd1234abcd1234abcd1234abcd1234"); update.setPatchSetId(psId); update.upsertComment(comment2); update.commit(); update = newUpdate(c, otherUser); CommentRange range3 = new CommentRange(3, 1, 4, 1); PatchLineComment comment3 = newPublishedComment(psId, "file2", uuid3, range3, range3.getEndLine(), otherUser, null, time3, message3, (short) 1, "abcd1234abcd1234abcd1234abcd1234abcd1234"); update.setPatchSetId(psId); update.upsertComment(comment3); update.commit(); ChangeNotes notes = newNotes(c); try (RevWalk walk = new RevWalk(repo)) { ArrayList<Note> notesInTree = Lists.newArrayList(notes.getNoteMap().iterator()); Note note = Iterables.getOnlyElement(notesInTree); byte[] bytes = walk.getObjectReader().open(note.getData(), Constants.OBJ_BLOB).getBytes(); String noteString = new String(bytes, UTF_8); assertThat(noteString).isEqualTo("Patch-set: 1\n" + "Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n" + "File: file1\n" + "\n" + "1:1-2:1\n" + CommentsInNotesUtil.formatTime(serverIdent, time1) + "\n" + "Author: Other Account <2@gerrit>\n" + "UUID: uuid1\n" + "Bytes: 9\n" + "comment 1\n" + "\n" + "2:1-3:1\n" + CommentsInNotesUtil.formatTime(serverIdent, time2) + "\n" + "Author: Other Account <2@gerrit>\n" + "UUID: uuid2\n" + "Bytes: 9\n" + "comment 2\n" + "\n" + "File: file2\n" + "\n" + "3:1-4:1\n" + CommentsInNotesUtil.formatTime(serverIdent, time3) + "\n" + "Author: Other Account <2@gerrit>\n" + "UUID: uuid3\n" + "Bytes: 9\n" + "comment 3\n" + "\n"); } }
From source file:com.google.gerrit.server.notedb.ChangeNotesTest.java
License:Apache License
@Test public void patchLineCommentNotesFormatSide0() throws Exception { Change c = newChange();/*from w ww .ja v a2 s .c om*/ ChangeUpdate update = newUpdate(c, otherUser); String uuid1 = "uuid1"; String uuid2 = "uuid2"; String message1 = "comment 1"; String message2 = "comment 2"; CommentRange range1 = new CommentRange(1, 1, 2, 1); Timestamp time1 = TimeUtil.nowTs(); Timestamp time2 = TimeUtil.nowTs(); PatchSet.Id psId = c.currentPatchSetId(); PatchLineComment comment1 = newPublishedComment(psId, "file1", uuid1, range1, range1.getEndLine(), otherUser, null, time1, message1, (short) 0, "abcd1234abcd1234abcd1234abcd1234abcd1234"); update.setPatchSetId(psId); update.upsertComment(comment1); update.commit(); update = newUpdate(c, otherUser); CommentRange range2 = new CommentRange(2, 1, 3, 1); PatchLineComment comment2 = newPublishedComment(psId, "file1", uuid2, range2, range2.getEndLine(), otherUser, null, time2, message2, (short) 0, "abcd1234abcd1234abcd1234abcd1234abcd1234"); update.setPatchSetId(psId); update.upsertComment(comment2); update.commit(); ChangeNotes notes = newNotes(c); try (RevWalk walk = new RevWalk(repo)) { ArrayList<Note> notesInTree = Lists.newArrayList(notes.getNoteMap().iterator()); Note note = Iterables.getOnlyElement(notesInTree); byte[] bytes = walk.getObjectReader().open(note.getData(), Constants.OBJ_BLOB).getBytes(); String noteString = new String(bytes, UTF_8); assertThat(noteString).isEqualTo("Base-for-patch-set: 1\n" + "Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n" + "File: file1\n" + "\n" + "1:1-2:1\n" + CommentsInNotesUtil.formatTime(serverIdent, time1) + "\n" + "Author: Other Account <2@gerrit>\n" + "UUID: uuid1\n" + "Bytes: 9\n" + "comment 1\n" + "\n" + "2:1-3:1\n" + CommentsInNotesUtil.formatTime(serverIdent, time2) + "\n" + "Author: Other Account <2@gerrit>\n" + "UUID: uuid2\n" + "Bytes: 9\n" + "comment 2\n" + "\n"); } }