]> git.proxmox.com Git - libgit2.git/blame - examples/common.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / examples / common.h
CommitLineData
66902d47 1/*
6cb831bd 2 * Utilities library for libgit2 examples
66902d47 3 *
6cb831bd
BS
4 * Written by the libgit2 contributors
5 *
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
9 *
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
66902d47 13 */
22a2d3d5
UG
14#ifndef INCLUDE_examples_common_h__
15#define INCLUDE_examples_common_h__
66902d47 16
22a2d3d5
UG
17#include <assert.h>
18#include <sys/types.h>
19#include <sys/stat.h>
66902d47
RB
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <git2.h>
22a2d3d5
UG
24#include <fcntl.h>
25
26#ifdef _WIN32
27# include <io.h>
28# include <Windows.h>
29# define open _open
30# define read _read
31# define close _close
32# define ssize_t int
33# define sleep(a) Sleep(a * 1000)
34#else
35# include <unistd.h>
36#endif
37
38#ifndef PRIuZ
c25aa7cd 39/* Define the printf format specifier to use for size_t output */
22a2d3d5
UG
40#if defined(_MSC_VER) || defined(__MINGW32__)
41# define PRIuZ "Iu"
42#else
43# define PRIuZ "zu"
44#endif
45#endif
46
47#ifdef _MSC_VER
e579e0f7 48#define snprintf _snprintf
22a2d3d5
UG
49#define strcasecmp strcmpi
50#endif
51
52#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
53#define UNUSED(x) (void)(x)
54
55#include "args.h"
56
57extern int lg2_add(git_repository *repo, int argc, char **argv);
58extern int lg2_blame(git_repository *repo, int argc, char **argv);
59extern int lg2_cat_file(git_repository *repo, int argc, char **argv);
60extern int lg2_checkout(git_repository *repo, int argc, char **argv);
61extern int lg2_clone(git_repository *repo, int argc, char **argv);
62extern int lg2_commit(git_repository *repo, int argc, char **argv);
63extern int lg2_config(git_repository *repo, int argc, char **argv);
64extern int lg2_describe(git_repository *repo, int argc, char **argv);
65extern int lg2_diff(git_repository *repo, int argc, char **argv);
66extern int lg2_fetch(git_repository *repo, int argc, char **argv);
67extern int lg2_for_each_ref(git_repository *repo, int argc, char **argv);
68extern int lg2_general(git_repository *repo, int argc, char **argv);
69extern int lg2_index_pack(git_repository *repo, int argc, char **argv);
70extern int lg2_init(git_repository *repo, int argc, char **argv);
71extern int lg2_log(git_repository *repo, int argc, char **argv);
72extern int lg2_ls_files(git_repository *repo, int argc, char **argv);
73extern int lg2_ls_remote(git_repository *repo, int argc, char **argv);
74extern int lg2_merge(git_repository *repo, int argc, char **argv);
75extern int lg2_push(git_repository *repo, int argc, char **argv);
76extern int lg2_remote(git_repository *repo, int argc, char **argv);
77extern int lg2_rev_list(git_repository *repo, int argc, char **argv);
78extern int lg2_rev_parse(git_repository *repo, int argc, char **argv);
79extern int lg2_show_index(git_repository *repo, int argc, char **argv);
80extern int lg2_stash(git_repository *repo, int argc, char **argv);
81extern int lg2_status(git_repository *repo, int argc, char **argv);
82extern int lg2_tag(git_repository *repo, int argc, char **argv);
66902d47
RB
83
84/**
85 * Check libgit2 error code, printing error to stderr on failure and
86 * exiting the program.
87 */
88extern void check_lg2(int error, const char *message, const char *extra);
89
90/**
22a2d3d5
UG
91 * Read a file into a buffer
92 *
93 * @param path The path to the file that shall be read
94 * @return NUL-terminated buffer if the file was successfully read, NULL-pointer otherwise
66902d47 95 */
22a2d3d5 96extern char *read_file(const char *path);
66902d47 97
ac3d33df 98/**
22a2d3d5 99 * Exit the program, printing error to stderr
ac3d33df 100 */
22a2d3d5 101extern void fatal(const char *message, const char *extra);
ac3d33df 102
66902d47
RB
103/**
104 * Basic output function for plain text diff output
105 * Pass `FILE*` such as `stdout` or `stderr` as payload (or NULL == `stdout`)
106 */
107extern int diff_output(
108 const git_diff_delta*, const git_diff_hunk*, const git_diff_line*, void*);
109
110/**
111 * Convert a treeish argument to an actual tree; this will call check_lg2
112 * and exit the program if `treeish` cannot be resolved to a tree
113 */
114extern void treeish_to_tree(
115 git_tree **out, git_repository *repo, const char *treeish);
eae0bfdc
PP
116
117/**
118 * A realloc that exits on failure
119 */
120extern void *xrealloc(void *oldp, size_t newsz);
ac3d33df
JK
121
122/**
123 * Convert a refish to an annotated commit.
124 */
125extern int resolve_refish(git_annotated_commit **commit, git_repository *repo, const char *refish);
22a2d3d5
UG
126
127/**
128 * Acquire credentials via command line
129 */
130extern int cred_acquire_cb(git_credential **out,
131 const char *url,
132 const char *username_from_url,
133 unsigned int allowed_types,
134 void *payload);
135
136#endif