File: Commit.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (63 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once

#include "Repository.h"
#include "GitException.h"
#include "Tree.h"
#include <git2.h>

namespace vcs
{

namespace git
{

class Commit final
{
private:
    git_commit* _commit;

public:
    using Ptr = std::shared_ptr<Commit>;

    Commit(git_commit* commit) :
        _commit(commit)
    {}

    ~Commit()
    {
        git_commit_free(_commit);
    }

    const git_oid* getOid() const
    {
        return git_commit_id(_commit);
    }

    std::shared_ptr<Tree> getTree()
    {
        git_tree* tree;
        auto error = git_commit_tree(&tree, _commit);
        GitException::ThrowOnError(error);

        return std::make_shared<Tree>(tree);
    }

    static Ptr LookupFromOid(git_repository* repository, git_oid* oid)
    {
        git_commit* commit;

        auto error = git_commit_lookup(&commit, repository, oid);
        GitException::ThrowOnError(error);

        return std::make_shared<Commit>(commit);
    }

    const git_commit* _get()
    {
        return _commit;
    }
};

}

}