【问题标题】:How to use `git_note` from libgit2?如何使用 libgit2 中的`git_note`?
【发布时间】:2020-11-16 21:54:24
【问题描述】:

我有如下代码(commit_id 已经设置):

  git_note* note;
  git_note_read(&note, repo, "refs/notes/label", &commit_oid);
  printf("%s\n", note->message);
  git_note_free(note);

它不编译,抱怨:

.../importer_test.cc:103:22: error: member access into incomplete type 'git_note'
  printf("%s\n", note->message);
                     ^
.../include/git2/types.h:160:16: note: forward declaration of 'git_note'
typedef struct git_note git_note;

如果我只是从src/notes.h 复制/粘贴到这个文件中:

struct git_note {
  git_oid id;
  git_signature *author;
  git_signature *committer;
  char *message;
};

它可以正确编译和运行。但这肯定不是正确的解决方案吗?

【问题讨论】:

    标签: libgit2


    【解决方案1】:

    git_note 是不透明类型。您不打算直接访问数据成员。您应该使用访问器函数来读取它。在您的情况下,您可能希望使用 git_note_message() 来获取消息。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多