Skip to content

Commit f55accc

Browse files
authored
Merge pull request libgit2#4040 from tiennou/examples/merge
Merge example
2 parents 341608d + 33f44db commit f55accc

File tree

7 files changed

+447
-36
lines changed

7 files changed

+447
-36
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
22
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
33

4-
FILE(GLOB_RECURSE SRC_EXAMPLE_GIT2 network/*.c network/*.h)
4+
FILE(GLOB_RECURSE SRC_EXAMPLE_GIT2 network/*.c network/*.h common.?)
55
ADD_EXECUTABLE(cgit2 ${SRC_EXAMPLE_GIT2})
66
IF(WIN32 OR ANDROID)
77
TARGET_LINK_LIBRARIES(cgit2 git2)

examples/common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,13 @@ void treeish_to_tree(
235235
git_object_free(obj);
236236
}
237237

238+
void *xrealloc(void *oldp, size_t newsz)
239+
{
240+
void *p = realloc(oldp, newsz);
241+
if (p == NULL) {
242+
fprintf(stderr, "Cannot allocate memory, exiting.\n");
243+
exit(1);
244+
}
245+
return p;
246+
}
247+

examples/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ extern int diff_output(
103103
*/
104104
extern void treeish_to_tree(
105105
git_tree **out, git_repository *repo, const char *treeish);
106+
107+
/**
108+
* A realloc that exits on failure
109+
*/
110+
extern void *xrealloc(void *oldp, size_t newsz);

examples/describe.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ typedef struct {
4747

4848
typedef struct args_info args_info;
4949

50-
static void *xrealloc(void *oldp, size_t newsz)
51-
{
52-
void *p = realloc(oldp, newsz);
53-
if (p == NULL) {
54-
fprintf(stderr, "Cannot allocate memory, exiting.\n");
55-
exit(1);
56-
}
57-
return p;
58-
}
59-
6050
static void opts_add_commit(describe_options *opts, const char *commit)
6151
{
6252
size_t sz;

0 commit comments

Comments
 (0)