From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>
Subject: [PATCH 17/19] shallow: migrate shallow information into the object parser
Date: Tue, 15 May 2018 16:42:31 -0700 [thread overview]
Message-ID: <20180515234233.143708-18-sbeller@google.com> (raw)
In-Reply-To: <20180515234233.143708-1-sbeller@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
commit.h | 9 +++------
object.c | 3 +++
object.h | 4 ++++
shallow.c | 50 ++++++++++++++++++++++++--------------------------
4 files changed, 34 insertions(+), 32 deletions(-)
diff --git a/commit.h b/commit.h
index d04bbed81cf..45114a95b25 100644
--- a/commit.h
+++ b/commit.h
@@ -190,18 +190,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
struct oid_array;
struct ref;
-#define register_shallow(r, o) register_shallow_##r(o);
-extern int register_shallow_the_repository(const struct object_id *oid);
+extern int register_shallow(struct repository *r, const struct object_id *oid);
extern int unregister_shallow(const struct object_id *oid);
extern int for_each_commit_graft(each_commit_graft_fn, void *);
-#define is_repository_shallow(r) is_repository_shallow_##r()
-extern int is_repository_shallow_the_repository(void);
+extern int is_repository_shallow(struct repository *r);
extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
extern struct commit_list *get_shallow_commits_by_rev_list(
int ac, const char **av, int shallow_flag, int not_shallow_flag);
-#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)
-extern void set_alternate_shallow_file_the_repository(const char *path, int override);
+extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
const struct oid_array *extra);
extern void setup_alternate_shallow(struct lock_file *shallow_lock,
diff --git a/object.c b/object.c
index 0116ed6529a..30b8a721cf6 100644
--- a/object.c
+++ b/object.c
@@ -464,6 +464,9 @@ struct parsed_object_pool *parsed_object_pool_new(void)
o->tag_state = allocate_alloc_state();
o->object_state = allocate_alloc_state();
+ o->is_shallow = -1;
+ o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
+
return o;
}
diff --git a/object.h b/object.h
index ec908f9bcc1..a314331acaf 100644
--- a/object.h
+++ b/object.h
@@ -16,6 +16,10 @@ struct parsed_object_pool {
/* parent substitutions from .git/info/grafts and .git/shallow */
struct commit_graft **grafts;
int grafts_alloc, grafts_nr;
+
+ int is_shallow;
+ struct stat_validity *shallow_stat;
+ char *alternate_shallow_file;
};
struct parsed_object_pool *parsed_object_pool_new(void);
diff --git a/shallow.c b/shallow.c
index a0e338459f9..560329d53a8 100644
--- a/shallow.c
+++ b/shallow.c
@@ -14,22 +14,21 @@
#include "commit-slab.h"
#include "revision.h"
#include "list-objects.h"
+#include "repository.h"
-static int is_shallow = -1;
-static struct stat_validity shallow_stat;
-static char *alternate_shallow_file;
+struct stat_validity the_repository_shallow_stat;
-void set_alternate_shallow_file_the_repository(const char *path, int override)
+void set_alternate_shallow_file(struct repository *r, const char *path, int override)
{
- if (is_shallow != -1)
+ if (r->parsed_objects->is_shallow != -1)
die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
- if (alternate_shallow_file && !override)
+ if (r->parsed_objects->alternate_shallow_file && !override)
return;
- free(alternate_shallow_file);
- alternate_shallow_file = xstrdup_or_null(path);
+ free(r->parsed_objects->alternate_shallow_file);
+ r->parsed_objects->alternate_shallow_file = xstrdup_or_null(path);
}
-int register_shallow_the_repository(const struct object_id *oid)
+int register_shallow(struct repository *r, const struct object_id *oid)
{
struct commit_graft *graft =
xmalloc(sizeof(struct commit_graft));
@@ -39,41 +38,41 @@ int register_shallow_the_repository(const struct object_id *oid)
graft->nr_parent = -1;
if (commit && commit->object.parsed)
commit->parents = NULL;
- return register_commit_graft(the_repository, graft, 0);
+ return register_commit_graft(r, graft, 0);
}
-int is_repository_shallow_the_repository(void)
+int is_repository_shallow(struct repository *r)
{
FILE *fp;
char buf[1024];
- const char *path = alternate_shallow_file;
+ const char *path = r->parsed_objects->alternate_shallow_file;
- if (is_shallow >= 0)
- return is_shallow;
+ if (r->parsed_objects->is_shallow >= 0)
+ return r->parsed_objects->is_shallow;
if (!path)
- path = git_path_shallow(the_repository);
+ path = git_path_shallow(r);
/*
* fetch-pack sets '--shallow-file ""' as an indicator that no
* 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 || (fp = fopen(path, "r")) == NULL) {
- stat_validity_clear(&shallow_stat);
- is_shallow = 0;
- return is_shallow;
+ stat_validity_clear(r->parsed_objects->shallow_stat);
+ r->parsed_objects->is_shallow = 0;
+ return r->parsed_objects->is_shallow;
}
- stat_validity_update(&shallow_stat, fileno(fp));
- is_shallow = 1;
+ stat_validity_update(r->parsed_objects->shallow_stat, fileno(fp));
+ r->parsed_objects->is_shallow = 1;
while (fgets(buf, sizeof(buf), fp)) {
struct object_id oid;
if (get_oid_hex(buf, &oid))
die("bad shallow line: %s", buf);
- register_shallow(the_repository, &oid);
+ register_shallow(r, &oid);
}
fclose(fp);
- return is_shallow;
+ return r->parsed_objects->is_shallow;
}
struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
@@ -217,13 +216,12 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
return result;
}
-#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r()
-static void check_shallow_file_for_update_the_repository(void)
+static void check_shallow_file_for_update(struct repository *r)
{
- if (is_shallow == -1)
+ if (r->parsed_objects->is_shallow == -1)
die("BUG: shallow must be initialized by now");
- if (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository)))
+ if (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository)))
die("shallow file has changed since we read it");
}
--
2.17.0.582.gccdcbd54c44.dirty
next prev parent reply other threads:[~2018-05-15 23:43 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 23:42 [RFC PATCH 00/19] object store: grafts and shallow Stefan Beller
2018-05-15 23:42 ` [PATCH 01/19] object-store: move object access functions to object-store.h Stefan Beller
2018-05-15 23:42 ` [PATCH 02/19] object: move grafts to object parser Stefan Beller
2018-05-15 23:42 ` [PATCH 03/19] commit: add repository argument to commit_graft_pos Stefan Beller
2018-05-15 23:42 ` [PATCH 04/19] commit: add repository argument to register_commit_graft Stefan Beller
2018-05-15 23:42 ` [PATCH 05/19] commit: add repository argument to read_graft_file Stefan Beller
2018-05-15 23:42 ` [PATCH 06/19] commit: add repository argument to prepare_commit_graft Stefan Beller
2018-05-15 23:42 ` [PATCH 07/19] commit: add repository argument to lookup_commit_graft Stefan Beller
2018-05-15 23:42 ` [PATCH 08/19] shallow: add repository argument to set_alternate_shallow_file Stefan Beller
2018-05-15 23:42 ` [PATCH 09/19] shallow: add repository argument to register_shallow Stefan Beller
2018-05-15 23:42 ` [PATCH 10/19] shallow: add repository argument to check_shallow_file_for_update Stefan Beller
2018-05-15 23:42 ` [PATCH 11/19] shallow: add repository argument to is_repository_shallow Stefan Beller
2018-05-15 23:42 ` [PATCH 12/19] commit: convert commit_graft_pos() to handle arbitrary repositories Stefan Beller
2018-05-15 23:42 ` [PATCH 13/19] commit: convert register_commit_graft " Stefan Beller
2018-05-15 23:42 ` [PATCH 14/19] commit: convert read_graft_file " Stefan Beller
2018-05-15 23:42 ` [PATCH 15/19] cache: convert get_graft_file " Stefan Beller
2018-05-15 23:42 ` [PATCH 16/19] path.c: migrate git_path_ to take a repository argument Stefan Beller
2018-05-15 23:42 ` Stefan Beller [this message]
2018-05-15 23:42 ` [PATCH 18/19] commit: allow prepare_commit_graft to handle arbitrary repositories Stefan Beller
2018-05-15 23:42 ` [PATCH 19/19] commit: allow lookup_commit_graft " Stefan Beller
2018-05-17 22:51 ` [PATCH 00/19] object store: grafts and shallow Stefan Beller
2018-05-17 22:51 ` [PATCH 01/19] object-store: move object access functions to object-store.h Stefan Beller
2018-05-17 22:51 ` [PATCH 02/19] object: move grafts to object parser Stefan Beller
2018-05-17 22:51 ` [PATCH 03/19] commit: add repository argument to commit_graft_pos Stefan Beller
2018-05-17 22:51 ` [PATCH 04/19] commit: add repository argument to register_commit_graft Stefan Beller
2018-05-17 22:51 ` [PATCH 05/19] commit: add repository argument to read_graft_file Stefan Beller
2018-05-17 22:51 ` [PATCH 06/19] commit: add repository argument to prepare_commit_graft Stefan Beller
2018-05-17 22:51 ` [PATCH 07/19] commit: add repository argument to lookup_commit_graft Stefan Beller
2018-05-17 22:51 ` [PATCH 08/19] shallow: add repository argument to set_alternate_shallow_file Stefan Beller
2018-05-17 22:51 ` [PATCH 09/19] shallow: add repository argument to register_shallow Stefan Beller
2018-05-17 22:51 ` [PATCH 10/19] shallow: add repository argument to check_shallow_file_for_update Stefan Beller
2018-05-17 22:51 ` [PATCH 11/19] shallow: add repository argument to is_repository_shallow Stefan Beller
2018-05-17 22:51 ` [PATCH 12/19] commit: convert commit_graft_pos() to handle arbitrary repositories Stefan Beller
2018-05-17 22:51 ` [PATCH 13/19] commit: convert register_commit_graft " Stefan Beller
2018-05-17 22:51 ` [PATCH 14/19] commit: convert read_graft_file " Stefan Beller
2018-05-17 22:51 ` [PATCH 15/19] cache: convert get_graft_file " Stefan Beller
2018-05-17 22:51 ` [PATCH 16/19] path.c: migrate global git_path_* to take a repository argument Stefan Beller
2018-05-17 22:51 ` [PATCH 17/19] shallow: migrate shallow information into the object parser Stefan Beller
2018-05-17 22:51 ` [PATCH 18/19] commit: allow prepare_commit_graft to handle arbitrary repositories Stefan Beller
2018-05-17 22:51 ` [PATCH 19/19] commit: allow lookup_commit_graft " Stefan Beller
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=20180515234233.143708-18-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
/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).