summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2018-07-12 19:39:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-20 18:27:28 (GMT)
commit396f257018a6031c4eb0803d4693441ad8a9fd10 (patch)
tree47b973ffeb95cc37dd760f83506dcf732d929aaa /midx.c
parent9208e318f548d28c677203a222f02a31a15c5d0e (diff)
downloadgit-396f257018a6031c4eb0803d4693441ad8a9fd10.zip
git-396f257018a6031c4eb0803d4693441ad8a9fd10.tar.gz
git-396f257018a6031c4eb0803d4693441ad8a9fd10.tar.bz2
multi-pack-index: read packfile list
When constructing a multi-pack-index file for a given object directory, read the files within the enclosed pack directory and find matches that end with ".idx" and find the correct paired packfile using add_packed_git(). Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/midx.c b/midx.c
index c1ff5ac..f742d7c 100644
--- a/midx.c
+++ b/midx.c
@@ -1,6 +1,8 @@
#include "cache.h"
#include "csum-file.h"
+#include "dir.h"
#include "lockfile.h"
+#include "packfile.h"
#include "object-store.h"
#include "midx.h"
@@ -109,12 +111,41 @@ static size_t write_midx_header(struct hashfile *f,
return MIDX_HEADER_SIZE;
}
+struct pack_list {
+ struct packed_git **list;
+ uint32_t nr;
+ uint32_t alloc_list;
+};
+
+static void add_pack_to_midx(const char *full_path, size_t full_path_len,
+ const char *file_name, void *data)
+{
+ struct pack_list *packs = (struct pack_list *)data;
+
+ if (ends_with(file_name, ".idx")) {
+ ALLOC_GROW(packs->list, packs->nr + 1, packs->alloc_list);
+
+ packs->list[packs->nr] = add_packed_git(full_path,
+ full_path_len,
+ 0);
+ if (!packs->list[packs->nr]) {
+ warning(_("failed to add packfile '%s'"),
+ full_path);
+ return;
+ }
+
+ packs->nr++;
+ }
+}
+
int write_midx_file(const char *object_dir)
{
unsigned char num_chunks = 0;
char *midx_name;
+ uint32_t i;
struct hashfile *f = NULL;
struct lock_file lk;
+ struct pack_list packs;
midx_name = get_midx_filename(object_dir);
if (safe_create_leading_directories(midx_name)) {
@@ -123,14 +154,29 @@ int write_midx_file(const char *object_dir)
midx_name);
}
+ packs.nr = 0;
+ packs.alloc_list = 16;
+ packs.list = NULL;
+ ALLOC_ARRAY(packs.list, packs.alloc_list);
+
+ for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs);
+
hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR);
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
FREE_AND_NULL(midx_name);
- write_midx_header(f, num_chunks, 0);
+ write_midx_header(f, num_chunks, packs.nr);
finalize_hashfile(f, NULL, CSUM_FSYNC | CSUM_HASH_IN_STREAM);
commit_lock_file(&lk);
+ for (i = 0; i < packs.nr; i++) {
+ if (packs.list[i]) {
+ close_pack(packs.list[i]);
+ free(packs.list[i]);
+ }
+ }
+
+ free(packs.list);
return 0;
}