Skip to content

Commit ea2c6e6

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f01c791 commit ea2c6e6

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

upload-pack.c

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
392392
die("git upload-pack: %s", abort_msg);
393393
}
394394

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)
397396
{
398-
struct object *o;
399397
int we_knew_they_have = 0;
398+
struct object *o = parse_object(the_repository, oid);
400399

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);
407400
if (!o)
408401
die("oops (%s)", oid_to_hex(oid));
409402
if (o->type == OBJ_COMMIT) {
@@ -427,6 +420,16 @@ static int got_oid(struct upload_pack_data *data,
427420
return 0;
428421
}
429422

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+
430433
static int ok_to_give_up(struct upload_pack_data *data)
431434
{
432435
uint32_t min_generation = GENERATION_NUMBER_ZERO;
@@ -1353,33 +1356,13 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
13531356
/* Process haves */
13541357
for (i = 0; i < data->haves.nr; i++) {
13551358
const struct object_id *oid = &data->haves.oid[i];
1356-
struct object *o;
1357-
int we_knew_they_have = 0;
13581359

13591360
if (!has_object_file(oid))
13601361
continue;
13611362

13621363
oid_array_append(common, oid);
13631364

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);
13831366
}
13841367

13851368
return 0;

0 commit comments

Comments
 (0)