Skip to content

Commit e96b16c

Browse files
bk2204peff
authored andcommitted
get_remote_heads: convert to struct object_id
Replace an unsigned char array with struct object_id and express several hard-coded constants in terms of GIT_SHA1_HEXSZ. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 8338c91 commit e96b16c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

connect.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
120120
*list = NULL;
121121
for (;;) {
122122
struct ref *ref;
123-
unsigned char old_sha1[20];
123+
struct object_id old_oid;
124124
char *name;
125125
int len, name_len;
126126
char *buffer = packet_buffer;
@@ -139,34 +139,36 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
139139
if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
140140
die("remote error: %s", arg);
141141

142-
if (len == 48 && skip_prefix(buffer, "shallow ", &arg)) {
143-
if (get_sha1_hex(arg, old_sha1))
142+
if (len == GIT_SHA1_HEXSZ + strlen("shallow ") &&
143+
skip_prefix(buffer, "shallow ", &arg)) {
144+
if (get_oid_hex(arg, &old_oid))
144145
die("protocol error: expected shallow sha-1, got '%s'", arg);
145146
if (!shallow_points)
146147
die("repository on the other end cannot be shallow");
147-
sha1_array_append(shallow_points, old_sha1);
148+
sha1_array_append(shallow_points, old_oid.hash);
148149
continue;
149150
}
150151

151-
if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
152+
if (len < GIT_SHA1_HEXSZ + 2 || get_oid_hex(buffer, &old_oid) ||
153+
buffer[GIT_SHA1_HEXSZ] != ' ')
152154
die("protocol error: expected sha/ref, got '%s'", buffer);
153-
name = buffer + 41;
155+
name = buffer + GIT_SHA1_HEXSZ + 1;
154156

155157
name_len = strlen(name);
156-
if (len != name_len + 41) {
158+
if (len != name_len + GIT_SHA1_HEXSZ + 1) {
157159
free(server_capabilities);
158160
server_capabilities = xstrdup(name + name_len + 1);
159161
}
160162

161163
if (extra_have && !strcmp(name, ".have")) {
162-
sha1_array_append(extra_have, old_sha1);
164+
sha1_array_append(extra_have, old_oid.hash);
163165
continue;
164166
}
165167

166168
if (!check_ref(name, flags))
167169
continue;
168-
ref = alloc_ref(buffer + 41);
169-
hashcpy(ref->old_oid.hash, old_sha1);
170+
ref = alloc_ref(buffer + GIT_SHA1_HEXSZ + 1);
171+
oidcpy(&ref->old_oid, &old_oid);
170172
*list = ref;
171173
list = &ref->next;
172174
got_at_least_one_head = 1;

0 commit comments

Comments
 (0)