summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/service/utils/git.h
blob: 59f06f0d92b761a83a24d82fe84d306319439b33 (plain)
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
#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_GIT_H
#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_GIT_H

#include <memory>
#include <git2.h>
#include <ostream>

namespace Gentoo {
	namespace Utils {
		namespace Git {
			void throwError(void * const func, int err);

			template<typename ... P, typename ... A>
			void
			gitSafe(int (*func)(P...), A ... p)
			{
				if (int _giterror = func(p...) < 0) {
					throwError((void * const)func, _giterror);
				}
			}

			template<typename R, typename ... P, typename ... A>
			std::unique_ptr<R, void(*)(R*)>
			gitSafeGet(int(*get)(R**, P...), void(*release)(R*), A ... p)
			{
				R * r = nullptr;
				gitSafe(get, &r, p...);
				return std::unique_ptr<R, void(*)(R*)>(r, release);
			}

			template<typename R, typename ... P, typename ... A>
			R
			gitSafeGet(int(*get)(R*, P...), A ... p)
			{
				R r;
				gitSafe(get, &r, p...);
				return r;
			}

			std::string operator*(const git_oid &);

			std::unique_ptr<git_annotated_commit, void (*)(git_annotated_commit*)>
			gitFetch(git_repository * repo, git_remote * remote, const char * branch);

			git_oid
			gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head);

			void
			updateRepository(const std::string & path, const std::string & upstream, const std::string & branch);
		}
	}
}

namespace std {
	std::ostream & operator<<(std::ostream &, const git_oid &);
}

#endif