Line data Source code
1 : /*! 2 : * \file esys/repo/libgit2/notes.h 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2023 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "esys/repo/esysrepo_defs.h" 21 : #include "esys/repo/result.h" 22 : #include "esys/repo/git/note.h" 23 : 24 : #include <git2.h> 25 : 26 : #include <map> 27 : 28 : namespace esys::repo::libgit2 29 : { 30 : 31 : class Git; 32 : class GitImpl; 33 : 34 : struct ESYSREPO_API Comparegit_oid 35 : { 36 : bool operator()(const git_oid &lhs, const git_oid &rhs) const; 37 : }; 38 : 39 : /*! \class Notes esys/repo/libgit2/notes.h "esys/repo/libgit2/notes.h" 40 : * \brief Handle all the notes of a git repository 41 : */ 42 : class ESYSREPO_API Notes 43 : { 44 : public: 45 : //! Default constructor 46 : /*! 47 : * \param[in] git the git instance used 48 : */ 49 : explicit Notes(Git *git); 50 : 51 : //! Get the git instance used 52 : /*! 53 : * \return the git instance used 54 : */ 55 : Git *get_git(); 56 : 57 : //! Get the git implementation instance used 58 : /*! 59 : * \return the git implementation instance used 60 : */ 61 : GitImpl *get_git_impl(); 62 : 63 : //! Load all notes references added to the git instance 64 : /*! 65 : * \return 0 if successful, < 0 otherwise 66 : */ 67 : Result load_all(); 68 : 69 : //! Load all notes references added to the git instance 70 : /*! 71 : * \param[in] ref the notes reference to load 72 : * \return 0 if successful, < 0 otherwise 73 : */ 74 : Result load(const std::string &ref); 75 : 76 : Result get_note(const git_oid ¬e_oid, std::vector<std::shared_ptr<git::Note>> ¬es) const; 77 : 78 : //! Tells if the notes have been loaded already 79 : /*! 80 : * \return true if the notes where already loaded, false otherwise 81 : */ 82 : bool is_loaded() const; 83 : 84 : //! Set if all notes have been loaded already 85 : /*! 86 : * \param[in] loaded true all notes have been loaded already, false otherwise 87 : */ 88 : void set_loaded(bool loaded); 89 : 90 : void clear(); 91 : private: 92 : //!< \cond DOXY_IMPL 93 : 94 : struct RefMapNotesItem; 95 : 96 : void add_note(std::shared_ptr<RefMapNotesItem> map, const git_oid ¬e_oid, const git_oid &commit_oid); 97 : 98 : Git *m_git = nullptr; //!< The git instance to be used 99 : bool m_loaded = false; //!< Tells if the notes have been loaded already 100 : 101 : struct OIDCommitMapNoteItem 102 : { 103 : OIDCommitMapNoteItem(); 104 : 105 : OIDCommitMapNoteItem(Notes *notes, const git_oid ¬e_oid, const git_oid &comment_oid, 106 : RefMapNotesItem *ref_map); 107 : 108 : std::shared_ptr<git::Note> get_note(); 109 : 110 : git_oid m_note_oid; 111 : git_oid m_comment_oid; 112 : std::shared_ptr<git::Note> m_note; 113 : RefMapNotesItem *m_ref_map = nullptr; 114 : Notes *m_notes = nullptr; 115 : std::string m_ref; 116 : }; 117 : 118 : using OIDCommitMapNoteVec = std::vector<OIDCommitMapNoteItem>; 119 : 120 6 : struct RefMapNotesItem 121 : { 122 : std::string m_ref; 123 : std::map<git_oid, std::shared_ptr<OIDCommitMapNoteVec>, Comparegit_oid> m_iod_commit_map_note; 124 : }; 125 : 126 : //! Map from the notes reference to 127 : std::map<std::string, std::shared_ptr<RefMapNotesItem>, std::less<>> m_ref_map_notes; 128 : 129 : //! Map from the commit oid to the vector of Notes attached to this commit 130 : std::map<git_oid, std::shared_ptr<OIDCommitMapNoteVec>, Comparegit_oid> m_oid_map_notes; 131 : //!< \endcond 132 : }; 133 : 134 : } // namespace esys::repo::libgit2