All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: [PATCH 03/39] object-store: move alt_odb_list and alt_odb_tail to object store
Date: Tue, 29 Aug 2017 23:53:21 -0700	[thread overview]
Message-ID: <20170830065321.GD153983@aiede.mtv.corp.google.com> (raw)
In-Reply-To: <20170830064634.GA153983@aiede.mtv.corp.google.com>

From: Stefan Beller <sbeller@google.com>

In a process with multiple repositories open, alternates should be
associated to a single repository and not shared globally. Move
alt_odb_list and alt_odb_tail into the_repository and adjust callers
to reflect this.

No functional change intended.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin/fsck.c |  4 +++-
 cache.h        |  4 ++--
 object-store.h |  6 +++++-
 packfile.c     |  3 ++-
 sha1_file.c    | 25 ++++++++++++-------------
 sha1_name.c    |  3 ++-
 6 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 1e4c471b41..188e32acd6 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "commit.h"
 #include "tree.h"
@@ -699,7 +700,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		fsck_object_dir(get_object_directory());
 
 		prepare_alt_odb();
-		for (alt = alt_odb_list; alt; alt = alt->next)
+		for (alt = the_repository->objects.alt_odb_list;
+				alt; alt = alt->next)
 			fsck_object_dir(alt->path);
 
 		if (check_full) {
diff --git a/cache.h b/cache.h
index 49b083ee0a..8d0d34f78b 100644
--- a/cache.h
+++ b/cache.h
@@ -1504,7 +1504,7 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);
 extern void schedule_dir_for_removal(const char *name, int len);
 extern void remove_scheduled_dirs(void);
 
-extern struct alternate_object_database {
+struct alternate_object_database {
 	struct alternate_object_database *next;
 
 	/* see alt_scratch_buf() */
@@ -1522,7 +1522,7 @@ extern struct alternate_object_database {
 	struct oid_array loose_objects_cache;
 
 	char path[FLEX_ARRAY];
-} *alt_odb_list;
+};
 extern void prepare_alt_odb(void);
 extern char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
diff --git a/object-store.h b/object-store.h
index 05722cdde0..ace3efbfab 100644
--- a/object-store.h
+++ b/object-store.h
@@ -1,8 +1,12 @@
 #ifndef OBJECT_STORE_H
 #define OBJECT_STORE_H
 
+#include "cache.h"
+
 struct object_store {
+	struct alternate_object_database *alt_odb_list;
+	struct alternate_object_database **alt_odb_tail;
 };
-#define OBJECT_STORE_INIT {}
+#define OBJECT_STORE_INIT { NULL, NULL }
 
 #endif /* OBJECT_STORE_H */
diff --git a/packfile.c b/packfile.c
index f69a5c8d60..5040c9f137 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "mru.h"
 #include "pack.h"
+#include "repository.h"
 #include "dir.h"
 #include "mergesort.h"
 #include "packfile.h"
@@ -873,7 +874,7 @@ void prepare_packed_git(void)
 		return;
 	prepare_packed_git_one(get_object_directory(), 1);
 	prepare_alt_odb();
-	for (alt = alt_odb_list; alt; alt = alt->next)
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next)
 		prepare_packed_git_one(alt->path, 0);
 	rearrange_packed_git();
 	prepare_packed_git_mru();
diff --git a/sha1_file.c b/sha1_file.c
index f56bb5cae7..7c6ffd205a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -22,6 +22,7 @@
 #include "pack-revindex.h"
 #include "sha1-lookup.h"
 #include "bulk-checkin.h"
+#include "repository.h"
 #include "streaming.h"
 #include "dir.h"
 #include "mru.h"
@@ -276,9 +277,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
 	return buf->buf;
 }
 
-struct alternate_object_database *alt_odb_list;
-static struct alternate_object_database **alt_odb_tail;
-
 /*
  * Return non-zero iff the path is usable as an alternate object database.
  */
@@ -298,7 +296,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
 	 * Prevent the common mistake of listing the same
 	 * thing twice, or object directory itself.
 	 */
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		if (!fspathcmp(path->buf, alt->path))
 			return 0;
 	}
@@ -358,8 +356,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
 	ent = alloc_alt_odb(pathbuf.buf);
 
 	/* add the alternate entry */
-	*alt_odb_tail = ent;
-	alt_odb_tail = &(ent->next);
+	*the_repository->objects.alt_odb_tail = ent;
+	the_repository->objects.alt_odb_tail = &(ent->next);
 	ent->next = NULL;
 
 	/* recursively add alternates */
@@ -502,7 +500,7 @@ void add_to_alternates_file(const char *reference)
 		fprintf_or_die(out, "%s\n", reference);
 		if (commit_lock_file(lock))
 			die_errno("unable to move new alternates file into place");
-		if (alt_odb_tail)
+		if (the_repository->objects.alt_odb_tail)
 			link_alt_odb_entries(reference, strlen(reference), '\n', NULL, 0);
 	}
 	free(alts);
@@ -600,7 +598,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
 	int r = 0;
 
 	prepare_alt_odb();
-	for (ent = alt_odb_list; ent; ent = ent->next) {
+	for (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) {
 		r = fn(ent, cb);
 		if (r)
 			break;
@@ -612,13 +610,14 @@ void prepare_alt_odb(void)
 {
 	const char *alt;
 
-	if (alt_odb_tail)
+	if (the_repository->objects.alt_odb_tail)
 		return;
 
 	alt = getenv(ALTERNATE_DB_ENVIRONMENT);
 	if (!alt) alt = "";
 
-	alt_odb_tail = &alt_odb_list;
+	the_repository->objects.alt_odb_tail =
+			&the_repository->objects.alt_odb_list;
 	link_alt_odb_entries(alt, strlen(alt), PATH_SEP, NULL, 0);
 
 	read_info_alternates(get_object_directory(), 0);
@@ -657,7 +656,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen)
 {
 	struct alternate_object_database *alt;
 	prepare_alt_odb();
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		const char *path = alt_sha1_path(alt, sha1);
 		if (check_and_freshen_file(path, freshen))
 			return 1;
@@ -813,7 +812,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
 
 	prepare_alt_odb();
 	errno = ENOENT;
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		if (!lstat(*path, st))
 			return 0;
@@ -839,7 +838,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
 	most_interesting_errno = errno;
 
 	prepare_alt_odb();
-	for (alt = alt_odb_list; alt; alt = alt->next) {
+	for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) {
 		*path = alt_sha1_path(alt, sha1);
 		fd = git_open(*path);
 		if (fd >= 0)
diff --git a/sha1_name.c b/sha1_name.c
index 134ac9742f..5b8ce1c42c 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -10,6 +10,7 @@
 #include "dir.h"
 #include "sha1-array.h"
 #include "packfile.h"
+#include "repository.h"
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
@@ -104,7 +105,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 		 */
 		fakeent = alloc_alt_odb(get_object_directory());
 	}
-	fakeent->next = alt_odb_list;
+	fakeent->next = the_repository->objects.alt_odb_list;
 
 	for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
 		int pos;
-- 
2.14.1.581.gf28d330327


  parent reply	other threads:[~2017-08-30  6:53 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30  6:46 [PATCH 00/39] per-repository object store, part 1 Jonathan Nieder
2017-08-30  6:48 ` [PATCH 01/39] pack: make packed_git_mru global a value instead of a pointer Jonathan Nieder
2017-08-30 19:44   ` Jeff King
2017-09-06 19:51     ` Junio C Hamano
2017-08-30  6:52 ` [PATCH 02/39] repository: introduce object store field Jonathan Nieder
2017-08-30  6:53 ` Jonathan Nieder [this message]
2017-08-30  6:54 ` [PATCH 04/39] object-store: move packed_git and packed_git_mru to object store Jonathan Nieder
2017-08-30  6:54 ` [PATCH 05/39] pack: move prepare_packed_git_run_once " Jonathan Nieder
2017-08-30  6:55 ` [PATCH 06/39] pack: move approximate object count " Jonathan Nieder
2017-08-30  6:56 ` [PATCH 07/39] sha1_file: add repository argument to alt_odb_usable Jonathan Nieder
2017-08-30 22:40   ` Brandon Williams
2017-08-30  6:57 ` [PATCH 08/39] sha1_file: add repository argument to link_alt_odb_entry Jonathan Nieder
2017-08-30  6:58 ` [PATCH 09/39] sha1_file: add repository argument to read_info_alternates Jonathan Nieder
2017-08-30  6:58 ` [PATCH 10/39] sha1_file: add repository argument to link_alt_odb_entries Jonathan Nieder
2017-08-30  6:59 ` [PATCH 11/39] sha1_file: add repository argument to stat_sha1_file Jonathan Nieder
2017-08-30  6:59 ` [PATCH 12/39] sha1_file: add repository argument to open_sha1_file Jonathan Nieder
2017-08-30  7:00 ` [PATCH 13/39] sha1_file: add repository argument to map_sha1_file_1 Jonathan Nieder
2017-08-30  7:01 ` [PATCH 14/39] sha1_file: add repository argument to sha1_loose_object_info Jonathan Nieder
2017-08-30  7:01 ` [PATCH 15/39] object-store: add repository argument to prepare_alt_odb Jonathan Nieder
2017-08-30  7:02 ` [PATCH 16/39] object-store: add repository argument to foreach_alt_odb Jonathan Nieder
2017-08-30  7:02 ` [PATCH 17/39] pack: add repository argument to install_packed_git Jonathan Nieder
2017-08-30  7:03 ` [PATCH 18/39] pack: add repository argument to prepare_packed_git_one Jonathan Nieder
2017-08-30  7:03 ` [PATCH 19/39] pack: add repository argument to rearrange_packed_git Jonathan Nieder
2017-08-30  7:04 ` [PATCH 20/39] pack: add repository argument to prepare_packed_git_mru Jonathan Nieder
2017-08-30  7:05 ` [PATCH 21/39] pack: add repository argument to prepare_packed_git Jonathan Nieder
2017-08-30  7:06 ` [PATCH 22/39] pack: add repository argument to reprepare_packed_git Jonathan Nieder
2017-08-30  7:06 ` [PATCH 23/39] pack: add repository argument to sha1_file_name Jonathan Nieder
2017-08-30  7:07 ` [PATCH 24/39] pack: add repository argument to map_sha1_file Jonathan Nieder
2017-08-30  7:08 ` [PATCH 25/39] sha1_file: allow alt_odb_usable to handle arbitrary repositories Jonathan Nieder
2017-09-06 20:01   ` Junio C Hamano
2017-09-06 21:59     ` Stefan Beller
2017-08-30  7:10 ` [PATCH 26/39] object-store: allow prepare_alt_odb " Jonathan Nieder
2017-08-30  7:11 ` [PATCH 27/39] object-store: allow foreach_alt_odb " Jonathan Nieder
2017-08-30  7:11 ` [PATCH 28/39] pack: allow install_packed_git " Jonathan Nieder
2017-08-30  7:12 ` [PATCH 29/39] pack: allow rearrange_packed_git " Jonathan Nieder
2017-08-30  7:12 ` [PATCH 30/39] pack: allow prepare_packed_git_mru " Jonathan Nieder
2017-08-30  7:13 ` [PATCH 31/39] pack: allow prepare_packed_git_one " Jonathan Nieder
2017-08-30  7:13 ` [PATCH 32/39] pack: allow prepare_packed_git " Jonathan Nieder
2017-08-30  7:14 ` [PATCH 33/39] pack: allow reprepare_packed_git " Jonathan Nieder
2017-08-30  7:14 ` [PATCH 34/39] pack: allow sha1_file_name " Jonathan Nieder
2017-08-30  7:15 ` [PATCH 35/39] pack: allow stat_sha1_file " Jonathan Nieder
2017-08-30  7:16 ` [PATCH 36/39] pack: allow open_sha1_file " Jonathan Nieder
2017-08-30  7:16 ` [PATCH 37/39] pack: allow map_sha1_file_1 " Jonathan Nieder
2017-08-30  7:16 ` [PATCH 38/39] pack: allow map_sha1_file " Jonathan Nieder
2017-08-30  7:18 ` [PATCH 39/39] pack: allow sha1_loose_object_info " Jonathan Nieder
2017-08-30 23:07 ` [PATCH 00/39] per-repository object store, part 1 Brandon Williams

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170830065321.GD153983@aiede.mtv.corp.google.com \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sandals@crustytoothpaste.net \
    --cc=sbeller@google.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.