builtin/show-ref: rewrite to use object_id
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
f0a011fa1f3030e49de9f316b02119b390c33e92
1 file changed
+15
-18
builtin/show-ref.c
+15
-18
@@ -17,16 +17,17 @@ static int deref_tags, show_head, tags_only, heads_only, found_match, verify,
17
static const char **pattern;
18
static const char *exclude_existing_arg;
19
20
-static void show_one(const char *refname, const unsigned char *sha1)
20
+static void show_one(const char *refname, const struct object_id *oid)
21
{
22
- const char *hex = find_unique_abbrev(sha1, abbrev);
22
+ const char *hex = find_unique_abbrev(oid->hash, abbrev);
23
if (hash_only)
24
printf("%s\n", hex);
25
else
26
printf("%s %s\n", hex, refname);
27
}
28
29
-static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
29
+static int show_ref(const char *refname, const struct object_id *oid,
30
+ int flag, void *cbdata)
31
{
32
const char *hex;
33
unsigned char peeled[20];
@@ -69,14 +70,14 @@ match:
70
* detect and return error if the repository is corrupt and
71
* ref points at a nonexistent object.
72
*/
72
- if (!has_sha1_file(sha1))
73
+ if (!has_sha1_file(oid->hash))
74
die("git show-ref: bad ref %s (%s)", refname,
74
- sha1_to_hex(sha1));
75
+ oid_to_hex(oid));
76
77
if (quiet)
78
return 0;
79
79
- show_one(refname, sha1);
80
+ show_one(refname, oid);
81
82
if (!deref_tags)
83
return 0;
@@ -88,7 +89,8 @@ match:
89
return 0;
90
}
91
91
-static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
92
+static int add_existing(const char *refname, const struct object_id *oid,
93
+ int flag, void *cbdata)
94
{
95
struct string_list *list = (struct string_list *)cbdata;
96
string_list_insert(list, refname);
@@ -109,10 +111,8 @@ static int exclude_existing(const char *match)
111
static struct string_list existing_refs = STRING_LIST_INIT_DUP;
112
char buf[1024];
113
int matchlen = match ? strlen(match) : 0;
112
- struct each_ref_fn_sha1_adapter wrapped_add_existing =
113
- {add_existing, &existing_refs};
114
115
- for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
115
+ for_each_ref(add_existing, &existing_refs);
116
while (fgets(buf, sizeof(buf), stdin)) {
117
char *ref;
118
int len = strlen(buf);
@@ -193,9 +193,6 @@ static const struct option show_ref_options[] = {
193
194
int cmd_show_ref(int argc, const char **argv, const char *prefix)
195
{
196
- struct each_ref_fn_sha1_adapter wrapped_show_ref =
197
- {show_ref, NULL};
198
-
196
if (argc == 2 && !strcmp(argv[1], "-h"))
197
usage_with_options(show_ref_usage, show_ref_options);
198
@@ -213,12 +210,12 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
210
if (!pattern)
211
die("--verify requires a reference");
212
while (*pattern) {
216
- unsigned char sha1[20];
213
+ struct object_id oid;
214
215
if (starts_with(*pattern, "refs/") &&
219
- !read_ref(*pattern, sha1)) {
216
+ !read_ref(*pattern, oid.hash)) {
217
if (!quiet)
221
- show_one(*pattern, sha1);
218
+ show_one(*pattern, &oid);
219
}
220
else if (!quiet)
221
die("'%s' - not a valid ref", *pattern);
@@ -230,8 +227,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
227
}
228
229
if (show_head)
233
- head_ref(each_ref_fn_adapter, &wrapped_show_ref);
234
- for_each_ref(each_ref_fn_adapter, &wrapped_show_ref);
230
+ head_ref(show_ref, NULL);
231
+ for_each_ref(show_ref, NULL);
232
if (!found_match) {
233
if (verify && !quiet)
234
die("No match");