Implement a new caching system to make repeated runs much much faster.
This commit is contained in:
parent
4a008a82b0
commit
5e0e140b09
8 changed files with 252 additions and 44 deletions
58
XD.c
58
XD.c
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -16,42 +17,11 @@
|
|||
#include <git2.h>
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include "hash.h"
|
||||
|
||||
#define P(X) fwrite(X, 1, 1, stdout)
|
||||
|
||||
#if defined(ERR) || defined(EXPLAIN)
|
||||
void
|
||||
l(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ERR
|
||||
#define L(...) l(__VA_ARGS__)
|
||||
#else
|
||||
#define L(...)
|
||||
#endif
|
||||
|
||||
#ifdef EXPLAIN
|
||||
static int explain = 0;
|
||||
#define E(...) if (explain) { \
|
||||
l(__VA_ARGS__); \
|
||||
} else
|
||||
#else
|
||||
#define E(...)
|
||||
#endif
|
||||
|
||||
#ifdef GIT
|
||||
/**
|
||||
* @brief search all parent directories for a git repo
|
||||
|
|
@ -194,9 +164,20 @@ has_untracked(git_repository *repo)
|
|||
{
|
||||
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
|
||||
git_status_list *list = NULL;
|
||||
repohash *storedhash;
|
||||
int r = 0;
|
||||
|
||||
/* FIXME: this is really slow in large git repos :( */
|
||||
#ifdef GITHASH
|
||||
if ((storedhash = read_hash(repo))
|
||||
&& storedhash->hash == generate_hash(repo)) {
|
||||
r = storedhash->changes;
|
||||
free(storedhash);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if we need to regen the hash then we need to do a hard check on the real
|
||||
* git repository */
|
||||
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
|
||||
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
|
||||
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
|
||||
|
|
@ -209,9 +190,10 @@ has_untracked(git_repository *repo)
|
|||
}
|
||||
|
||||
/* if any changes are found return 1 */
|
||||
if (git_status_list_entrycount(list) > 0) {
|
||||
r = 1;
|
||||
}
|
||||
r = git_status_list_entrycount(list) > 0;
|
||||
#ifdef GITHASH
|
||||
write_hash(repo, (repohash){ .hash = generate_hash(repo), .changes = r });
|
||||
#endif
|
||||
|
||||
git_status_list_free(list);
|
||||
return r;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue