List of usage examples for org.eclipse.jgit.notes Note getName
public final String getName()
From source file:com.buildautomation.jgit.api.AddAndListNoteOfCommit.java
License:Apache License
public static void addAndListNoteOfCommit() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.exactRef("refs/heads/master"); System.out.println("Found head: " + head); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Found Commit: " + commit); try (Git git = new Git(repository)) { git.notesAdd().setMessage("some note message").setObjectId(commit).call(); System.out.println("Added Note to commit " + commit); List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { // check if we found the note for this commit if (!note.getName().equals(head.getObjectId().getName())) { System.out.println("Note " + note + " did not match commit " + head); continue; }//ww w. ja v a 2s .com System.out.println("Found note: " + note + " for commit " + head); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); } } walk.dispose(); } } }
From source file:com.buildautomation.jgit.api.ListNotes.java
License:Apache License
public static void listNotes() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: "); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); }//from ww w . jav a2 s.com } } }
From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java
License:Open Source License
/** * Retrieves all the reviews in the current project's repository by commit hash. *///from ww w. jav a 2s . c o m public Map<String, Review> listReviews() throws GitClientException { // Get the most up-to-date list of reviews. syncCommentsAndReviews(); Map<String, Review> reviews = new LinkedHashMap<>(); Git git = new Git(repo); try { ListNotesCommand cmd = git.notesList(); cmd.setNotesRef(REVIEWS_REF); List<Note> notes = cmd.call(); for (Note note : notes) { String rawNoteDataStr = noteToString(repo, note); Review latest = extractLatestReviewFromNotes(rawNoteDataStr); if (latest != null) { reviews.put(note.getName(), latest); } } } catch (Exception e) { throw new GitClientException(e); } finally { git.close(); } return reviews; }
From source file:com.google.gerrit.server.account.externalids.ExternalIdReader.java
License:Apache License
/** Reads and returns all external IDs. */ private Set<ExternalId> all(Repository repo, ObjectId rev) throws IOException { if (rev.equals(ObjectId.zeroId())) { return ImmutableSet.of(); }/* w ww . j a va2 s . c o m*/ try (Timer0.Context ctx = readAllLatency.start(); RevWalk rw = new RevWalk(repo)) { NoteMap noteMap = readNoteMap(rw, rev); Set<ExternalId> extIds = new HashSet<>(); for (Note note : noteMap) { byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); try { extIds.add(ExternalId.parse(note.getName(), raw)); } catch (Exception e) { log.error(String.format("Ignoring invalid external ID note %s", note.getName()), e); } } return extIds; } }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsConsistencyChecker.java
License:Apache License
private List<ConsistencyProblemInfo> check(Repository repo, ObjectId commit) throws IOException { List<ConsistencyProblemInfo> problems = new ArrayList<>(); ListMultimap<String, ExternalId.Key> emails = MultimapBuilder.hashKeys().arrayListValues().build(); try (RevWalk rw = new RevWalk(repo)) { NoteMap noteMap = ExternalIdReader.readNoteMap(rw, commit); 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); problems.addAll(validateExternalId(extId)); if (extId.email() != null) { emails.put(extId.email(), extId.key()); }//from w w w . j av a2 s . co m } catch (ConfigInvalidException e) { addError(String.format(e.getMessage()), problems); } } } emails.asMap().entrySet().stream().filter(e -> e.getValue().size() > 1).forEach(e -> addError( String.format("Email '%s' is not unique, it's used by the following external IDs: %s", e.getKey(), e.getValue().stream().map(k -> "'" + k.get() + "'").sorted().collect(joining(", "))), problems)); return problems; }
From source file:com.google.gerrit.server.schema.Schema_148.java
License:Apache License
@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;//ww w.ja va2s .c o m } } 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); } }
From source file:com.maiereni.sling.sources.git.GitProjectDownloader.java
License:Apache License
private void update(final Git git) throws Exception { logger.debug("Fetch from remote"); FetchResult fr = git.fetch().call(); // .setRemote(url) Collection<Ref> refs = fr.getAdvertisedRefs(); Iterable<RevCommit> logs = git.log().call(); for (RevCommit rev : logs) { PersonIdent authorIdent = rev.getAuthorIdent(); Date date = authorIdent.getWhen(); String authName = authorIdent.getName(); logger.debug("Commit at " + SDF.format(date) + " by " + authName + ": " + rev.getId().name() + " text: " + rev.getShortMessage()); }//from w ww . j av a2 s. c om List<Note> notes = git.notesList().call(); for (Ref ref : refs) { if (ref.getName().equals("HEAD")) { git.rebase().setUpstream(ref.getObjectId()).call(); logger.debug("Rebase on HEAD"); for (Note note : notes) { if (note.getName().equals(ref.getObjectId().getName())) { logger.debug("Found note: " + note + " for commit " + ref.getName()); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = git.getRepository().open(note.getData()); loader.copyTo(System.out); } } } } }
From source file:edu.nju.cs.inform.jgit.porcelain.AddAndListNoteOfCommit.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.exactRef("refs/heads/master"); System.out.println("Found head: " + head); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Found Commit: " + commit); try (Git git = new Git(repository)) { git.notesAdd().setMessage("some note message").setObjectId(commit).call(); System.out.println("Added Note to commit " + commit); List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { // check if we found the note for this commit if (!note.getName().equals(head.getObjectId().getName())) { System.out.println("Note " + note + " did not match commit " + head); continue; }//from www . ja va 2s .c o m System.out.println("Found note: " + note + " for commit " + head); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); } } walk.dispose(); } } }
From source file:edu.nju.cs.inform.jgit.porcelain.ListNotes.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: "); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); }/* w ww . j ava2 s .co m*/ } } }