Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
530f5a54c8
|
|||
01567bb069
|
|||
d834bac2f4 |
2
XD.1
2
XD.1
@@ -85,6 +85,6 @@ $ \fBXD -e $?\fR
|
|||||||
.br
|
.br
|
||||||
In a git repository.
|
In a git repository.
|
||||||
.br
|
.br
|
||||||
The're staged changes.
|
There staged changes.
|
||||||
.br
|
.br
|
||||||
Return code of 130, ctrl-c was pressed, or SIGTERM sent.
|
Return code of 130, ctrl-c was pressed, or SIGTERM sent.
|
||||||
|
34
XD.c
34
XD.c
@@ -61,8 +61,9 @@ static int explain = 0;
|
|||||||
char
|
char
|
||||||
*find_git_repo()
|
*find_git_repo()
|
||||||
{
|
{
|
||||||
char path[PATH_MAX] = ".", *rpath;
|
char path[PATH_MAX] = ".", fstr[PATH_MAX], *rpath, *res;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
FILE *f;
|
||||||
int i, c;
|
int i, c;
|
||||||
|
|
||||||
/* find the number of jumps to the root of the fs */
|
/* find the number of jumps to the root of the fs */
|
||||||
@@ -83,8 +84,26 @@ char
|
|||||||
strcat(path, "/.git");
|
strcat(path, "/.git");
|
||||||
|
|
||||||
/* if there seems to be a git directory return the directory it was found in */
|
/* if there seems to be a git directory return the directory it was found in */
|
||||||
if (stat(path, &s) == 0 && S_ISDIR(s.st_mode)) {
|
if (stat(path, &s) == 0) {
|
||||||
|
if (S_ISDIR(s.st_mode)) {
|
||||||
return realpath(path, NULL);
|
return realpath(path, NULL);
|
||||||
|
} else if (S_ISREG(s.st_mode)) {
|
||||||
|
/* we do some special magic here to check if we're in a submodule */
|
||||||
|
f = fopen(path, "r");
|
||||||
|
if (!f) {
|
||||||
|
L("fopen: %s", strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
res = fgets(fstr, PATH_MAX, f);
|
||||||
|
fclose(f);
|
||||||
|
if (!res) {
|
||||||
|
L("fgets: %s", strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (strncmp(fstr, "gitdir: ", strlen("gitdir: ")) == 0) {
|
||||||
|
return realpath(strndup(fstr + strlen("gitdir: "), strlen(fstr + strlen("gitdir: ")) - 1), NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset contents of gpath, and go up a directory */
|
/* reset contents of gpath, and go up a directory */
|
||||||
@@ -113,13 +132,12 @@ git_repository
|
|||||||
|
|
||||||
/* disable a bunch of git options to hopefully speed things up */
|
/* disable a bunch of git options to hopefully speed things up */
|
||||||
git_libgit2_opts(GIT_OPT_ENABLE_CACHING, 0);
|
git_libgit2_opts(GIT_OPT_ENABLE_CACHING, 0);
|
||||||
|
|
||||||
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "");
|
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "");
|
||||||
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, "");
|
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, "");
|
||||||
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, "");
|
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, "");
|
||||||
git_libgit2_opts(GIT_OPT_SET_TEMPLATE_PATH, "");
|
git_libgit2_opts(GIT_OPT_SET_TEMPLATE_PATH, "");
|
||||||
|
|
||||||
git_libgit2_opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, 1);
|
git_libgit2_opts(GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, 1);
|
||||||
|
git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0);
|
||||||
|
|
||||||
/* initialize the git library and repository */
|
/* initialize the git library and repository */
|
||||||
if (git_libgit2_init() < 0) {
|
if (git_libgit2_init() < 0) {
|
||||||
@@ -177,9 +195,11 @@ has_untracked(git_repository *repo)
|
|||||||
git_status_list *list = NULL;
|
git_status_list *list = NULL;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
|
/* FIXME: this is really slow in large git repos :( */
|
||||||
|
opts.show = GIT_STATUS_SHOW_WORKDIR_ONLY;
|
||||||
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
|
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
|
||||||
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
|
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
|
||||||
|
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
|
||||||
|
|
||||||
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);
|
||||||
@@ -300,7 +320,7 @@ 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_staged(repo)) {
|
if (has_staged(repo)) {
|
||||||
E("They're staged changes.")
|
E("There staged changes.")
|
||||||
P("*"); /* change to broken nose for staged changes */
|
P("*"); /* change to broken nose for staged changes */
|
||||||
} else if (has_untracked(repo)) {
|
} else if (has_untracked(repo)) {
|
||||||
E("There are untracked changes in the repository.")
|
E("There are untracked changes in the repository.")
|
||||||
|
Reference in New Issue
Block a user