show_reference(): rewrite to take an object_id argument

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 25, 2015 at 18:38 UTC d70d7a8a4d1e985dea02713a3b1fda3a08d4325e
1 file changed +8 -10
builtin/replace.c
+8 -10
@@ -35,7 +35,7 @@ struct show_data {
35 enum replace_format format;
36 };
37
38 -static int show_reference(const char *refname, const unsigned char *sha1,
38 +static int show_reference(const char *refname, const struct object_id *oid,
39 int flag, void *cb_data)
40 {
41 struct show_data *data = cb_data;
@@ -44,19 +44,19 @@ static int show_reference(const char *refname, const unsigned char *sha1,
44 if (data->format == REPLACE_FORMAT_SHORT)
45 printf("%s\n", refname);
46 else if (data->format == REPLACE_FORMAT_MEDIUM)
47 - printf("%s -> %s\n", refname, sha1_to_hex(sha1));
47 + printf("%s -> %s\n", refname, oid_to_hex(oid));
48 else { /* data->format == REPLACE_FORMAT_LONG */
49 - unsigned char object[20];
49 + struct object_id object;
50 enum object_type obj_type, repl_type;
51
52 - if (get_sha1(refname, object))
52 + if (get_sha1(refname, object.hash))
53 return error("Failed to resolve '%s' as a valid ref.", refname);
54
55 - obj_type = sha1_object_info(object, NULL);
56 - repl_type = sha1_object_info(sha1, NULL);
55 + obj_type = sha1_object_info(object.hash, NULL);
56 + repl_type = sha1_object_info(oid->hash, NULL);
57
58 printf("%s (%s) -> %s (%s)\n", refname, typename(obj_type),
59 - sha1_to_hex(sha1), typename(repl_type));
59 + oid_to_hex(oid), typename(repl_type));
60 }
61 }
62
@@ -66,8 +66,6 @@ static int show_reference(const char *refname, const unsigned char *sha1,
66 static int list_replace_refs(const char *pattern, const char *format)
67 {
68 struct show_data data;
69 - struct each_ref_fn_sha1_adapter wrapped_show_reference =
70 - {show_reference, (void *) &data};
69
70 if (pattern == NULL)
71 pattern = "*";
@@ -84,7 +82,7 @@ static int list_replace_refs(const char *pattern, const char *format)
82 "valid formats are 'short', 'medium' and 'long'\n",
83 format);
84
87 - for_each_replace_ref(each_ref_fn_adapter, &wrapped_show_reference);
85 + for_each_replace_ref(show_reference, (void *)&data);
86
87 return 0;
88 }