From patchwork Wed Sep 12 15:47:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 10597801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A63F913BF for ; Wed, 12 Sep 2018 15:47:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95F082A521 for ; Wed, 12 Sep 2018 15:47:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8850E2A535; Wed, 12 Sep 2018 15:47:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2923E2A521 for ; Wed, 12 Sep 2018 15:47:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727611AbeILUwx (ORCPT ); Wed, 12 Sep 2018 16:52:53 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:49091 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbeILUwx (ORCPT ); Wed, 12 Sep 2018 16:52:53 -0400 Received: by mail-qk1-f201.google.com with SMTP id u129-v6so1955961qkf.15 for ; Wed, 12 Sep 2018 08:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KdcF0PvvH4CW9ZFCYbckJxcaB1xkaZswpoyDZjaXtvM=; b=nJTmRI4zXIbXPBDRPSFoJUNPbJlNTnG7a/bdVHn9go1FoSu5CKQry6aeE5QQIjvTJY RGCgVuqk9UQpeQD/sR0HknJXpdivNykBsbfUT00cd/cHfpy7ipCx+j8bgRqnQtHZlTFy M48f3xf1FCSY7qC/06BrneDilveOnfqvFWtKx4F3lxJ3/x2z7/TeefUMd79duOmHAHyh sLJgfWxull5ZfokhdVwnlRO/nCUvhZUfoEkbPR177oXLF9bvOkHMytijOuBfNMHLLjnr IdNVV8jMSTuVA7UKnSvTqlb07h0nOjy4tPMLx+lDIRgLiLOZVSS/MBv9QWYT+bYtGt6d yiWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KdcF0PvvH4CW9ZFCYbckJxcaB1xkaZswpoyDZjaXtvM=; b=Yiamasqc9TexaGrE2YrkZZ1/l4MWar+jX9kqU59amXU2ZLJAOWm82DhItntz2F0tmU Gg2Z3us7+Rdw66HHmqNFA6aE3LhaHN/ng5H23mCTXAYr0jKQoj69ZoKvPFZDDSK0jrBb pn6DS68hkJPpSqGJCSLPgToMBn4dYuTaAapjSSDth8rqWY8A97zaFihsQOwLUlehHzGl leJ69NggjBB+bS0pMxfw/qVEWGUXdGKsxayFQ3WG+iAPE7j3ia6U/I6sS974sFE+eyqZ bCacVao9Jap88/Xu87VjMS/10D9cNQCSlMQ6R/oTd1PFmqHwNcnd3lluCL6E4CvxvaQI IUkg== X-Gm-Message-State: APzg51CeJyrf/da/jDdmp6QmWcTHT7IXRQ6Ood6kOBihEQGhbfoVe8Yr dN23d/dvyTXLzOhpZvaUgROtfSw5O5+Hs7+Z7s5//LMky6bA5eSTIBW1t+hj7hGGP9gFKwumOYU Q+SbbC8NirDQAh6W/Ply2HCZ3Pkl8vtZwedM3i/Hy/xMXumM7CSFqtCTwf6vFVrMlpBKPRWMMiI 5P X-Google-Smtp-Source: ANB0VdY7IEbByNGzGsHl4KsxAm7B9udBJIXDk06YH7Gbwyu294Cd2qJgYODAYBvzB671/G12nPdL1S/9bqmFGtWR9OuD X-Received: by 2002:a0c:8937:: with SMTP id 52-v6mr748825qvp.54.1536767266276; Wed, 12 Sep 2018 08:47:46 -0700 (PDT) Date: Wed, 12 Sep 2018 08:47:37 -0700 In-Reply-To: Message-Id: <72399daf65b9c0a7ed12589584f5108a9ff6fc26.1536767071.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 1/2] fetch-object: provide only one fetching function From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP fetch-object.h currently provides two functions (fetch_object() and fetch_objects()) that could be replaced by a single, more flexible function. Replace those two functions with the more flexible function. Signed-off-by: Jonathan Tan --- fetch-object.c | 16 +++++----------- fetch-object.h | 8 ++------ sha1-file.c | 2 +- unpack-trees.c | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/fetch-object.c b/fetch-object.c index 853624f81..1af1bf857 100644 --- a/fetch-object.c +++ b/fetch-object.c @@ -23,21 +23,15 @@ static void fetch_refs(const char *remote_name, struct ref *ref) fetch_if_missing = original_fetch_if_missing; } -void fetch_object(const char *remote_name, const unsigned char *sha1) -{ - struct ref *ref = alloc_ref(sha1_to_hex(sha1)); - hashcpy(ref->old_oid.hash, sha1); - fetch_refs(remote_name, ref); -} - -void fetch_objects(const char *remote_name, const struct oid_array *to_fetch) +void fetch_objects(const char *remote_name, const struct object_id *oids, + int oid_nr) { struct ref *ref = NULL; int i; - for (i = 0; i < to_fetch->nr; i++) { - struct ref *new_ref = alloc_ref(oid_to_hex(&to_fetch->oid[i])); - oidcpy(&new_ref->old_oid, &to_fetch->oid[i]); + for (i = 0; i < oid_nr; i++) { + struct ref *new_ref = alloc_ref(oid_to_hex(&oids[i])); + oidcpy(&new_ref->old_oid, &oids[i]); new_ref->next = ref; ref = new_ref; } diff --git a/fetch-object.h b/fetch-object.h index 4b269d07e..d2f996d4e 100644 --- a/fetch-object.h +++ b/fetch-object.h @@ -1,11 +1,7 @@ #ifndef FETCH_OBJECT_H #define FETCH_OBJECT_H -#include "sha1-array.h" - -extern void fetch_object(const char *remote_name, const unsigned char *sha1); - -extern void fetch_objects(const char *remote_name, - const struct oid_array *to_fetch); +void fetch_objects(const char *remote_name, const struct object_id *oids, + int oid_nr); #endif diff --git a/sha1-file.c b/sha1-file.c index 97b742384..2edf4564f 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -1317,7 +1317,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid, * TODO Pass a repository struct through fetch_object, * such that arbitrary repositories work. */ - fetch_object(repository_format_partial_clone, real->hash); + fetch_objects(repository_format_partial_clone, real, 1); already_retried = 1; continue; } diff --git a/unpack-trees.c b/unpack-trees.c index f25089b87..82a83dbc6 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -392,7 +392,7 @@ static int check_updates(struct unpack_trees_options *o) } if (to_fetch.nr) fetch_objects(repository_format_partial_clone, - &to_fetch); + to_fetch.oid, to_fetch.nr); fetch_if_missing = fetch_if_missing_store; oid_array_clear(&to_fetch); } From patchwork Wed Sep 12 15:47:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 10597805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF0AE14E0 for ; Wed, 12 Sep 2018 15:47:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF6972A521 for ; Wed, 12 Sep 2018 15:47:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3D3C2A535; Wed, 12 Sep 2018 15:47:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DC622A521 for ; Wed, 12 Sep 2018 15:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727648AbeILUwz (ORCPT ); Wed, 12 Sep 2018 16:52:55 -0400 Received: from mail-ua1-f74.google.com ([209.85.222.74]:33092 "EHLO mail-ua1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbeILUwz (ORCPT ); Wed, 12 Sep 2018 16:52:55 -0400 Received: by mail-ua1-f74.google.com with SMTP id z12-v6so955280uao.0 for ; Wed, 12 Sep 2018 08:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xcTIXo7gtWLZrN+H3N58BQs6TPjxzld49znyDDEfQ8M=; b=iL/YRXdJI+eUXdKlcV4uVoklBVFXTzUTpev0jZgfX7PN4e/L+QCgJXnShONBztrwp6 Ict07vFUHs+P8K6BUijij2a0ik4C6OuRhXQFD6kwq9MFjr9ZDnhXxJsxAhB000VjxE+F hL9zNeTGO0ZUCF29lrQpZnADjMrfjJ752YnDcVU5tbHtXi1ZjafU2UyxDVm3Km10s86v mNKMCyXAdiU/1vNTi628lyPL4K3RfJwMVbXusR6uakEykjJNE+u4qCpJJ6qyCUGjVWVq Agy1fJlQ5bmGJ4iCxW4v8FM8n3CsFximXGO0+SNh2rHZhCb5Vx5hVdpfq8PQlF/1ydX0 L/GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xcTIXo7gtWLZrN+H3N58BQs6TPjxzld49znyDDEfQ8M=; b=DMAm1bJ5MX/fZIPcjOzEsqztWnmuTu2eRUZOni695zo5nsb2k57U5xEXGrrDhmoPo1 TsfCvNLAg+jOb02pxqCYOn7Xa2BdaxXX40FkK7Gab5vc8v9hQGs4PxJMdAPuVNO+xyoa +curhRYpdj8/4pHyANBluWOx7I/JgubL0pJ32wxlcd5WsRv7LCMuIYm3Xoz4C3w8x0kb RhNKipoJ7xBefiQjjHkw4uy6L/UpWrb/MxYdUth8bpoCqNRH1RtTBMNkAaokiUyfxlrd 6qgGPX0ocu/TsCgzyIpvL4EYidOh+d8UGE/bh8h8sQi6Gks/SAOtkeNgcc/NTe7mJw06 /J2A== X-Gm-Message-State: APzg51Am87uUh8JSZA1Bt1L8taFH4zJPo5wAET3Hhlm1qzEPZt63INoT aqhWcfif+AqrjbfkxKdywSTd+Q8HzBvuVwptMiUaGAaGFmi3/J4fBa47Op0aDDogtO//njUAKoI ppRXhxTwOfzsEqbZSxNSw2yCLx2iuz1GYM+YY3UEv7TU0Fb+tNjUFMbkh1lrctcEUJOgQKy4xlO Vm X-Google-Smtp-Source: ANB0VdbW5agxZ2ndGhHMaE+mktmZOAFFURcrdelK3VFR73stKf206vISGdWiOPiCvEkaZjtCTM91CXGuF5tHK131mK3j X-Received: by 2002:ab0:264e:: with SMTP id q14-v6mr563047uao.49.1536767268988; Wed, 12 Sep 2018 08:47:48 -0700 (PDT) Date: Wed, 12 Sep 2018 08:47:38 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 2/2] fetch-object: set exact_oid when fetching From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP fetch_objects() currently does not set exact_oid in struct ref when invoking transport_fetch_refs(). If the server supports ref-in-want, fetch_pack() uses this field to determine whether a wanted ref should be requested as a "want-ref" line or a "want" line; without the setting of exact_oid, the wrong line will be sent. Set exact_oid, so that the correct line is sent. Signed-off-by: Jonathan Tan --- fetch-object.c | 1 + t/t0410-partial-clone.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/fetch-object.c b/fetch-object.c index 1af1bf857..426654880 100644 --- a/fetch-object.c +++ b/fetch-object.c @@ -32,6 +32,7 @@ void fetch_objects(const char *remote_name, const struct object_id *oids, for (i = 0; i < oid_nr; i++) { struct ref *new_ref = alloc_ref(oid_to_hex(&oids[i])); oidcpy(&new_ref->old_oid, &oids[i]); + new_ref->exact_oid = 1; new_ref->next = ref; ref = new_ref; } diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index 128130066..0ab02c337 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -170,6 +170,18 @@ test_expect_success 'fetching of missing objects' ' git verify-pack --verbose "$IDX" | grep "$HASH" ' +test_expect_success 'fetching of missing objects works with ref-in-want enabled' ' + # ref-in-want requires protocol version 2 + git -C server config protocol.version 2 && + git -C server config uploadpack.allowrefinwant 1 && + git -C repo config protocol.version 2 && + + rm -rf repo/.git/objects/* && + rm -f trace && + GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" && + grep "git< fetch=.*ref-in-want" trace +' + test_expect_success 'rev-list stops traversal at missing and promised commit' ' rm -rf repo && test_create_repo repo &&