1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.api;
11
12 import java.io.IOException;
13
14 import org.eclipse.jgit.api.errors.GitAPIException;
15 import org.eclipse.jgit.api.errors.JGitInternalException;
16 import org.eclipse.jgit.lib.Constants;
17 import org.eclipse.jgit.lib.Ref;
18 import org.eclipse.jgit.lib.Repository;
19 import org.eclipse.jgit.notes.Note;
20 import org.eclipse.jgit.notes.NoteMap;
21 import org.eclipse.jgit.revwalk.RevCommit;
22 import org.eclipse.jgit.revwalk.RevObject;
23 import org.eclipse.jgit.revwalk.RevWalk;
24
25
26
27
28
29
30
31 public class ShowNoteCommand extends GitCommand<Note> {
32
33 private RevObject id;
34
35 private String notesRef = Constants.R_NOTES_COMMITS;
36
37
38
39
40
41
42
43 protected ShowNoteCommand(Repository repo) {
44 super(repo);
45 }
46
47
48 @Override
49 public Note call() throws GitAPIException {
50 checkCallable();
51 NoteMap map = NoteMap.newEmptyMap();
52 RevCommit notesCommit = null;
53 try (RevWalk walk = new RevWalk(repo)) {
54 Ref ref = repo.exactRef(notesRef);
55
56 if (ref != null) {
57 notesCommit = walk.parseCommit(ref.getObjectId());
58 map = NoteMap.read(walk.getObjectReader(), notesCommit);
59 }
60 return map.getNote(id);
61 } catch (IOException e) {
62 throw new JGitInternalException(e.getMessage(), e);
63 }
64 }
65
66
67
68
69
70
71
72
73
74 public ShowNoteCommand setObjectId(RevObject id) {
75 checkCallable();
76 this.id = id;
77 return this;
78 }
79
80
81
82
83
84
85
86
87
88
89
90 public ShowNoteCommand setNotesRef(String notesRef) {
91 checkCallable();
92 this.notesRef = notesRef;
93 return this;
94 }
95
96 }