From patchwork Wed Apr 29 22:39:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 11518919 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 F147192C for ; Wed, 29 Apr 2020 22:39:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4B132076B for ; Wed, 29 Apr 2020 22:39:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20150623.gappssmtp.com header.i=@ttaylorr-com.20150623.gappssmtp.com header.b="lWBjZPkX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbgD2Wje (ORCPT ); Wed, 29 Apr 2020 18:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726164AbgD2Wjd (ORCPT ); Wed, 29 Apr 2020 18:39:33 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39F51C03C1AE for ; Wed, 29 Apr 2020 15:39:32 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id c21so1426653plz.4 for ; Wed, 29 Apr 2020 15:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7dkz/Jd0fjk6gIBT8np814V6zRlWTh2MCX37MDQT3EM=; b=lWBjZPkXDy1rbKK+JaBFtNUTeqdTYl6gACJZ2D5qkJ6tjWIBo0cickMNrvZRu0Preh kppGJGh83brU646ZMgGcw/e+QAwfVQS8bZdaGSzm7OD3i59mo3rT9kVVXUB1p5AI7imM yZjTaPU1MTGnKEfzbIJDS9Slk71/0Yyiza6+luOjFXpK8xMgSCg2R0SmG2VME+koI4M5 AF56A9SMuzn0eO8f6F9Va2/Ytp/dlNECd2hCuVvV9p+IwAM9udnT0VU29Y/p6S3aXRHc aP2xyEzoDv6p+dCQzs6CuWBHQxE4EdGwsomB4cSjA1WbfrBidv/cSlYHti8nQrLwCIj0 7X7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7dkz/Jd0fjk6gIBT8np814V6zRlWTh2MCX37MDQT3EM=; b=gITbDpoNPPPFySpZmXKxZmMtN7HPiOQB0eaW21E3kLK2dpAQyibWlONgvBJ/7e9nnq fYsTAbIOuT4bR5vRor2F/esF2w0YhvnA7AHA8HnccKXAKqP//pmpNhK8PWFFA362BVvW dwaikCIWg7Y255GHnESHte5YQCR/wJweYpLSC2AnkIonpZHLaJQI/vXk2mpRPPjolWmS apbvzYI9Do7Y3RZXanxMx2leNTOdrzEFzVK+sZRIQ+7MDgHBTfDFpS6Pu1I/LcZZTJe5 TQNPhh9dSsu3TcORT88CCNoi+8KlPMoGbWh75IYZmug5WXGlWmRaUjp/TZV2ZgTMWXLv XZUA== X-Gm-Message-State: AGi0PuZrreALxYmOVliomC8ekENQ+6vbl8uo4j1/DHWQIH5M+vhEReHl F20A0iiGYStFVriWhkt7MwbkKyr2ObGBd7TS X-Google-Smtp-Source: APiQypJL2qEXzC4+T7856uB+mhAVdoWil1UiZaJOvLTD6EGllTUnyHqv86gLx9UkQRWY23DotOT/MQ== X-Received: by 2002:a17:902:9693:: with SMTP id n19mr629934plp.277.1588199971370; Wed, 29 Apr 2020 15:39:31 -0700 (PDT) Received: from localhost ([8.44.146.30]) by smtp.gmail.com with ESMTPSA id v94sm226509pjb.39.2020.04.29.15.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 15:39:30 -0700 (PDT) Date: Wed, 29 Apr 2020 16:39:29 -0600 From: Taylor Blau To: git@vger.kernel.org Cc: gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH 1/5] commit: make 'commit_graft_pos' non-static Message-ID: <8ac4c63735f2e48dc83e9f31c9fbbbfb47d7e79d.1588199705.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the next patch, some functions will be moved from 'commit.c' to have prototypes in a new 'shallow.h' and their implementations in 'shallow.c'. Three functions in 'commit.c' use 'commit_graft_pos()' (they are 'register_commit_graft()', 'lookup_commit_graft()', and 'unregister_shallow()'). The first two of these will stay in 'commit.c', but the latter will move to 'shallow.c', and thus needs 'commit_graft_pos' to be non-static. Prepare for that by making 'commit_graft_pos' non-static so that it can be called from both 'commit.c' and 'shallow.c'. Signed-off-by: Taylor Blau --- commit.c | 2 +- commit.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/commit.c b/commit.c index c7099daeac..b76f7d72be 100644 --- a/commit.c +++ b/commit.c @@ -110,7 +110,7 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table) return commit_graft_table[index]->oid.hash; } -static int commit_graft_pos(struct repository *r, const unsigned char *sha1) +int commit_graft_pos(struct repository *r, const unsigned char *sha1) { return sha1_pos(sha1, r->parsed_objects->grafts, r->parsed_objects->grafts_nr, diff --git a/commit.h b/commit.h index ab91d21131..eb42e8b6d2 100644 --- a/commit.h +++ b/commit.h @@ -236,6 +236,7 @@ struct commit_graft { typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); struct commit_graft *read_graft_line(struct strbuf *line); +int commit_graft_pos(struct repository *r, const unsigned char *sha1); int register_commit_graft(struct repository *r, struct commit_graft *, int); void prepare_commit_graft(struct repository *r); struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid); From patchwork Wed Apr 29 22:39:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 11518921 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 3038D92A for ; Wed, 29 Apr 2020 22:39:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 131762076B for ; Wed, 29 Apr 2020 22:39:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20150623.gappssmtp.com header.i=@ttaylorr-com.20150623.gappssmtp.com header.b="mANlSWf0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbgD2Wji (ORCPT ); Wed, 29 Apr 2020 18:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726164AbgD2Wji (ORCPT ); Wed, 29 Apr 2020 18:39:38 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE5DC03C1AE for ; Wed, 29 Apr 2020 15:39:37 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id x77so1836328pfc.0 for ; Wed, 29 Apr 2020 15:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WqJi3XiGTmdEV4DQZK3YFDBkKYU4DufX8SKsAF47NQU=; b=mANlSWf0HPVW38xL0CQBiWooX8/q2vDBfs7X9fTbM456AbmGZBaI02yep8WwsugUnw R3i+hL6KyFwZrI4UBqBEnrRY2Pxy+483NFANn3827Fkz15ikRR9MuZJirfxiiOmmXfq8 wFZVl6Vjibht4De/xyTgsP9Xgr4O9t3Jn2tC4p8KC1MvRGCNxlORLR+PGTJGDb8JxW1S d0ycSZ46Y9Pi2hyU4BLT7LPbaowMB5JFgzYVvU5nIasQOKUKVJq0L6HD/0jjPp6yST8U ewgDK2RoI2o+Zw44s+HK8rWy8GQqaC+lxylGXkU4XU616409AbKWwhZ8PnCps6TKc2bD eQcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WqJi3XiGTmdEV4DQZK3YFDBkKYU4DufX8SKsAF47NQU=; b=bjtao77egObraXLinvcEqYfrn6hu4AA6CTiwadeNez4EF8SanhHjbUxG5WHoAVI/CL oLEF1PUwxHbzLpKGf045Lu/qKQPvxAscwBoGAaBTWIet8EIZApoDXUIaOkvh2frM7vB5 tvsRNeKSs9BtwI+InV140uIR7PrX3wLdKybZOFX5rHDPbYjETCSjXlCrJ3BuxqtKqF4W 3VxOHcOk4uwdaeg80eohJQasYc4nUfe6aQySpbcZ5Hqh9ieAAZeja/wLEH/CAv4RgIhH O/tOcrjGaoRrQni6S9Zpza0AU7lLZSYaHKnLKkrWzd5VYxtncmNyuNw7q8jFGjCoQkm0 p5xw== X-Gm-Message-State: AGi0PuanVP1rduFWizPABLZRUEaExMhTq+QO31POjTytcJ+5cdvG8RUe ja79i8fnBP/RBUVCIGzEtwwwdqI9Sv5aZSnJ X-Google-Smtp-Source: APiQypKJFTtayesRBbpTUt52FF4yUYLdNLnBLTJP8WHdfM5+3VtOGd3HnLGZzUfUbwoPWz9KwcpjUg== X-Received: by 2002:a62:17c3:: with SMTP id 186mr366909pfx.159.1588199976198; Wed, 29 Apr 2020 15:39:36 -0700 (PDT) Received: from localhost ([8.44.146.30]) by smtp.gmail.com with ESMTPSA id a136sm1875390pfa.99.2020.04.29.15.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 15:39:35 -0700 (PDT) Date: Wed, 29 Apr 2020 16:39:34 -0600 From: Taylor Blau To: git@vger.kernel.org Cc: gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH 2/5] shallow: extract a header file for shallow-related functions Message-ID: <0b93abe072aa35ab96ba3b97118caa8ffe8e439d.1588199705.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There are many functions in commit.h that are more related to shallow repositories than they are to any sort of generic commit machinery. Likely this began when there were only a few shallow-related functions, and commit.h seemed a reasonable enough place to put them. But, now there are a good number of shallow-related functions, and placing them all in 'commit.h' doesn't make sense. This patch extracts a 'shallow.h', which takes all of the headers from 'commit.h' for functions which already exist in 'shallow.c'. We will bring the remaining shallow-related functions defined in 'commit.c' in a subsequent patch. For now, move only the ones that already are implemented in 'shallow.c', and update the necessary includes. Signed-off-by: Taylor Blau --- builtin.h | 1 + commit.c | 1 + commit.h | 48 --------------------------------------- fetch-pack.c | 1 + send-pack.c | 1 + shallow.c | 1 + shallow.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ upload-pack.c | 1 + 8 files changed, 69 insertions(+), 48 deletions(-) create mode 100644 shallow.h diff --git a/builtin.h b/builtin.h index 2b25a80cde..2e701a023c 100644 --- a/builtin.h +++ b/builtin.h @@ -5,6 +5,7 @@ #include "strbuf.h" #include "cache.h" #include "commit.h" +#include "shallow.h" /* * builtin API diff --git a/commit.c b/commit.c index b76f7d72be..eebfbeb45d 100644 --- a/commit.c +++ b/commit.c @@ -20,6 +20,7 @@ #include "refs.h" #include "commit-reach.h" #include "run-command.h" +#include "shallow.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); diff --git a/commit.h b/commit.h index eb42e8b6d2..5cd984939b 100644 --- a/commit.h +++ b/commit.h @@ -248,55 +248,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit); struct oid_array; struct ref; -int register_shallow(struct repository *r, const struct object_id *oid); -int unregister_shallow(const struct object_id *oid); -int commit_shallow_file(struct repository *r, struct lock_file *lk); -void rollback_shallow_file(struct repository *r, struct lock_file *lk); int for_each_commit_graft(each_commit_graft_fn, void *); -int is_repository_shallow(struct repository *r); -struct commit_list *get_shallow_commits(struct object_array *heads, - int depth, int shallow_flag, int not_shallow_flag); -struct commit_list *get_shallow_commits_by_rev_list( - int ac, const char **av, int shallow_flag, int not_shallow_flag); -void set_alternate_shallow_file(struct repository *r, const char *path, int override); -int write_shallow_commits(struct strbuf *out, int use_pack_protocol, - const struct oid_array *extra); -void setup_alternate_shallow(struct lock_file *shallow_lock, - const char **alternate_shallow_file, - const struct oid_array *extra); -const char *setup_temporary_shallow(const struct oid_array *extra); -void advertise_shallow_grafts(int); - -/* - * Initialize with prepare_shallow_info() or zero-initialize (equivalent to - * prepare_shallow_info with a NULL oid_array). - */ -struct shallow_info { - struct oid_array *shallow; - int *ours, nr_ours; - int *theirs, nr_theirs; - struct oid_array *ref; - - /* for receive-pack */ - uint32_t **used_shallow; - int *need_reachability_test; - int *reachable; - int *shallow_ref; - struct commit **commits; - int nr_commits; -}; - -void prepare_shallow_info(struct shallow_info *, struct oid_array *); -void clear_shallow_info(struct shallow_info *); -void remove_nonexistent_theirs_shallow(struct shallow_info *); -void assign_shallow_commits_to_refs(struct shallow_info *info, - uint32_t **used, - int *ref_status); -int delayed_reachability_test(struct shallow_info *si, int c); -#define PRUNE_SHOW_ONLY 1 -#define PRUNE_QUICK 2 -void prune_shallow(unsigned options); -extern struct trace_key trace_shallow; int interactive_add(int argc, const char **argv, const char *prefix, int patch); int run_add_interactive(const char *revision, const char *patch_mode, diff --git a/fetch-pack.c b/fetch-pack.c index a618f3b029..401d028e41 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -22,6 +22,7 @@ #include "connected.h" #include "fetch-negotiator.h" #include "fsck.h" +#include "shallow.h" static int transfer_unpack_limit = -1; static int fetch_unpack_limit = -1; diff --git a/send-pack.c b/send-pack.c index 0407841ae8..e0ccfef75a 100644 --- a/send-pack.c +++ b/send-pack.c @@ -15,6 +15,7 @@ #include "sha1-array.h" #include "gpg-interface.h" #include "cache.h" +#include "shallow.h" int option_parse_push_signed(const struct option *opt, const char *arg, int unset) diff --git a/shallow.c b/shallow.c index 5010a6c732..d0191c7609 100644 --- a/shallow.c +++ b/shallow.c @@ -14,6 +14,7 @@ #include "commit-slab.h" #include "list-objects.h" #include "commit-reach.h" +#include "shallow.h" void set_alternate_shallow_file(struct repository *r, const char *path, int override) { diff --git a/shallow.h b/shallow.h new file mode 100644 index 0000000000..14dd748625 --- /dev/null +++ b/shallow.h @@ -0,0 +1,63 @@ +#ifndef SHALLOW_H +#define SHALLOW_H + +#include "lockfile.h" +#include "object.h" +#include "repository.h" +#include "strbuf.h" + +void set_alternate_shallow_file(struct repository *r, const char *path, int override); +int register_shallow(struct repository *r, const struct object_id *oid); +int is_repository_shallow(struct repository *r); +int commit_shallow_file(struct repository *r, struct lock_file *lk); +void rollback_shallow_file(struct repository *r, struct lock_file *lk); + +struct commit_list *get_shallow_commits(struct object_array *heads, + int depth, int shallow_flag, int not_shallow_flag); +struct commit_list *get_shallow_commits_by_rev_list( + int ac, const char **av, int shallow_flag, int not_shallow_flag); +int write_shallow_commits(struct strbuf *out, int use_pack_protocol, + const struct oid_array *extra); + +void setup_alternate_shallow(struct lock_file *shallow_lock, + const char **alternate_shallow_file, + const struct oid_array *extra); + +const char *setup_temporary_shallow(const struct oid_array *extra); + +void advertise_shallow_grafts(int); + +#define PRUNE_SHOW_ONLY 1 +#define PRUNE_QUICK 2 +void prune_shallow(unsigned options); + +/* + * Initialize with prepare_shallow_info() or zero-initialize (equivalent to + * prepare_shallow_info with a NULL oid_array). + */ +struct shallow_info { + struct oid_array *shallow; + int *ours, nr_ours; + int *theirs, nr_theirs; + struct oid_array *ref; + + /* for receive-pack */ + uint32_t **used_shallow; + int *need_reachability_test; + int *reachable; + int *shallow_ref; + struct commit **commits; + int nr_commits; +}; + +void prepare_shallow_info(struct shallow_info *, struct oid_array *); +void clear_shallow_info(struct shallow_info *); +void remove_nonexistent_theirs_shallow(struct shallow_info *); +void assign_shallow_commits_to_refs(struct shallow_info *info, + uint32_t **used, + int *ref_status); +int delayed_reachability_test(struct shallow_info *si, int c); + +extern struct trace_key trace_shallow; + +#endif /* SHALLOW_H */ diff --git a/upload-pack.c b/upload-pack.c index c53249cac1..e71b068291 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -26,6 +26,7 @@ #include "serve.h" #include "commit-graph.h" #include "commit-reach.h" +#include "shallow.h" /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) From patchwork Wed Apr 29 22:39:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 11518923 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 C713192C for ; Wed, 29 Apr 2020 22:39:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE2072076B for ; Wed, 29 Apr 2020 22:39:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20150623.gappssmtp.com header.i=@ttaylorr-com.20150623.gappssmtp.com header.b="UxUliOcY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbgD2Wjm (ORCPT ); Wed, 29 Apr 2020 18:39:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726164AbgD2Wjm (ORCPT ); Wed, 29 Apr 2020 18:39:42 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C64C03C1AE for ; Wed, 29 Apr 2020 15:39:41 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id x15so1832993pfa.1 for ; Wed, 29 Apr 2020 15:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9p4GzULsIw7Ze3ZZseCqf4KsvtZHdtvnA7ukG6lznSU=; b=UxUliOcYdgnxuGn9y0NSWrTAGbml0cVo0l6db92jlwaRIdILRdKRcTwPGDkUSFTNL/ 420lq/1+7vh4cIlZOba1D+Bwn1f4bsSuX7RsqMuN9WB3WgjWBGSZmx4Nnqwe0nDXtwh5 EuiJGdpOI71LGRlSVCzyAfYKzPCte+3zZx9aZw8/8WreON1dDwsFQPkAziq8lr8sUKjL UVWYdorg78/yliuGjfXwXsB1LJZikGv3iwvPKTVqo+CS4YyQJdzzx69JqHajILwId820 RvyKFq1kJIifQOpYvGGpSn7wiqVeLlAwOhEZ0ahqownIknNuL8M95f7RAX586Kz/7v1P ameg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9p4GzULsIw7Ze3ZZseCqf4KsvtZHdtvnA7ukG6lznSU=; b=KCPkhLiSg1WUDt+JhVIsO1OPY5Vya5GSSMDIb6B/JdRK4/ySYfH4ZisSrMy3MhyrZr NElXm48M4+db4aBrqNgPgSMxQ6R0JWWWSLppM4BJNQZ/tY2C/2IvziWvJG75TOJqj5JY FQuebGFObWTj2zVViiP9L+1XHCeYpxrUbx/qlH8Twe2jYiwsRFNzD6xL07iklRTsuwHR 2Tc2GfIUa/QvDe3fQ41T/SimDj8QjH+9K5yolJtFR+OnVw4RDQe7x3vnuXamZ7OBR7UR 3AfJ7gGTfzwBRM8DjQxe5PQ2Xp1p+HcVToCswqozBKNmm4l4zMinSXeenJU49tU0Vzqj ibAA== X-Gm-Message-State: AGi0PubWWppyA0I7vIpXF7wsYokK0r8rHCC/8esioLbN/mYNZEWO1hHb sP9296IMle9Mzyw1FH0IPo4gplirSSEaLWOi X-Google-Smtp-Source: APiQypJFoPvSxASMJ5SKEjSfhMktLyp6alMoV8PjlmI4ppFT6NDc7wXHMUBNefbOonuYk3vWVYS1Ig== X-Received: by 2002:a63:c70e:: with SMTP id n14mr395388pgg.249.1588199980330; Wed, 29 Apr 2020 15:39:40 -0700 (PDT) Received: from localhost ([8.44.146.30]) by smtp.gmail.com with ESMTPSA id g25sm1801571pfo.150.2020.04.29.15.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 15:39:39 -0700 (PDT) Date: Wed, 29 Apr 2020 16:39:38 -0600 From: Taylor Blau To: git@vger.kernel.org Cc: gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH 3/5] commit: move 'unregister_shallow' to 'shallow.h' Message-ID: <65ecfeaba56807926fbe532f94921c98298e50d5.1588199705.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the last commit, we introduced a header for the functions defined in 'shallow.c'. There is one remaining shallow-related function in commit.c which should be moved, too. This patch moves that function. Signed-off-by: Taylor Blau Reviewed-by: Jonathan Nieder --- commit.c | 13 ------------- shallow.c | 13 +++++++++++++ shallow.h | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/commit.c b/commit.c index eebfbeb45d..87686a7055 100644 --- a/commit.c +++ b/commit.c @@ -246,19 +246,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) return ret; } -int unregister_shallow(const struct object_id *oid) -{ - int pos = commit_graft_pos(the_repository, oid->hash); - if (pos < 0) - return -1; - if (pos + 1 < the_repository->parsed_objects->grafts_nr) - MOVE_ARRAY(the_repository->parsed_objects->grafts + pos, - the_repository->parsed_objects->grafts + pos + 1, - the_repository->parsed_objects->grafts_nr - pos - 1); - the_repository->parsed_objects->grafts_nr--; - return 0; -} - struct commit_buffer { void *buffer; unsigned long size; diff --git a/shallow.c b/shallow.c index d0191c7609..76e00893fe 100644 --- a/shallow.c +++ b/shallow.c @@ -39,6 +39,19 @@ int register_shallow(struct repository *r, const struct object_id *oid) return register_commit_graft(r, graft, 0); } +int unregister_shallow(const struct object_id *oid) +{ + int pos = commit_graft_pos(the_repository, oid->hash); + if (pos < 0) + return -1; + if (pos + 1 < the_repository->parsed_objects->grafts_nr) + MOVE_ARRAY(the_repository->parsed_objects->grafts + pos, + the_repository->parsed_objects->grafts + pos + 1, + the_repository->parsed_objects->grafts_nr - pos - 1); + the_repository->parsed_objects->grafts_nr--; + return 0; +} + int is_repository_shallow(struct repository *r) { FILE *fp; diff --git a/shallow.h b/shallow.h index 14dd748625..b50a85ed7e 100644 --- a/shallow.h +++ b/shallow.h @@ -8,6 +8,7 @@ void set_alternate_shallow_file(struct repository *r, const char *path, int override); int register_shallow(struct repository *r, const struct object_id *oid); +int unregister_shallow(const struct object_id *oid); int is_repository_shallow(struct repository *r); int commit_shallow_file(struct repository *r, struct lock_file *lk); void rollback_shallow_file(struct repository *r, struct lock_file *lk); From patchwork Wed Apr 29 22:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 11518925 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 9B7A292C for ; Wed, 29 Apr 2020 22:39:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 842AA208E0 for ; Wed, 29 Apr 2020 22:39:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20150623.gappssmtp.com header.i=@ttaylorr-com.20150623.gappssmtp.com header.b="dhgXwc4E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbgD2Wjq (ORCPT ); Wed, 29 Apr 2020 18:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726164AbgD2Wjp (ORCPT ); Wed, 29 Apr 2020 18:39:45 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3DD1C03C1AE for ; Wed, 29 Apr 2020 15:39:44 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id q124so1720699pgq.13 for ; Wed, 29 Apr 2020 15:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=8WTa9ZPG8ytkvnScnokmDHf+KiHubFgFeKynQGhi0zk=; b=dhgXwc4EcAtMdVF8hJHk1wBGpoeq34xDtF0ukQ4IF49gUcl/6OWCbfhvpkm7ptTlBO bbqLifF+oVfTlBsBoscIMY+74pwWwUCZKLruk95cpsDhx2VU1Vds1ErtCTWjaR7h2ZoK XkGImn8PoeOmGyGVB8cG2ITHRAesZeeOnQWBwqW32t2c3vD24h2TNO/fVKr9BD0VwoMT Jvz3np2huYVZoBnEgMUrqhQfbHnOtV9ANT7MGay9qyENywIZw6nGu1Sl+zoiSAoe2AFj T7IhlrtNCYU2trWd5rCEEA6N+Hwz8ORy7/AURN8hH0y2UPiR7sNg8apqh1AYO1tLvx6U JOUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8WTa9ZPG8ytkvnScnokmDHf+KiHubFgFeKynQGhi0zk=; b=hbz/bKhg/+EpH1ty3j/ApGWT3sPUS+vrAIINlWM12VEZhycid1ZXUlPOYc/tPnXgO9 qot0PFFRohTtjmV9PEAh4wyuqORSLK3uXkpbzLbps1qCu778PKBEMvjst8I7fsLg4QSc LbHlQ5q9GEoCp4aWHsDbwoEl692PItSh90O7eUIg3L7e9YwfVPGon49N/i6UGYAYjcAM K1oQ4ZIqn1/0zMHYBUte/HOxkkuOBKaswN+9fS1uyqJ8wQ+VZ3c8mnsxzLuT7BV14V2c KWg2c46sRThAxWgecEtVL03hTJdj/KzreEQIRdFwkMj24GaSSgp8I+uS24aj8aUGCMwH cK+A== X-Gm-Message-State: AGi0Pub6rU2Dy10H50Q1OQRu3F8006xmJR02AI9Pkan8mzjvI1N45V5n NZEdJkHO6wo1eiqRsKFt6/ZWdA1Sg+dt+w2h X-Google-Smtp-Source: APiQypJdKEMgTUNZB4qgUN3TxquHLqYMovUlPv11mu/9kETbO1shjwu83Nqj9jUHRNdMfdWV9n/D/A== X-Received: by 2002:a62:7c16:: with SMTP id x22mr343346pfc.267.1588199983823; Wed, 29 Apr 2020 15:39:43 -0700 (PDT) Received: from localhost ([8.44.146.30]) by smtp.gmail.com with ESMTPSA id y25sm1767339pgc.36.2020.04.29.15.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 15:39:43 -0700 (PDT) Date: Wed, 29 Apr 2020 16:39:42 -0600 From: Taylor Blau To: git@vger.kernel.org Cc: gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH 4/5] shallow.h: document '{commit,rollback}_shallow_file' Message-ID: <7828def924a767e54dd43b6c107e8f98c1698f55.1588199705.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When 'commit_shallow_file()' and 'rollback_shallow_file()' were introduced, they did not have an documenting comment, when they could have benefited from one. Add a brief note about what these functions do, and make a special note that they reset stat-validity checks. Signed-off-by: Taylor Blau --- shallow.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shallow.h b/shallow.h index b50a85ed7e..08e1bc4fd0 100644 --- a/shallow.h +++ b/shallow.h @@ -10,6 +10,10 @@ void set_alternate_shallow_file(struct repository *r, const char *path, int over int register_shallow(struct repository *r, const struct object_id *oid); int unregister_shallow(const struct object_id *oid); int is_repository_shallow(struct repository *r); +/* + * {commit,rollback}_shallow_file commits or performs a rollback to the + * '.git/shallow' file, respectively, and resets stat-validity checks. + */ int commit_shallow_file(struct repository *r, struct lock_file *lk); void rollback_shallow_file(struct repository *r, struct lock_file *lk); From patchwork Wed Apr 29 22:39:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 11518927 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 A734A92A for ; Wed, 29 Apr 2020 22:39:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B1752076B for ; Wed, 29 Apr 2020 22:39:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ttaylorr-com.20150623.gappssmtp.com header.i=@ttaylorr-com.20150623.gappssmtp.com header.b="LHhCv8SO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727093AbgD2Wjt (ORCPT ); Wed, 29 Apr 2020 18:39:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726164AbgD2Wjt (ORCPT ); Wed, 29 Apr 2020 18:39:49 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57AF3C03C1AE for ; Wed, 29 Apr 2020 15:39:49 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f8so1427854plt.2 for ; Wed, 29 Apr 2020 15:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PNWk2mKWb0iPa5yOQ/fYd8YsI2T86DD1ZAaKO3D/Rlc=; b=LHhCv8SOkwffjeEU70vwY0QhYZYi2i8jusFYGtiMTkjYWQsnzNPqtrR1q0WyiR8wmS H9Ofun4TJUrmNiva0id6YC+6qrhZ0TPLQE7nbd/K6LwkUnxvcmvWWczs2e7v++AFBuQm g6pnG5QaH9HbmWV3qzC2xmUd78NVDfSyLqgVAB2KrhhYVP6RXDEbvBL2OXige5NDFLXf hsJn8zj4sgIDEtwpBOpyljfC1xSuWR3S998vRVrWoDLxts8W3pHfn+meq3jC8N/Qwciy CgZqUcj84Wp0CXLH6XO3RzuY0wX5ctUKXLAgZt9Dk+Lpxqfw4QDiwpEys+gZTaXauqxC pN6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PNWk2mKWb0iPa5yOQ/fYd8YsI2T86DD1ZAaKO3D/Rlc=; b=IlnB3EOtoaL1bdSsuArImi80g7Q3TuSOQ51aARrF9xkP4U38avdR0rSOqJGoqDhtFH WKYQtKk01VIMdrzU44nYJpEINXxTJzXhcwaTO/MAmnx1OiEJUbGSEDn/fQ2frXH346IC U/gkuBSaiQUm3LSbA8VOZh1zNGGHuHa2wCduGhoF75lBpQufj5hM6QsCGlcj2Qm7l03O gY/D6LWIhAgFLENvWd3uy4Lk9pi3cvNFMHvIbXV2U4iOczcwBdoN65RDJKTJUxamEAzi 6EBHPB2CVLo2anNP6xUAJiB1jLXsTUIFW/A8vufjdVNq1vQTsxPgombr7SFPHbIEW43I iY2w== X-Gm-Message-State: AGi0PuZvEq5mQm6hr+c/Xg7dTe2+6CCSMQGJLqMzvcpNktNG9f16PAnp 0OalWCgJwA0+aViCNsVWit6GQ0b9it0pAdZP X-Google-Smtp-Source: APiQypL4oLEVbGptj1VkTbF3+9dcr7C4dUitjOGoOKkcuY6AHo1JUki6ePaslQGyDcQWJZkDknMAdA== X-Received: by 2002:a17:90a:20a8:: with SMTP id f37mr824351pjg.148.1588199988117; Wed, 29 Apr 2020 15:39:48 -0700 (PDT) Received: from localhost ([8.44.146.30]) by smtp.gmail.com with ESMTPSA id c2sm1863040pfp.118.2020.04.29.15.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 15:39:47 -0700 (PDT) Date: Wed, 29 Apr 2020 16:39:46 -0600 From: Taylor Blau To: git@vger.kernel.org Cc: gitster@pobox.com, jonathantanmy@google.com, jrnieder@gmail.com Subject: [PATCH 5/5] shallow: use struct 'shallow_lock' for additional safety Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In previous patches, the functions 'commit_shallow_file' and 'rollback_shallow_file' were introduced to reset the shallowness validity checks on a repository after potentially modifying '.git/shallow'. These functions can be made safer by wrapping the 'struct lockfile *' in a new type, 'shallow_lock', so that they cannot be called with a raw lock (and potentially misused by other code that happens to possess a lockfile, but has nothing to do with shallowness). This patch introduces that type as a thin wrapper around 'struct lockfile', and updates the two aforementioned functions and their callers to use it. Suggested-by: Junio C Hamano Signed-off-by: Taylor Blau Reviewed-by: Jonathan Nieder --- builtin/receive-pack.c | 2 +- fetch-pack.c | 2 +- shallow.c | 22 +++++++++++----------- shallow.h | 16 +++++++++++++--- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 652661fa99..10fd2c52ec 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -855,7 +855,7 @@ static void refuse_unconfigured_deny_delete_current(void) static int command_singleton_iterator(void *cb_data, struct object_id *oid); static int update_shallow_ref(struct command *cmd, struct shallow_info *si) { - struct lock_file shallow_lock = LOCK_INIT; + struct shallow_lock shallow_lock = SHALLOW_LOCK_INIT; struct oid_array extra = OID_ARRAY_INIT; struct check_connected_options opt = CHECK_CONNECTED_INIT; uint32_t mask = 1 << (cmd->index % 32); diff --git a/fetch-pack.c b/fetch-pack.c index 401d028e41..27d2d08cc0 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -35,7 +35,7 @@ static int fetch_fsck_objects = -1; static int transfer_fsck_objects = -1; static int agent_supported; static int server_supports_filtering; -static struct lock_file shallow_lock; +static struct shallow_lock shallow_lock; static const char *alternate_shallow_file; static struct strbuf fsck_msg_types = STRBUF_INIT; diff --git a/shallow.c b/shallow.c index 76e00893fe..1acf8ce95b 100644 --- a/shallow.c +++ b/shallow.c @@ -92,16 +92,16 @@ static void reset_repository_shallow(struct repository *r) stat_validity_clear(r->parsed_objects->shallow_stat); } -int commit_shallow_file(struct repository *r, struct lock_file *lk) +int commit_shallow_file(struct repository *r, struct shallow_lock *lk) { - int res = commit_lock_file(lk); + int res = commit_lock_file(&lk->lk); reset_repository_shallow(r); return res; } -void rollback_shallow_file(struct repository *r, struct lock_file *lk) +void rollback_shallow_file(struct repository *r, struct shallow_lock *lk) { - rollback_lock_file(lk); + rollback_lock_file(&lk->lk); reset_repository_shallow(r); } @@ -366,22 +366,22 @@ const char *setup_temporary_shallow(const struct oid_array *extra) return ""; } -void setup_alternate_shallow(struct lock_file *shallow_lock, +void setup_alternate_shallow(struct shallow_lock *shallow_lock, const char **alternate_shallow_file, const struct oid_array *extra) { struct strbuf sb = STRBUF_INIT; int fd; - fd = hold_lock_file_for_update(shallow_lock, + fd = hold_lock_file_for_update(&shallow_lock->lk, git_path_shallow(the_repository), LOCK_DIE_ON_ERROR); check_shallow_file_for_update(the_repository); if (write_shallow_commits(&sb, 0, extra)) { if (write_in_full(fd, sb.buf, sb.len) < 0) die_errno("failed to write to %s", - get_lock_file_path(shallow_lock)); - *alternate_shallow_file = get_lock_file_path(shallow_lock); + get_lock_file_path(&shallow_lock->lk)); + *alternate_shallow_file = get_lock_file_path(&shallow_lock->lk); } else /* * is_repository_shallow() sees empty string as "no @@ -414,7 +414,7 @@ void advertise_shallow_grafts(int fd) */ void prune_shallow(unsigned options) { - struct lock_file shallow_lock = LOCK_INIT; + struct shallow_lock shallow_lock = SHALLOW_LOCK_INIT; struct strbuf sb = STRBUF_INIT; unsigned flags = SEEN_ONLY; int fd; @@ -428,14 +428,14 @@ void prune_shallow(unsigned options) strbuf_release(&sb); return; } - fd = hold_lock_file_for_update(&shallow_lock, + fd = hold_lock_file_for_update(&shallow_lock.lk, git_path_shallow(the_repository), LOCK_DIE_ON_ERROR); check_shallow_file_for_update(the_repository); if (write_shallow_commits_1(&sb, 0, NULL, flags)) { if (write_in_full(fd, sb.buf, sb.len) < 0) die_errno("failed to write to %s", - get_lock_file_path(&shallow_lock)); + get_lock_file_path(&shallow_lock.lk)); commit_shallow_file(the_repository, &shallow_lock); } else { unlink(git_path_shallow(the_repository)); diff --git a/shallow.h b/shallow.h index 08e1bc4fd0..d12096fbc4 100644 --- a/shallow.h +++ b/shallow.h @@ -10,12 +10,22 @@ void set_alternate_shallow_file(struct repository *r, const char *path, int over int register_shallow(struct repository *r, const struct object_id *oid); int unregister_shallow(const struct object_id *oid); int is_repository_shallow(struct repository *r); + +/* + * shallow_lock is a thin wrapper around 'struct lock_file' in order to restrict + * which locks can be used with '{commit,rollback}_shallow_file()'. + */ +struct shallow_lock { + struct lock_file lk; +}; +#define SHALLOW_LOCK_INIT { LOCK_INIT } + /* * {commit,rollback}_shallow_file commits or performs a rollback to the * '.git/shallow' file, respectively, and resets stat-validity checks. */ -int commit_shallow_file(struct repository *r, struct lock_file *lk); -void rollback_shallow_file(struct repository *r, struct lock_file *lk); +int commit_shallow_file(struct repository *r, struct shallow_lock *lk); +void rollback_shallow_file(struct repository *r, struct shallow_lock *lk); struct commit_list *get_shallow_commits(struct object_array *heads, int depth, int shallow_flag, int not_shallow_flag); @@ -24,7 +34,7 @@ struct commit_list *get_shallow_commits_by_rev_list( int write_shallow_commits(struct strbuf *out, int use_pack_protocol, const struct oid_array *extra); -void setup_alternate_shallow(struct lock_file *shallow_lock, +void setup_alternate_shallow(struct shallow_lock *shallow_lock, const char **alternate_shallow_file, const struct oid_array *extra);