]>
git.proxmox.com Git - libgit2.git/blob - examples/common.h
f86e92c3574c7f46d8335c714a35859b4e24fdcd
2 * Utilities library for libgit2 examples
4 * Written by the libgit2 contributors
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.
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/>.
14 #ifndef INCLUDE_examples_common_h__
15 #define INCLUDE_examples_common_h__
18 #include <sys/types.h>
33 # define sleep(a) Sleep(a * 1000)
39 /* Define the printf format specifier to use for size_t output */
40 #if defined(_MSC_VER) || defined(__MINGW32__)
48 #define snprintf sprintf_s
49 #define strcasecmp strcmpi
52 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
53 #define UNUSED(x) (void)(x)
57 extern int lg2_add(git_repository
*repo
, int argc
, char **argv
);
58 extern int lg2_blame(git_repository
*repo
, int argc
, char **argv
);
59 extern int lg2_cat_file(git_repository
*repo
, int argc
, char **argv
);
60 extern int lg2_checkout(git_repository
*repo
, int argc
, char **argv
);
61 extern int lg2_clone(git_repository
*repo
, int argc
, char **argv
);
62 extern int lg2_commit(git_repository
*repo
, int argc
, char **argv
);
63 extern int lg2_config(git_repository
*repo
, int argc
, char **argv
);
64 extern int lg2_describe(git_repository
*repo
, int argc
, char **argv
);
65 extern int lg2_diff(git_repository
*repo
, int argc
, char **argv
);
66 extern int lg2_fetch(git_repository
*repo
, int argc
, char **argv
);
67 extern int lg2_for_each_ref(git_repository
*repo
, int argc
, char **argv
);
68 extern int lg2_general(git_repository
*repo
, int argc
, char **argv
);
69 extern int lg2_index_pack(git_repository
*repo
, int argc
, char **argv
);
70 extern int lg2_init(git_repository
*repo
, int argc
, char **argv
);
71 extern int lg2_log(git_repository
*repo
, int argc
, char **argv
);
72 extern int lg2_ls_files(git_repository
*repo
, int argc
, char **argv
);
73 extern int lg2_ls_remote(git_repository
*repo
, int argc
, char **argv
);
74 extern int lg2_merge(git_repository
*repo
, int argc
, char **argv
);
75 extern int lg2_push(git_repository
*repo
, int argc
, char **argv
);
76 extern int lg2_remote(git_repository
*repo
, int argc
, char **argv
);
77 extern int lg2_rev_list(git_repository
*repo
, int argc
, char **argv
);
78 extern int lg2_rev_parse(git_repository
*repo
, int argc
, char **argv
);
79 extern int lg2_show_index(git_repository
*repo
, int argc
, char **argv
);
80 extern int lg2_stash(git_repository
*repo
, int argc
, char **argv
);
81 extern int lg2_status(git_repository
*repo
, int argc
, char **argv
);
82 extern int lg2_tag(git_repository
*repo
, int argc
, char **argv
);
85 * Check libgit2 error code, printing error to stderr on failure and
86 * exiting the program.
88 extern void check_lg2(int error
, const char *message
, const char *extra
);
91 * Read a file into a buffer
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
96 extern char *read_file(const char *path
);
99 * Exit the program, printing error to stderr
101 extern void fatal(const char *message
, const char *extra
);
104 * Basic output function for plain text diff output
105 * Pass `FILE*` such as `stdout` or `stderr` as payload (or NULL == `stdout`)
107 extern int diff_output(
108 const git_diff_delta
*, const git_diff_hunk
*, const git_diff_line
*, void*);
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
114 extern void treeish_to_tree(
115 git_tree
**out
, git_repository
*repo
, const char *treeish
);
118 * A realloc that exits on failure
120 extern void *xrealloc(void *oldp
, size_t newsz
);
123 * Convert a refish to an annotated commit.
125 extern int resolve_refish(git_annotated_commit
**commit
, git_repository
*repo
, const char *refish
);
128 * Acquire credentials via command line
130 extern int cred_acquire_cb(git_credential
**out
,
132 const char *username_from_url
,
133 unsigned int allowed_types
,