Exemple #1
0
END_TEST

START_TEST(test_map_clear_no_keys)
{
    bloom_hashmap *map;
    int res = hashmap_init(0, &map);
    fail_unless(res == 0);

    fail_unless(hashmap_clear(map) == 0);

    res = hashmap_destroy(map);
    fail_unless(res == 0);
}
Exemple #2
0
// Called from libc_init_dynamic() just after system properties have been initialized.
__LIBC_HIDDEN__ void pthread_debug_init() {
#if PTHREAD_DEBUG_ENABLED
    char env[PROP_VALUE_MAX];
    if (__system_property_get("debug.libc.pthread", env)) {
        int level = atoi(env);
        if (level) {
            LOGI("pthread deadlock detection level %d enabled for pid %d (%s)",
                    level, getpid(), __progname);
            hashmap_init(&sMutexMap);
            sPthreadDebugLevel = level;
        }
    }
#endif
}
Exemple #3
0
JNIEXPORT void JNICALL Java_gov_nasa_jpf_symbolic_dp_NativeInterface_initializeCVCL
  (JNIEnv *env, jclass cls)
{
  // initialize stuff
  hashmap_init(&vars, 0, hash_str, cmp_str, NULL, NULL);
  linkedlist_init(&exprPool, 0, NULL);
  
  //flags = vc_createFlags();
  //vc_setStringFlag(flags, "dump-log", "test1.cvc");
  //vc = vc_createValidityChecker(flags);
  vc = vc_createValidityChecker(NULL);
  intType = vc_intType(vc);
  realType = vc_realType(vc);
}
Exemple #4
0
/**
 * Initializes the metrics struct.
 * @arg eps The maximum error for the quantiles
 * @arg quantiles A sorted array of double quantile values, must be on (0, 1)
 * @arg num_quants The number of entries in the quantiles array
 * @arg histograms A radix tree with histogram settings. This is not owned
 * by the metrics object. It is assumed to exist for the life of the metrics.
 * @arg set_precision The precision to use for sets
 * @return 0 on success.
 */
int init_metrics(double timer_eps, double *quantiles, uint32_t num_quants, radix_tree *histograms, unsigned char set_precision, metrics *m) {
    // Copy the inputs
    m->timer_eps = timer_eps;
    m->num_quants = num_quants;
    m->quantiles = malloc(num_quants * sizeof(double));
    memcpy(m->quantiles, quantiles, num_quants * sizeof(double));
    m->histograms = histograms;
    m->set_precision = set_precision;

    // Allocate the hashmaps
    int res = hashmap_init(0, &m->counters);
    if (res) return res;
    res = hashmap_init(0, &m->timers);
    if (res) return res;
    res = hashmap_init(0, &m->sets);
    if (res) return res;
    res = hashmap_init(0, &m->gauges);
    if (res) return res;

    // Set the head of our linked list to null
    m->kv_vals = NULL;
    return 0;
}
Exemple #5
0
static void
isvn_globals_init(void)
{
	mtx_init(&g_lock);
	cond_init(&g_rev_cond);
	cond_init(&g_commitdone_cond);

	g_locks_initted = true;

	/* Override defaults (noops) w/ our edit CBs */
	assert_status_noerr(apr_pool_create(&g_apr_pool, NULL),
	    "apr_pool_create");

	hashmap_init(&g_fetchdone_hash, (hashmap_cmp_fn)fetchdone_range_cmp);
	hashmap_init(&g_commitdone_hash, (hashmap_cmp_fn)fetchdone_range_cmp);
	hashmap_init(&g_commitdrain_hash, (hashmap_cmp_fn)fetchdone_range_cmp);

	g_fetch_workers = xcalloc(g_nr_fetch_workers, sizeof(*g_fetch_workers));
	g_branch_workers = xcalloc(g_nr_commit_workers, sizeof(*g_branch_workers));

	if (option_verbosity >= 3)
		printf("Initialized with %u fetchers, %u committers.\n",
		    g_nr_fetch_workers, g_nr_commit_workers);
}
Exemple #6
0
static char* test_hashmap_keys () {
	hashmap_t hashmap;
	hashmap_init(&hashmap, sizeof(int), 64);

	int val1 = 99;
	int val2 = 100;
	hashmap_put(&hashmap, "key1", &val1);
	hashmap_put(&hashmap, "key2", &val2);

	mu_assert("key1 not stored", strcmp("key1", vector_get(hashmap.keys, 0, char*)) == 0);
	mu_assert("key2 not stored", strcmp("key2", vector_get(hashmap.keys, 1, char*)) == 0);

	hashmap_destroy(&hashmap);

	return 0;
}
Exemple #7
0
/*
 * Register the specified ref_store to be the one that should be used
 * for submodule (or the main repository if submodule is NULL). It is
 * a fatal error to call this function twice for the same submodule.
 */
static void register_ref_store(struct ref_store *refs, const char *submodule)
{
	if (!submodule) {
		if (main_ref_store)
			die("BUG: main_ref_store initialized twice");

		main_ref_store = refs;
	} else {
		if (!submodule_ref_stores.tablesize)
			hashmap_init(&submodule_ref_stores, submodule_hash_cmp, 0);

		if (hashmap_put(&submodule_ref_stores,
				alloc_submodule_hash_entry(submodule, refs)))
			die("BUG: ref_store for submodule '%s' initialized twice",
			    submodule);
	}
}
Exemple #8
0
int init_util() {
    log_info("Init id list");
    id_list = id_generator_init(MIN_RESOURCE, MAX_RESOURCE);
    if(id_list == NULL) {
        log_err("Cannot init id list!!!");
        return ERROR;
    }
      
    log_info("Init id pool");
    idp = hashmap_init();
    if(idp == NULL) {
        log_err("Cannot init hash map id pool");
        return ERROR;
    }   
    log_info("Util init done");
    return 0;
}
Exemple #9
0
END_TEST

START_TEST(test_map_delete_no_keys)
{
    hashmap *map;
    int res = hashmap_init(0, &map);
    fail_unless(res == 0);
    fail_unless(hashmap_size(map) == 0);

    char buf[100];
    for (int i=0; i<100;i++) {
        snprintf((char*)&buf, 100, "test%d", i);
        fail_unless(hashmap_delete(map, (char*)buf) == -1);
    }

    res = hashmap_destroy(map);
    fail_unless(res == 0);
}
Exemple #10
0
int main()
{
	int i;
	struct test *t;
	struct hashmap map;

	hashmap_init(&map, hash_test, cmp_test);

	for (i = 0; i < COUNT; ++i) {
		t = calloc(1, sizeof *t);
		t->i = i;
		t->j = i + 123;

		hashmap_insert(&map, &t->node, &i);
	}

	for (i = 0; i < GET_COUNT; ++i) {
		int k = rand() % COUNT;
		struct test *t;
		struct hash_node *node = hashmap_get(&map, &k);
		if (node == NULL) {
			printf("%d not found\n", k);
			assert(0);
		}
		t = container_of(node, struct test, node);
		assert (t->i == k && t->j == k + 123);
	}

	for (i = 0; i < COUNT; ++i) {
		int k = COUNT - 1 - i;
		struct hash_node *node = hashmap_remove(&map, &k);
		if (node == NULL) {
			printf("%d not found\n", k);
			assert(0);
		}
		t = container_of(node, struct test, node);;
		assert (t->i == k && t->j == k + 123);
	}

	assert(map.len == MIN_SLOTS);

	return 0;
}
Exemple #11
0
END_TEST

START_TEST(test_map_put)
{
    bloom_hashmap *map;
    int res = hashmap_init(0, &map);
    fail_unless(res == 0);
    fail_unless(hashmap_size(map) == 0);

    char buf[100];
    for (int i=0; i<100;i++) {
        snprintf((char*)&buf, 100, "test%d", i);
        fail_unless(hashmap_put(map, (char*)buf, NULL) == 1);
    }
    fail_unless(hashmap_size(map) == 100);

    res = hashmap_destroy(map);
    fail_unless(res == 0);
}
Exemple #12
0
static devicedef_t* create_devicedef(parse_context_t* context, int nb_attributes, const xmlChar** attributes) {

	const xmlChar* id = get_attribute(context, nb_attributes, attributes, ATTR_ID);
	const xmlChar* user_agent = get_attribute(context, nb_attributes, attributes, ATTR_USER_AGENT);
	const xmlChar* fallback = get_attribute(context, nb_attributes, attributes, ATTR_FALL_BACK);
	const xmlChar* actual_device_root = get_attribute(context, nb_attributes, attributes, ATTR_ACTUAL_DEVICE_ROOT);

	devicedef_t* devicedef = malloc(sizeof(devicedef_t));
	if(devicedef==NULL) {
		error(1, errno, "error allocating device");
	}
	hashmap_options_t caps_opts = {400, .75f};
	devicedef->capabilities = hashmap_init(&string_eq, &string_hash, &caps_opts);


	if(!id || xmlStrlen(id)==0) {
		error(2,0,"The device id must be != null");
	}
	else {
		devicedef->id = create_string(id, context);
	}

	if(!user_agent || xmlStrlen(user_agent)==0) {
		devicedef->user_agent = NULL;
	}
	else {
		devicedef->user_agent = create_string(user_agent, context);
	}

	if(xmlStrEqual(fallback, BAD_CAST("root")) || xmlStrlen(fallback)<=0) {
		devicedef->fall_back = NULL;
	}
	else {
		devicedef->fall_back = create_string(fallback, context);
	}
	devicedef->actual_device_root = xmlStrEqual(actual_device_root, BAD_CAST("true"));

	return devicedef;


}
Exemple #13
0
static void i18n_open(void)
{
	struct stat sb;
	struct sbuf s;
	static int has_run;

	if (!has_run) {
		hashmap_init(&map, (hashmap_cmp_fn) cmp, 0);
		has_run = 1;
	}
	BUG_ON(!translation_file);
	if (translation_file[0] == '\0')
		return;
	sbuf_init(&s);
	sbuf_cpy(&s, translation_file);
	sbuf_expand_tilde(&s);
	if (stat(s.buf, &sb) < 0)
		die("%s: stat()", __func__);
	parse_file(s.buf);
	xfree(s.buf);
}
Exemple #14
0
hashmap_t *hashmap_create_with_buckets( size_t num_buckets )
{
	hashmap_t *hashmap;

	assert( num_buckets > 0 );

	hashmap = malloc( sizeof(hashmap_t) );

	if( NULL != hashmap )
	{
		int err = hashmap_init( hashmap );

		if( 0 != err )
		{
			free( hashmap );
			hashmap = NULL;
		}
	}

	return hashmap;
}
Exemple #15
0
END_TEST

START_TEST(test_map_put_iter)
{
    bloom_hashmap *map;
    int res = hashmap_init(0, &map);
    fail_unless(res == 0);

    char buf[100];
    for (int i=0; i<100;i++) {
        snprintf((char*)&buf, 100, "test%d", i);
        fail_unless(hashmap_put(map, (char*)buf, NULL) == 1);
    }

    int val = 0;
    fail_unless(hashmap_iter(map, iter_test, (void*)&val) == 0);
    fail_unless(val == 100);

    res = hashmap_destroy(map);
    fail_unless(res == 0);
}
Exemple #16
0
static void find_exact_matches(struct string_list *a, struct string_list *b)
{
	struct hashmap map;
	int i;

	hashmap_init(&map, (hashmap_cmp_fn)patch_util_cmp, NULL, 0);

	/* First, add the patches of a to a hash map */
	for (i = 0; i < a->nr; i++) {
		struct patch_util *util = a->items[i].util;

		util->i = i;
		util->patch = a->items[i].string;
		util->diff = util->patch + util->diff_offset;
		hashmap_entry_init(util, strhash(util->diff));
		hashmap_add(&map, util);
	}

	/* Now try to find exact matches in b */
	for (i = 0; i < b->nr; i++) {
		struct patch_util *util = b->items[i].util, *other;

		util->i = i;
		util->patch = b->items[i].string;
		util->diff = util->patch + util->diff_offset;
		hashmap_entry_init(util, strhash(util->diff));
		other = hashmap_remove(&map, util, NULL);
		if (other) {
			if (other->matching >= 0)
				BUG("already assigned!");

			other->matching = i;
			util->matching = other->i;
		}
	}

	hashmap_free(&map, 0);
}
Exemple #17
0
END_TEST

START_TEST(test_map_put_grow)
{
    hashmap *map;
    int res = hashmap_init(32, &map);  // Only 32 slots
    fail_unless(res == 0);

    char buf[100];
    void *out;
    for (int i=0; i<1000;i++) {
        snprintf((char*)&buf, 100, "test%d", i);
        fail_unless(hashmap_put(map, (char*)buf, NULL) == 1);
    }

    int val = 0;
    fail_unless(hashmap_iter(map, iter_test, (void*)&val) == 0);
    fail_unless(val == 1000);
    fail_unless(hashmap_size(map) == 1000);

    res = hashmap_destroy(map);
    fail_unless(res == 0);
}
Exemple #18
0
static void clear_test( void )
{
	int res;
	hashmap_t hashmap;
	size_t size;
	unsigned int existed;

	res = hashmap_init( &hashmap );
	assert( 0 == res );

	res = hashmap_insert( &hashmap, "test", 1 );
	assert( 0 == res );

	hashmap_clear( &hashmap );

	size = hashmap_size( &hashmap );
	assert( 0 == size );
	res = hashmap_insert_existed( &hashmap, "test", 1, &existed );
	assert( 0 == res );
	assert( 0 == existed );

	hashmap_term( &hashmap );
}
int main(int argc, char **argv)
{
	hashmap_t * map;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s string\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	map = (hashmap_t *)malloc(sizeof(hashmap_t));

	hashmap_init(map);

	decode(argv[1], map);

	hashmap_iterate(map,print_hashmap);

	hashmap_delete_all(map);

	hashmap_free(map);
	free(map);

	exit(0);
}
Exemple #20
0
int
main(int argc, char *argv[])
{
	char **args;
	char *type = "jcifs";
	int verbose = 0;
	char *filename = NULL, *outname = NULL;
	char symtabpath[PATH_MAX + 1], *sp;
	struct hashmap macros;

	if (argc < 2) {
usage:
		fprintf(stderr, "usage: %s [-v|-d] [-s <symtab>] [-t jcifs|java|samba|c] [-o outfile] [-Dmacro=defn] <filename>\n", argv[0]);
		return EXIT_FAILURE;
	}

	errno = 0;

	if (hashmap_init(&macros, 0, hash_text, cmp_text, NULL, NULL) == -1) {
		MMSG("");
		return EXIT_FAILURE;
	}

	args = argv;
	args++; argc--;

	sp = symtabpath;
#ifdef _DATADIR
	sp += sprintf(sp, "%s%c", _DATADIR, SEP);
#endif
	sprintf(sp, "symtab%s.txt", type);

	while (argc) {
		if (strcmp(*args, "-v") == 0) {
			verbose++;
		} else if (strcmp(*args, "-d") == 0) {
			verbose += 2;
		} else if (strcmp(*args, "-s") == 0) {
			args++; argc--;
			if (!argc) {
				MMSG("-s requires a symtab path");
				goto usage;
			}
			strncpy(symtabpath, *args, PATH_MAX);
		} else if (strcmp(*args, "-t") == 0) {
			args++; argc--;
			if (!argc) {
				MMSG("-t requires a type");
				goto usage;
			}

			sp = symtabpath;
#ifdef _DATADIR
			sp += sprintf(sp, "%s%c", _DATADIR, SEP);
#endif
			type = *args;
			sprintf(sp, "symtab%s.txt", type);
		} else if (strncmp(*args, "-D", 2) == 0) {
			char *p, *macro, *defn = NULL;

			p = macro = (*args) + 2;

			for ( ;; p++) {
				if (*p == '\0') {
					if (p == macro) {
						macro = NULL;
					} else if (defn == NULL) {
						defn = "1";
					}
					break;
				} else if (defn == NULL && isspace(*p)) {
					MMSG("invalid macro: %s", *args);
					goto usage;
				} else if (*p == '=') {
					if (p == macro) {
						MMSG("invalid macro: %s", *args);
						goto usage;
					}
					*p = '\0';
					defn = p + 1;
				}
			}
			if (macro && hashmap_put(&macros, macro, defn) == -1) {
				MMSG("");
				return EXIT_FAILURE;
			}
		} else if (strcmp(*args, "-o") == 0) {
			args++; argc--;
			if (!argc) {
				MMSG("-o requires a filename");
				goto usage;
			}
			outname = *args;
		} else if (filename || **args == '-') {
			MMSG("Invalid argument: %s", *args);
			goto usage;
		} else {
			filename = *args;
		}
		args++; argc--;
	}
	if (!filename) {
		MMSG("A filename must be specified");
		goto usage;
	}

	if (run(argc, argv, filename, outname, type, symtabpath, &macros, verbose) == -1) {
		MMSG("");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Exemple #21
0
static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
			int argc, const char **argv)
{
	char tmpdir[PATH_MAX];
	struct strbuf info = STRBUF_INIT, lpath = STRBUF_INIT;
	struct strbuf rpath = STRBUF_INIT, buf = STRBUF_INIT;
	struct strbuf ldir = STRBUF_INIT, rdir = STRBUF_INIT;
	struct strbuf wtdir = STRBUF_INIT;
	char *lbase_dir, *rbase_dir;
	size_t ldir_len, rdir_len, wtdir_len;
	const char *workdir, *tmp;
	int ret = 0, i;
	FILE *fp;
	struct hashmap working_tree_dups, submodules, symlinks2;
	struct hashmap_iter iter;
	struct pair_entry *entry;
	struct index_state wtindex;
	struct checkout lstate, rstate;
	int rc, flags = RUN_GIT_CMD, err = 0;
	struct child_process child = CHILD_PROCESS_INIT;
	const char *helper_argv[] = { "difftool--helper", NULL, NULL, NULL };
	struct hashmap wt_modified, tmp_modified;
	int indices_loaded = 0;

	workdir = get_git_work_tree();

	/* Setup temp directories */
	tmp = getenv("TMPDIR");
	xsnprintf(tmpdir, sizeof(tmpdir), "%s/git-difftool.XXXXXX", tmp ? tmp : "/tmp");
	if (!mkdtemp(tmpdir))
		return error("could not create '%s'", tmpdir);
	strbuf_addf(&ldir, "%s/left/", tmpdir);
	strbuf_addf(&rdir, "%s/right/", tmpdir);
	strbuf_addstr(&wtdir, workdir);
	if (!wtdir.len || !is_dir_sep(wtdir.buf[wtdir.len - 1]))
		strbuf_addch(&wtdir, '/');
	mkdir(ldir.buf, 0700);
	mkdir(rdir.buf, 0700);

	memset(&wtindex, 0, sizeof(wtindex));

	memset(&lstate, 0, sizeof(lstate));
	lstate.base_dir = lbase_dir = xstrdup(ldir.buf);
	lstate.base_dir_len = ldir.len;
	lstate.force = 1;
	memset(&rstate, 0, sizeof(rstate));
	rstate.base_dir = rbase_dir = xstrdup(rdir.buf);
	rstate.base_dir_len = rdir.len;
	rstate.force = 1;

	ldir_len = ldir.len;
	rdir_len = rdir.len;
	wtdir_len = wtdir.len;

	hashmap_init(&working_tree_dups,
		     (hashmap_cmp_fn)working_tree_entry_cmp, NULL, 0);
	hashmap_init(&submodules, (hashmap_cmp_fn)pair_cmp, NULL, 0);
	hashmap_init(&symlinks2, (hashmap_cmp_fn)pair_cmp, NULL, 0);

	child.no_stdin = 1;
	child.git_cmd = 1;
	child.use_shell = 0;
	child.clean_on_exit = 1;
	child.dir = prefix;
	child.out = -1;
	argv_array_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
			 NULL);
	for (i = 0; i < argc; i++)
		argv_array_push(&child.args, argv[i]);
	if (start_command(&child))
		die("could not obtain raw diff");
	fp = xfdopen(child.out, "r");

	/* Build index info for left and right sides of the diff */
	i = 0;
	while (!strbuf_getline_nul(&info, fp)) {
		int lmode, rmode;
		struct object_id loid, roid;
		char status;
		const char *src_path, *dst_path;

		if (starts_with(info.buf, "::"))
			die(N_("combined diff formats('-c' and '--cc') are "
			       "not supported in\n"
			       "directory diff mode('-d' and '--dir-diff')."));

		if (parse_index_info(info.buf, &lmode, &rmode, &loid, &roid,
				     &status))
			break;
		if (strbuf_getline_nul(&lpath, fp))
			break;
		src_path = lpath.buf;

		i++;
		if (status != 'C' && status != 'R') {
			dst_path = src_path;
		} else {
			if (strbuf_getline_nul(&rpath, fp))
				break;
			dst_path = rpath.buf;
		}

		if (S_ISGITLINK(lmode) || S_ISGITLINK(rmode)) {
			strbuf_reset(&buf);
			strbuf_addf(&buf, "Subproject commit %s",
				    oid_to_hex(&loid));
			add_left_or_right(&submodules, src_path, buf.buf, 0);
			strbuf_reset(&buf);
			strbuf_addf(&buf, "Subproject commit %s",
				    oid_to_hex(&roid));
			if (!oidcmp(&loid, &roid))
				strbuf_addstr(&buf, "-dirty");
			add_left_or_right(&submodules, dst_path, buf.buf, 1);
			continue;
		}

		if (S_ISLNK(lmode)) {
			char *content = get_symlink(&loid, src_path);
			add_left_or_right(&symlinks2, src_path, content, 0);
			free(content);
		}

		if (S_ISLNK(rmode)) {
			char *content = get_symlink(&roid, dst_path);
			add_left_or_right(&symlinks2, dst_path, content, 1);
			free(content);
		}

		if (lmode && status != 'C') {
			if (checkout_path(lmode, &loid, src_path, &lstate)) {
				ret = error("could not write '%s'", src_path);
				goto finish;
			}
		}

		if (rmode && !S_ISLNK(rmode)) {
			struct working_tree_entry *entry;

			/* Avoid duplicate working_tree entries */
			FLEX_ALLOC_STR(entry, path, dst_path);
			hashmap_entry_init(entry, strhash(dst_path));
			if (hashmap_get(&working_tree_dups, entry, NULL)) {
				free(entry);
				continue;
			}
			hashmap_add(&working_tree_dups, entry);

			if (!use_wt_file(workdir, dst_path, &roid)) {
				if (checkout_path(rmode, &roid, dst_path,
						  &rstate)) {
					ret = error("could not write '%s'",
						    dst_path);
					goto finish;
				}
			} else if (!is_null_oid(&roid)) {
				/*
				 * Changes in the working tree need special
				 * treatment since they are not part of the
				 * index.
				 */
				struct cache_entry *ce2 =
					make_cache_entry(rmode, roid.hash,
							 dst_path, 0, 0);

				add_index_entry(&wtindex, ce2,
						ADD_CACHE_JUST_APPEND);

				add_path(&rdir, rdir_len, dst_path);
				if (ensure_leading_directories(rdir.buf)) {
					ret = error("could not create "
						    "directory for '%s'",
						    dst_path);
					goto finish;
				}
				add_path(&wtdir, wtdir_len, dst_path);
				if (symlinks) {
					if (symlink(wtdir.buf, rdir.buf)) {
						ret = error_errno("could not symlink '%s' to '%s'", wtdir.buf, rdir.buf);
						goto finish;
					}
				} else {
					struct stat st;
					if (stat(wtdir.buf, &st))
						st.st_mode = 0644;
					if (copy_file(rdir.buf, wtdir.buf,
						      st.st_mode)) {
						ret = error("could not copy '%s' to '%s'", wtdir.buf, rdir.buf);
						goto finish;
					}
				}
			}
		}
	}

	fclose(fp);
	fp = NULL;
	if (finish_command(&child)) {
		ret = error("error occurred running diff --raw");
		goto finish;
	}

	if (!i)
		goto finish;

	/*
	 * Changes to submodules require special treatment.This loop writes a
	 * temporary file to both the left and right directories to show the
	 * change in the recorded SHA1 for the submodule.
	 */
	hashmap_iter_init(&submodules, &iter);
	while ((entry = hashmap_iter_next(&iter))) {
		if (*entry->left) {
			add_path(&ldir, ldir_len, entry->path);
			ensure_leading_directories(ldir.buf);
			write_file(ldir.buf, "%s", entry->left);
		}
		if (*entry->right) {
			add_path(&rdir, rdir_len, entry->path);
			ensure_leading_directories(rdir.buf);
			write_file(rdir.buf, "%s", entry->right);
		}
	}

	/*
	 * Symbolic links require special treatment.The standard "git diff"
	 * shows only the link itself, not the contents of the link target.
	 * This loop replicates that behavior.
	 */
	hashmap_iter_init(&symlinks2, &iter);
	while ((entry = hashmap_iter_next(&iter))) {
		if (*entry->left) {
			add_path(&ldir, ldir_len, entry->path);
			ensure_leading_directories(ldir.buf);
			write_file(ldir.buf, "%s", entry->left);
		}
		if (*entry->right) {
			add_path(&rdir, rdir_len, entry->path);
			ensure_leading_directories(rdir.buf);
			write_file(rdir.buf, "%s", entry->right);
		}
	}

	strbuf_release(&buf);

	strbuf_setlen(&ldir, ldir_len);
	helper_argv[1] = ldir.buf;
	strbuf_setlen(&rdir, rdir_len);
	helper_argv[2] = rdir.buf;

	if (extcmd) {
		helper_argv[0] = extcmd;
		flags = 0;
	} else
		setenv("GIT_DIFFTOOL_DIRDIFF", "true", 1);
	rc = run_command_v_opt(helper_argv, flags);

	/*
	 * If the diff includes working copy files and those
	 * files were modified during the diff, then the changes
	 * should be copied back to the working tree.
	 * Do not copy back files when symlinks are used and the
	 * external tool did not replace the original link with a file.
	 *
	 * These hashes are loaded lazily since they aren't needed
	 * in the common case of --symlinks and the difftool updating
	 * files through the symlink.
	 */
	hashmap_init(&wt_modified, (hashmap_cmp_fn)path_entry_cmp,
		     NULL, wtindex.cache_nr);
	hashmap_init(&tmp_modified, (hashmap_cmp_fn)path_entry_cmp,
		     NULL, wtindex.cache_nr);

	for (i = 0; i < wtindex.cache_nr; i++) {
		struct hashmap_entry dummy;
		const char *name = wtindex.cache[i]->name;
		struct stat st;

		add_path(&rdir, rdir_len, name);
		if (lstat(rdir.buf, &st))
			continue;

		if ((symlinks && S_ISLNK(st.st_mode)) || !S_ISREG(st.st_mode))
			continue;

		if (!indices_loaded) {
			static struct lock_file lock;
			strbuf_reset(&buf);
			strbuf_addf(&buf, "%s/wtindex", tmpdir);
			if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 ||
			    write_locked_index(&wtindex, &lock, COMMIT_LOCK)) {
				ret = error("could not write %s", buf.buf);
				rollback_lock_file(&lock);
				goto finish;
			}
			changed_files(&wt_modified, buf.buf, workdir);
			strbuf_setlen(&rdir, rdir_len);
			changed_files(&tmp_modified, buf.buf, rdir.buf);
			add_path(&rdir, rdir_len, name);
			indices_loaded = 1;
		}

		hashmap_entry_init(&dummy, strhash(name));
		if (hashmap_get(&tmp_modified, &dummy, name)) {
			add_path(&wtdir, wtdir_len, name);
			if (hashmap_get(&wt_modified, &dummy, name)) {
				warning(_("both files modified: '%s' and '%s'."),
					wtdir.buf, rdir.buf);
				warning(_("working tree file has been left."));
				warning("%s", "");
				err = 1;
			} else if (unlink(wtdir.buf) ||
				   copy_file(wtdir.buf, rdir.buf, st.st_mode))
				warning_errno(_("could not copy '%s' to '%s'"),
					      rdir.buf, wtdir.buf);
		}
	}

	if (err) {
		warning(_("temporary files exist in '%s'."), tmpdir);
		warning(_("you may want to cleanup or recover these."));
		exit(1);
	} else
		exit_cleanup(tmpdir, rc);

finish:
	if (fp)
		fclose(fp);

	free(lbase_dir);
	free(rbase_dir);
	strbuf_release(&ldir);
	strbuf_release(&rdir);
	strbuf_release(&wtdir);
	strbuf_release(&buf);

	return ret;
}
Exemple #22
0
/* Initialize an 'attr_hashmap' object */
static void attr_hashmap_init(struct attr_hashmap *map)
{
	hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, 0);
}
Exemple #23
0
/* Initialize an 'attr_hashmap' object */
static void attr_hashmap_init(struct attr_hashmap *map)
{
	hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
}
Exemple #24
0
static void submodule_cache_init(struct submodule_cache *cache)
{
	hashmap_init(&cache->for_path, config_path_cmp, NULL, 0);
	hashmap_init(&cache->for_name, config_name_cmp, NULL, 0);
	cache->initialized = 1;
}
Exemple #25
0
/*
 * Clears the cache.
 */
static void fscache_clear(void)
{
	hashmap_free(&map, 1);
	hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
}
Exemple #26
0
int cmd_describe(int argc, const char **argv, const char *prefix)
{
	int contains = 0;
	struct option options[] = {
		OPT_BOOL(0, "contains",   &contains, N_("find the tag that comes after the commit")),
		OPT_BOOL(0, "debug",      &debug, N_("debug search strategy on stderr")),
		OPT_BOOL(0, "all",        &all, N_("use any ref")),
		OPT_BOOL(0, "tags",       &tags, N_("use any tag, even unannotated")),
		OPT_BOOL(0, "long",       &longformat, N_("always use long format")),
		OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
		OPT__ABBREV(&abbrev),
		OPT_SET_INT(0, "exact-match", &max_candidates,
			    N_("only output exact matches"), 0),
		OPT_INTEGER(0, "candidates", &max_candidates,
			    N_("consider <n> most recent tags (default: 10)")),
		OPT_STRING(0, "match",       &pattern, N_("pattern"),
			   N_("only consider tags matching <pattern>")),
		OPT_BOOL(0, "always",        &always,
			N_("show abbreviated commit object as fallback")),
		{OPTION_STRING, 0, "dirty",  &dirty, N_("mark"),
			N_("append <mark> on dirty working tree (default: \"-dirty\")"),
			PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
		OPT_END(),
	};

	git_config(git_default_config, NULL);
	argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
	if (abbrev < 0)
		abbrev = DEFAULT_ABBREV;

	if (max_candidates < 0)
		max_candidates = 0;
	else if (max_candidates > MAX_TAGS)
		max_candidates = MAX_TAGS;

	save_commit_buffer = 0;

	if (longformat && abbrev == 0)
		die(_("--long is incompatible with --abbrev=0"));

	if (contains) {
		struct argv_array args;

		argv_array_init(&args);
		argv_array_pushl(&args, "name-rev",
				 "--peel-tag", "--name-only", "--no-undefined",
				 NULL);
		if (always)
			argv_array_push(&args, "--always");
		if (!all) {
			argv_array_push(&args, "--tags");
			if (pattern)
				argv_array_pushf(&args, "--refs=refs/tags/%s", pattern);
		}
		if (argc)
			argv_array_pushv(&args, argv);
		else
			argv_array_push(&args, "HEAD");
		return cmd_name_rev(args.argc, args.argv, prefix);
	}

	hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);
	for_each_rawref(get_name, NULL);
	if (!names.size && !always)
		die(_("No names found, cannot describe anything."));

	if (argc == 0) {
		if (dirty) {
			static struct lock_file index_lock;
			int fd;

			read_cache_preload(NULL);
			refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
				      NULL, NULL, NULL);
			fd = hold_locked_index(&index_lock, 0);
			if (0 <= fd)
				update_index_if_able(&the_index, &index_lock);

			if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
					    diff_index_args, prefix))
				dirty = NULL;
		}
		describe("HEAD", 1);
	} else if (dirty) {
		die(_("--dirty is incompatible with commit-ishes"));
	} else {
		while (argc-- > 0)
			describe(*argv++, argc == 0);
	}
	return 0;
}
Exemple #27
0
/*
 * Read stdin line by line and print result of commands to stdout:
 *
 * hash key -> strhash(key) memhash(key) strihash(key) memihash(key)
 * put key value -> NULL / old value
 * get key -> NULL / value
 * remove key -> NULL / old value
 * iterate -> key1 value1\nkey2 value2\n...
 * size -> tablesize numentries
 *
 * perfhashmap method rounds -> test hashmap.[ch] performance
 */
int main(int argc, char *argv[])
{
	char line[1024];
	struct hashmap map;
	int icase;

	/* init hash map */
	icase = argc > 1 && !strcmp("ignorecase", argv[1]);
	hashmap_init(&map, (hashmap_cmp_fn) (icase ? test_entry_cmp_icase
			: test_entry_cmp), 0);

	/* process commands from stdin */
	while (fgets(line, sizeof(line), stdin)) {
		char *cmd, *p1 = NULL, *p2 = NULL;
		int l1 = 0, l2 = 0, hash = 0;
		struct test_entry *entry;

		/* break line into command and up to two parameters */
		cmd = strtok(line, DELIM);
		/* ignore empty lines */
		if (!cmd || *cmd == '#')
			continue;

		p1 = strtok(NULL, DELIM);
		if (p1) {
			l1 = strlen(p1);
			hash = icase ? strihash(p1) : strhash(p1);
			p2 = strtok(NULL, DELIM);
			if (p2)
				l2 = strlen(p2);
		}

		if (!strcmp("hash", cmd) && l1) {

			/* print results of different hash functions */
			printf("%u %u %u %u\n", strhash(p1), memhash(p1, l1),
					strihash(p1), memihash(p1, l1));

		} else if (!strcmp("add", cmd) && l1 && l2) {

			/* create entry with key = p1, value = p2 */
			entry = alloc_test_entry(hash, p1, l1, p2, l2);

			/* add to hashmap */
			hashmap_add(&map, entry);

		} else if (!strcmp("put", cmd) && l1 && l2) {

			/* create entry with key = p1, value = p2 */
			entry = alloc_test_entry(hash, p1, l1, p2, l2);

			/* add / replace entry */
			entry = hashmap_put(&map, entry);

			/* print and free replaced entry, if any */
			puts(entry ? get_value(entry) : "NULL");
			free(entry);

		} else if (!strcmp("get", cmd) && l1) {

			/* lookup entry in hashmap */
			entry = hashmap_get_from_hash(&map, hash, p1);

			/* print result */
			if (!entry)
				puts("NULL");
			while (entry) {
				puts(get_value(entry));
				entry = hashmap_get_next(&map, entry);
			}

		} else if (!strcmp("remove", cmd) && l1) {

			/* setup static key */
			struct hashmap_entry key;
			hashmap_entry_init(&key, hash);

			/* remove entry from hashmap */
			entry = hashmap_remove(&map, &key, p1);

			/* print result and free entry*/
			puts(entry ? get_value(entry) : "NULL");
			free(entry);

		} else if (!strcmp("iterate", cmd)) {

			struct hashmap_iter iter;
			hashmap_iter_init(&map, &iter);
			while ((entry = hashmap_iter_next(&iter)))
				printf("%s %s\n", entry->key, get_value(entry));

		} else if (!strcmp("size", cmd)) {

			/* print table sizes */
			printf("%u %u\n", map.tablesize, map.size);

		} else if (!strcmp("intern", cmd) && l1) {

			/* test that strintern works */
			const char *i1 = strintern(p1);
			const char *i2 = strintern(p1);
			if (strcmp(i1, p1))
				printf("strintern(%s) returns %s\n", p1, i1);
			else if (i1 == p1)
				printf("strintern(%s) returns input pointer\n", p1);
			else if (i1 != i2)
				printf("strintern(%s) != strintern(%s)", i1, i2);
			else
				printf("%s\n", i1);

		} else if (!strcmp("perfhashmap", cmd) && l1 && l2) {

			perf_hashmap(atoi(p1), atoi(p2));

		} else {

			printf("Unknown command %s\n", cmd);

		}
	}

	hashmap_free(&map, 1);
	return 0;
}
Exemple #28
0
int main(int argc, char** argv)
{
  if(argc < 2)
    throwRuntimeException( "must specify the file name that contains the query" );

  printf( "argc: %d\n", argc);

  printf("%s\n",argv[1]);


  // initialize stuff
  hashmap_init(&vars, 0, hash_str, cmp_str, NULL, NULL);
  linkedlist_init(&exprPool, 0, NULL);
  
  //flags = vc_createFlags();
  //vc_setStringFlag(flags, "dump-log", "test1.cvc");
  //vc = vc_createValidityChecker(flags);
  vc = vc_createValidityChecker(NULL);
  intType = vc_intType(vc);
  realType = vc_realType(vc);

  constraint = (char*) malloc(sizeof(char)*10000);

  int k = 0;
  FILE* fpt = fopen(argv[1],"r");

  while(1){
    char c = fgetc(fpt);
    if (c == EOF) break;
    constraint[k++]=c;
  }
  constraint[k]='\0';


  if (constraint[0] == '\0')
    return TRUE;

  vc_push(vc);
  marker = 0;
  int constraintCount = 1;
  char c;
  int i = 0;
  do{
    c = constraint[i++];
    if (c == ',')
      constraintCount++;
  }while(c != '\0');
  
  Expr* constraintArray = (Expr*) malloc(sizeof(Expr)*constraintCount);
  i = 0;
  char token[2]; // it must be just a comma and '\0'
  do{
    constraintArray[i++] = parse();
  }while(readToken(token));

  Expr andExpr = vc_andExprN(vc, constraintArray, constraintCount);
  linkedlist_add(&exprPool, andExpr);

  jboolean result = check(vc, andExpr);

  //clean up
  free(constraintArray);
  freeStuff();
  vc_pop(vc);

  if(result)
    printf("satisfiable");
  else
    printf("unsatisfiable");

  return EXIT_SUCCESS;
}
Exemple #29
0
static void cache_init(struct submodule_cache *cache)
{
	hashmap_init(&cache->for_path, (hashmap_cmp_fn) config_path_cmp, 0);
	hashmap_init(&cache->for_name, (hashmap_cmp_fn) config_name_cmp, 0);
}
Exemple #30
0
void oidmap_init(struct oidmap *map, size_t initial_size)
{
	hashmap_init(&map->map, cmpfn, NULL, initial_size);
}