Skip to content

Commit ce37586

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 5f95c9f commit ce37586

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

replace_object.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
#include "refs.h"
44
#include "commit.h"
55

6+
/*
7+
* An array of replacements. The array is kept sorted by the original
8+
* sha1.
9+
*/
610
static struct replace_object {
7-
unsigned char sha1[2][20];
11+
unsigned char original[20];
12+
unsigned char replacement[20];
813
} **replace_object;
914

1015
static int replace_object_alloc, replace_object_nr;
1116

1217
static const unsigned char *replace_sha1_access(size_t index, void *table)
1318
{
1419
struct replace_object **replace = table;
15-
return replace[index]->sha1[0];
20+
return replace[index]->original;
1621
}
1722

1823
static int replace_object_pos(const unsigned char *sha1)
@@ -24,7 +29,7 @@ static int replace_object_pos(const unsigned char *sha1)
2429
static int register_replace_object(struct replace_object *replace,
2530
int ignore_dups)
2631
{
27-
int pos = replace_object_pos(replace->sha1[0]);
32+
int pos = replace_object_pos(replace->original);
2833

2934
if (0 <= pos) {
3035
if (ignore_dups)
@@ -60,14 +65,14 @@ static int register_replace_ref(const char *refname,
6065
const char *hash = slash ? slash + 1 : refname;
6166
struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
6267

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)) {
6469
free(repl_obj);
6570
warning("bad replace ref name: %s", refname);
6671
return 0;
6772
}
6873

6974
/* Copy sha1 from the read ref */
70-
hashcpy(repl_obj->sha1[1], sha1);
75+
hashcpy(repl_obj->replacement, sha1);
7176

7277
/* Register new object */
7378
if (register_replace_object(repl_obj, 1))
@@ -107,7 +112,7 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
107112

108113
pos = replace_object_pos(cur);
109114
if (0 <= pos)
110-
cur = replace_object[pos]->sha1[1];
115+
cur = replace_object[pos]->replacement;
111116
} while (0 <= pos);
112117

113118
return cur;

0 commit comments

Comments
 (0)