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>
brian m. carlson committed
Feb 21, 2017 at 23:47 UTC
6439b5d941d9a04f59a0bbc1ff90a258ae07a2e9
1 file changed
+25
-25
builtin/describe.c
+25
-25
@@ -39,11 +39,11 @@ static const char *diff_index_args[] = {
39
40
struct commit_name {
41
struct hashmap_entry entry;
42
- unsigned char peeled[20];
42
+ struct object_id peeled;
43
struct tag *tag;
44
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
45
unsigned name_checked:1;
46
- unsigned char sha1[20];
46
+ struct object_id oid;
47
char *path;
48
};
49
@@ -54,17 +54,17 @@ static const char *prio_names[] = {
54
static int commit_name_cmp(const struct commit_name *cn1,
55
const struct commit_name *cn2, const void *peeled)
56
{
57
- return hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);
57
+ return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
58
}
59
60
-static inline struct commit_name *find_commit_name(const unsigned char *peeled)
60
+static inline struct commit_name *find_commit_name(const struct object_id *peeled)
61
{
62
- return hashmap_get_from_hash(&names, sha1hash(peeled), peeled);
62
+ return hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);
63
}
64
65
static int replace_name(struct commit_name *e,
66
int prio,
67
- const unsigned char *sha1,
67
+ const struct object_id *oid,
68
struct tag **tag)
69
{
70
if (!e || e->prio < prio)
@@ -77,13 +77,13 @@ static int replace_name(struct commit_name *e,
77
struct tag *t;
78
79
if (!e->tag) {
80
- t = lookup_tag(e->sha1);
80
+ t = lookup_tag(e->oid.hash);
81
if (!t || parse_tag(t))
82
return 1;
83
e->tag = t;
84
}
85
86
- t = lookup_tag(sha1);
86
+ t = lookup_tag(oid->hash);
87
if (!t || parse_tag(t))
88
return 0;
89
*tag = t;
@@ -96,24 +96,24 @@ static int replace_name(struct commit_name *e,
96
}
97
98
static void add_to_known_names(const char *path,
99
- const unsigned char *peeled,
99
+ const struct object_id *peeled,
100
int prio,
101
- const unsigned char *sha1)
101
+ const struct object_id *oid)
102
{
103
struct commit_name *e = find_commit_name(peeled);
104
struct tag *tag = NULL;
105
- if (replace_name(e, prio, sha1, &tag)) {
105
+ if (replace_name(e, prio, oid, &tag)) {
106
if (!e) {
107
e = xmalloc(sizeof(struct commit_name));
108
- hashcpy(e->peeled, peeled);
109
- hashmap_entry_init(e, sha1hash(peeled));
108
+ oidcpy(&e->peeled, peeled);
109
+ hashmap_entry_init(e, sha1hash(peeled->hash));
110
hashmap_add(&names, e);
111
e->path = NULL;
112
}
113
e->tag = tag;
114
e->prio = prio;
115
e->name_checked = 0;
116
- hashcpy(e->sha1, sha1);
116
+ oidcpy(&e->oid, oid);
117
free(e->path);
118
e->path = xstrdup(path);
119
}
@@ -154,7 +154,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
154
else
155
prio = 0;
156
157
- add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);
157
+ add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
158
return 0;
159
}
160
@@ -212,7 +212,7 @@ static unsigned long finish_depth_computation(
212
static void display_name(struct commit_name *n)
213
{
214
if (n->prio == 2 && !n->tag) {
215
- n->tag = lookup_tag(n->sha1);
215
+ n->tag = lookup_tag(n->oid.hash);
216
if (!n->tag || parse_tag(n->tag))
217
die(_("annotated tag %s not available"), n->path);
218
}
@@ -230,14 +230,14 @@ static void display_name(struct commit_name *n)
230
printf("%s", n->path);
231
}
232
233
-static void show_suffix(int depth, const unsigned char *sha1)
233
+static void show_suffix(int depth, const struct object_id *oid)
234
{
235
- printf("-%d-g%s", depth, find_unique_abbrev(sha1, abbrev));
235
+ printf("-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
236
}
237
238
static void describe(const char *arg, int last_one)
239
{
240
- unsigned char sha1[20];
240
+ struct object_id oid;
241
struct commit *cmit, *gave_up_on = NULL;
242
struct commit_list *list;
243
struct commit_name *n;
@@ -246,20 +246,20 @@ static void describe(const char *arg, int last_one)
246
unsigned long seen_commits = 0;
247
unsigned int unannotated_cnt = 0;
248
249
- if (get_sha1(arg, sha1))
249
+ if (get_oid(arg, &oid))
250
die(_("Not a valid object name %s"), arg);
251
- cmit = lookup_commit_reference(sha1);
251
+ cmit = lookup_commit_reference(oid.hash);
252
if (!cmit)
253
die(_("%s is not a valid '%s' object"), arg, commit_type);
254
255
- n = find_commit_name(cmit->object.oid.hash);
255
+ n = find_commit_name(&cmit->object.oid);
256
if (n && (tags || all || n->prio == 2)) {
257
/*
258
* Exact match to an existing ref.
259
*/
260
display_name(n);
261
if (longformat)
262
- show_suffix(0, n->tag ? n->tag->tagged->oid.hash : sha1);
262
+ show_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);
263
if (dirty)
264
printf("%s", dirty);
265
printf("\n");
@@ -276,7 +276,7 @@ static void describe(const char *arg, int last_one)
276
struct commit *c;
277
struct commit_name *n = hashmap_iter_first(&names, &iter);
278
for (; n; n = hashmap_iter_next(&iter)) {
279
- c = lookup_commit_reference_gently(n->peeled, 1);
279
+ c = lookup_commit_reference_gently(n->peeled.hash, 1);
280
if (c)
281
c->util = n;
282
}
@@ -380,7 +380,7 @@ static void describe(const char *arg, int last_one)
380
381
display_name(all_matches[0].name);
382
if (abbrev)
383
- show_suffix(all_matches[0].depth, cmit->object.oid.hash);
383
+ show_suffix(all_matches[0].depth, &cmit->object.oid);
384
if (dirty)
385
printf("%s", dirty);
386
printf("\n");