@ -12,20 +12,20 @@ static const char describe_usage[] =
static int all; /* Default to annotated tags only */
static int all; /* Default to annotated tags only */
static int tags; /* But allow any tags if --tags is specified */
static int tags; /* But allow any tags if --tags is specified */
static int abbrev = DEFAULT_ABBREV;
static int abbrev = DEFAULT_ABBREV;
static int names, allocs;
static unsigned int names[256], allocs[256];
static struct commit_name {
static struct commit_name {
struct commit *commit;
struct commit *commit;
int prio; /* annotated tag = 2, tag = 1, head = 0 */
int prio; /* annotated tag = 2, tag = 1, head = 0 */
char path[FLEX_ARRAY]; /* more */
char path[FLEX_ARRAY]; /* more */
} **name_array = NULL;
} **name_array[256];
static struct commit_name *match(struct commit *cmit)
static struct commit_name *match(struct commit *cmit)
{
{
int i = names;
unsigned char m = cmit->object.sha1[0];
struct commit_name **p = name_array;
unsigned int i = names[m];
struct commit_name **p = name_array[m];
while (i-- > 0) {
while (i-- > 0) {
struct commit_name *n = *p++;
struct commit_name *n = *p++;
@ -42,17 +42,19 @@ static void add_to_known_names(const char *path,
int idx;
int idx;
int len = strlen(path)+1;
int len = strlen(path)+1;
struct commit_name *name = xmalloc(sizeof(struct commit_name) + len);
struct commit_name *name = xmalloc(sizeof(struct commit_name) + len);
unsigned char m = commit->object.sha1[0];
name->commit = commit;
name->commit = commit;
name->prio = prio;
name->prio = prio;
memcpy(name->path, path, len);
memcpy(name->path, path, len);
idx = names;
idx = names[m];
if (idx >= allocs) {
if (idx >= allocs[m]) {
allocs = (idx + 50) * 3 / 2;
allocs[m] = (idx + 50) * 3 / 2;
name_array = xrealloc(name_array, allocs*sizeof(*name_array));
name_array[m] = xrealloc(name_array[m],
allocs[m] * sizeof(*name_array));
}
}
name_array[idx] = name;
name_array[m][idx] = name;
names = ++idx;
names[m] = ++idx;
}
}
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
@ -121,9 +123,12 @@ static void describe(const char *arg, int last_one)
die("%s is not a valid '%s' object", arg, commit_type);
die("%s is not a valid '%s' object", arg, commit_type);
if (!initialized) {
if (!initialized) {
unsigned int m;
initialized = 1;
initialized = 1;
for_each_ref(get_name, NULL);
for_each_ref(get_name, NULL);
qsort(name_array, names, sizeof(*name_array), compare_names);
for (m = 0; m < ARRAY_SIZE(name_array); m++)
qsort(name_array[m], names[m],
sizeof(*name_array[m]), compare_names);
}
}
n = match(cmit);
n = match(cmit);