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:
19
XD.c
19
XD.c
@ -9,10 +9,10 @@
|
||||
#include <git2.h>
|
||||
#endif
|
||||
|
||||
#ifdef ERR
|
||||
void
|
||||
l(const char *fmt, ...)
|
||||
{
|
||||
#ifdef ERR
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
@ -25,8 +25,11 @@ l(const char *fmt, ...)
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#define L(...) l(__VA_ARGS__)
|
||||
#else
|
||||
#define L(...)
|
||||
#endif
|
||||
|
||||
#ifdef GIT
|
||||
/**
|
||||
@ -41,17 +44,17 @@ git_repository
|
||||
git_repository *repo;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
@ -78,7 +81,7 @@ has_stashes(git_repository *repo)
|
||||
git_error_clear();
|
||||
return 0;
|
||||
} 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;
|
||||
} else {
|
||||
e = 1;
|
||||
@ -106,7 +109,7 @@ has_untracked(git_repository *repo)
|
||||
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -127,7 +130,7 @@ has_staged(git_repository *repo)
|
||||
int i, c, r = 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user