builtin/rev-parse: convert to struct object_id

Some of the functions converted are callers of lookup_commit_reference. However, the changes involved in converting the entire thing are not too large, so we might as well convert it all. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 1, 2017 at 02:29 UTC 8bc095f7d5b847501e06e8bc1eafc50a314b99b9
1 file changed +28 -28
builtin/rev-parse.c
+28 -28
@@ -121,7 +121,7 @@ static void show_with_type(int type, const char *arg)
121 }
122
123 /* Output a revision, only if filter allows it */
124 -static void show_rev(int type, const unsigned char *sha1, const char *name)
124 +static void show_rev(int type, const struct object_id *oid, const char *name)
125 {
126 if (!(filter & DO_REVS))
127 return;
@@ -129,10 +129,10 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
129
130 if ((symbolic || abbrev_ref) && name) {
131 if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
132 - unsigned char discard[20];
132 + struct object_id discard;
133 char *full;
134
135 - switch (dwim_ref(name, strlen(name), discard, &full)) {
135 + switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
136 case 0:
137 /*
138 * Not found -- not a ref. We could
@@ -158,9 +158,9 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
158 }
159 }
160 else if (abbrev)
161 - show_with_type(type, find_unique_abbrev(sha1, abbrev));
161 + show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
162 else
163 - show_with_type(type, sha1_to_hex(sha1));
163 + show_with_type(type, oid_to_hex(oid));
164 }
165
166 /* Output a flag, only if filter allows it. */
@@ -180,11 +180,11 @@ static int show_default(void)
180 const char *s = def;
181
182 if (s) {
183 - unsigned char sha1[20];
183 + struct object_id oid;
184
185 def = NULL;
186 - if (!get_sha1(s, sha1)) {
187 - show_rev(NORMAL, sha1, s);
186 + if (!get_oid(s, &oid)) {
187 + show_rev(NORMAL, &oid, s);
188 return 1;
189 }
190 }
@@ -195,19 +195,19 @@ static int show_reference(const char *refname, const struct object_id *oid, int
195 {
196 if (ref_excluded(ref_excludes, refname))
197 return 0;
198 - show_rev(NORMAL, oid->hash, refname);
198 + show_rev(NORMAL, oid, refname);
199 return 0;
200 }
201
202 static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)
203 {
204 - show_rev(REVERSED, oid->hash, refname);
204 + show_rev(REVERSED, oid, refname);
205 return 0;
206 }
207
208 static int show_abbrev(const struct object_id *oid, void *cb_data)
209 {
210 - show_rev(NORMAL, oid->hash, NULL);
210 + show_rev(NORMAL, oid, NULL);
211 return 0;
212 }
213
@@ -242,8 +242,8 @@ static int show_file(const char *arg, int output_prefix)
242 static int try_difference(const char *arg)
243 {
244 char *dotdot;
245 - unsigned char sha1[20];
246 - unsigned char end[20];
245 + struct object_id oid;
246 + struct object_id end;
247 const char *next;
248 const char *this;
249 int symmetric;
@@ -273,18 +273,18 @@ static int try_difference(const char *arg)
273 return 0;
274 }
275
276 - if (!get_sha1_committish(this, sha1) && !get_sha1_committish(next, end)) {
277 - show_rev(NORMAL, end, next);
278 - show_rev(symmetric ? NORMAL : REVERSED, sha1, this);
276 + if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
277 + show_rev(NORMAL, &end, next);
278 + show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
279 if (symmetric) {
280 struct commit_list *exclude;
281 struct commit *a, *b;
282 - a = lookup_commit_reference(sha1);
283 - b = lookup_commit_reference(end);
282 + a = lookup_commit_reference(oid.hash);
283 + b = lookup_commit_reference(end.hash);
284 exclude = get_merge_bases(a, b);
285 while (exclude) {
286 struct commit *commit = pop_commit(&exclude);
287 - show_rev(REVERSED, commit->object.oid.hash, NULL);
287 + show_rev(REVERSED, &commit->object.oid, NULL);
288 }
289 }
290 *dotdot = '.';
@@ -297,7 +297,7 @@ static int try_difference(const char *arg)
297 static int try_parent_shorthands(const char *arg)
298 {
299 char *dotdot;
300 - unsigned char sha1[20];
300 + struct object_id oid;
301 struct commit *commit;
302 struct commit_list *parents;
303 int parent_number;
@@ -327,12 +327,12 @@ static int try_parent_shorthands(const char *arg)
327 return 0;
328
329 *dotdot = 0;
330 - if (get_sha1_committish(arg, sha1)) {
330 + if (get_sha1_committish(arg, oid.hash)) {
331 *dotdot = '^';
332 return 0;
333 }
334
335 - commit = lookup_commit_reference(sha1);
335 + commit = lookup_commit_reference(oid.hash);
336 if (exclude_parent &&
337 exclude_parent > commit_list_count(commit->parents)) {
338 *dotdot = '^';
@@ -340,7 +340,7 @@ static int try_parent_shorthands(const char *arg)
340 }
341
342 if (include_rev)
343 - show_rev(NORMAL, sha1, arg);
343 + show_rev(NORMAL, &oid, arg);
344 for (parents = commit->parents, parent_number = 1;
345 parents;
346 parents = parents->next, parent_number++) {
@@ -352,7 +352,7 @@ static int try_parent_shorthands(const char *arg)
352 if (symbolic)
353 name = xstrfmt("%s^%d", arg, parent_number);
354 show_rev(include_parents ? NORMAL : REVERSED,
355 - parents->item->object.oid.hash, name);
355 + &parents->item->object.oid, name);
356 free(name);
357 }
358
@@ -571,7 +571,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
571 int did_repo_setup = 0;
572 int has_dashdash = 0;
573 int output_prefix = 0;
574 - unsigned char sha1[20];
574 + struct object_id oid;
575 unsigned int flags = 0;
576 const char *name = NULL;
577 struct object_context unused;
@@ -910,11 +910,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
910 name++;
911 type = REVERSED;
912 }
913 - if (!get_sha1_with_context(name, flags, sha1, &unused)) {
913 + if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
914 if (verify)
915 revs_count++;
916 else
917 - show_rev(type, sha1, name);
917 + show_rev(type, &oid, name);
918 continue;
919 }
920 if (verify)
@@ -929,7 +929,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
929 strbuf_release(&buf);
930 if (verify) {
931 if (revs_count == 1) {
932 - show_rev(type, sha1, name);
932 + show_rev(type, &oid, name);
933 return 0;
934 } else if (revs_count == 0 && show_default())
935 return 0;