Merge branch 'kb/fast-hashmap'

Improvements to our hash table to get it to meet the needs of the
msysgit fscache project, with some nice performance improvements.

* kb/fast-hashmap:
  name-hash: retire unused index_name_exists()
  hashmap.h: use 'unsigned int' for hash-codes everywhere
  test-hashmap.c: drop unnecessary #includes
  .gitignore: test-hashmap is a generated file
  read-cache.c: fix memory leaks caused by removed cache entries
  builtin/update-index.c: cleanup update_one
  fix 'git update-index --verbose --again' output
  remove old hash.[ch] implementation
  name-hash.c: remove cache entries instead of marking them CE_UNHASHED
  name-hash.c: use new hash map implementation for cache entries
  name-hash.c: remove unreferenced directory entries
  name-hash.c: use new hash map implementation for directories
  diffcore-rename.c: use new hash map implementation
  diffcore-rename.c: simplify finding exact renames
  diffcore-rename.c: move code around to prepare for the next patch
  buitin/describe.c: use new hash map implementation
  add a hashtable implementation that supports O(1) removal
  submodule: don't access the .gitmodules cache entry after removing it
This commit is contained in:
Junio C Hamano
2014-02-27 14:01:09 -08:00
20 changed files with 1218 additions and 540 deletions

View File

@ -6,7 +6,7 @@
#include "exec_cmd.h"
#include "parse-options.h"
#include "diff.h"
#include "hash.h"
#include "hashmap.h"
#include "argv-array.h"
#define SEEN (1u << 0)
@ -25,7 +25,7 @@ static int longformat;
static int first_parent;
static int abbrev = -1; /* unspecified */
static int max_candidates = 10;
static struct hash_table names;
static struct hashmap names;
static int have_util;
static const char *pattern;
static int always;
@ -37,7 +37,7 @@ static const char *diff_index_args[] = {
};
struct commit_name {
struct commit_name *next;
struct hashmap_entry entry;
unsigned char peeled[20];
struct tag *tag;
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
@ -50,6 +50,12 @@ static const char *prio_names[] = {
"head", "lightweight", "annotated",
};
static int commit_name_cmp(const struct commit_name *cn1,
const struct commit_name *cn2, const void *peeled)
{
return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);
}
static inline unsigned int hash_sha1(const unsigned char *sha1)
{
unsigned int hash;
@ -59,21 +65,9 @@ static inline unsigned int hash_sha1(const unsigned char *sha1)
static inline struct commit_name *find_commit_name(const unsigned char *peeled)
{
struct commit_name *n = lookup_hash(hash_sha1(peeled), &names);
while (n && !!hashcmp(peeled, n->peeled))
n = n->next;
return n;
}
static int set_util(void *chain, void *data)
{
struct commit_name *n;
for (n = chain; n; n = n->next) {
struct commit *c = lookup_commit_reference_gently(n->peeled, 1);
if (c)
c->util = n;
}
return 0;
struct commit_name key;
hashmap_entry_init(&key, hash_sha1(peeled));
return hashmap_get(&names, &key, peeled);
}
static int replace_name(struct commit_name *e,
@ -118,16 +112,10 @@ static void add_to_known_names(const char *path,
struct tag *tag = NULL;
if (replace_name(e, prio, sha1, &tag)) {
if (!e) {
void **pos;
e = xmalloc(sizeof(struct commit_name));
hashcpy(e->peeled, peeled);
pos = insert_hash(hash_sha1(peeled), e, &names);
if (pos) {
e->next = *pos;
*pos = e;
} else {
e->next = NULL;
}
hashmap_entry_init(e, hash_sha1(peeled));
hashmap_add(&names, e);
e->path = NULL;
}
e->tag = tag;
@ -292,7 +280,14 @@ static void describe(const char *arg, int last_one)
fprintf(stderr, _("searching to describe %s\n"), arg);
if (!have_util) {
for_each_hash(&names, set_util, NULL);
struct hashmap_iter iter;
struct commit *c;
struct commit_name *n = hashmap_iter_first(&names, &iter);
for (; n; n = hashmap_iter_next(&iter)) {
c = lookup_commit_reference_gently(n->peeled, 1);
if (c)
c->util = n;
}
have_util = 1;
}
@ -463,9 +458,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
return cmd_name_rev(args.argc, args.argv, prefix);
}
init_hash(&names);
hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);
for_each_rawref(get_name, NULL);
if (!names.nr && !always)
if (!names.size && !always)
die(_("No names found, cannot describe anything."));
if (argc == 0) {