提交 3a1ec60c 编写于 作者: J Junio C Hamano

Merge branch 'sb/packfiles-in-repository'

Refactoring of the internal global data structure continues.

* sb/packfiles-in-repository:
  packfile: keep prepare_packed_git() private
  packfile: allow find_pack_entry to handle arbitrary repositories
  packfile: add repository argument to find_pack_entry
  packfile: allow reprepare_packed_git to handle arbitrary repositories
  packfile: allow prepare_packed_git to handle arbitrary repositories
  packfile: allow prepare_packed_git_one to handle arbitrary repositories
  packfile: add repository argument to reprepare_packed_git
  packfile: add repository argument to prepare_packed_git
  packfile: add repository argument to prepare_packed_git_one
  packfile: allow install_packed_git to handle arbitrary repositories
  packfile: allow rearrange_packed_git to handle arbitrary repositories
  packfile: allow prepare_packed_git_mru to handle arbitrary repositories
...@@ -122,8 +122,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) ...@@ -122,8 +122,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
struct strbuf loose_buf = STRBUF_INIT; struct strbuf loose_buf = STRBUF_INIT;
struct strbuf pack_buf = STRBUF_INIT; struct strbuf pack_buf = STRBUF_INIT;
struct strbuf garbage_buf = STRBUF_INIT; struct strbuf garbage_buf = STRBUF_INIT;
if (!get_packed_git(the_repository))
prepare_packed_git();
for (p = get_packed_git(the_repository); p; p = p->next) { for (p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local) if (!p->pack_local)
continue; continue;
......
...@@ -735,8 +735,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) ...@@ -735,8 +735,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
uint32_t total = 0, count = 0; uint32_t total = 0, count = 0;
struct progress *progress = NULL; struct progress *progress = NULL;
prepare_packed_git();
if (show_progress) { if (show_progress) {
for (p = get_packed_git(the_repository); p; for (p = get_packed_git(the_repository); p;
p = p->next) { p = p->next) {
......
...@@ -174,7 +174,6 @@ static int too_many_packs(void) ...@@ -174,7 +174,6 @@ static int too_many_packs(void)
if (gc_auto_pack_limit <= 0) if (gc_auto_pack_limit <= 0)
return 0; return 0;
prepare_packed_git();
for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) { for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local) if (!p->pack_local)
continue; continue;
...@@ -481,7 +480,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) ...@@ -481,7 +480,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
return error(FAILED_RUN, rerere.argv[0]); return error(FAILED_RUN, rerere.argv[0]);
report_garbage = report_pack_garbage; report_garbage = report_pack_garbage;
reprepare_packed_git(); reprepare_packed_git(the_repository);
if (pack_garbage.nr > 0) if (pack_garbage.nr > 0)
clean_pack_garbage(); clean_pack_garbage();
......
...@@ -3148,7 +3148,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) ...@@ -3148,7 +3148,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (progress && all_progress_implied) if (progress && all_progress_implied)
progress = 2; progress = 2;
prepare_packed_git();
if (ignore_packed_keep) { if (ignore_packed_keep) {
struct packed_git *p; struct packed_git *p;
for (p = get_packed_git(the_repository); p; p = p->next) for (p = get_packed_git(the_repository); p; p = p->next)
......
...@@ -631,8 +631,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix) ...@@ -631,8 +631,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
break; break;
} }
prepare_packed_git();
if (load_all_packs) if (load_all_packs)
load_all(); load_all();
else else
......
#include "builtin.h" #include "builtin.h"
#include "repository.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"
#include "pack.h" #include "pack.h"
...@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si) ...@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
status = finish_command(&child); status = finish_command(&child);
if (status) if (status)
return "index-pack abnormal exit"; return "index-pack abnormal exit";
reprepare_packed_git(); reprepare_packed_git(the_repository);
} }
return NULL; return NULL;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "bulk-checkin.h" #include "bulk-checkin.h"
#include "repository.h"
#include "csum-file.h" #include "csum-file.h"
#include "pack.h" #include "pack.h"
#include "strbuf.h" #include "strbuf.h"
...@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state) ...@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
strbuf_release(&packname); strbuf_release(&packname);
/* Make objects we just wrote available to ourselves */ /* Make objects we just wrote available to ourselves */
reprepare_packed_git(); reprepare_packed_git(the_repository);
} }
static int already_written(struct bulk_checkin_state *state, struct object_id *oid) static int already_written(struct bulk_checkin_state *state, struct object_id *oid)
......
...@@ -1038,7 +1038,7 @@ static void end_packfile(void) ...@@ -1038,7 +1038,7 @@ static void end_packfile(void)
if (!new_p) if (!new_p)
die("core git rejected index %s", idx_name); die("core git rejected index %s", idx_name);
all_packs[pack_id] = new_p; all_packs[pack_id] = new_p;
install_packed_git(new_p); install_packed_git(the_repository, new_p);
free(idx_name); free(idx_name);
/* Print the boundary */ /* Print the boundary */
...@@ -3476,7 +3476,6 @@ int cmd_main(int argc, const char **argv) ...@@ -3476,7 +3476,6 @@ int cmd_main(int argc, const char **argv)
rc_free[i].next = &rc_free[i + 1]; rc_free[i].next = &rc_free[i + 1];
rc_free[cmd_save - 1].next = NULL; rc_free[cmd_save - 1].next = NULL;
prepare_packed_git();
start_packfile(); start_packfile();
set_die_routine(die_nicely); set_die_routine(die_nicely);
set_checkpoint_signal(); set_checkpoint_signal();
......
#include "cache.h" #include "cache.h"
#include "repository.h"
#include "config.h" #include "config.h"
#include "lockfile.h" #include "lockfile.h"
#include "refs.h" #include "refs.h"
...@@ -1240,7 +1241,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args, ...@@ -1240,7 +1241,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
prepare_shallow_info(&si, shallow); prepare_shallow_info(&si, shallow);
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
&si, pack_lockfile); &si, pack_lockfile);
reprepare_packed_git(); reprepare_packed_git(the_repository);
update_shallow(args, sought, nr_sought, &si); update_shallow(args, sought, nr_sought, &si);
clear_shallow_info(&si); clear_shallow_info(&si);
return ref_cpy; return ref_cpy;
......
...@@ -519,7 +519,6 @@ static void get_info_packs(struct strbuf *hdr, char *arg) ...@@ -519,7 +519,6 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
size_t cnt = 0; size_t cnt = 0;
select_getanyfile(hdr); select_getanyfile(hdr);
prepare_packed_git();
for (p = get_packed_git(the_repository); p; p = p->next) { for (p = get_packed_git(the_repository); p; p = p->next) {
if (p->pack_local) if (p->pack_local)
cnt++; cnt++;
......
...@@ -2136,7 +2136,7 @@ int finish_http_pack_request(struct http_pack_request *preq) ...@@ -2136,7 +2136,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
return -1; return -1;
} }
install_packed_git(p); install_packed_git(the_repository, p);
free(tmp_idx); free(tmp_idx);
return 0; return 0;
} }
......
...@@ -336,7 +336,6 @@ static int open_pack_bitmap(void) ...@@ -336,7 +336,6 @@ static int open_pack_bitmap(void)
assert(!bitmap_git.map && !bitmap_git.loaded); assert(!bitmap_git.map && !bitmap_git.loaded);
prepare_packed_git();
for (p = get_packed_git(the_repository); p; p = p->next) { for (p = get_packed_git(the_repository); p; p = p->next) {
if (open_pack_bitmap_1(p) == 0) if (open_pack_bitmap_1(p) == 0)
ret = 0; ret = 0;
......
...@@ -680,13 +680,13 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local) ...@@ -680,13 +680,13 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
return p; return p;
} }
void install_packed_git(struct packed_git *pack) void install_packed_git(struct repository *r, struct packed_git *pack)
{ {
if (pack->pack_fd != -1) if (pack->pack_fd != -1)
pack_open_fds++; pack_open_fds++;
pack->next = the_repository->objects->packed_git; pack->next = r->objects->packed_git;
the_repository->objects->packed_git = pack; r->objects->packed_git = pack;
} }
void (*report_garbage)(unsigned seen_bits, const char *path); void (*report_garbage)(unsigned seen_bits, const char *path);
...@@ -735,7 +735,7 @@ static void report_pack_garbage(struct string_list *list) ...@@ -735,7 +735,7 @@ static void report_pack_garbage(struct string_list *list)
report_helper(list, seen_bits, first, list->nr); report_helper(list, seen_bits, first, list->nr);
} }
static void prepare_packed_git_one(char *objdir, int local) static void prepare_packed_git_one(struct repository *r, char *objdir, int local)
{ {
struct strbuf path = STRBUF_INIT; struct strbuf path = STRBUF_INIT;
size_t dirnamelen; size_t dirnamelen;
...@@ -768,7 +768,7 @@ static void prepare_packed_git_one(char *objdir, int local) ...@@ -768,7 +768,7 @@ static void prepare_packed_git_one(char *objdir, int local)
base_len = path.len; base_len = path.len;
if (strip_suffix_mem(path.buf, &base_len, ".idx")) { if (strip_suffix_mem(path.buf, &base_len, ".idx")) {
/* Don't reopen a pack we already have. */ /* Don't reopen a pack we already have. */
for (p = the_repository->objects->packed_git; p; for (p = r->objects->packed_git; p;
p = p->next) { p = p->next) {
size_t len; size_t len;
if (strip_suffix(p->pack_name, ".pack", &len) && if (strip_suffix(p->pack_name, ".pack", &len) &&
...@@ -782,7 +782,7 @@ static void prepare_packed_git_one(char *objdir, int local) ...@@ -782,7 +782,7 @@ static void prepare_packed_git_one(char *objdir, int local)
* corresponding .pack file that we can map. * corresponding .pack file that we can map.
*/ */
(p = add_packed_git(path.buf, path.len, local)) != NULL) (p = add_packed_git(path.buf, path.len, local)) != NULL)
install_packed_git(p); install_packed_git(r, p);
} }
if (!report_garbage) if (!report_garbage)
...@@ -803,6 +803,7 @@ static void prepare_packed_git_one(char *objdir, int local) ...@@ -803,6 +803,7 @@ static void prepare_packed_git_one(char *objdir, int local)
strbuf_release(&path); strbuf_release(&path);
} }
static void prepare_packed_git(struct repository *r);
/* /*
* Give a fast, rough count of the number of objects in the repository. This * Give a fast, rough count of the number of objects in the repository. This
* ignores loose objects completely. If you have a lot of them, then either * ignores loose objects completely. If you have a lot of them, then either
...@@ -816,7 +817,7 @@ unsigned long approximate_object_count(void) ...@@ -816,7 +817,7 @@ unsigned long approximate_object_count(void)
unsigned long count; unsigned long count;
struct packed_git *p; struct packed_git *p;
prepare_packed_git(); prepare_packed_git(the_repository);
count = 0; count = 0;
for (p = the_repository->objects->packed_git; p; p = p->next) { for (p = the_repository->objects->packed_git; p; p = p->next) {
if (open_pack_index(p)) if (open_pack_index(p))
...@@ -866,52 +867,54 @@ static int sort_pack(const void *a_, const void *b_) ...@@ -866,52 +867,54 @@ static int sort_pack(const void *a_, const void *b_)
return -1; return -1;
} }
static void rearrange_packed_git(void) static void rearrange_packed_git(struct repository *r)
{ {
the_repository->objects->packed_git = llist_mergesort( r->objects->packed_git = llist_mergesort(
the_repository->objects->packed_git, get_next_packed_git, r->objects->packed_git, get_next_packed_git,
set_next_packed_git, sort_pack); set_next_packed_git, sort_pack);
} }
static void prepare_packed_git_mru(void) static void prepare_packed_git_mru(struct repository *r)
{ {
struct packed_git *p; struct packed_git *p;
INIT_LIST_HEAD(&the_repository->objects->packed_git_mru); INIT_LIST_HEAD(&r->objects->packed_git_mru);
for (p = the_repository->objects->packed_git; p; p = p->next) for (p = r->objects->packed_git; p; p = p->next)
list_add_tail(&p->mru, &the_repository->objects->packed_git_mru); list_add_tail(&p->mru, &r->objects->packed_git_mru);
} }
void prepare_packed_git(void) static void prepare_packed_git(struct repository *r)
{ {
struct alternate_object_database *alt; struct alternate_object_database *alt;
if (the_repository->objects->packed_git_initialized) if (r->objects->packed_git_initialized)
return; return;
prepare_packed_git_one(get_object_directory(), 1); prepare_packed_git_one(r, r->objects->objectdir, 1);
prepare_alt_odb(the_repository); prepare_alt_odb(r);
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) for (alt = r->objects->alt_odb_list; alt; alt = alt->next)
prepare_packed_git_one(alt->path, 0); prepare_packed_git_one(r, alt->path, 0);
rearrange_packed_git(); rearrange_packed_git(r);
prepare_packed_git_mru(); prepare_packed_git_mru(r);
the_repository->objects->packed_git_initialized = 1; r->objects->packed_git_initialized = 1;
} }
void reprepare_packed_git(void) void reprepare_packed_git(struct repository *r)
{ {
the_repository->objects->approximate_object_count_valid = 0; r->objects->approximate_object_count_valid = 0;
the_repository->objects->packed_git_initialized = 0; r->objects->packed_git_initialized = 0;
prepare_packed_git(); prepare_packed_git(r);
} }
struct packed_git *get_packed_git(struct repository *r) struct packed_git *get_packed_git(struct repository *r)
{ {
prepare_packed_git(r);
return r->objects->packed_git; return r->objects->packed_git;
} }
struct list_head *get_packed_git_mru(struct repository *r) struct list_head *get_packed_git_mru(struct repository *r)
{ {
prepare_packed_git(r);
return &r->objects->packed_git_mru; return &r->objects->packed_git_mru;
} }
...@@ -1834,23 +1837,18 @@ static int fill_pack_entry(const unsigned char *sha1, ...@@ -1834,23 +1837,18 @@ static int fill_pack_entry(const unsigned char *sha1,
return 1; return 1;
} }
/* int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e)
* Iff a pack file contains the object named by sha1, return true and
* store its location to e.
*/
int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
{ {
struct list_head *pos; struct list_head *pos;
prepare_packed_git(); prepare_packed_git(r);
if (!the_repository->objects->packed_git) if (!r->objects->packed_git)
return 0; return 0;
list_for_each(pos, &the_repository->objects->packed_git_mru) { list_for_each(pos, &r->objects->packed_git_mru) {
struct packed_git *p = list_entry(pos, struct packed_git, mru); struct packed_git *p = list_entry(pos, struct packed_git, mru);
if (fill_pack_entry(sha1, e, p)) { if (fill_pack_entry(sha1, e, p)) {
list_move(&p->mru, list_move(&p->mru, &r->objects->packed_git_mru);
&the_repository->objects->packed_git_mru);
return 1; return 1;
} }
} }
...@@ -1860,7 +1858,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) ...@@ -1860,7 +1858,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
int has_sha1_pack(const unsigned char *sha1) int has_sha1_pack(const unsigned char *sha1)
{ {
struct pack_entry e; struct pack_entry e;
return find_pack_entry(sha1, &e); return find_pack_entry(the_repository, sha1, &e);
} }
int has_pack_index(const unsigned char *sha1) int has_pack_index(const unsigned char *sha1)
...@@ -1896,7 +1894,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags) ...@@ -1896,7 +1894,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
int r = 0; int r = 0;
int pack_errors = 0; int pack_errors = 0;
prepare_packed_git(); prepare_packed_git(the_repository);
for (p = the_repository->objects->packed_git; p; p = p->next) { for (p = the_repository->objects->packed_git; p; p = p->next) {
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
continue; continue;
......
...@@ -34,9 +34,8 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_ ...@@ -34,9 +34,8 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
#define PACKDIR_FILE_GARBAGE 4 #define PACKDIR_FILE_GARBAGE 4
extern void (*report_garbage)(unsigned seen_bits, const char *path); extern void (*report_garbage)(unsigned seen_bits, const char *path);
extern void prepare_packed_git(void); extern void reprepare_packed_git(struct repository *r);
extern void reprepare_packed_git(void); extern void install_packed_git(struct repository *r, struct packed_git *pack);
extern void install_packed_git(struct packed_git *pack);
struct packed_git *get_packed_git(struct repository *r); struct packed_git *get_packed_git(struct repository *r);
struct list_head *get_packed_git_mru(struct repository *r); struct list_head *get_packed_git_mru(struct repository *r);
...@@ -131,7 +130,11 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje ...@@ -131,7 +130,11 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1); extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1); extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e); /*
* Iff a pack file in the given repository contains the object named by sha1,
* return true and store its location to e.
*/
extern int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e);
extern int has_sha1_pack(const unsigned char *sha1); extern int has_sha1_pack(const unsigned char *sha1);
......
...@@ -201,7 +201,6 @@ static void init_pack_info(const char *infofile, int force) ...@@ -201,7 +201,6 @@ static void init_pack_info(const char *infofile, int force)
objdir = get_object_directory(); objdir = get_object_directory();
objdirlen = strlen(objdir); objdirlen = strlen(objdir);
prepare_packed_git();
for (p = get_packed_git(the_repository); p; p = p->next) { for (p = get_packed_git(the_repository); p; p = p->next) {
/* we ignore things on alternate path since they are /* we ignore things on alternate path since they are
* not available to the pullers in general. * not available to the pullers in general.
......
...@@ -1268,7 +1268,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi ...@@ -1268,7 +1268,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
} }
while (1) { while (1) {
if (find_pack_entry(real->hash, &e)) if (find_pack_entry(the_repository, real->hash, &e))
break; break;
if (flags & OBJECT_INFO_IGNORE_LOOSE) if (flags & OBJECT_INFO_IGNORE_LOOSE)
...@@ -1280,8 +1280,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi ...@@ -1280,8 +1280,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
/* Not a loose object; someone else may have just packed it. */ /* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) { if (!(flags & OBJECT_INFO_QUICK)) {
reprepare_packed_git(); reprepare_packed_git(the_repository);
if (find_pack_entry(real->hash, &e)) if (find_pack_entry(the_repository, real->hash, &e))
break; break;
} }
...@@ -1669,7 +1669,7 @@ static int freshen_loose_object(const unsigned char *sha1) ...@@ -1669,7 +1669,7 @@ static int freshen_loose_object(const unsigned char *sha1)
static int freshen_packed_object(const unsigned char *sha1) static int freshen_packed_object(const unsigned char *sha1)
{ {
struct pack_entry e; struct pack_entry e;
if (!find_pack_entry(sha1, &e)) if (!find_pack_entry(the_repository, sha1, &e))
return 0; return 0;
if (e.p->freshened) if (e.p->freshened)
return 1; return 1;
......
...@@ -179,7 +179,6 @@ static void find_short_packed_object(struct disambiguate_state *ds) ...@@ -179,7 +179,6 @@ static void find_short_packed_object(struct disambiguate_state *ds)
{ {
struct packed_git *p; struct packed_git *p;
prepare_packed_git();
for (p = get_packed_git(the_repository); p && !ds->ambiguous; for (p = get_packed_git(the_repository); p && !ds->ambiguous;
p = p->next) p = p->next)
unique_in_pack(p, ds); unique_in_pack(p, ds);
...@@ -534,7 +533,6 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad) ...@@ -534,7 +533,6 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
{ {
struct packed_git *p; struct packed_git *p;
prepare_packed_git();
for (p = get_packed_git(the_repository); p; p = p->next) for (p = get_packed_git(the_repository); p; p = p->next)
find_abbrev_len_for_pack(p, mad); find_abbrev_len_for_pack(p, mad);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册