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 <sandals@crustytoothpaste.net> Signed-off-by: Jeff King <peff@peff.net>
brian m. carlson committed
Nov 10, 2015 at 02:22 UTC
e96b16cc2a1920ab8349a58e2501a3d30818f9e9
1 file changed
+12
-10
connect.c
+12
-10
@@ -120,7 +120,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
120
*list = NULL;
121
for (;;) {
122
struct ref *ref;
123
- unsigned char old_sha1[20];
123
+ struct object_id old_oid;
124
char *name;
125
int len, name_len;
126
char *buffer = packet_buffer;
@@ -139,34 +139,36 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
139
if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
140
die("remote error: %s", arg);
141
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))
145
die("protocol error: expected shallow sha-1, got '%s'", arg);
146
if (!shallow_points)
147
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);
149
continue;
150
}
151
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] != ' ')
154
die("protocol error: expected sha/ref, got '%s'", buffer);
153
- name = buffer + 41;
155
+ name = buffer + GIT_SHA1_HEXSZ + 1;
156
157
name_len = strlen(name);
156
- if (len != name_len + 41) {
158
+ if (len != name_len + GIT_SHA1_HEXSZ + 1) {
159
free(server_capabilities);
160
server_capabilities = xstrdup(name + name_len + 1);
161
}
162
163
if (extra_have && !strcmp(name, ".have")) {
162
- sha1_array_append(extra_have, old_sha1);
164
+ sha1_array_append(extra_have, old_oid.hash);
165
continue;
166
}
167
168
if (!check_ref(name, flags))
169
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);
172
*list = ref;
173
list = &ref->next;
174
got_at_least_one_head = 1;