replace_object: use struct members instead of an array

Give the poor humans some names to help them make sense of things. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Feb 21, 2014 at 17:32 UTC ce375864759f14498126e1f5e630058b6656d187
1 file changed +11 -6
replace_object.c
+11 -6
@@ -3,8 +3,13 @@
3 #include "refs.h"
4 #include "commit.h"
5
6 +/*
7 + * An array of replacements. The array is kept sorted by the original
8 + * sha1.
9 + */
10 static struct replace_object {
7 - unsigned char sha1[2][20];
11 + unsigned char original[20];
12 + unsigned char replacement[20];
13 } **replace_object;
14
15 static int replace_object_alloc, replace_object_nr;
@@ -12,7 +17,7 @@ static int replace_object_alloc, replace_object_nr;
17 static const unsigned char *replace_sha1_access(size_t index, void *table)
18 {
19 struct replace_object **replace = table;
15 - return replace[index]->sha1[0];
20 + return replace[index]->original;
21 }
22
23 static int replace_object_pos(const unsigned char *sha1)
@@ -24,7 +29,7 @@ static int replace_object_pos(const unsigned char *sha1)
29 static int register_replace_object(struct replace_object *replace,
30 int ignore_dups)
31 {
27 - int pos = replace_object_pos(replace->sha1[0]);
32 + int pos = replace_object_pos(replace->original);
33
34 if (0 <= pos) {
35 if (ignore_dups)
@@ -60,14 +65,14 @@ static int register_replace_ref(const char *refname,
65 const char *hash = slash ? slash + 1 : refname;
66 struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
67
63 - if (strlen(hash) != 40 || get_sha1_hex(hash, repl_obj->sha1[0])) {
68 + if (strlen(hash) != 40 || get_sha1_hex(hash, repl_obj->original)) {
69 free(repl_obj);
70 warning("bad replace ref name: %s", refname);
71 return 0;
72 }
73
74 /* Copy sha1 from the read ref */
70 - hashcpy(repl_obj->sha1[1], sha1);
75 + hashcpy(repl_obj->replacement, sha1);
76
77 /* Register new object */
78 if (register_replace_object(repl_obj, 1))
@@ -107,7 +112,7 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
112
113 pos = replace_object_pos(cur);
114 if (0 <= pos)
110 - cur = replace_object[pos]->sha1[1];
115 + cur = replace_object[pos]->replacement;
116 } while (0 <= pos);
117
118 return cur;