From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v3 2/4] fetch-pack: prepare updated shallow file before fetching the pack
Date: Tue, 07 May 2013 08:59:58 -0700 [thread overview]
Message-ID: <7va9o6lr0h.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1367584514-19806-3-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Fri, 3 May 2013 19:35:12 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> index-pack --strict looks up and follows parent commits. If shallow
> information is not ready by the time index-pack is run, index-pack may
> be lead to non-existent objects. Make fetch-pack save shallow file to
> disk before invoking index-pack.
>
> git learns new global option --shallow-file to pass on the alternate
> shallow file path. Undocumented (and not even support --shallow-file=
> syntax) because it's unlikely to be used again elsewhere.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> commit.h | 2 ++
> fetch-pack.c | 69 +++++++++++++++++++++++++--------------------------
> git.c | 5 ++++
> shallow.c | 45 +++++++++++++++++++++++++++++++--
> t/t5500-fetch-pack.sh | 7 ++++++
> 5 files changed, 91 insertions(+), 37 deletions(-)
>
> diff --git a/commit.h b/commit.h
> index 67bd509..6e9c7cd 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -176,6 +176,8 @@ extern int for_each_commit_graft(each_commit_graft_fn, void *);
> extern int is_repository_shallow(void);
> extern struct commit_list *get_shallow_commits(struct object_array *heads,
> int depth, int shallow_flag, int not_shallow_flag);
> +extern void check_shallow_file_for_update(void);
> +extern void set_alternate_shallow_file(const char *path);
>
> int is_descendant_of(struct commit *, struct commit_list *);
> int in_merge_bases(struct commit *, struct commit *);
> diff --git a/fetch-pack.c b/fetch-pack.c
> index f156dd4..1ca4f6b 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -20,6 +20,8 @@ static int no_done;
> static int fetch_fsck_objects = -1;
> static int transfer_fsck_objects = -1;
> static int agent_supported;
> +static struct lock_file shallow_lock;
> +static const char *alternate_shallow_file;
>
> #define COMPLETE (1U << 0)
> #define COMMON (1U << 1)
> @@ -683,7 +685,7 @@ static int get_pack(struct fetch_pack_args *args,
> int xd[2], char **pack_lockfile)
> {
> struct async demux;
> - const char *argv[20];
> + const char *argv[22];
> char keep_arg[256];
> char hdr_arg[256];
> const char **av;
> @@ -724,6 +726,11 @@ static int get_pack(struct fetch_pack_args *args,
> do_keep = 1;
> }
>
> + if (alternate_shallow_file) {
> + *av++ = "--shallow-file";
> + *av++ = alternate_shallow_file;
> + }
> +
> if (do_keep) {
> if (pack_lockfile)
> cmd.out = -1;
> @@ -779,6 +786,23 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
> return strcmp(a->name, b->name);
> }
>
> +static void setup_alternate_shallow(void)
> +{
> + struct strbuf sb = STRBUF_INIT;
> + int fd;
> +
> + check_shallow_file_for_update();
> + fd = hold_lock_file_for_update(&shallow_lock, git_path("shallow"),
> + LOCK_DIE_ON_ERROR);
> + if (write_shallow_commits(&sb, 0)) {
> + if (write_in_full(fd, sb.buf, sb.len) != sb.len)
> + die_errno("failed to write to %s", shallow_lock.filename);
> + alternate_shallow_file = shallow_lock.filename;
> + } else
> + alternate_shallow_file = "";
This "empty string, not NULL" trick needs to be commented here to
match the other place that uses this as a cue to do things
differently.
> + strbuf_release(&sb);
> +}
> +
> static struct ref *do_fetch_pack(struct fetch_pack_args *args,
> int fd[2],
> const struct ref *orig_ref,
> @@ -858,6 +882,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
>
> if (args->stateless_rpc)
> packet_flush(fd[1]);
> + if (args->depth > 0)
> + setup_alternate_shallow();
> if (get_pack(args, fd, pack_lockfile))
> die("git fetch-pack: fetch failed.");
>
> @@ -936,15 +962,9 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
> struct ref **sought, int nr_sought,
> char **pack_lockfile)
> {
> struct ref *ref_cpy;
>
> fetch_pack_setup();
> if (nr_sought)
> nr_sought = remove_duplicates_in_refs(sought, nr_sought);
>
> @@ -955,34 +975,13 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
> ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
>
> if (args->depth > 0) {
> + struct stat st;
> + if (!fstat(shallow_lock.fd, &st) &&
> + st.st_size == 0) {
> + unlink_or_warn(git_path("shallow"));
Are we unlinking the right file here?
> + rollback_lock_file(&shallow_lock);
> + } else
> + commit_lock_file(&shallow_lock);
> }
>
> reprepare_packed_git();
> diff --git a/git.c b/git.c
> index 1ada169..6450a38 100644
> --- a/git.c
> +++ b/git.c
> @@ -4,6 +4,7 @@
> #include "help.h"
> #include "quote.h"
> #include "run-command.h"
> +#include "commit.h"
>
> const char git_usage_string[] =
> "git [--version] [--help] [-c name=value]\n"
> @@ -146,6 +147,10 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
> setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "0", 1);
> if (envchanged)
> *envchanged = 1;
> + } else if (!strcmp(cmd, "--shallow-file")) {
> + (*argv)++;
> + (*argc)--;
> + set_alternate_shallow_file((*argv)[0]);
Should this count as "envchanged"?
> diff --git a/shallow.c b/shallow.c
> index 6be915f..bdae988 100644
> --- a/shallow.c
> +++ b/shallow.c
> @@ -3,6 +3,16 @@
> #include "tag.h"
>
> static int is_shallow = -1;
> +static struct stat shallow_stat;
> +static char *alternate_shallow_file;
> +
> +void set_alternate_shallow_file(const char *path)
> +{
> + if (is_shallow != -1)
> + die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
> + free(alternate_shallow_file);
> + alternate_shallow_file = path ? xstrdup(path) : NULL;
> +}
>
> int register_shallow(const unsigned char *sha1)
> {
> @@ -21,12 +31,21 @@ int is_repository_shallow(void)
> {
> FILE *fp;
> char buf[1024];
> + const char *path = alternate_shallow_file;
>
> if (is_shallow >= 0)
> return is_shallow;
>
> - fp = fopen(git_path("shallow"), "r");
> - if (!fp) {
> + if (!path)
> + path = git_path("shallow");
> + /*
> + * fetch-pack set '--shallow-file ""' as an indicator that no
s/set/&s/?
> + * shallow file should be used. We could just open it and it
> + * will likely fail. But let's do an explicit check instead.
> + */
> + if (!*path ||
> + stat(path, &shallow_stat) ||
> + (fp = fopen(path, "r")) == NULL) {
> is_shallow = 0;
> return is_shallow;
> }
> @@ -108,3 +127,25 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
>
> return result;
> }
> +
> +void check_shallow_file_for_update(void)
> +{
> + struct stat st;
> +
> + if (getenv("GIT_SHALLOW_FILE"))
> + die("GIT_SHALLOW_FILE should not be manually set");
Forgot to remove this?
> + if (!is_shallow)
> + return;
> + else if (is_shallow == -1)
> + die("BUG: shallow must be initialized by now");
> +
> + if (stat(git_path("shallow"), &st))
> + die("shallow file was removed during fetch");
> + else if (st.st_mtime != shallow_stat.st_mtime
> +#ifdef USE_NSEC
> + || ST_MTIME_NSEC(st) != ST_MTIME_NSEC(shallow_stat)
> +#endif
> + )
> + die("shallow file was changed during fetch");
> +}
> diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
> index d574085..557b073 100755
> --- a/t/t5500-fetch-pack.sh
> +++ b/t/t5500-fetch-pack.sh
> @@ -135,6 +135,13 @@ test_expect_success 'clone shallow depth 1' '
> test "`git --git-dir=shallow0/.git rev-list --count HEAD`" = 1
> '
>
> +test_expect_success 'clone shallow depth 1 with fsck' '
> + git config --global fetch.fsckobjects true &&
> + git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0fsck &&
> + test "`git --git-dir=shallow0fsck/.git rev-list --count HEAD`" = 1 &&
> + git config --global --unset fetch.fsckobjects
> +'
> +
> test_expect_success 'clone shallow' '
> git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
> '
next prev parent reply other threads:[~2013-05-07 16:00 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-31 11:09 [PATCH 0/4] check_everything_connected replacement Nguyễn Thái Ngọc Duy
2013-03-31 11:09 ` [PATCH 1/4] fetch-pack: save shallow file before fetching the pack Nguyễn Thái Ngọc Duy
2013-04-01 14:53 ` Junio C Hamano
2013-04-05 2:11 ` Duy Nguyen
2013-03-31 11:09 ` [PATCH 2/4] index-pack: remove dead code (it should never happen) Nguyễn Thái Ngọc Duy
2013-03-31 11:09 ` [PATCH 3/4] index-pack, unpack-objects: add --not-so-strict for connectivity check Nguyễn Thái Ngọc Duy
2013-03-31 11:09 ` [PATCH 4/4] Use --not-so-strict on all pack transfer " Nguyễn Thái Ngọc Duy
2013-04-01 14:48 ` [PATCH 0/4] check_everything_connected replacement Junio C Hamano
2013-05-01 10:59 ` [PATCH v2 0/5] " Nguyễn Thái Ngọc Duy
2013-05-01 10:59 ` [PATCH v2 1/5] clone: let the user know when check_everything_connected is run Nguyễn Thái Ngọc Duy
2013-05-01 10:59 ` [PATCH v2 2/5] fetch-pack: prepare updated shallow file before fetching the pack Nguyễn Thái Ngọc Duy
2013-05-01 20:27 ` Junio C Hamano
2013-05-02 10:04 ` Duy Nguyen
2013-05-01 10:59 ` [PATCH v2 3/5] index-pack: remove dead code (it should never happen) Nguyễn Thái Ngọc Duy
2013-05-01 10:59 ` [PATCH v2 4/5] index-pack, unpack-objects: add --not-so-strict for connectivity check Nguyễn Thái Ngọc Duy
2013-05-01 23:35 ` Junio C Hamano
2013-05-02 9:53 ` Duy Nguyen
2013-05-02 16:27 ` Junio C Hamano
2013-05-03 2:29 ` Duy Nguyen
2013-05-03 6:33 ` Junio C Hamano
2013-05-03 6:55 ` Junio C Hamano
2013-05-03 7:09 ` Duy Nguyen
2013-05-03 8:16 ` Eric Sunshine
2013-05-01 10:59 ` [PATCH v2 5/5] Use --not-so-strict on all pack transfer " Nguyễn Thái Ngọc Duy
2013-05-03 12:35 ` [PATCH v3 0/4] check_everything_connected replacement Nguyễn Thái Ngọc Duy
2013-05-03 12:35 ` [PATCH v3 1/4] clone: let the user know when check_everything_connected is run Nguyễn Thái Ngọc Duy
2013-05-03 12:35 ` [PATCH v3 2/4] fetch-pack: prepare updated shallow file before fetching the pack Nguyễn Thái Ngọc Duy
2013-05-03 12:37 ` Eric Sunshine
2013-05-07 15:59 ` Junio C Hamano [this message]
2013-05-26 1:01 ` Duy Nguyen
2013-05-03 12:35 ` [PATCH v3 3/4] index-pack: remove dead code (it should never happen) Nguyễn Thái Ngọc Duy
2013-05-03 12:35 ` [PATCH v3 4/4] clone: open a shortcut for connectivity check Nguyễn Thái Ngọc Duy
2013-05-03 12:41 ` Eric Sunshine
2013-05-03 16:15 ` Junio C Hamano
2013-05-04 1:10 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7va9o6lr0h.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).