summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c117
1 files changed, 110 insertions, 7 deletions
diff --git a/src/commit.c b/src/commit.c
index 534757c..84e088f 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -15,6 +15,23 @@
#include "cli_parse.h"
#include "cli_path_utils.h"
+struct DirIndex {
+ int dirname_index;
+ int dirname_ct;
+ struct DirSort** dirname;
+};
+
+struct DirSort {
+ char name[255];
+ unsigned long priority;
+};
+
+/*
+static int g_dirname_index = 0;
+static int g_dirname_ct = 0;
+static struct DirSort** g_dirname = NULL;
+*/
+
static char def_name[] = DEF_NAME;
static char tag_name[] = TAG_NAME;
static char opaque_name[] = OPQ_NAME;
@@ -52,17 +69,92 @@ static void make_dir()
return;
}
#endif
+/*
+static int
+compare_dirname(const void *p, const void *q)
+{
+ const struct DirSort *a = (const struct DirSort*)*(struct Dirsort **)p;
+ const struct DirSort *b = (const struct DirSort*)*(struct Dirsort **)q;
+ if (a->priority == b->priority) {
+ return strcmp(a->name,b->name);
+ }
+ return ((long)b->priority - (long)a->priority);
+}
-static struct dirent *
-get_next_filtered_dirent(DIR *dp, int exclude_wh)
+void
+init_next_filtered_dirname(DIR *dp, struct DirIndex *di, int exclude_wh)
{
- struct dirent *dirp = NULL;
+ // fprintf(out_stream,"\n");
+ di->dirname = malloc(1024 * sizeof(char*));
+ di->dirname_ct = 0;
+ di->dirname_index = 0;
+
+ int i;
+
+ //NOTE: need to free ct round up to next 1024 when shutting down commit
+
+ struct dirent *dirp;
while ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0
|| strcmp(dirp->d_name, MOD_NAME) == 0
|| strcmp(dirp->d_name, opaque_name) == 0
|| (exclude_wh && strncmp(dirp->d_name, ".wh.", 4) == 0)) {
continue;
+ }
+ else {
+ struct DirSort *d = malloc(sizeof(struct DirSort));
+ if (strlen(dirp->d_name) >= 255) {
+ bye("configuration value exceeds 255 chars\n");
+ }
+ strcpy(d->name,dirp->d_name);
+ d->priority = (unsigned long)0;
+
+ //retreive priority now
+ vtw_def def;
+ char *path;
+ path = malloc(strlen(t_path.path)+strlen(dirp->d_name)+2+8);
+ sprintf(path,"%s/%s/node.def",t_path.path,dirp->d_name);
+ struct stat s;
+ if ((lstat(path,&s) >= 0) &&
+ ((s.st_mode & S_IFMT) == S_IFREG)) {
+ memset(&def, 0, sizeof(def));
+ if (parse_def(&def,path,FALSE) == 0) {
+ // fprintf(out_stream, "found(D): %s:%d\n",dirp->d_name, def.def_priority);
+ d->priority = def.def_priority;
+ }
+ }
+ free(path);
+
+ di->dirname[di->dirname_ct++] = d;
+ if (di->dirname_ct % 1024 == 0) {
+ di->dirname = realloc(di->dirname, (di->dirname_ct+1024)*sizeof(char*));
+ }
+ }
+ }
+ qsort(di->dirname, di->dirname_ct, sizeof(char*), compare_dirname);
+}
+
+static char*
+get_next_filtered_dirname(struct DirIndex *di)
+{
+ if (di->dirname_index == di->dirname_ct) {
+ return NULL;
+ }
+ //just return the collection ptr;
+ // fprintf(out_stream, "get_next: %s\n", di->dirname[di->dirname_index]->name);
+ return di->dirname[di->dirname_index++]->name;
+}
+*/
+static struct dirent *
+get_next_filtered_dirent(DIR *dp, int exclude_wh)
+{
+ struct dirent *dirp = NULL;
+ while ((dirp = readdir(dp)) != NULL) {
+ if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0
+ || strcmp(dirp->d_name, MOD_NAME) == 0
+ || strcmp(dirp->d_name, opaque_name) == 0
+ || (exclude_wh && strncmp(dirp->d_name, ".wh.", 4) == 0)) {
+ continue;
} else {
return dirp;
}
@@ -89,6 +181,7 @@ static boolean validate_dir_for_commit()
int subdirs_number=0;
DIR *dp=NULL;
struct dirent *dirp=NULL;
+ char *dirname = NULL;
char *cp=NULL;
boolean ret=TRUE;
char *uename = NULL;
@@ -130,8 +223,12 @@ static boolean validate_dir_for_commit()
if (def_present && def.tag) {
push_path(&t_path, tag_name); /* PUSH 2a */
}
-
- while ((dirp = get_next_filtered_dirent(dp, 1)) != NULL) {
+ /*
+ struct DirIndex *di = malloc(sizeof(struct DirIndex));
+ init_next_filtered_dirname(dp,di,1);
+ while ((dirname = get_next_filtered_dirname(di)) != NULL) {
+ */
+ while ((dirp = get_next_filtered_dirent(dp,1)) != NULL) {
subdirs_number++;
if(uename)
@@ -962,11 +1059,17 @@ static void
get_filtered_directory_listing(DIR *dp, valstruct *mvals, vtw_type_e type,
int exclude_wh)
{
- struct dirent *dirp = NULL;
+ char *dname = NULL;
char *cp = NULL;
+ struct dirent *dirp = NULL;
memset(mvals, 0, sizeof (valstruct));
- while ((dirp = get_next_filtered_dirent(dp, exclude_wh)) != NULL) {
+ /*
+ struct DirIndex *di = malloc(sizeof(struct DirIndex));
+ init_next_filtered_dirname(dp,di,exclude_wh);
+ while ((dname = get_next_filtered_dirname(di)) != NULL) {
+ */
+ while ((dirp = get_next_filtered_dirent(dp,exclude_wh)) != NULL) {
cp = clind_unescape(dirp->d_name);
valstruct_append(mvals, cp, type);
}