add nose for staged changes, and remove unnecessary includes

This commit is contained in:
2024-12-19 09:12:37 -06:00
parent 1a2fcaa610
commit fc0da57dff

40
XD.c
View File

@ -7,12 +7,6 @@
#ifdef GIT #ifdef GIT
#include <git2.h> #include <git2.h>
#include <git2/common.h>
#include <git2/errors.h>
#include <git2/global.h>
#include <git2/refs.h>
#include <git2/repository.h>
#include <git2/status.h>
#endif #endif
enum face { EYES, NOSE, MOUTH }; enum face { EYES, NOSE, MOUTH };
@ -126,6 +120,36 @@ has_untracked(git_repository *repo)
git_status_list_free(list); git_status_list_free(list);
return r; return r;
} }
int
has_staged(git_repository *repo)
{
git_status_entry entry;
git_status_list *list = NULL;
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);
return 0;
}
/* if any staged changes are found return 1 */
if ((c = git_status_list_entrycount(list)) > 0) {
for (i = 0; i < c; i++) {
entry = *git_status_byindex(list, i);
if (entry.status & GIT_STATUS_INDEX_NEW
|| entry.status & GIT_STATUS_INDEX_DELETED
|| entry.status & GIT_STATUS_INDEX_MODIFIED) {
r = 1;
break;
}
}
}
git_status_list_free(list);
return r;
}
#endif #endif
int int
@ -153,7 +177,9 @@ main(int argc, char *argv[])
} }
/* change the nose depending on the current git repo's status */ /* change the nose depending on the current git repo's status */
if (has_untracked(repo)) { if (has_staged(repo)) {
face[NOSE] = '*'; /* change to broken nose for staged changes */
} else if (has_untracked(repo)) {
face[NOSE] = '^'; /* add a little nose when there are untracked changes in the repo */ face[NOSE] = '^'; /* add a little nose when there are untracked changes in the repo */
} else if (git_repository_head_detached(repo)) { } else if (git_repository_head_detached(repo)) {
face[NOSE] = '-'; /* add a minus nose when the HEAD is detached */ face[NOSE] = '-'; /* add a minus nose when the HEAD is detached */