From patchwork Thu Jun 11 12:05:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599839 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A65C1667 for ; Thu, 11 Jun 2020 12:05:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 799722053B for ; Thu, 11 Jun 2020 12:05:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CwymZNAv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727975AbgFKMFg (ORCPT ); Thu, 11 Jun 2020 08:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbgFKMFf (ORCPT ); Thu, 11 Jun 2020 08:05:35 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19AB2C08C5C2 for ; Thu, 11 Jun 2020 05:05:35 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c3so5855675wru.12 for ; Thu, 11 Jun 2020 05:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=80tB2gi809Iclic/onhayifTdDZuro2omtm0DhEsF1c=; b=CwymZNAvPNiJXR4uRWIkv9yat5rexwoWhttIkT8ejWq9fPBqYvPGkjm8iWaMyKd33L xz1anRYRIaeriVmvtgRWky2XGPVWvbSq0cpwapuGgAcFnZQco++Rco1CwJ5TWUoBuI82 Z4wcSYJ5j0xkZffT1o3RvmBE4SBvHpA+AQ7bViytUi98y/PALie7XRS89xYRq8lgUz+8 dpvHtlyzDXH79PCaONyneHeZ+aNTJwpKY0Wn77+pFIEfXhyrOdL5d2XbP0qPS+ewV6Vr m3COJ9frnv8MO0nenL4L+tjIfn8U7K/WxAk8YgqpXUOkUz6FIUHjO8iMsorxhElDU1LV ojJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=80tB2gi809Iclic/onhayifTdDZuro2omtm0DhEsF1c=; b=HoFPyx3crlOBZ0anTGdYVBnHVMwQX4La+XRsVFBWCyuiX4O91+JFy0w2rsRz9ohWfH QmDP0jYdxtor5MlOUouRQ+PaVkMVBpiU9d0iuknxxI6Dp2OlHSjqYAYXs3v/+NS1lZY8 oNnZITTyCjOXXNWVsLPkYDdY+d509NCoiqqEOKOfYP5gJ34M4DZ1Jif0DkLY7Ahg2U+2 WLMgGriIfObv4RSxyKRmjFwvHrmnsfLDw3YB7kpJQtWkXbaeqSNCeMpwUS13vRnBgapT InBfTGkTcCfYJ+hwuRf5VkAOa/UIxgJ1749moIJCipiqEGz8AL7x7oiGii+ejgc18Zf+ muTQ== X-Gm-Message-State: AOAM530SHAQPMBa8U4Pm2NB1kktoFE+Ffc+WQRwDwEIevuwVAe2pxjAB Rt30YBo7QUGcQlVF0i4ZSpIx2q4VP7A= X-Google-Smtp-Source: ABdhPJyzH/LWetfQJ0x5Sl/hO+Ft2jNaaX6TUh2CUONjp1zTRwH6ukl+zi4MiVlMlJANzgFOpOS2eA== X-Received: by 2002:a5d:42cd:: with SMTP id t13mr8987476wrr.355.1591877133417; Thu, 11 Jun 2020 05:05:33 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:32 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 01/14] upload-pack: pass upload_pack_data to send_shallow_list() Date: Thu, 11 Jun 2020 14:05:05 +0200 Message-Id: <20200611120518.10771-2-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to send_shallow_list(), so that this function can use all the fields of the struct. This will be used in followup commits to move static variables into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 57 +++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index bc7e3ca19d..ada9082b06 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -808,53 +808,49 @@ static void deepen_by_rev_list(struct packet_writer *writer, int ac, } /* Returns 1 if a shallow list is sent or 0 otherwise */ -static int send_shallow_list(struct packet_writer *writer, - int depth, int deepen_rev_list, - timestamp_t deepen_since, - struct string_list *deepen_not, - int deepen_relative, - struct object_array *shallows, - struct object_array *want_obj) +static int send_shallow_list(struct upload_pack_data *data) { int ret = 0; - if (depth > 0 && deepen_rev_list) + if (data->depth > 0 && data->deepen_rev_list) die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together"); - if (depth > 0) { - deepen(writer, depth, deepen_relative, shallows, want_obj); + if (data->depth > 0) { + deepen(&data->writer, data->depth, data->deepen_relative, + &data->shallows, &data->want_obj); ret = 1; - } else if (deepen_rev_list) { + } else if (data->deepen_rev_list) { struct argv_array av = ARGV_ARRAY_INIT; int i; argv_array_push(&av, "rev-list"); - if (deepen_since) - argv_array_pushf(&av, "--max-age=%"PRItime, deepen_since); - if (deepen_not->nr) { + if (data->deepen_since) + argv_array_pushf(&av, "--max-age=%"PRItime, data->deepen_since); + if (data->deepen_not.nr) { argv_array_push(&av, "--not"); - for (i = 0; i < deepen_not->nr; i++) { - struct string_list_item *s = deepen_not->items + i; + for (i = 0; i < data->deepen_not.nr; i++) { + struct string_list_item *s = data->deepen_not.items + i; argv_array_push(&av, s->string); } argv_array_push(&av, "--not"); } - for (i = 0; i < want_obj->nr; i++) { - struct object *o = want_obj->objects[i].item; + for (i = 0; i < data->want_obj.nr; i++) { + struct object *o = data->want_obj.objects[i].item; argv_array_push(&av, oid_to_hex(&o->oid)); } - deepen_by_rev_list(writer, av.argc, av.argv, shallows, want_obj); + deepen_by_rev_list(&data->writer, av.argc, av.argv, + &data->shallows, &data->want_obj); argv_array_clear(&av); ret = 1; } else { - if (shallows->nr > 0) { + if (data->shallows.nr > 0) { int i; - for (i = 0; i < shallows->nr; i++) + for (i = 0; i < data->shallows.nr; i++) register_shallow(the_repository, - &shallows->objects[i].item->oid); + &data->shallows.objects[i].item->oid); } } - shallow_nr += shallows->nr; + shallow_nr += data->shallows.nr; return ret; } @@ -1022,14 +1018,7 @@ static void receive_needs(struct upload_pack_data *data, if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0) return; - if (send_shallow_list(&data->writer, - data->depth, - data->deepen_rev_list, - data->deepen_since, - &data->deepen_not, - data->deepen_relative, - &data->shallows, - &data->want_obj)) + if (send_shallow_list(data)) packet_flush(1); } @@ -1473,11 +1462,7 @@ static void send_shallow_info(struct upload_pack_data *data) packet_writer_write(&data->writer, "shallow-info\n"); - if (!send_shallow_list(&data->writer, data->depth, - data->deepen_rev_list, - data->deepen_since, &data->deepen_not, - data->deepen_relative, - &data->shallows, &data->want_obj) && + if (!send_shallow_list(data) && is_repository_shallow(the_repository)) deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative, &data->shallows, &data->want_obj); From patchwork Thu Jun 11 12:05:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E2E413B1 for ; Thu, 11 Jun 2020 12:05:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34FE72078D for ; Thu, 11 Jun 2020 12:05:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jS8i3LDj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727998AbgFKMFl (ORCPT ); Thu, 11 Jun 2020 08:05:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727780AbgFKMFh (ORCPT ); Thu, 11 Jun 2020 08:05:37 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC35DC08C5C1 for ; Thu, 11 Jun 2020 05:05:36 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x6so5848821wrm.13 for ; Thu, 11 Jun 2020 05:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cG/zu+4G8PWCH//ql+TEDKup6eQGMfvqRWo9iA6rEQA=; b=jS8i3LDj+lvbSuGc4XR0iRX6SM9QQzKYw2CcAmgY3WKOGomPnz/0VdABLdMuURxOst SEhDTiwtiwUGUX/+bqNBLFizVQT8T7Ko10YpvQ5wfvoZSL9n39EEa1ZNipAQkHIKnUar AnDB6N2/udOx5wrtt9K+Y/gtN2/pLUCEl6qoUq6g6fVTk/0koY+1oylMUTjgU+c5iYrB /095M3NcGfHlubb3LgpkRjmzIbadsduSITJ+BlKYAUB+qt15/bR5B7cFA3EWIaWvC6lb IsY2bgOE1R/kX3+7cmTUDqHntR9dsajPjH3vc3nvhh5uK4g0IbwkoIGl2+Mr7O8xDim1 lGIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cG/zu+4G8PWCH//ql+TEDKup6eQGMfvqRWo9iA6rEQA=; b=CiOc8zcNhX1UZ32TNBE9QQAfQWnF4ZwvEUSB1Ijh+eWyjSVKhwzL+IvekNUKKuX2Kb 7Ues56M8butXs3yiln5vSQwxdQleLNKXjN11GwuUZEmTUkDJ6WsdOftKPzZPWkFRAaju psP2SvsC56XSL1iJCK82caHWU4tFP5FSZ91ewT/kj1LhKS+JjBRv72oE2SLfxNE2LKVO T7Vihmp3P84IZbIrtsjJ9htW4hwux1kFxgSmtqsQRvl6I0bgir6/SOFR/JIu6KWUDcyF 65PA9Z+X5odJBur1jPjftgL1hxDMg/36ildLayyFfL/nwcgqgMaYcgIeMn5ObChHZIbQ MANQ== X-Gm-Message-State: AOAM533SIPRT0cg8df2YCN7wFkhPhpssoNzCY8Dv0XX5zrbzICwHIRDI v3ytN0sB/4sWAGbLPK+QyvdUzVX/NhA= X-Google-Smtp-Source: ABdhPJzeutUHYvr43AihNNdA/+4alrWTxyT4BdTIXONbV8Bufb9b4hiqWJMcG9Igb62AGuMJqmx+nQ== X-Received: by 2002:adf:fec8:: with SMTP id q8mr9586497wrs.2.1591877135027; Thu, 11 Jun 2020 05:05:35 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:34 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 02/14] upload-pack: pass upload_pack_data to deepen() Date: Thu, 11 Jun 2020 14:05:06 +0200 Message-Id: <20200611120518.10771-3-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to deepen(), so that this function can use all the fields of the struct. This will be used in followup commits to move static variables into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index ada9082b06..3f15828fd2 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -753,17 +753,16 @@ static void send_unshallow(struct packet_writer *writer, static int check_ref(const char *refname_full, const struct object_id *oid, int flag, void *cb_data); -static void deepen(struct packet_writer *writer, int depth, int deepen_relative, - struct object_array *shallows, struct object_array *want_obj) +static void deepen(struct upload_pack_data *data, int depth) { if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) { int i; - for (i = 0; i < shallows->nr; i++) { - struct object *object = shallows->objects[i].item; + for (i = 0; i < data->shallows.nr; i++) { + struct object *object = data->shallows.objects[i].item; object->flags |= NOT_SHALLOW; } - } else if (deepen_relative) { + } else if (data->deepen_relative) { struct object_array reachable_shallows = OBJECT_ARRAY_INIT; struct commit_list *result; @@ -774,23 +773,23 @@ static void deepen(struct packet_writer *writer, int depth, int deepen_relative, head_ref_namespaced(check_ref, NULL); for_each_namespaced_ref(check_ref, NULL); - get_reachable_list(shallows, &reachable_shallows); + get_reachable_list(&data->shallows, &reachable_shallows); result = get_shallow_commits(&reachable_shallows, depth + 1, SHALLOW, NOT_SHALLOW); - send_shallow(writer, result); + send_shallow(&data->writer, result); free_commit_list(result); object_array_clear(&reachable_shallows); } else { struct commit_list *result; - result = get_shallow_commits(want_obj, depth, + result = get_shallow_commits(&data->want_obj, depth, SHALLOW, NOT_SHALLOW); - send_shallow(writer, result); + send_shallow(&data->writer, result); free_commit_list(result); } - send_unshallow(writer, shallows, want_obj); + send_unshallow(&data->writer, &data->shallows, &data->want_obj); } static void deepen_by_rev_list(struct packet_writer *writer, int ac, @@ -815,8 +814,7 @@ static int send_shallow_list(struct upload_pack_data *data) if (data->depth > 0 && data->deepen_rev_list) die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together"); if (data->depth > 0) { - deepen(&data->writer, data->depth, data->deepen_relative, - &data->shallows, &data->want_obj); + deepen(data, data->depth); ret = 1; } else if (data->deepen_rev_list) { struct argv_array av = ARGV_ARRAY_INIT; @@ -1464,8 +1462,7 @@ static void send_shallow_info(struct upload_pack_data *data) if (!send_shallow_list(data) && is_repository_shallow(the_repository)) - deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative, - &data->shallows, &data->want_obj); + deepen(data, INFINITE_DEPTH); packet_delim(1); } From patchwork Thu Jun 11 12:05:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599841 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A8B71667 for ; Thu, 11 Jun 2020 12:05:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1B1F20760 for ; Thu, 11 Jun 2020 12:05:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OhUvZ+Dw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728006AbgFKMFm (ORCPT ); Thu, 11 Jun 2020 08:05:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbgFKMFi (ORCPT ); Thu, 11 Jun 2020 08:05:38 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65149C08C5C2 for ; Thu, 11 Jun 2020 05:05:38 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id y20so4794118wmi.2 for ; Thu, 11 Jun 2020 05:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U+Ejt/ZZl2KjNXrDFDrT2nFLvrKfgYWMA5ePRMfK+Ig=; b=OhUvZ+DwCgI3e2WqlkGHpMX31SyvgnFjlMC3ZPRTzJikuLKsYhA0lqBHl5vKnfnVjM dN2zOFvUW0GX6CAZhfACqN6Agz2SpWyJegbWAERTjpvQT3ziRb0n3dKET2JzzcqDdzWY ZdzQLNon8eeRIyYETA20JxKZkAkJq0uNQb7p0WO/Qlh1K7NrLQhpHuN8Qz9WAvjluGni DPjsn8gGBJEJNGGsz16I6/FPXwY0Ten1jS2sBijMusyfeqLxX98KRABdEeKHE1iWPkjf 5TtmTEieS1XzzMh9WJq6Twpv5wGg3UIhGreRBP4/JkZI55RTLDZbeYTl1Qi6XQ21r/ee SR4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U+Ejt/ZZl2KjNXrDFDrT2nFLvrKfgYWMA5ePRMfK+Ig=; b=Bsn4Szh20NVaZpk732HihiUC72zTFHnQsFzavdLh0JqKC2O0+kR1oKnNwuT7X/09BA JAu1it3OFVrJN/1LXCzSEXcjMIcAZYOOjcCGKTSvftfEG6VgpuxxvD0NvwCcHHSC7vaP +/iQt6s452SGfRZUGoXGzCyI8GQ/3bGdbAT0p7s3tsdNkW70FbTg8/asmh7jkipBe200 yjTRZzVnMmyztbTusuW8OGjSodsG7GvdpliI4KRFNSEWlYGCZplFwD+Ul7aDoRiwMuwU KmxOqyD5Fm3rzrbPFh/UVF+LUyrUcm9pu/plCpfFQvj0Tn8PBp4uCZ6zaa+7CaHqugId RkAA== X-Gm-Message-State: AOAM532gMMfNJC303s/wWz43APtfH7BR7rSlCB5Ua/6bTaS2GUHLhTDb HnAIX+yhSPC9D7nPhlxixAj3hp7tMlY= X-Google-Smtp-Source: ABdhPJwbDQDqjVh8AsoJ9LQLH5kJNQyYhO/WE1uWzfixFSGQC9Y4peBMh0nIqbhPySMsuavkKIUyQQ== X-Received: by 2002:a7b:cbd9:: with SMTP id n25mr7841963wmi.30.1591877136650; Thu, 11 Jun 2020 05:05:36 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:36 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 03/14] upload-pack: pass upload_pack_data to deepen_by_rev_list() Date: Thu, 11 Jun 2020 14:05:07 +0200 Message-Id: <20200611120518.10771-4-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to deepen_by_rev_list(), so that this function can use all the fields of the struct. This will be used in followup commits to move static variables into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 3f15828fd2..aa8cde6dbf 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -792,18 +792,17 @@ static void deepen(struct upload_pack_data *data, int depth) send_unshallow(&data->writer, &data->shallows, &data->want_obj); } -static void deepen_by_rev_list(struct packet_writer *writer, int ac, - const char **av, - struct object_array *shallows, - struct object_array *want_obj) +static void deepen_by_rev_list(struct upload_pack_data *data, + int ac, + const char **av) { struct commit_list *result; disable_commit_graph(the_repository); result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); - send_shallow(writer, result); + send_shallow(&data->writer, result); free_commit_list(result); - send_unshallow(writer, shallows, want_obj); + send_unshallow(&data->writer, &data->shallows, &data->want_obj); } /* Returns 1 if a shallow list is sent or 0 otherwise */ @@ -835,8 +834,7 @@ static int send_shallow_list(struct upload_pack_data *data) struct object *o = data->want_obj.objects[i].item; argv_array_push(&av, oid_to_hex(&o->oid)); } - deepen_by_rev_list(&data->writer, av.argc, av.argv, - &data->shallows, &data->want_obj); + deepen_by_rev_list(data, av.argc, av.argv); argv_array_clear(&av); ret = 1; } else { From patchwork Thu Jun 11 12:05:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2B7F159A for ; Thu, 11 Jun 2020 12:05:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A471F20760 for ; Thu, 11 Jun 2020 12:05:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gKYfAbjc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728010AbgFKMFm (ORCPT ); Thu, 11 Jun 2020 08:05:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727979AbgFKMFk (ORCPT ); Thu, 11 Jun 2020 08:05:40 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1128C08C5C3 for ; Thu, 11 Jun 2020 05:05:39 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id r15so4790078wmh.5 for ; Thu, 11 Jun 2020 05:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZpoYXp44avpR1ovbikkhbHProtxbWL0REBJrEQezDM0=; b=gKYfAbjcTfoyMTS55wjdiYigimR+mMSOB3QmiARbgO9IIlSc4c1swafC2yeLCu9Mfg AY0Z+769Ys0KzAWSSGz6F/qL9TLiFY8rri2kI0pra97Q+Zg5COHImSUwg12RaUyTNjuI HbJr9I5fCUtrUa911BJZzurjEyFF5MKFUR6RYIShA8Q3g4s2a3/lLrbmA8l1CG5RO6J5 vxQ9gPNwbfp1Es1oy366ev+40SjhUNFjqSWJbRWw1biOjlZhBJ7KC+JfJPfQXXqw42KT sNlNiH9w3KQoBUe6V2S3wu/nvMKojz4L3PxyuvJjoDFNUMvtQbITAuAnHasy/hsNo72q GsGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZpoYXp44avpR1ovbikkhbHProtxbWL0REBJrEQezDM0=; b=G50ostAITVQfM0JuK0URk4xfVZjzP4sINc5jHXaSnOKfdCphqWNSyVJQbBWN3AlR0z eRdGGKtNEcSWJbCjd2zgqjM5OYs504WsfJp8yuEtHW5knJhJI6mBfnkYhPqYYw2TMuq3 07KreGqmOZYkXGfc/n4M5+SjNvNtTShAxp8aW/fHhvo1DI9AQHZdmuZUe5MSQxYstvkG 3G2SKpmMg0SAF+HO0dU4lmzDebwa+flG9WpaZJxSOqnB/Uf8OpPB8SK5gGJSkJiaEX2k vPVLOXhcaWfwq+wksH7Zp84fN9/e6YdRl6qW8r1y7Gw9IcSo79ep6XPAnOrlArRFMvKu pp5w== X-Gm-Message-State: AOAM532yFEbQM+p7ObIh2qhsSOKI982NuaKFsRSWE54mk1maQIT8e9iI uVDH9mCiGP/nSQCjp2ACWZdg8o54aa0= X-Google-Smtp-Source: ABdhPJy6AU0ppVdDJNML9INF9ZZiukov3hDry2QtYqcj2scoq3blBVykwL5f/CRAHCSxT+WyCuEcrw== X-Received: by 2002:a7b:cf31:: with SMTP id m17mr7449910wmg.47.1591877138108; Thu, 11 Jun 2020 05:05:38 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:37 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 04/14] upload-pack: pass upload_pack_data to send_unshallow() Date: Thu, 11 Jun 2020 14:05:08 +0200 Message-Id: <20200611120518.10771-5-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to send_unshallow(), so that this function can use all the fields of the struct. This will be used in followup commits to move static variables into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index aa8cde6dbf..3b4749d120 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -715,17 +715,15 @@ static void send_shallow(struct packet_writer *writer, } } -static void send_unshallow(struct packet_writer *writer, - const struct object_array *shallows, - struct object_array *want_obj) +static void send_unshallow(struct upload_pack_data *data) { int i; - for (i = 0; i < shallows->nr; i++) { - struct object *object = shallows->objects[i].item; + for (i = 0; i < data->shallows.nr; i++) { + struct object *object = data->shallows.objects[i].item; if (object->flags & NOT_SHALLOW) { struct commit_list *parents; - packet_writer_write(writer, "unshallow %s", + packet_writer_write(&data->writer, "unshallow %s", oid_to_hex(&object->oid)); object->flags &= ~CLIENT_SHALLOW; /* @@ -741,7 +739,7 @@ static void send_unshallow(struct packet_writer *writer, parents = ((struct commit *)object)->parents; while (parents) { add_object_array(&parents->item->object, - NULL, want_obj); + NULL, &data->want_obj); parents = parents->next; } add_object_array(object, NULL, &extra_edge_obj); @@ -789,7 +787,7 @@ static void deepen(struct upload_pack_data *data, int depth) free_commit_list(result); } - send_unshallow(&data->writer, &data->shallows, &data->want_obj); + send_unshallow(data); } static void deepen_by_rev_list(struct upload_pack_data *data, @@ -802,7 +800,7 @@ static void deepen_by_rev_list(struct upload_pack_data *data, result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); send_shallow(&data->writer, result); free_commit_list(result); - send_unshallow(&data->writer, &data->shallows, &data->want_obj); + send_unshallow(data); } /* Returns 1 if a shallow list is sent or 0 otherwise */ From patchwork Thu Jun 11 12:05:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A064913B1 for ; Thu, 11 Jun 2020 12:05:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 889672078D for ; Thu, 11 Jun 2020 12:05:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZR8orlGa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728031AbgFKMFq (ORCPT ); Thu, 11 Jun 2020 08:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbgFKMFl (ORCPT ); Thu, 11 Jun 2020 08:05:41 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57A56C08C5C4 for ; Thu, 11 Jun 2020 05:05:41 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id r15so4790174wmh.5 for ; Thu, 11 Jun 2020 05:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x7+bNtX6SO0pt0Erto7KC294bramb5v5kH/PlTrfA4Y=; b=ZR8orlGa9+g8jj2OfxUvEtbXTgH3ashfSBrb7AjnZ+j1sUHy+MdSXU4VmHCYX1TEy0 DHmYHsPB7RtF2x/EGLkR4yJWbQDjomk6LZMeINcjb1nae6fqvtGyEWWxDh/ZBIjZKJeI x5fBjhzxx/ahBg49srkqcvZrzkbD1o8U5Sx6KYixGNa3ogtHDZ84yMnmtdU8zhhV8HEk IXraPXHqM+0nM5pKdaXRBQ/v2gC0s4CuXvxv7KRy9GxmDoVFEJQh4Hshih7PX96Kl4Ky BQo6HqQcQ/OeupUVgi17rIlMas/GV0zoP9PGrmZmRE5N0Huh9TgrPnN+iak8J+wTEUG8 j8XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x7+bNtX6SO0pt0Erto7KC294bramb5v5kH/PlTrfA4Y=; b=LCaMRwJEvqtVbCPRV+W8d0u3fvoD+EZoZJo2M8HgLQdmO9pVIi6T4IomTHGQ5K4ogK u4N/DwAIYdupYtvFU0NDWY4/EXZobnX+jBsO5o33FbPV0puYikF32N1A8B7At4h26CAV GveqmuoEwHQpJoS+EdGCA0k/n4XPJ93v9gV/HicVwsyBaCMrEMtKDVqtNf+btWJ3E+R2 D4OBrnstNaV3m9qi7iz52NM0XeN1PmuI+Yslfrav0+wuPxg8FUvN9K1VuCeGelUQ5QsA LEEOL0y2BITP4vwppMc7QvMeikXS8LxE4n6pYFGaQzYJA4UsMbD9XU/AU8vNqz2hdRAU ueAA== X-Gm-Message-State: AOAM531s0qnD+ZEpaUACC/7uqmX29iHeaNIu393FaO/ArtwzgViaGpvu PSb9IVVwODV+V9fhLi9tV99KpJQzysY= X-Google-Smtp-Source: ABdhPJzc+Ns3xP2uOdF+SvUMoJ5foTHU6p2LtgOBgh8NP9iEdVbjAPzT3KPWNfBFsPEVDbdYg86Qrw== X-Received: by 2002:a7b:c2a9:: with SMTP id c9mr7394016wmk.11.1591877139692; Thu, 11 Jun 2020 05:05:39 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:39 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 05/14] upload-pack: move shallow_nr to upload_pack_data Date: Thu, 11 Jun 2020 14:05:09 +0200 Message-Id: <20200611120518.10771-6-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the 'shallow_nr' static variable into this struct. It is used by code common to protocol v0 and protocol v2. Signed-off-by: Christian Couder --- upload-pack.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 3b4749d120..d00a8d6b77 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -51,7 +51,6 @@ static timestamp_t oldest_have; /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ #define ALLOW_ANY_SHA1 07 static unsigned int allow_unadvertised_object_request; -static int shallow_nr; static struct object_array extra_edge_obj; /* @@ -72,6 +71,7 @@ struct upload_pack_data { int deepen_rev_list; int deepen_relative; int keepalive; + int shallow_nr; unsigned int timeout; /* v0 only */ enum { @@ -192,7 +192,7 @@ static void create_pack_file(struct upload_pack_data *pack_data) pack_objects.use_shell = 1; } - if (shallow_nr) { + if (pack_data->shallow_nr) { argv_array_push(&pack_objects.args, "--shallow-file"); argv_array_push(&pack_objects.args, ""); } @@ -202,7 +202,7 @@ static void create_pack_file(struct upload_pack_data *pack_data) argv_array_push(&pack_objects.args, "--thin"); argv_array_push(&pack_objects.args, "--stdout"); - if (shallow_nr) + if (pack_data->shallow_nr) argv_array_push(&pack_objects.args, "--shallow"); if (!pack_data->no_progress) argv_array_push(&pack_objects.args, "--progress"); @@ -233,7 +233,7 @@ static void create_pack_file(struct upload_pack_data *pack_data) pipe_fd = xfdopen(pack_objects.in, "w"); - if (shallow_nr) + if (pack_data->shallow_nr) for_each_commit_graft(write_one_shallow, pipe_fd); for (i = 0; i < pack_data->want_obj.nr; i++) @@ -700,16 +700,16 @@ static void check_non_tip(struct upload_pack_data *data) } } -static void send_shallow(struct packet_writer *writer, +static void send_shallow(struct upload_pack_data *data, struct commit_list *result) { while (result) { struct object *object = &result->item->object; if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) { - packet_writer_write(writer, "shallow %s", + packet_writer_write(&data->writer, "shallow %s", oid_to_hex(&object->oid)); register_shallow(the_repository, &object->oid); - shallow_nr++; + data->shallow_nr++; } result = result->next; } @@ -775,7 +775,7 @@ static void deepen(struct upload_pack_data *data, int depth) result = get_shallow_commits(&reachable_shallows, depth + 1, SHALLOW, NOT_SHALLOW); - send_shallow(&data->writer, result); + send_shallow(data, result); free_commit_list(result); object_array_clear(&reachable_shallows); } else { @@ -783,7 +783,7 @@ static void deepen(struct upload_pack_data *data, int depth) result = get_shallow_commits(&data->want_obj, depth, SHALLOW, NOT_SHALLOW); - send_shallow(&data->writer, result); + send_shallow(data, result); free_commit_list(result); } @@ -798,7 +798,7 @@ static void deepen_by_rev_list(struct upload_pack_data *data, disable_commit_graph(the_repository); result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); - send_shallow(&data->writer, result); + send_shallow(data, result); free_commit_list(result); send_unshallow(data); } @@ -844,7 +844,7 @@ static int send_shallow_list(struct upload_pack_data *data) } } - shallow_nr += data->shallows.nr; + data->shallow_nr += data->shallows.nr; return ret; } @@ -922,7 +922,7 @@ static void receive_needs(struct upload_pack_data *data, { int has_non_tip = 0; - shallow_nr = 0; + data->shallow_nr = 0; for (;;) { struct object *o; const char *features; From patchwork Thu Jun 11 12:05:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94325159A for ; Thu, 11 Jun 2020 12:05:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B762207C3 for ; Thu, 11 Jun 2020 12:05:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vu4217Ae" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727849AbgFKMFx (ORCPT ); Thu, 11 Jun 2020 08:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727979AbgFKMFo (ORCPT ); Thu, 11 Jun 2020 08:05:44 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2C81C08C5C1 for ; Thu, 11 Jun 2020 05:05:42 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id k26so4787739wmi.4 for ; Thu, 11 Jun 2020 05:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CBkoA5bP9U4k1FkqEJXWUd6cIv4gdRbSUWXRIUOZTLA=; b=Vu4217AegXEfI1oG6XhZA90mXB0sCZpPLhxsfEHtazLdLsAHLAm5NyX2J7xfEdDQIT TmUgENtvgvunxfxoAyBbN4ar0FEbOWCKlAFn/xOqDJB/Em72h8eLeClTUo1Izt8MGeDl fJTWoRzVtUifCh+wZnLeqkXjBlfBc7JuA2y2xyccG0axoEAcjYLrkbkkJ4UQRggAfG3n oY7tzEBRE8L7BDgxEURuyEofM3MmxXDVB9Habja7nxGYfUgf2sco24gClU1B2tPowrXZ JLzSkOIpw85HDT4XRYdqRzH8QshikEK1ClDMM+kJeKytw8wUx15LqdW9J1B6hgtelEZd BfDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CBkoA5bP9U4k1FkqEJXWUd6cIv4gdRbSUWXRIUOZTLA=; b=WwDZoUwGKdjiiaSwjT75D0LlsPtFdi4tcCJUNskjceWW2Afp5s/ItWiNGGCVGYKrD5 P63pwSaUpOZjElE7OyfC2f5vnAcT/oaa/N7yYYANWXcQ4+9pKG3agB4GuInCTAedXnox qIY89XqKXIBntos3Ix1d0V6zOhUuzIzeu2bPxbZsgjTuPh+5XF7Wfl1EsiSjTB4uGoXZ nwJD+82pj/XfpXcOA0VfPlp4qbzuM8CK9kQEYTdDgpmkAafwRfKXsTTVPDQZ3VUBcVsc dF0r5cHOx+r2PtmuJRFbQIqkYDe/+8sTRJ4m3LmFLJSNezda+Pq+/Nq2zjksBkKJBf6b 1idA== X-Gm-Message-State: AOAM5327QomVlXRcCjOm2azrVc+lqbbReZHm7C9FWl/f7OhBapaxO3EZ WDgNU8v8i70aenD5z7WjorQTGjzl10U= X-Google-Smtp-Source: ABdhPJyp1OVA8hwIz+v9f1+xDAEQQ4cNPETD3xiLtDZ5jhOSEa+YeO85ZQ5LtBQajvrYbGPagdeM9A== X-Received: by 2002:a7b:cf35:: with SMTP id m21mr8176390wmg.181.1591877140999; Thu, 11 Jun 2020 05:05:40 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:40 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 06/14] upload-pack: move extra_edge_obj to upload_pack_data Date: Thu, 11 Jun 2020 14:05:10 +0200 Message-Id: <20200611120518.10771-7-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the 'extra_edge_obj' static variable into this struct. It is used by code common to protocol v0 and protocol v2. While at it let's properly initialize and clear 'extra_edge_obj' in the appropriate 'upload_pack_data' initialization and clearing functions. Signed-off-by: Christian Couder --- upload-pack.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index d00a8d6b77..acddfe28d6 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -51,7 +51,6 @@ static timestamp_t oldest_have; /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ #define ALLOW_ANY_SHA1 07 static unsigned int allow_unadvertised_object_request; -static struct object_array extra_edge_obj; /* * Please annotate, and if possible group together, fields used only @@ -66,6 +65,7 @@ struct upload_pack_data { struct object_array shallows; struct string_list deepen_not; + struct object_array extra_edge_obj; int depth; timestamp_t deepen_since; int deepen_rev_list; @@ -114,6 +114,7 @@ static void upload_pack_data_init(struct upload_pack_data *data) struct oid_array haves = OID_ARRAY_INIT; struct object_array shallows = OBJECT_ARRAY_INIT; struct string_list deepen_not = STRING_LIST_INIT_DUP; + struct object_array extra_edge_obj = OBJECT_ARRAY_INIT; memset(data, 0, sizeof(*data)); data->symref = symref; @@ -123,6 +124,7 @@ static void upload_pack_data_init(struct upload_pack_data *data) data->haves = haves; data->shallows = shallows; data->deepen_not = deepen_not; + data->extra_edge_obj = extra_edge_obj; packet_writer_init(&data->writer, 1); data->keepalive = 5; @@ -137,6 +139,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data) oid_array_clear(&data->haves); object_array_clear(&data->shallows); string_list_clear(&data->deepen_not, 0); + object_array_clear(&data->extra_edge_obj); list_objects_filter_release(&data->filter_options); free((char *)data->pack_objects_hook); @@ -243,9 +246,9 @@ static void create_pack_file(struct upload_pack_data *pack_data) for (i = 0; i < pack_data->have_obj.nr; i++) fprintf(pipe_fd, "%s\n", oid_to_hex(&pack_data->have_obj.objects[i].item->oid)); - for (i = 0; i < extra_edge_obj.nr; i++) + for (i = 0; i < pack_data->extra_edge_obj.nr; i++) fprintf(pipe_fd, "%s\n", - oid_to_hex(&extra_edge_obj.objects[i].item->oid)); + oid_to_hex(&pack_data->extra_edge_obj.objects[i].item->oid)); fprintf(pipe_fd, "\n"); fflush(pipe_fd); fclose(pipe_fd); @@ -742,7 +745,7 @@ static void send_unshallow(struct upload_pack_data *data) NULL, &data->want_obj); parents = parents->next; } - add_object_array(object, NULL, &extra_edge_obj); + add_object_array(object, NULL, &data->extra_edge_obj); } /* make sure commit traversal conforms to client */ register_shallow(the_repository, &object->oid); From patchwork Thu Jun 11 12:05:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F179159A for ; Thu, 11 Jun 2020 12:05:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AC082078D for ; Thu, 11 Jun 2020 12:05:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N7Vbu7jS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728013AbgFKMFt (ORCPT ); Thu, 11 Jun 2020 08:05:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728027AbgFKMFp (ORCPT ); Thu, 11 Jun 2020 08:05:45 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20005C08C5C3 for ; Thu, 11 Jun 2020 05:05:45 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id l26so4742456wme.3 for ; Thu, 11 Jun 2020 05:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AjtFMT5xPjzuul5HDYktJ5Bp59qGVX8BGmNsrPxRMQE=; b=N7Vbu7jSvAhwpXH8zDSTRDhryLcSTgHryqq/5yP9ffIKjHBb1VHwo7E9/bZ6VlQVz9 +DYHeMMwUiPPPUkxdCQBFfo++t4tSqDWQ0npK7Ubv6utkFQNMnMkGD4lFt9NUYupcTn8 TM/2Z1q80PP0c+5zqTKg80GaGtZz4hu2/xSEQqxJav1j/dk+QpdXg12yMhaf5a8xenXV 3sWl/tc0tIDARB4chZSRFqx+eDlh8v1okLbld2gZMwCzVKUPhz0+IZ+CcmgLv8lW16a0 urt4KGjPkjLyUtmkB+30DI3CWe2XWTcaNxE5cGAvEb2+8OApdYBfXAgdWkeiq3rZOaCD Qqng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AjtFMT5xPjzuul5HDYktJ5Bp59qGVX8BGmNsrPxRMQE=; b=k3BhXYkStQ8EwtPE1eWzVcTUQD5MN4NgVrm03tkd1hme0sRp6nNpQfQPSECIVPc2wz rf3i2E5gFYIp+H+WrguQ8AgAfdCkFqaJk1nmetlk5F7S/LtGVfLpdkmKB46GYrW/2HtW QQsjYRjVwUgpL56GdRSuZGr5ExpPTCKa2mp21K3FAYtQiOKlMMbmnpq3E9t6MSB7elim dkqp0o5IHTASSgf0nvUPOzRvgiP7afA7D7Tx6Vc0h/WTTgoQFNKNTqHznN2by/Niwboh rGWzO/ps8qAbJyLnCvu5i42MQ46ToUvx6VSzcurYXmQcCMQ1VQPp6P5R5l/K2pa6zG5P apYw== X-Gm-Message-State: AOAM530/KCjR2eeFhGLOThXmwQKlMKdbob9QNwkvK3c1hn84eDxzqufI MUednZy4gubQYjE8oW4vPao019YwPL4= X-Google-Smtp-Source: ABdhPJzADuteSlGCizjDKw/8h9/6P0ZuyKb8BS77Sx43YYOn+kT3XG5zYpq7ykljeVg8tSzoFEgB8g== X-Received: by 2002:a1c:2d83:: with SMTP id t125mr8176293wmt.187.1591877142898; Thu, 11 Jun 2020 05:05:42 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:42 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 07/14] upload-pack: move allow_unadvertised_object_request to upload_pack_data Date: Thu, 11 Jun 2020 14:05:11 +0200 Message-Id: <20200611120518.10771-8-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the 'allow_unadvertised_object_request' static variable into this struct. It is used by code common to protocol v0 and protocol v2. Signed-off-by: Christian Couder --- upload-pack.c | 55 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index acddfe28d6..5cd1342f62 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -44,13 +44,13 @@ static timestamp_t oldest_have; +/* Values for allow_unadvertised_object_request flags */ /* Allow specifying sha1 if it is a ref tip. */ #define ALLOW_TIP_SHA1 01 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */ #define ALLOW_REACHABLE_SHA1 02 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ #define ALLOW_ANY_SHA1 07 -static unsigned int allow_unadvertised_object_request; /* * Please annotate, and if possible group together, fields used only @@ -83,6 +83,9 @@ struct upload_pack_data { /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */ int use_sideband; + /* See ALLOW_* values defined above */ + unsigned int allow_unadvertised_object_request; + struct list_objects_filter_options filter_options; struct packet_writer writer; @@ -514,7 +517,8 @@ static int get_common_commits(struct upload_pack_data *data, } } -static int is_our_ref(struct object *o) +static int is_our_ref(struct object *o, + unsigned int allow_unadvertised_object_request) { int allow_hidden_ref = (allow_unadvertised_object_request & (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); @@ -526,7 +530,8 @@ static int is_our_ref(struct object *o) */ static int do_reachable_revlist(struct child_process *cmd, struct object_array *src, - struct object_array *reachable) + struct object_array *reachable, + unsigned int allow_unadvertised_object_request) { static const char *argv[] = { "rev-list", "--stdin", NULL, @@ -560,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd, continue; if (reachable && o->type == OBJ_COMMIT) o->flags &= ~TMP_MARK; - if (!is_our_ref(o)) + if (!is_our_ref(o, allow_unadvertised_object_request)) continue; memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz); if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0) @@ -569,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd, namebuf[hexsz] = '\n'; for (i = 0; i < src->nr; i++) { o = src->objects[i].item; - if (is_our_ref(o)) { + if (is_our_ref(o, allow_unadvertised_object_request)) { if (reachable) add_object_array(o, NULL, reachable); continue; @@ -596,7 +601,7 @@ static int do_reachable_revlist(struct child_process *cmd, return -1; } -static int get_reachable_list(struct object_array *src, +static int get_reachable_list(struct upload_pack_data *data, struct object_array *reachable) { struct child_process cmd = CHILD_PROCESS_INIT; @@ -605,7 +610,8 @@ static int get_reachable_list(struct object_array *src, char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ const unsigned hexsz = the_hash_algo->hexsz; - if (do_reachable_revlist(&cmd, src, reachable) < 0) + if (do_reachable_revlist(&cmd, &data->shallows, reachable, + data->allow_unadvertised_object_request) < 0) return -1; while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) { @@ -636,13 +642,15 @@ static int get_reachable_list(struct object_array *src, return 0; } -static int has_unreachable(struct object_array *src) +static int has_unreachable(struct object_array *src, + unsigned int allow_unadvertised_object_request) { struct child_process cmd = CHILD_PROCESS_INIT; char buf[1]; int i; - if (do_reachable_revlist(&cmd, src, NULL) < 0) + if (do_reachable_revlist(&cmd, src, NULL, + allow_unadvertised_object_request) < 0) return 1; /* @@ -683,9 +691,10 @@ static void check_non_tip(struct upload_pack_data *data) * non-tip requests can never happen. */ if (!data->stateless_rpc - && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1)) + && !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1)) goto error; - if (!has_unreachable(&data->want_obj)) + if (!has_unreachable(&data->want_obj, + data->allow_unadvertised_object_request)) /* All the non-tip ones are ancestors of what we advertised */ return; @@ -693,7 +702,7 @@ static void check_non_tip(struct upload_pack_data *data) /* Pick one of them (we know there at least is one) */ for (i = 0; i < data->want_obj.nr; i++) { struct object *o = data->want_obj.objects[i].item; - if (!is_our_ref(o)) { + if (!is_our_ref(o, data->allow_unadvertised_object_request)) { packet_writer_error(&data->writer, "upload-pack: not our ref %s", oid_to_hex(&o->oid)); @@ -774,7 +783,7 @@ static void deepen(struct upload_pack_data *data, int depth) head_ref_namespaced(check_ref, NULL); for_each_namespaced_ref(check_ref, NULL); - get_reachable_list(&data->shallows, &reachable_shallows); + get_reachable_list(data, &reachable_shallows); result = get_shallow_commits(&reachable_shallows, depth + 1, SHALLOW, NOT_SHALLOW); @@ -992,8 +1001,8 @@ static void receive_needs(struct upload_pack_data *data, } if (!(o->flags & WANTED)) { o->flags |= WANTED; - if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 - || is_our_ref(o))) + if (!((data->allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 + || is_our_ref(o, data->allow_unadvertised_object_request))) has_non_tip = 1; add_object_array(o, NULL, &data->want_obj); } @@ -1072,9 +1081,9 @@ static int send_ref(const char *refname, const struct object_id *oid, packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n", oid_to_hex(oid), refname_nons, 0, capabilities, - (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ? + (data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ? " allow-tip-sha1-in-want" : "", - (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ? + (data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ? " allow-reachable-sha1-in-want" : "", data->stateless_rpc ? " no-done" : "", symref_info.buf, @@ -1112,19 +1121,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data) if (!strcmp("uploadpack.allowtipsha1inwant", var)) { if (git_config_bool(var, value)) - allow_unadvertised_object_request |= ALLOW_TIP_SHA1; + data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1; else - allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1; + data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1; } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) { if (git_config_bool(var, value)) - allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; + data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; else - allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1; + data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1; } else if (!strcmp("uploadpack.allowanysha1inwant", var)) { if (git_config_bool(var, value)) - allow_unadvertised_object_request |= ALLOW_ANY_SHA1; + data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1; else - allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1; + data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1; } else if (!strcmp("uploadpack.keepalive", var)) { data->keepalive = git_config_int(var, value); if (!data->keepalive) From patchwork Thu Jun 11 12:05:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 782F9159A for ; Thu, 11 Jun 2020 12:05:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59C65207ED for ; Thu, 11 Jun 2020 12:05:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="roY1HaEi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728050AbgFKMFu (ORCPT ); Thu, 11 Jun 2020 08:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbgFKMFr (ORCPT ); Thu, 11 Jun 2020 08:05:47 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E372C08C5C1 for ; Thu, 11 Jun 2020 05:05:46 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id e1so5888529wrt.5 for ; Thu, 11 Jun 2020 05:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XVwia3sigb5Wo8L5lvGQ0V2KBptthOaQFfQdxux7OHc=; b=roY1HaEiMNddhl3A4kxVtel3czQ0dhLg1pisU4/Njyv7eHEjJSvJlr1tl9WSxFdGvu np6CAyAcy9LQE3IRO5WKGrZc/B4axf1EUR1zgDROL1jXbbMSCj6BOXUCVvB6mM/cl6y0 75YGnKTp5qGWWzFy+q7SUDgw+HgQ+nRDGt7pmJGBOvyUs1vaBdkc1TQ3zJ4RvRLM1ryB d9GMvPki3SXEk7xm/rA7NGAaU2ZBKSPqFdZNk/nG1KmLMX1BPUBAuLo1/51r8z21zUGT qD1yDGjzyYpOCi4TTKJziqSzqsdb57aW/MbeKXGk47icE9QXgo/HSAuFKQOv2S+mGmW2 mC1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XVwia3sigb5Wo8L5lvGQ0V2KBptthOaQFfQdxux7OHc=; b=PdbRaMbTsNHZ/1Xx2003zH/BSUJiXgXauTN/ntGpcpM7L0KzRFiu8CpERuOp6a8nxd Br2wo1U8bRvny0JjFNYsF4oLY3RXwTLgAWmYhcFyzcXNCl//EhIK+l1mHwFideHIbY7p 1uUZSLWnYEFHUpL+rx3FfB+E5nGtyCXHvva+H3idu6vHdPs0z0AvRyhsj3mfd31bNBbm A0ctGsPPJ5VfQUn9Sh78BfUnnxb2BkjXQoi5Ey5wIwGZcgJa63M98FSYPOwLeqFeE1LN FcQAT+Fy75fmk0qowQ+haL1IZ4BHzrChFC1aqhtHBEAJRcq0HSx7yZMJ6lBC5r8it9Y2 dfHw== X-Gm-Message-State: AOAM5317AYs49OEdXfiYlzSHBrwJYFmwTtlPF0H4SyZVFAf1b1dPGttH yZS47Ao1wtXbuwyAfzW3ef582UKLYTI= X-Google-Smtp-Source: ABdhPJxuwXZbBMXodf1bZBsxX9qPC9bDDWmVWcYqSs6L4t0bjPP1GSE29KHnaU64mIZ5905Ni7mLlw== X-Received: by 2002:a5d:5006:: with SMTP id e6mr9713181wrt.170.1591877144607; Thu, 11 Jun 2020 05:05:44 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:43 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 08/14] upload-pack: change allow_unadvertised_object_request to an enum Date: Thu, 11 Jun 2020 14:05:12 +0200 Message-Id: <20200611120518.10771-9-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's change allow_unadvertised_object_request, which is now part of 'upload_pack_data', from an 'unsigned int' to an enum. This will make it clear which values this variable can take. While at it let's change this variable name to 'allow_uor' to make it shorter. Signed-off-by: Christian Couder --- upload-pack.c | 68 ++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 5cd1342f62..0b30794d91 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -44,13 +44,15 @@ static timestamp_t oldest_have; -/* Values for allow_unadvertised_object_request flags */ -/* Allow specifying sha1 if it is a ref tip. */ -#define ALLOW_TIP_SHA1 01 -/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */ -#define ALLOW_REACHABLE_SHA1 02 -/* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ -#define ALLOW_ANY_SHA1 07 +/* Enum for allowed unadvertised object request (UOR) */ +enum allow_uor { + /* Allow specifying sha1 if it is a ref tip. */ + ALLOW_TIP_SHA1 = 0x01, + /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */ + ALLOW_REACHABLE_SHA1 = 0x02, + /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ + ALLOW_ANY_SHA1 = 0x07 +}; /* * Please annotate, and if possible group together, fields used only @@ -83,8 +85,7 @@ struct upload_pack_data { /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */ int use_sideband; - /* See ALLOW_* values defined above */ - unsigned int allow_unadvertised_object_request; + enum allow_uor allow_uor; struct list_objects_filter_options filter_options; @@ -517,11 +518,10 @@ static int get_common_commits(struct upload_pack_data *data, } } -static int is_our_ref(struct object *o, - unsigned int allow_unadvertised_object_request) +static int is_our_ref(struct object *o, enum allow_uor allow_uor) { - int allow_hidden_ref = (allow_unadvertised_object_request & - (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); + int allow_hidden_ref = (allow_uor & + (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF); } @@ -531,7 +531,7 @@ static int is_our_ref(struct object *o, static int do_reachable_revlist(struct child_process *cmd, struct object_array *src, struct object_array *reachable, - unsigned int allow_unadvertised_object_request) + enum allow_uor allow_uor) { static const char *argv[] = { "rev-list", "--stdin", NULL, @@ -565,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd, continue; if (reachable && o->type == OBJ_COMMIT) o->flags &= ~TMP_MARK; - if (!is_our_ref(o, allow_unadvertised_object_request)) + if (!is_our_ref(o, allow_uor)) continue; memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz); if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0) @@ -574,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd, namebuf[hexsz] = '\n'; for (i = 0; i < src->nr; i++) { o = src->objects[i].item; - if (is_our_ref(o, allow_unadvertised_object_request)) { + if (is_our_ref(o, allow_uor)) { if (reachable) add_object_array(o, NULL, reachable); continue; @@ -611,7 +611,7 @@ static int get_reachable_list(struct upload_pack_data *data, const unsigned hexsz = the_hash_algo->hexsz; if (do_reachable_revlist(&cmd, &data->shallows, reachable, - data->allow_unadvertised_object_request) < 0) + data->allow_uor) < 0) return -1; while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) { @@ -642,15 +642,13 @@ static int get_reachable_list(struct upload_pack_data *data, return 0; } -static int has_unreachable(struct object_array *src, - unsigned int allow_unadvertised_object_request) +static int has_unreachable(struct object_array *src, enum allow_uor allow_uor) { struct child_process cmd = CHILD_PROCESS_INIT; char buf[1]; int i; - if (do_reachable_revlist(&cmd, src, NULL, - allow_unadvertised_object_request) < 0) + if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0) return 1; /* @@ -690,11 +688,9 @@ static void check_non_tip(struct upload_pack_data *data) * uploadpack.allowReachableSHA1InWant, * non-tip requests can never happen. */ - if (!data->stateless_rpc - && !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1)) + if (!data->stateless_rpc && !(data->allow_uor & ALLOW_REACHABLE_SHA1)) goto error; - if (!has_unreachable(&data->want_obj, - data->allow_unadvertised_object_request)) + if (!has_unreachable(&data->want_obj, data->allow_uor)) /* All the non-tip ones are ancestors of what we advertised */ return; @@ -702,7 +698,7 @@ static void check_non_tip(struct upload_pack_data *data) /* Pick one of them (we know there at least is one) */ for (i = 0; i < data->want_obj.nr; i++) { struct object *o = data->want_obj.objects[i].item; - if (!is_our_ref(o, data->allow_unadvertised_object_request)) { + if (!is_our_ref(o, data->allow_uor)) { packet_writer_error(&data->writer, "upload-pack: not our ref %s", oid_to_hex(&o->oid)); @@ -1001,8 +997,8 @@ static void receive_needs(struct upload_pack_data *data, } if (!(o->flags & WANTED)) { o->flags |= WANTED; - if (!((data->allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 - || is_our_ref(o, data->allow_unadvertised_object_request))) + if (!((data->allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 + || is_our_ref(o, data->allow_uor))) has_non_tip = 1; add_object_array(o, NULL, &data->want_obj); } @@ -1081,9 +1077,9 @@ static int send_ref(const char *refname, const struct object_id *oid, packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n", oid_to_hex(oid), refname_nons, 0, capabilities, - (data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ? + (data->allow_uor & ALLOW_TIP_SHA1) ? " allow-tip-sha1-in-want" : "", - (data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ? + (data->allow_uor & ALLOW_REACHABLE_SHA1) ? " allow-reachable-sha1-in-want" : "", data->stateless_rpc ? " no-done" : "", symref_info.buf, @@ -1121,19 +1117,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data) if (!strcmp("uploadpack.allowtipsha1inwant", var)) { if (git_config_bool(var, value)) - data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1; + data->allow_uor |= ALLOW_TIP_SHA1; else - data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1; + data->allow_uor &= ~ALLOW_TIP_SHA1; } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) { if (git_config_bool(var, value)) - data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; + data->allow_uor |= ALLOW_REACHABLE_SHA1; else - data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1; + data->allow_uor &= ~ALLOW_REACHABLE_SHA1; } else if (!strcmp("uploadpack.allowanysha1inwant", var)) { if (git_config_bool(var, value)) - data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1; + data->allow_uor |= ALLOW_ANY_SHA1; else - data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1; + data->allow_uor &= ~ALLOW_ANY_SHA1; } else if (!strcmp("uploadpack.keepalive", var)) { data->keepalive = git_config_int(var, value); if (!data->keepalive) From patchwork Thu Jun 11 12:05:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599863 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 210041667 for ; Thu, 11 Jun 2020 12:06:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05309207C3 for ; Thu, 11 Jun 2020 12:06:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SAhewm8N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728062AbgFKMF4 (ORCPT ); Thu, 11 Jun 2020 08:05:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728039AbgFKMFs (ORCPT ); Thu, 11 Jun 2020 08:05:48 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B61C8C08C5C1 for ; Thu, 11 Jun 2020 05:05:47 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x13so5894951wrv.4 for ; Thu, 11 Jun 2020 05:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R2ynU3cvIOZRETshm7q92+Ucq6MT4ZzQrbrUH0tWK5U=; b=SAhewm8Nc5efO9Kt+6658NVfKQ75kbDTRFoWPWwTQBHTiFc9PPuZlQVCpeS2i27oBB LILHKbpoOHxVSYe/XBFgwZzDWJUKk9hdUYNkjms7ZYce9CFUC+eHdZqcPlT/zQa7y1F4 TRqMZdDhnDSDjUWnbWLGHFVdmgrpvtiujWw0Fw+1a+B56JNtHabkn4ahpNUtlUbhMnHG t2knSUNj7LfGLyuL0AAhmWiiykfnxIrgWCR4FqODiUI1abwrBC+btFrfgb68boh5cu28 Jz7xQPatXcgU7vsvTpFxSoENZyzkfrIpqUrgbEX9cf31nzsW6EHT6+5OWP/yh4QCHgUn y1iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R2ynU3cvIOZRETshm7q92+Ucq6MT4ZzQrbrUH0tWK5U=; b=eHiY5CV3/aE91gTVcuad+l65sMM4DNEBeWOxO0rTqu7fswHKrB9bScpWGhNZ7bSAGw Xk1VWyEMC6gwbw3CrqdEM7kZJvIyhfq/BnVh/xsRnlv/erev6DL3bWsQb8LNCzzDLOME 9mN2VIwhCfO3Fk406O0vXkD0pAV5YqV8eVWrD4VS8Bfbv0q2BrrJqZuKMszxcHruGJqQ p8P5Px+EE+VNVDVXdEVOCt40DZfP0Z3kFb3M4SxnsAHJHplrb9DnJMm8hBWVbHG53JEK uCHQU1XHPU7FwVCOQ1UWbSaVBScf+A4A0u3hScOBtg+hqfDXi1I1qccABe0NwhTCkd2P O5/A== X-Gm-Message-State: AOAM530QO6fLfGkNtY4/BXj+8/QlP8rI1EvdEQIcny4uYlaFIiaPRWm6 ehFrV21CHT281TzxQ2Wt5vXw6IzRUC0= X-Google-Smtp-Source: ABdhPJx3K0fV8at82eDgORK9SklCUT3YL9k1km57qTk/kBojjT7vUKr859h0aynhZHTgh26o30S5LA== X-Received: by 2002:adf:9c12:: with SMTP id f18mr9910362wrc.105.1591877146123; Thu, 11 Jun 2020 05:05:46 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:45 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 09/14] upload-pack: pass upload_pack_data to process_haves() Date: Thu, 11 Jun 2020 14:05:13 +0200 Message-Id: <20200611120518.10771-10-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to process_haves(), so that this function can use all the fields of the struct. This will be used in followup commits to move a static variable into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 0b30794d91..b20600fceb 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1348,14 +1348,13 @@ static void process_args(struct packet_reader *request, die(_("expected flush after fetch arguments")); } -static int process_haves(struct oid_array *haves, struct oid_array *common, - struct object_array *have_obj) +static int process_haves(struct upload_pack_data *data, struct oid_array *common) { int i; /* Process haves */ - for (i = 0; i < haves->nr; i++) { - const struct object_id *oid = &haves->oid[i]; + 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; @@ -1382,7 +1381,7 @@ static int process_haves(struct oid_array *haves, struct oid_array *common, parents->item->object.flags |= THEY_HAVE; } if (!we_knew_they_have) - add_object_array(o, NULL, have_obj); + add_object_array(o, NULL, &data->have_obj); } return 0; @@ -1419,7 +1418,7 @@ static int process_haves_and_send_acks(struct upload_pack_data *data) struct oid_array common = OID_ARRAY_INIT; int ret = 0; - process_haves(&data->haves, &common, &data->have_obj); + process_haves(data, &common); if (data->done) { ret = 1; } else if (send_acks(&data->writer, &common, From patchwork Thu Jun 11 12:05:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 097F4159A for ; Thu, 11 Jun 2020 12:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2B22207C3 for ; Thu, 11 Jun 2020 12:05:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GCe0mPJw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728066AbgFKMF5 (ORCPT ); Thu, 11 Jun 2020 08:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728045AbgFKMFt (ORCPT ); Thu, 11 Jun 2020 08:05:49 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61BC5C08C5C2 for ; Thu, 11 Jun 2020 05:05:49 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c3so5856494wru.12 for ; Thu, 11 Jun 2020 05:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VVL+VZ9daRjfPSOUsTO3BXrEhhb/3hvEgqsE2NY9l+w=; b=GCe0mPJwhjLMFVOMVjKZJ+WIYLlCBgKUUzcfu9DAG+oCPTwI7qUivse+z0eMPlUmBa TwJ2NKfXxUgxb0L1UiZS6AZaNshkZEf1RfXb6EKBLHvPzdM+dIHEMSaJ94uZ0FomIKj4 wXtp2G58mzwoq3YPOJD8fw75bGUGikiczHQy8Igrx+hAe+HOPALyN/YRBkFU8BsZUgRn Uk6TCDTNg1cal4ACixWPPsu4Tuyb+W5hBHxi1iY3fiLrNvnDDILk9rqL54B/UpUzPBgo IXINDjpwznkXWRM8Z/t2Kz2dAPRiK43PRLcLp2yVMGHM6r+ha8NJ6TL4YOuM4sZ9JZoA Il5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VVL+VZ9daRjfPSOUsTO3BXrEhhb/3hvEgqsE2NY9l+w=; b=t9f7KnFJlP/huTDk7L1hxCMUXV7Kc5E5kvUjKnaoVXFajH0H2S+ObdL3aTy23CZUTX cghsu5M8/E+fCh5y/GtDPu5NeJVYG5YydLhyknNInHjBL9K5r10ZSqg7QvQDFAGLC8xk PBUbqxubKA7dvJ+AepXBPHWaiTyXt46l+vK/mGnRpqp/baCtgVYf7XhvVdq+WJUAg2qA MEO5a+UQxm0Aae7Kte+F2MyHeH3VKF7hzBrluRCTt59KW6Lip1bMCzAtzMzlhvd4U616 Yu7gbIeW3FoJM7ycjuqSh07+tqdsNgX3BBcY7sMdT0+VqhbIkaMc3qUuwdeH39yEQfw3 iarw== X-Gm-Message-State: AOAM533gKHIMf0XBfp/uk4flHhgqugC3uQko5gtauPsbLXPJmbTh+h/n Lgf4+OOl+JcSdm+i7dOtwY7GiJejNis= X-Google-Smtp-Source: ABdhPJxQEkAhkvZUOUssJyAd3cScHCVTmdSjYXYh1qDInsUlp2rX0rz2k7N7fImJeZ0E8X8fKhHePw== X-Received: by 2002:adf:fec8:: with SMTP id q8mr9587464wrs.2.1591877147751; Thu, 11 Jun 2020 05:05:47 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:47 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 10/14] upload-pack: pass upload_pack_data to send_acks() Date: Thu, 11 Jun 2020 14:05:14 +0200 Message-Id: <20200611120518.10771-11-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to send_acks(), so that this function can use all the fields of the struct. This will be used in followup commits to move a static variable into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index b20600fceb..0523feaac2 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1387,26 +1387,24 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common return 0; } -static int send_acks(struct packet_writer *writer, struct oid_array *acks, - const struct object_array *have_obj, - struct object_array *want_obj) +static int send_acks(struct upload_pack_data *data, struct oid_array *acks) { int i; - packet_writer_write(writer, "acknowledgments\n"); + packet_writer_write(&data->writer, "acknowledgments\n"); /* Send Acks */ if (!acks->nr) - packet_writer_write(writer, "NAK\n"); + packet_writer_write(&data->writer, "NAK\n"); for (i = 0; i < acks->nr; i++) { - packet_writer_write(writer, "ACK %s\n", + packet_writer_write(&data->writer, "ACK %s\n", oid_to_hex(&acks->oid[i])); } - if (ok_to_give_up(have_obj, want_obj)) { + if (ok_to_give_up(&data->have_obj, &data->want_obj)) { /* Send Ready */ - packet_writer_write(writer, "ready\n"); + packet_writer_write(&data->writer, "ready\n"); return 1; } @@ -1421,8 +1419,7 @@ static int process_haves_and_send_acks(struct upload_pack_data *data) process_haves(data, &common); if (data->done) { ret = 1; - } else if (send_acks(&data->writer, &common, - &data->have_obj, &data->want_obj)) { + } else if (send_acks(data, &common)) { packet_writer_delim(&data->writer); ret = 1; } else { From patchwork Thu Jun 11 12:05:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599859 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B520013B1 for ; Thu, 11 Jun 2020 12:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97562207C3 for ; Thu, 11 Jun 2020 12:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fm145hiX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbgFKMF5 (ORCPT ); Thu, 11 Jun 2020 08:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727989AbgFKMFv (ORCPT ); Thu, 11 Jun 2020 08:05:51 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC8ADC08C5C3 for ; Thu, 11 Jun 2020 05:05:50 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id t18so5884921wru.6 for ; Thu, 11 Jun 2020 05:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xKHKMd5iywnEpPHMQd4uKXcR1FpO0yE40dWh82MUXIs=; b=fm145hiXzqFTSSz5yxxHKoQZ4dIgX5OszV8RZIhkUOGvQq12tHu3kn1Ea2f6kzT/9g Qjk1ZoNeTKtVdHvqVllYp4VgJ648VQtja3oBRaabosAGvkjQOMdCDFzHdmGjNkQCnDLx CQlD8NWbKhoCpUvi///UN1tE4RRqXh7B1V3uj1KM11pZ5C3ePkZNRv40Uq4p4OBxhQIf rNJY3pJig0sG+s9z8W7bcr7+AdhRiyPPpGZnbh3kkpJtywrg4PgKW9ShXHZXvq4aTEBh PnCIwneACIFi3rcw9lDajqlk3GjWy/jfIh8ubU28ZskAMAU4rwg0ZqlaPGlO9SgW+k3p ntyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xKHKMd5iywnEpPHMQd4uKXcR1FpO0yE40dWh82MUXIs=; b=O7IsRbY1wJpx0zubOm21LSFiUU1SwGXQ4r07YBl8D4RiDu+Gq48YUBlext7L+GMO4v OhhozKWso7tpurOfmCe3/dH1CEmXNXw8HttTjJDn3hOX0pzcNaPx35giev60rFKfXUIs bWO2v5WwKsiNqhZEPHGDRXWD2nmB40RHp0iLE1AU+Dma7RYsfLcyuGtaseWZFxWdEgGS haTUvWvehgobiPlTzFVlZhR5oEMjy8du6/YItWaG/+Mzsg/o1FpPqH6VbED1Ewe5Lto9 vJtNvK08UlERnjK0BiXCNJdfWh9FZdfIsH7ph8Bf5fVkVpXSF9H7/KlstUkKGcNHoqj/ fvGA== X-Gm-Message-State: AOAM532CpnCzbSpqax0ntAhx6FhTq2u1DRv6JgMetaCAFIUgjWXpFfnJ Y58Dxh+S/QaA0Zu7OSmUi2IjMQUaCzs= X-Google-Smtp-Source: ABdhPJwLc9prk52uggrnG4fU20bklHX6sy/+NrD2S+nomB6mAe8Uh6F7wCbe6NTxZkghiaWxK1AW6g== X-Received: by 2002:adf:b60b:: with SMTP id f11mr9130810wre.7.1591877149286; Thu, 11 Jun 2020 05:05:49 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:48 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 11/14] upload-pack: pass upload_pack_data to ok_to_give_up() Date: Thu, 11 Jun 2020 14:05:15 +0200 Message-Id: <20200611120518.10771-12-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to ok_to_give_up(), so that this function can use all the fields of the struct. This will be used in followup commits to move a static variable into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 0523feaac2..245eda8ba1 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -428,15 +428,14 @@ static int got_oid(const char *hex, struct object_id *oid, return 0; } -static int ok_to_give_up(const struct object_array *have_obj, - struct object_array *want_obj) +static int ok_to_give_up(struct upload_pack_data *data) { uint32_t min_generation = GENERATION_NUMBER_ZERO; - if (!have_obj->nr) + if (!data->have_obj.nr) return 0; - return can_all_from_reach_with_flag(want_obj, THEY_HAVE, + return can_all_from_reach_with_flag(&data->want_obj, THEY_HAVE, COMMON_KNOWN, oldest_have, min_generation); } @@ -461,7 +460,7 @@ static int get_common_commits(struct upload_pack_data *data, if (data->multi_ack == MULTI_ACK_DETAILED && got_common && !got_other - && ok_to_give_up(&data->have_obj, &data->want_obj)) { + && ok_to_give_up(data)) { sent_ready = 1; packet_write_fmt(1, "ACK %s ready\n", last_hex); } @@ -483,7 +482,7 @@ static int get_common_commits(struct upload_pack_data *data, case -1: /* they have what we do not */ got_other = 1; if (data->multi_ack - && ok_to_give_up(&data->have_obj, &data->want_obj)) { + && ok_to_give_up(data)) { const char *hex = oid_to_hex(&oid); if (data->multi_ack == MULTI_ACK_DETAILED) { sent_ready = 1; @@ -1402,7 +1401,7 @@ static int send_acks(struct upload_pack_data *data, struct oid_array *acks) oid_to_hex(&acks->oid[i])); } - if (ok_to_give_up(&data->have_obj, &data->want_obj)) { + if (ok_to_give_up(data)) { /* Send Ready */ packet_writer_write(&data->writer, "ready\n"); return 1; From patchwork Thu Jun 11 12:05:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD2CA159A for ; Thu, 11 Jun 2020 12:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A366D207C3 for ; Thu, 11 Jun 2020 12:05:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oV31lEZM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728078AbgFKMF6 (ORCPT ); Thu, 11 Jun 2020 08:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbgFKMFx (ORCPT ); Thu, 11 Jun 2020 08:05:53 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49924C08C5C4 for ; Thu, 11 Jun 2020 05:05:52 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l17so4762912wmj.0 for ; Thu, 11 Jun 2020 05:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0APQgqlDE2yF+o5a60unQuOkJxpEta4Yy1BnJzPkn/M=; b=oV31lEZMKIaxRnL+cXCrCjXqKJwwcYA48Xfk/QQt+ITmFEOKtdL1YqskKoSuGahtve tJtYOV0+jUrcLw6oS2fyc85O2RahcRIehDe1bhXUp2qK56vpwKzdhx+Wj1MlyGXx0a/I +rTZYrsleHxNgJEMogx1PHYREgp1OGOK7TQzo3mrbx+qvJ4Eab+ebEGKU3KMCbtP9rbu RpMRjeQ6m3WVHgghL9V1794XckI9AFoX5SBK/5buGoxj+bNYqlCPfNZ+9aLI3wcD67Ux tHqXBF1Y8Js/ByZ3pFzKZ0ooR0IiaXZvPGVFMzddQGB3rYOF/MFrs5j5BvVUzgPo3YPA EB0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0APQgqlDE2yF+o5a60unQuOkJxpEta4Yy1BnJzPkn/M=; b=k2zLbu7X6rTruApXB65RNglHATSWCBoP8uJpGfpZVWD8VbkWcXMzkFHAHn8RZGBzuL auqTPvgXOXHuHwtYQGPYCsp222mvSy1lVlH7jhXwk7UzxyjttizeOIQDnAlfjlx+F4FS B7EdRnwBo38vDnIvEQBnhHZd7+nXW1Tg2b9hPiPw30JUEKucEYaaAVcMptUEogidyNVM Ug8TzoS/+6KYGBs3a2tjBntTzpnBoya5dioNNhaiw2H1NZUv1cGNmuqu7L06P8pAcrZj +BY53IOMmJ+XlYl3haN0zWcY4VuAE5xcpusBqAtPCq6c/EXcm8WODVm73mAZbeOX7uHd 5ASA== X-Gm-Message-State: AOAM530HFszwz+lLfYWWS36QgzOrwLRpUwW51mJqhVZ7Qm6IkbRU1n1G zX18o+NMCSGSh6f0Y10YGzLH0xGTmX0= X-Google-Smtp-Source: ABdhPJx2gX6NmPJDEcDecO5S4nEpjcci74DUkSrDYsTudcSYQaDC8Gpe7/b2MZijYJK2krKFrZOCyg== X-Received: by 2002:a7b:cbd9:: with SMTP id n25mr7842917wmi.30.1591877150657; Thu, 11 Jun 2020 05:05:50 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:50 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 12/14] upload-pack: pass upload_pack_data to got_oid() Date: Thu, 11 Jun 2020 14:05:16 +0200 Message-Id: <20200611120518.10771-13-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass that struct to got_oid(), so that this function can use all the fields of the struct. This will be used in followup commits to move a static variable into 'upload_pack_data'. Signed-off-by: Christian Couder --- upload-pack.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 245eda8ba1..6729c17cf4 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -393,8 +393,8 @@ static void create_pack_file(struct upload_pack_data *pack_data) die("git upload-pack: %s", abort_msg); } -static int got_oid(const char *hex, struct object_id *oid, - struct object_array *have_obj) +static int got_oid(struct upload_pack_data *data, + const char *hex, struct object_id *oid) { struct object *o; int we_knew_they_have = 0; @@ -422,7 +422,7 @@ static int got_oid(const char *hex, struct object_id *oid, parents->item->object.flags |= THEY_HAVE; } if (!we_knew_they_have) { - add_object_array(o, NULL, have_obj); + add_object_array(o, NULL, &data->have_obj); return 1; } return 0; @@ -478,7 +478,7 @@ static int get_common_commits(struct upload_pack_data *data, continue; } if (skip_prefix(reader->line, "have ", &arg)) { - switch (got_oid(arg, &oid, &data->have_obj)) { + switch (got_oid(data, arg, &oid)) { case -1: /* they have what we do not */ got_other = 1; if (data->multi_ack From patchwork Thu Jun 11 12:05:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A8AB159A for ; Thu, 11 Jun 2020 12:06:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8257A2078D for ; Thu, 11 Jun 2020 12:06:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jgmw7fXS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbgFKMGC (ORCPT ); Thu, 11 Jun 2020 08:06:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727979AbgFKMFz (ORCPT ); Thu, 11 Jun 2020 08:05:55 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF9DAC08C5C5 for ; Thu, 11 Jun 2020 05:05:54 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id q25so4808384wmj.0 for ; Thu, 11 Jun 2020 05:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nLlJTaNl6hMATl6VGkHQHEYRagKeJBNEb4tJvPE4YjY=; b=jgmw7fXSe9dYX8LQmB/gvlpiMhTz5cNn4U3TkeuaAQTnqw4wBM9BhD+0FDpUavLlW+ Rz0geVIoHCyLEfKjHhV0W9Rr5o8nh9UbBNvADyYneWeAZwyzrxa3U7/lbb1uZEvIQOLh iNppTyhBvoVJ8RajhzkmSEHFw4ot9OkzjNy+qnuEN11dSZYqTJmNaiNW05NsAazoBdt6 6YnA0wRvK8odlqRHcTgZxx6jtmhai/KQ9vsdD/Uj+JQ5HCDyoIELptCbQ9GxezbVkdf6 OJJ/XW7sE2hB9mYKasNxPDYsg42/UimkMaF9RsmQbhkNJXo5pPfYBOdaclIL/otezK0k rd6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nLlJTaNl6hMATl6VGkHQHEYRagKeJBNEb4tJvPE4YjY=; b=D3Iihf1F4xyuf3I/WQDLnKkpIGS2hNvNTV34wTAOe3I9a7aPc0k96Ymad5LOFRonq3 7asjHnrVgz1Kyq58Sz4kQjOrW2ueR2eQ9oUHAH5U70OUiPYyPTShnjV9/kRrZLTa6inD 0JdcMttX+/kUnYvbqguDLaPpE1W2R8aOb+ms2ML+cK2Av8NmLG2yeSVQOCGXOHTc+Hpw JmKPlfT85pAAN+alL6Lg4x5Ravi9nkgU92GR4eVWWD/vHpePBnGN3Kbu4TMstSv8lse5 x1o8Zqcp4DVlDURrl8pp7zFfU2keOI8As7J+2xU5j78gFiqVeTWm5zNg/pG5PpCxEUzv rZyA== X-Gm-Message-State: AOAM533ALlHr8PuzgX+LgG66uYqmgKFQ7+8zhtublru5kyXUHqOKgWbC dkNKzQKh3d5Vvenx5JKuLuqD+afrgAU= X-Google-Smtp-Source: ABdhPJzcVFAQo+XR9Sycg07RF36+NH2fgI7UfBVEWYKdmr7r8/1IM9NbY3LAhi3GqRkp29ERPTGwzQ== X-Received: by 2002:a1c:2644:: with SMTP id m65mr7827584wmm.178.1591877152163; Thu, 11 Jun 2020 05:05:52 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:51 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 13/14] upload-pack: move oldest_have to upload_pack_data Date: Thu, 11 Jun 2020 14:05:17 +0200 Message-Id: <20200611120518.10771-14-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the 'oldest_have' static variable into this struct. It is used by both protocol v0 and protocol v2 code. Signed-off-by: Christian Couder --- upload-pack.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/upload-pack.c b/upload-pack.c index 6729c17cf4..3d331bedfa 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -42,8 +42,6 @@ #define ALL_FLAGS (THEY_HAVE | OUR_REF | WANTED | COMMON_KNOWN | SHALLOW | \ NOT_SHALLOW | CLIENT_SHALLOW | HIDDEN_REF) -static timestamp_t oldest_have; - /* Enum for allowed unadvertised object request (UOR) */ enum allow_uor { /* Allow specifying sha1 if it is a ref tip. */ @@ -74,6 +72,7 @@ struct upload_pack_data { int deepen_relative; int keepalive; int shallow_nr; + timestamp_t oldest_have; unsigned int timeout; /* v0 only */ enum { @@ -414,8 +413,8 @@ static int got_oid(struct upload_pack_data *data, we_knew_they_have = 1; else o->flags |= THEY_HAVE; - if (!oldest_have || (commit->date < oldest_have)) - oldest_have = commit->date; + if (!data->oldest_have || (commit->date < data->oldest_have)) + data->oldest_have = commit->date; for (parents = commit->parents; parents; parents = parents->next) @@ -436,7 +435,7 @@ static int ok_to_give_up(struct upload_pack_data *data) return 0; return can_all_from_reach_with_flag(&data->want_obj, THEY_HAVE, - COMMON_KNOWN, oldest_have, + COMMON_KNOWN, data->oldest_have, min_generation); } @@ -1372,8 +1371,8 @@ static int process_haves(struct upload_pack_data *data, struct oid_array *common we_knew_they_have = 1; else o->flags |= THEY_HAVE; - if (!oldest_have || (commit->date < oldest_have)) - oldest_have = commit->date; + if (!data->oldest_have || (commit->date < data->oldest_have)) + data->oldest_have = commit->date; for (parents = commit->parents; parents; parents = parents->next) From patchwork Thu Jun 11 12:05:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 11599865 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FF84159A for ; Thu, 11 Jun 2020 12:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4318C207C3 for ; Thu, 11 Jun 2020 12:06:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jDN4rXrn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728080AbgFKMGB (ORCPT ); Thu, 11 Jun 2020 08:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbgFKMF4 (ORCPT ); Thu, 11 Jun 2020 08:05:56 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CFAC08C5C6 for ; Thu, 11 Jun 2020 05:05:55 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id q11so5900497wrp.3 for ; Thu, 11 Jun 2020 05:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R4N8wq0vZuV3gtkfEwnO4bpv25RraGCfdPxsYkh3pnw=; b=jDN4rXrn40KWt3ywWrgpdT78b1q6Mf92+F1egKIGnMjPyJfK91k8o4sEAh5zv5weD7 dcRzaQWVZBXn8pdRfBInA9B7qhxu09AawWwhBP4amAle0NQTfEQgq+IaTyf9jhCG1aYA lVegatGL0xCxLGUg3QVY8w4MA2XiN9BcAtJk3/ptdxytxFyngCu1cYlOub8FAvAoyth1 fO0tjfkDBlxcLQ5i9WZ81hr5maxCllcddS2+i7NqOr16s8X5yd+dOpmvzb/ZVXDeJsd5 /y7ZaFwruGZ+UXd/87f/f1HUaCQaPRjsrPFGx/pr4H+PgYl9Iw9Hcr4t/f8Oo6AeI9p4 q1ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R4N8wq0vZuV3gtkfEwnO4bpv25RraGCfdPxsYkh3pnw=; b=mHQQoeOaC/nYN1hYhmzCuB0OhA9nyAwnrhV1H9SYfP94l/beGUJYunXLs7N8A9zztK Ki5ujqiZe0gWU7WtqxNmxn+dRoUan34QhwMYjb0rrk7gjAXLTkQ3N72UCDXtpknU4gsF NEGiJxg3V+9caTd7s58M2RMdtDhr1zxFJlg5u8xtYSqWhFn5UB4LUOPYMhConM8ZeEwT LAjQabHUYGETZpyeCj96XXf/a6cAwKeVmSLwSZdfMJKkgJYJM5o3DLzD0+cft3qcgvmz 4SA/2BM/QxFkC7j+dn8TSp6jun3yRkpaRFFobHR64UWhJOkYjBAJvNzOXHk3yv9Q5WoS CyiQ== X-Gm-Message-State: AOAM532P7Z16WpEVTW0MtVVNy54jz3b5IOazw5YbvL8lOd4tEFS95grl tReeMYzUfFy1rqIX34Idarn1VovsLnM= X-Google-Smtp-Source: ABdhPJyzZtU/smiF7+r47IaPYzQLvTmzlkKPR1SznicXOj4A/YV05g6xT9rE7uAAEzYGwhu6tY6Ipg== X-Received: by 2002:a5d:558a:: with SMTP id i10mr9773402wrv.207.1591877153538; Thu, 11 Jun 2020 05:05:53 -0700 (PDT) Received: from localhost.localdomain ([185.228.229.208]) by smtp.gmail.com with ESMTPSA id o8sm4047174wmb.20.2020.06.11.05.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:05:53 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff King , Taylor Blau , Jonathan Tan , Jonathan Nieder , Christian Couder Subject: [PATCH 14/14] upload-pack: refactor common code into do_got_oid() Date: Thu, 11 Jun 2020 14:05:18 +0200 Message-Id: <20200611120518.10771-15-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.27.0.90.gabb59f83a2 In-Reply-To: <20200611120518.10771-1-chriscool@tuxfamily.org> References: <20200515100454.14486-1-chriscool@tuxfamily.org> <20200611120518.10771-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- upload-pack.c | 43 +++++++++++++------------------------------ 1 file 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;