builtin/describe: convert to struct object_id
Convert the functions in this file and struct commit_name to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5f5e936d4a
commit
6439b5d941
@ -39,11 +39,11 @@ static const char *diff_index_args[] = {
|
|||||||
|
|
||||||
struct commit_name {
|
struct commit_name {
|
||||||
struct hashmap_entry entry;
|
struct hashmap_entry entry;
|
||||||
unsigned char peeled[20];
|
struct object_id peeled;
|
||||||
struct tag *tag;
|
struct tag *tag;
|
||||||
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
|
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
|
||||||
unsigned name_checked:1;
|
unsigned name_checked:1;
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
char *path;
|
char *path;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,17 +54,17 @@ static const char *prio_names[] = {
|
|||||||
static int commit_name_cmp(const struct commit_name *cn1,
|
static int commit_name_cmp(const struct commit_name *cn1,
|
||||||
const struct commit_name *cn2, const void *peeled)
|
const struct commit_name *cn2, const void *peeled)
|
||||||
{
|
{
|
||||||
return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);
|
return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct commit_name *find_commit_name(const unsigned char *peeled)
|
static inline struct commit_name *find_commit_name(const struct object_id *peeled)
|
||||||
{
|
{
|
||||||
return hashmap_get_from_hash(&names, sha1hash(peeled), peeled);
|
return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int replace_name(struct commit_name *e,
|
static int replace_name(struct commit_name *e,
|
||||||
int prio,
|
int prio,
|
||||||
const unsigned char *sha1,
|
const struct object_id *oid,
|
||||||
struct tag **tag)
|
struct tag **tag)
|
||||||
{
|
{
|
||||||
if (!e || e->prio < prio)
|
if (!e || e->prio < prio)
|
||||||
@ -77,13 +77,13 @@ static int replace_name(struct commit_name *e,
|
|||||||
struct tag *t;
|
struct tag *t;
|
||||||
|
|
||||||
if (!e->tag) {
|
if (!e->tag) {
|
||||||
t = lookup_tag(e->sha1);
|
t = lookup_tag(e->oid.hash);
|
||||||
if (!t || parse_tag(t))
|
if (!t || parse_tag(t))
|
||||||
return 1;
|
return 1;
|
||||||
e->tag = t;
|
e->tag = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = lookup_tag(sha1);
|
t = lookup_tag(oid->hash);
|
||||||
if (!t || parse_tag(t))
|
if (!t || parse_tag(t))
|
||||||
return 0;
|
return 0;
|
||||||
*tag = t;
|
*tag = t;
|
||||||
@ -96,24 +96,24 @@ static int replace_name(struct commit_name *e,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void add_to_known_names(const char *path,
|
static void add_to_known_names(const char *path,
|
||||||
const unsigned char *peeled,
|
const struct object_id *peeled,
|
||||||
int prio,
|
int prio,
|
||||||
const unsigned char *sha1)
|
const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct commit_name *e = find_commit_name(peeled);
|
struct commit_name *e = find_commit_name(peeled);
|
||||||
struct tag *tag = NULL;
|
struct tag *tag = NULL;
|
||||||
if (replace_name(e, prio, sha1, &tag)) {
|
if (replace_name(e, prio, oid, &tag)) {
|
||||||
if (!e) {
|
if (!e) {
|
||||||
e = xmalloc(sizeof(struct commit_name));
|
e = xmalloc(sizeof(struct commit_name));
|
||||||
hashcpy(e->peeled, peeled);
|
oidcpy(&e->peeled, peeled);
|
||||||
hashmap_entry_init(e, sha1hash(peeled));
|
hashmap_entry_init(e, sha1hash(peeled->hash));
|
||||||
hashmap_add(&names, e);
|
hashmap_add(&names, e);
|
||||||
e->path = NULL;
|
e->path = NULL;
|
||||||
}
|
}
|
||||||
e->tag = tag;
|
e->tag = tag;
|
||||||
e->prio = prio;
|
e->prio = prio;
|
||||||
e->name_checked = 0;
|
e->name_checked = 0;
|
||||||
hashcpy(e->sha1, sha1);
|
oidcpy(&e->oid, oid);
|
||||||
free(e->path);
|
free(e->path);
|
||||||
e->path = xstrdup(path);
|
e->path = xstrdup(path);
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
|
|||||||
else
|
else
|
||||||
prio = 0;
|
prio = 0;
|
||||||
|
|
||||||
add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);
|
add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ static unsigned long finish_depth_computation(
|
|||||||
static void display_name(struct commit_name *n)
|
static void display_name(struct commit_name *n)
|
||||||
{
|
{
|
||||||
if (n->prio == 2 && !n->tag) {
|
if (n->prio == 2 && !n->tag) {
|
||||||
n->tag = lookup_tag(n->sha1);
|
n->tag = lookup_tag(n->oid.hash);
|
||||||
if (!n->tag || parse_tag(n->tag))
|
if (!n->tag || parse_tag(n->tag))
|
||||||
die(_("annotated tag %s not available"), n->path);
|
die(_("annotated tag %s not available"), n->path);
|
||||||
}
|
}
|
||||||
@ -230,14 +230,14 @@ static void display_name(struct commit_name *n)
|
|||||||
printf("%s", n->path);
|
printf("%s", n->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_suffix(int depth, const unsigned char *sha1)
|
static void show_suffix(int depth, const struct object_id *oid)
|
||||||
{
|
{
|
||||||
printf("-%d-g%s", depth, find_unique_abbrev(sha1, abbrev));
|
printf("-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void describe(const char *arg, int last_one)
|
static void describe(const char *arg, int last_one)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
struct commit *cmit, *gave_up_on = NULL;
|
struct commit *cmit, *gave_up_on = NULL;
|
||||||
struct commit_list *list;
|
struct commit_list *list;
|
||||||
struct commit_name *n;
|
struct commit_name *n;
|
||||||
@ -246,20 +246,20 @@ static void describe(const char *arg, int last_one)
|
|||||||
unsigned long seen_commits = 0;
|
unsigned long seen_commits = 0;
|
||||||
unsigned int unannotated_cnt = 0;
|
unsigned int unannotated_cnt = 0;
|
||||||
|
|
||||||
if (get_sha1(arg, sha1))
|
if (get_oid(arg, &oid))
|
||||||
die(_("Not a valid object name %s"), arg);
|
die(_("Not a valid object name %s"), arg);
|
||||||
cmit = lookup_commit_reference(sha1);
|
cmit = lookup_commit_reference(oid.hash);
|
||||||
if (!cmit)
|
if (!cmit)
|
||||||
die(_("%s is not a valid '%s' object"), arg, commit_type);
|
die(_("%s is not a valid '%s' object"), arg, commit_type);
|
||||||
|
|
||||||
n = find_commit_name(cmit->object.oid.hash);
|
n = find_commit_name(&cmit->object.oid);
|
||||||
if (n && (tags || all || n->prio == 2)) {
|
if (n && (tags || all || n->prio == 2)) {
|
||||||
/*
|
/*
|
||||||
* Exact match to an existing ref.
|
* Exact match to an existing ref.
|
||||||
*/
|
*/
|
||||||
display_name(n);
|
display_name(n);
|
||||||
if (longformat)
|
if (longformat)
|
||||||
show_suffix(0, n->tag ? n->tag->tagged->oid.hash : sha1);
|
show_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);
|
||||||
if (dirty)
|
if (dirty)
|
||||||
printf("%s", dirty);
|
printf("%s", dirty);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -276,7 +276,7 @@ static void describe(const char *arg, int last_one)
|
|||||||
struct commit *c;
|
struct commit *c;
|
||||||
struct commit_name *n = hashmap_iter_first(&names, &iter);
|
struct commit_name *n = hashmap_iter_first(&names, &iter);
|
||||||
for (; n; n = hashmap_iter_next(&iter)) {
|
for (; n; n = hashmap_iter_next(&iter)) {
|
||||||
c = lookup_commit_reference_gently(n->peeled, 1);
|
c = lookup_commit_reference_gently(n->peeled.hash, 1);
|
||||||
if (c)
|
if (c)
|
||||||
c->util = n;
|
c->util = n;
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ static void describe(const char *arg, int last_one)
|
|||||||
|
|
||||||
display_name(all_matches[0].name);
|
display_name(all_matches[0].name);
|
||||||
if (abbrev)
|
if (abbrev)
|
||||||
show_suffix(all_matches[0].depth, cmit->object.oid.hash);
|
show_suffix(all_matches[0].depth, &cmit->object.oid);
|
||||||
if (dirty)
|
if (dirty)
|
||||||
printf("%s", dirty);
|
printf("%s", dirty);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Reference in New Issue
Block a user