mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 01:58:32 +00:00
Add some funny options for debugging status
This allows you to use a --repeat option to run status over and over and see how the output changes as you make local directory changes without reopening the git_repository object each time. Also, adds a flag to explicitly list the submodules before status.
This commit is contained in:
parent
e402d2f134
commit
d543d59cf0
@ -13,6 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This example demonstrates the use of the libgit2 status APIs,
|
* This example demonstrates the use of the libgit2 status APIs,
|
||||||
@ -44,19 +45,22 @@ enum {
|
|||||||
#define MAX_PATHSPEC 8
|
#define MAX_PATHSPEC 8
|
||||||
|
|
||||||
struct opts {
|
struct opts {
|
||||||
git_status_options statusopt;
|
git_status_options statusopt;
|
||||||
char *repodir;
|
char *repodir;
|
||||||
char *pathspec[MAX_PATHSPEC];
|
char *pathspec[MAX_PATHSPEC];
|
||||||
int npaths;
|
int npaths;
|
||||||
int format;
|
int format;
|
||||||
int zterm;
|
int zterm;
|
||||||
int showbranch;
|
int showbranch;
|
||||||
|
int showsubmod;
|
||||||
|
int repeat;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void parse_opts(struct opts *o, int argc, char *argv[]);
|
static void parse_opts(struct opts *o, int argc, char *argv[]);
|
||||||
static void show_branch(git_repository *repo, int format);
|
static void show_branch(git_repository *repo, int format);
|
||||||
static void print_long(git_status_list *status);
|
static void print_long(git_status_list *status);
|
||||||
static void print_short(git_repository *repo, git_status_list *status);
|
static void print_short(git_repository *repo, git_status_list *status);
|
||||||
|
static int print_submod(git_submodule *sm, const char *name, void *payload);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -84,6 +88,10 @@ int main(int argc, char *argv[])
|
|||||||
fatal("Cannot report status on bare repository",
|
fatal("Cannot report status on bare repository",
|
||||||
git_repository_path(repo));
|
git_repository_path(repo));
|
||||||
|
|
||||||
|
show_status:
|
||||||
|
if (o.repeat)
|
||||||
|
printf("\033[H\033[2J");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run status on the repository
|
* Run status on the repository
|
||||||
*
|
*
|
||||||
@ -98,17 +106,29 @@ int main(int argc, char *argv[])
|
|||||||
* about what results are presented.
|
* about what results are presented.
|
||||||
*/
|
*/
|
||||||
check_lg2(git_status_list_new(&status, repo, &o.statusopt),
|
check_lg2(git_status_list_new(&status, repo, &o.statusopt),
|
||||||
"Could not get status", NULL);
|
"Could not get status", NULL);
|
||||||
|
|
||||||
if (o.showbranch)
|
if (o.showbranch)
|
||||||
show_branch(repo, o.format);
|
show_branch(repo, o.format);
|
||||||
|
|
||||||
|
if (o.showsubmod) {
|
||||||
|
int submod_count = 0;
|
||||||
|
check_lg2(git_submodule_foreach(repo, print_submod, &submod_count),
|
||||||
|
"Cannot iterate submodules", o.repodir);
|
||||||
|
}
|
||||||
|
|
||||||
if (o.format == FORMAT_LONG)
|
if (o.format == FORMAT_LONG)
|
||||||
print_long(status);
|
print_long(status);
|
||||||
else
|
else
|
||||||
print_short(repo, status);
|
print_short(repo, status);
|
||||||
|
|
||||||
git_status_list_free(status);
|
git_status_list_free(status);
|
||||||
|
|
||||||
|
if (o.repeat) {
|
||||||
|
sleep(o.repeat);
|
||||||
|
goto show_status;
|
||||||
|
}
|
||||||
|
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
git_threads_shutdown();
|
git_threads_shutdown();
|
||||||
|
|
||||||
@ -381,7 +401,7 @@ static void print_short(git_repository *repo, git_status_list *status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now that we have all the information, it's time to format the output.
|
* Now that we have all the information, format the output.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (s->head_to_index) {
|
if (s->head_to_index) {
|
||||||
@ -417,6 +437,21 @@ static void print_short(git_repository *repo, git_status_list *status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int print_submod(git_submodule *sm, const char *name, void *payload)
|
||||||
|
{
|
||||||
|
int *count = payload;
|
||||||
|
(void)name;
|
||||||
|
|
||||||
|
if (*count == 0)
|
||||||
|
printf("# Submodules\n");
|
||||||
|
(*count)++;
|
||||||
|
|
||||||
|
printf("# - submodule '%s' at %s\n",
|
||||||
|
git_submodule_name(sm), git_submodule_path(sm));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse options that git's status command supports.
|
* Parse options that git's status command supports.
|
||||||
*/
|
*/
|
||||||
@ -462,6 +497,12 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
|
|||||||
o->statusopt.flags |= GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
|
o->statusopt.flags |= GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
|
||||||
else if (!strncmp(a, "--git-dir=", strlen("--git-dir=")))
|
else if (!strncmp(a, "--git-dir=", strlen("--git-dir=")))
|
||||||
o->repodir = a + strlen("--git-dir=");
|
o->repodir = a + strlen("--git-dir=");
|
||||||
|
else if (!strcmp(a, "--repeat"))
|
||||||
|
o->repeat = 10;
|
||||||
|
else if (match_int_arg(&o->repeat, &args, "--repeat", 0))
|
||||||
|
/* okay */;
|
||||||
|
else if (!strcmp(a, "--list-submodules"))
|
||||||
|
o->showsubmod = 1;
|
||||||
else
|
else
|
||||||
check_lg2(-1, "Unsupported option", a);
|
check_lg2(-1, "Unsupported option", a);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user