upload-pack: refactor common code into do_got_oid()
As 'upload-pack.c' is now using 'struct upload_pack_data' thoroughly, let's refactor some common code into a new do_got_oid() function. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jun 11, 2020 at 14:05 UTC
ea2c6e6083c710fb37bff9962dbd6235f1f87d5a
1 file changed
+13
-30
upload-pack.c
+13
-30
@@ -392,18 +392,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
392
die("git upload-pack: %s", abort_msg);
393
}
394
395
-static int got_oid(struct upload_pack_data *data,
396
- const char *hex, struct object_id *oid)
395
+static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid)
396
{
398
- struct object *o;
397
int we_knew_they_have = 0;
398
+ struct object *o = parse_object(the_repository, oid);
399
401
- if (get_oid_hex(hex, oid))
402
- die("git upload-pack: expected SHA1 object, got '%s'", hex);
403
- if (!has_object_file(oid))
404
- return -1;
405
-
406
- o = parse_object(the_repository, oid);
400
if (!o)
401
die("oops (%s)", oid_to_hex(oid));
402
if (o->type == OBJ_COMMIT) {
@@ -427,6 +420,16 @@ static int got_oid(struct upload_pack_data *data,
420
return 0;
421
}
422
423
+static int got_oid(struct upload_pack_data *data,
424
+ const char *hex, struct object_id *oid)
425
+{
426
+ if (get_oid_hex(hex, oid))
427
+ die("git upload-pack: expected SHA1 object, got '%s'", hex);
428
+ if (!has_object_file(oid))
429
+ return -1;
430
+ return do_got_oid(data, oid);
431
+}
432
+
433
static int ok_to_give_up(struct upload_pack_data *data)
434
{
435
uint32_t min_generation = GENERATION_NUMBER_ZERO;
@@ -1353,33 +1356,13 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
1356
/* Process haves */
1357
for (i = 0; i < data->haves.nr; i++) {
1358
const struct object_id *oid = &data->haves.oid[i];
1356
- struct object *o;
1357
- int we_knew_they_have = 0;
1359
1360
if (!has_object_file(oid))
1361
continue;
1362
1363
oid_array_append(common, oid);
1364
1364
- o = parse_object(the_repository, oid);
1365
- if (!o)
1366
- die("oops (%s)", oid_to_hex(oid));
1367
- if (o->type == OBJ_COMMIT) {
1368
- struct commit_list *parents;
1369
- struct commit *commit = (struct commit *)o;
1370
- if (o->flags & THEY_HAVE)
1371
- we_knew_they_have = 1;
1372
- else
1373
- o->flags |= THEY_HAVE;
1374
- if (!data->oldest_have || (commit->date < data->oldest_have))
1375
- data->oldest_have = commit->date;
1376
- for (parents = commit->parents;
1377
- parents;
1378
- parents = parents->next)
1379
- parents->item->object.flags |= THEY_HAVE;
1380
- }
1381
- if (!we_knew_they_have)
1382
- add_object_array(o, NULL, &data->have_obj);
1365
+ do_got_oid(data, oid);
1366
}
1367
1368
return 0;