3

libgit2で最後のコミットを取得するためのコピー アンド ペーストの例がないため、追加する必要があると考えました。libgit2 の例では、git_oid_fromstr()...

libgit2 は現時点 (2013 年 3 月) で完全に開発中であることを忘れないでください。新しい機能が毎日追加されているため、公式ドキュメントとソース コードを参照してください。

4

1 に答える 1

8
git_commit * getLastCommit ( git_repository * repo )
{
  int rc;
  git_commit * commit = NULL; /* the result */
  git_oid oid_parent_commit;  /* the SHA1 for last commit */

  /* resolve HEAD into a SHA1 */
  rc = git_reference_name_to_id( &oid_parent_commit, repo, "HEAD" );
  if ( rc == 0 )
  {
    /* get the actual commit structure */
    rc = git_commit_lookup( &commit, repo, &oid_parent_commit );
    if ( rc == 0 )
    {
      return commit;
    }
  }
  return NULL;
}

git_commit_free()作業が完了したら、電話する必要があります。

于 2013-03-30T10:43:47.663 に答える