aboutsummaryrefslogtreecommitdiff
path: root/odb.c
diff options
context:
space:
mode:
Diffstat (limited to 'odb.c')
-rw-r--r--odb.c191
1 files changed, 22 insertions, 169 deletions
diff --git a/odb.c b/odb.c
index 776de5356c..84a31084d3 100644
--- a/odb.c
+++ b/odb.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "chdir-notify.h"
#include "commit-graph.h"
#include "config.h"
#include "dir.h"
@@ -132,10 +131,10 @@ out:
return usable;
}
-static void parse_alternates(const char *string,
- int sep,
- const char *relative_base,
- struct strvec *out)
+void parse_alternates(const char *string,
+ int sep,
+ const char *relative_base,
+ struct strvec *out)
{
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf buf = STRBUF_INIT;
@@ -199,41 +198,6 @@ static void parse_alternates(const char *string,
strbuf_release(&buf);
}
-static void odb_source_read_alternates(struct odb_source *source,
- struct strvec *out)
-{
- struct strbuf buf = STRBUF_INIT;
- char *path;
-
- path = xstrfmt("%s/info/alternates", source->path);
- if (strbuf_read_file(&buf, path, 1024) < 0) {
- warn_on_fopen_errors(path);
- free(path);
- return;
- }
- parse_alternates(buf.buf, '\n', source->path, out);
-
- strbuf_release(&buf);
- free(path);
-}
-
-
-static struct odb_source *odb_source_new(struct object_database *odb,
- const char *path,
- bool local)
-{
- struct odb_source *source;
-
- CALLOC_ARRAY(source, 1);
- source->odb = odb;
- source->local = local;
- source->path = xstrdup(path);
- source->loose = odb_source_loose_new(source);
- source->packfiles = packfile_store_new(source);
-
- return source;
-}
-
static struct odb_source *odb_add_alternate_recursively(struct object_database *odb,
const char *source,
int depth)
@@ -272,58 +236,6 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
return alternate;
}
-static int odb_source_write_alternate(struct odb_source *source,
- const char *alternate)
-{
- struct lock_file lock = LOCK_INIT;
- char *path = xstrfmt("%s/%s", source->path, "info/alternates");
- FILE *in, *out;
- int found = 0;
- int ret;
-
- hold_lock_file_for_update(&lock, path, LOCK_DIE_ON_ERROR);
- out = fdopen_lock_file(&lock, "w");
- if (!out) {
- ret = error_errno(_("unable to fdopen alternates lockfile"));
- goto out;
- }
-
- in = fopen(path, "r");
- if (in) {
- struct strbuf line = STRBUF_INIT;
-
- while (strbuf_getline(&line, in) != EOF) {
- if (!strcmp(alternate, line.buf)) {
- found = 1;
- break;
- }
- fprintf_or_die(out, "%s\n", line.buf);
- }
-
- strbuf_release(&line);
- fclose(in);
- } else if (errno != ENOENT) {
- ret = error_errno(_("unable to read alternates file"));
- goto out;
- }
-
- if (found) {
- rollback_lock_file(&lock);
- } else {
- fprintf_or_die(out, "%s\n", alternate);
- if (commit_lock_file(&lock)) {
- ret = error_errno(_("unable to move new alternates file into place"));
- goto out;
- }
- }
-
- ret = 0;
-
-out:
- free(path);
- return ret;
-}
-
void odb_add_to_alternates_file(struct object_database *odb,
const char *dir)
{
@@ -373,14 +285,6 @@ struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
return source->next;
}
-static void odb_source_free(struct odb_source *source)
-{
- free(source->path);
- odb_source_loose_free(source->loose);
- packfile_store_free(source->packfiles);
- free(source);
-}
-
void odb_restore_primary_source(struct object_database *odb,
struct odb_source *restore_source,
const char *old_path)
@@ -714,18 +618,19 @@ static int do_oid_object_info_extended(struct object_database *odb,
while (1) {
struct odb_source *source;
- /* Most likely it's a loose object. */
- for (source = odb->sources; source; source = source->next) {
- if (!packfile_store_read_object_info(source->packfiles, real, oi, flags) ||
- !odb_source_loose_read_object_info(source, real, oi, flags))
+ for (source = odb->sources; source; source = source->next)
+ if (!odb_source_read_object_info(source, real, oi, flags))
return 0;
- }
- /* Not a loose object; someone else may have just packed it. */
+ /*
+ * When the object hasn't been found we try a second read and
+ * tell the sources so. This may cause them to invalidate
+ * caches or reload on-disk state.
+ */
if (!(flags & OBJECT_INFO_QUICK)) {
- odb_reprepare(odb->repo->objects);
for (source = odb->sources; source; source = source->next)
- if (!packfile_store_read_object_info(source->packfiles, real, oi, flags))
+ if (!odb_source_read_object_info(source, real, oi,
+ flags | OBJECT_INFO_SECOND_READ))
return 0;
}
@@ -984,16 +889,10 @@ int odb_freshen_object(struct object_database *odb,
const struct object_id *oid)
{
struct odb_source *source;
-
odb_prepare_alternates(odb);
- for (source = odb->sources; source; source = source->next) {
- if (packfile_store_freshen_object(source->packfiles, oid))
+ for (source = odb->sources; source; source = source->next)
+ if (odb_source_freshen_object(source, oid))
return 1;
-
- if (odb_source_loose_freshen_object(source, oid))
- return 1;
- }
-
return 0;
}
@@ -1010,15 +909,7 @@ int odb_for_each_object(struct object_database *odb,
if (flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY && !source->local)
continue;
- if (!(flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY)) {
- ret = odb_source_loose_for_each_object(source, request,
- cb, cb_data, flags);
- if (ret)
- return ret;
- }
-
- ret = packfile_store_for_each_object(source->packfiles, request,
- cb, cb_data, flags);
+ ret = odb_source_for_each_object(source, request, cb, cb_data, flags);
if (ret)
return ret;
}
@@ -1044,47 +935,15 @@ int odb_write_object_ext(struct object_database *odb,
struct object_id *compat_oid,
unsigned flags)
{
- return odb_source_loose_write_object(odb->sources, buf, len, type,
- oid, compat_oid, flags);
+ return odb_source_write_object(odb->sources, buf, len, type,
+ oid, compat_oid, flags);
}
int odb_write_object_stream(struct object_database *odb,
struct odb_write_stream *stream, size_t len,
struct object_id *oid)
{
- return odb_source_loose_write_stream(odb->sources, stream, len, oid);
-}
-
-static void odb_update_commondir(const char *name UNUSED,
- const char *old_cwd,
- const char *new_cwd,
- void *cb_data)
-{
- struct object_database *odb = cb_data;
- struct tmp_objdir *tmp_objdir;
- struct odb_source *source;
-
- tmp_objdir = tmp_objdir_unapply_primary_odb();
-
- /*
- * In theory, we only have to do this for the primary object source, as
- * alternates' paths are always resolved to an absolute path.
- */
- for (source = odb->sources; source; source = source->next) {
- char *path;
-
- if (is_absolute_path(source->path))
- continue;
-
- path = reparent_relative_path(old_cwd, new_cwd,
- source->path);
-
- free(source->path);
- source->path = path;
- }
-
- if (tmp_objdir)
- tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
+ return odb_source_write_object_stream(odb->sources, stream, len, oid);
}
struct object_database *odb_new(struct repository *repo,
@@ -1107,8 +966,6 @@ struct object_database *odb_new(struct repository *repo,
free(to_free);
- chdir_notify_register(NULL, odb_update_commondir, o);
-
return o;
}
@@ -1116,7 +973,7 @@ void odb_close(struct object_database *o)
{
struct odb_source *source;
for (source = o->sources; source; source = source->next)
- packfile_store_close(source->packfiles);
+ odb_source_close(source);
close_commit_graph(o);
}
@@ -1152,8 +1009,6 @@ void odb_free(struct object_database *o)
string_list_clear(&o->submodule_source_paths, 0);
- chdir_notify_unregister(NULL, odb_update_commondir, o);
-
free(o);
}
@@ -1172,10 +1027,8 @@ void odb_reprepare(struct object_database *o)
o->loaded_alternates = 0;
odb_prepare_alternates(o);
- for (source = o->sources; source; source = source->next) {
- odb_source_loose_reprepare(source);
- packfile_store_reprepare(source->packfiles);
- }
+ for (source = o->sources; source; source = source->next)
+ odb_source_reprepare(source);
o->approximate_object_count_valid = 0;