summaryrefslogtreecommitdiff
path: root/upload-pack.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2020-06-11 14:05:18 +0200
committerJunio C Hamano <gitster@pobox.com>2020-06-11 13:35:35 -0700
commitea2c6e6083c710fb37bff9962dbd6235f1f87d5a (patch)
tree89ce4d68c84ebc8917f01927dc33c355d67e255b /upload-pack.c
parentf01c7916b884366b842b585aa55c1c14ba524537 (diff)
downloadgit-ea2c6e6083c710fb37bff9962dbd6235f1f87d5a.tar.gz
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>
Diffstat (limited to 'upload-pack.c')
-rw-r--r--upload-pack.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/upload-pack.c b/upload-pack.c
index 3d331bedfa..f899fdf46a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -392,18 +392,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
die("git upload-pack: %s", abort_msg);
}
-static int got_oid(struct upload_pack_data *data,
- const char *hex, struct object_id *oid)
+static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid)
{
- struct object *o;
int we_knew_they_have = 0;
+ struct object *o = parse_object(the_repository, oid);
- if (get_oid_hex(hex, oid))
- die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object_file(oid))
- return -1;
-
- o = parse_object(the_repository, oid);
if (!o)
die("oops (%s)", oid_to_hex(oid));
if (o->type == OBJ_COMMIT) {
@@ -427,6 +420,16 @@ static int got_oid(struct upload_pack_data *data,
return 0;
}
+static int got_oid(struct upload_pack_data *data,
+ const char *hex, struct object_id *oid)
+{
+ if (get_oid_hex(hex, oid))
+ die("git upload-pack: expected SHA1 object, got '%s'", hex);
+ if (!has_object_file(oid))
+ return -1;
+ return do_got_oid(data, oid);
+}
+
static int ok_to_give_up(struct upload_pack_data *data)
{
uint32_t min_generation = GENERATION_NUMBER_ZERO;
@@ -1353,33 +1356,13 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common
/* Process haves */
for (i = 0; i < data->haves.nr; i++) {
const struct object_id *oid = &data->haves.oid[i];
- struct object *o;
- int we_knew_they_have = 0;
if (!has_object_file(oid))
continue;
oid_array_append(common, oid);
- o = parse_object(the_repository, oid);
- if (!o)
- die("oops (%s)", oid_to_hex(oid));
- if (o->type == OBJ_COMMIT) {
- struct commit_list *parents;
- struct commit *commit = (struct commit *)o;
- if (o->flags & THEY_HAVE)
- we_knew_they_have = 1;
- else
- o->flags |= THEY_HAVE;
- if (!data->oldest_have || (commit->date < data->oldest_have))
- data->oldest_have = commit->date;
- for (parents = commit->parents;
- parents;
- parents = parents->next)
- parents->item->object.flags |= THEY_HAVE;
- }
- if (!we_knew_they_have)
- add_object_array(o, NULL, &data->have_obj);
+ do_got_oid(data, oid);
}
return 0;