optimize further...
make sure to not include useless function calls when errors arent enabled by wrapping all l calls in a macro
This commit is contained in:
39
XD.c
39
XD.c
@ -9,24 +9,27 @@
|
|||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ERR
|
||||||
void
|
void
|
||||||
l(const char *fmt, ...)
|
l(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
#ifdef ERR
|
va_list ap;
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||||
fputc(' ', stderr);
|
fputc(' ', stderr);
|
||||||
perror(NULL);
|
perror(NULL);
|
||||||
} else {
|
} else {
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#define L(...) l(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define L(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef GIT
|
#ifdef GIT
|
||||||
/**
|
/**
|
||||||
@ -41,17 +44,17 @@ git_repository
|
|||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
|
|
||||||
if (git_libgit2_init() < 0) {
|
if (git_libgit2_init() < 0) {
|
||||||
l("Failed to initalize libgit2, proceeding without git functionality enabled.");
|
L("Failed to initalize libgit2, proceeding without git functionality enabled.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (git_repository_discover(&buf, ".", 0, NULL) < 0) {
|
if (git_repository_discover(&buf, ".", 0, NULL) < 0) {
|
||||||
l("Failed to discover git repo: %s", git_error_last()->message);
|
L("Failed to discover git repo: %s", git_error_last()->message);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (git_repository_open(&repo, buf.ptr) < 0) {
|
if (git_repository_open(&repo, buf.ptr) < 0) {
|
||||||
l("Failed to open git repo: %s", git_error_last()->message);
|
L("Failed to open git repo: %s", git_error_last()->message);
|
||||||
git_buf_dispose(&buf);
|
git_buf_dispose(&buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -78,7 +81,7 @@ has_stashes(git_repository *repo)
|
|||||||
git_error_clear();
|
git_error_clear();
|
||||||
return 0;
|
return 0;
|
||||||
} else if (e < GIT_OK) {
|
} else if (e < GIT_OK) {
|
||||||
l("Error looking up stash reference: %s", git_error_last()->message);
|
L("Error looking up stash reference: %s", git_error_last()->message);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
e = 1;
|
e = 1;
|
||||||
@ -106,7 +109,7 @@ has_untracked(git_repository *repo)
|
|||||||
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
|
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
|
||||||
|
|
||||||
if (git_status_list_new(&list, repo, &opts) < 0) {
|
if (git_status_list_new(&list, repo, &opts) < 0) {
|
||||||
l("Error checking for untracked changes: %s", git_error_last()->message);
|
L("Error checking for untracked changes: %s", git_error_last()->message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +130,7 @@ has_staged(git_repository *repo)
|
|||||||
int i, c, r = 0;
|
int i, c, r = 0;
|
||||||
|
|
||||||
if (git_status_list_new(&list, repo, NULL) < 0) {
|
if (git_status_list_new(&list, repo, NULL) < 0) {
|
||||||
l("Error checking for staged changes: %s", git_error_last()->message);
|
L("Error checking for staged changes: %s", git_error_last()->message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user