Skip to content

Commit

Permalink
Merge branch 'jk/dumb-http-finalize' into jch
Browse files Browse the repository at this point in the history
* jk/dumb-http-finalize:
  packfile: use oidread() instead of hashcpy() to fill object_id
  packfile: use object_id in find_pack_entry_one()
  packfile: convert find_sha1_pack() to use object_id
  http-walker: use object_id instead of bare hash
  packfile: warn people away from parse_packed_git()
  packfile: drop sha1_pack_index_name()
  packfile: drop sha1_pack_name()
  packfile: drop has_pack_index()
  dumb-http: store downloaded pack idx as tempfile
  t5550: count fetches in "previously-fetched .idx" test
  midx: avoid duplicate packed_git entries
  • Loading branch information
ttaylorr committed Oct 25, 2024
2 parents 307bc2e + 863f245 commit 6978793
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 101 deletions.
6 changes: 2 additions & 4 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,7 @@ static int store_object(
if (e->idx.offset) {
duplicate_count_by_type[type]++;
return 1;
} else if (find_sha1_pack(oid.hash,
get_all_packs(the_repository))) {
} else if (find_oid_pack(&oid, get_all_packs(the_repository))) {
e->type = type;
e->pack_id = MAX_PACK_ID;
e->idx.offset = 1; /* just not zero! */
Expand Down Expand Up @@ -1167,8 +1166,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
duplicate_count_by_type[OBJ_BLOB]++;
truncate_pack(&checkpoint);

} else if (find_sha1_pack(oid.hash,
get_all_packs(the_repository))) {
} else if (find_oid_pack(&oid, get_all_packs(the_repository))) {
e->type = OBJ_BLOB;
e->pack_id = MAX_PACK_ID;
e->idx.offset = 1; /* just not zero! */
Expand Down
4 changes: 2 additions & 2 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ static int want_object_in_pack_one(struct packed_git *p,
if (p == *found_pack)
offset = *found_offset;
else
offset = find_pack_entry_one(oid->hash, p);
offset = find_pack_entry_one(oid, p);

if (offset) {
if (!*found_pack) {
Expand Down Expand Up @@ -4205,7 +4205,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
while (p) {
if ((!p->pack_local || p->pack_keep ||
p->pack_keep_in_core) &&
find_pack_entry_one(oid->hash, p)) {
find_pack_entry_one(oid, p)) {
last_found = p;
return 1;
}
Expand Down
5 changes: 4 additions & 1 deletion builtin/pack-redundant.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "packfile.h"
#include "object-store-ll.h"
#include "strbuf.h"

#define BLKSIZE 512

Expand Down Expand Up @@ -591,6 +592,7 @@ static void load_all(void)
int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;
struct llist *ignore;
struct strbuf idx_name = STRBUF_INIT;
char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */

if (argc == 2 && !strcmp(argv[1], "-h"))
Expand Down Expand Up @@ -688,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
pl = red = pack_list_difference(local_packs, min);
while (pl) {
printf("%s\n%s\n",
sha1_pack_index_name(pl->pack->hash),
odb_pack_name(&idx_name, pl->pack->hash, "idx"),
pl->pack->pack_name);
pl = pl->next;
}
Expand All @@ -699,5 +701,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
pack_list_free(red);
pack_list_free(min);
llist_free(ignore);
strbuf_release(&idx_name);
return 0;
}
4 changes: 2 additions & 2 deletions connected.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
for (p = get_all_packs(the_repository); p; p = p->next) {
if (!p->pack_promisor)
continue;
if (find_pack_entry_one(oid->hash, p))
if (find_pack_entry_one(oid, p))
goto promisor_pack_found;
}
/*
Expand Down Expand Up @@ -144,7 +144,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
* are sure the ref is good and not sending it to
* rev-list for verification.
*/
if (new_pack && find_pack_entry_one(oid->hash, new_pack))
if (new_pack && find_pack_entry_one(oid, new_pack))
continue;

if (fprintf(rev_list_in, "%s\n", oid_to_hex(oid)) < 0)
Expand Down
4 changes: 2 additions & 2 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static void start_fetch_packed(struct transfer_request *request)
struct transfer_request *check_request = request_queue_head;
struct http_pack_request *preq;

target = find_sha1_pack(request->obj->oid.hash, repo->packs);
target = find_oid_pack(&request->obj->oid, repo->packs);
if (!target) {
fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", oid_to_hex(&request->obj->oid));
repo->can_update_info_refs = 0;
Expand Down Expand Up @@ -681,7 +681,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
get_remote_object_list(obj->oid.hash[0]);
if (obj->flags & (REMOTE | PUSHING))
return 0;
target = find_sha1_pack(obj->oid.hash, repo->packs);
target = find_oid_pack(&obj->oid, repo->packs);
if (target) {
obj->flags |= REMOTE;
return 0;
Expand Down
25 changes: 13 additions & 12 deletions http-walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ static int fill_active_slot(void *data UNUSED)
return 0;
}

static void prefetch(struct walker *walker, unsigned char *sha1)
static void prefetch(struct walker *walker, const struct object_id *oid)
{
struct object_request *newreq;
struct walker_data *data = walker->data;

newreq = xmalloc(sizeof(*newreq));
newreq->walker = walker;
oidread(&newreq->oid, sha1, the_repository->hash_algo);
oidcpy(&newreq->oid, oid);
newreq->repo = data->alt;
newreq->state = WAITING;
newreq->req = NULL;
Expand Down Expand Up @@ -422,7 +422,8 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
return ret;
}

static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1)
static int http_fetch_pack(struct walker *walker, struct alt_base *repo,
const struct object_id *oid)
{
struct packed_git *target;
int ret;
Expand All @@ -431,7 +432,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne

if (fetch_indices(walker, repo))
return -1;
target = find_sha1_pack(sha1, repo->packs);
target = find_oid_pack(oid, repo->packs);
if (!target)
return -1;
close_pack_index(target);
Expand All @@ -440,7 +441,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
fprintf(stderr, "Getting pack %s\n",
hash_to_hex(target->hash));
fprintf(stderr, " which contains %s\n",
hash_to_hex(sha1));
oid_to_hex(oid));
}

preq = new_http_pack_request(target->hash, repo->base);
Expand Down Expand Up @@ -477,17 +478,17 @@ static void abort_object_request(struct object_request *obj_req)
release_object_request(obj_req);
}

static int fetch_object(struct walker *walker, unsigned char *hash)
static int fetch_object(struct walker *walker, const struct object_id *oid)
{
char *hex = hash_to_hex(hash);
char *hex = oid_to_hex(oid);
int ret = 0;
struct object_request *obj_req = NULL;
struct http_object_request *req;
struct list_head *pos, *head = &object_queue_head;

list_for_each(pos, head) {
obj_req = list_entry(pos, struct object_request, node);
if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo))
if (oideq(&obj_req->oid, oid))
break;
}
if (!obj_req)
Expand Down Expand Up @@ -548,20 +549,20 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
return ret;
}

static int fetch(struct walker *walker, unsigned char *hash)
static int fetch(struct walker *walker, const struct object_id *oid)
{
struct walker_data *data = walker->data;
struct alt_base *altbase = data->alt;

if (!fetch_object(walker, hash))
if (!fetch_object(walker, oid))
return 0;
while (altbase) {
if (!http_fetch_pack(walker, altbase, hash))
if (!http_fetch_pack(walker, altbase, oid))
return 0;
fetch_alternates(walker, data->alt->base);
altbase = altbase->next;
}
return error("Unable to find %s under %s", hash_to_hex(hash),
return error("Unable to find %s under %s", oid_to_hex(oid),
data->alt->base);
}

Expand Down
43 changes: 30 additions & 13 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "string-list.h"
#include "object-file.h"
#include "object-store-ll.h"
#include "tempfile.h"

static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
static int trace_curl_data = 1;
Expand Down Expand Up @@ -2332,8 +2333,24 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url)
strbuf_addf(&buf, "objects/pack/pack-%s.idx", hash_to_hex(hash));
url = strbuf_detach(&buf, NULL);

strbuf_addf(&buf, "%s.temp", sha1_pack_index_name(hash));
tmp = strbuf_detach(&buf, NULL);
/*
* Don't put this into packs/, since it's just temporary and we don't
* want to confuse it with our local .idx files. We'll generate our
* own index if we choose to download the matching packfile.
*
* It's tempting to use xmks_tempfile() here, but it's important that
* the file not exist, otherwise http_get_file() complains. So we
* create a filename that should be unique, and then just register it
* as a tempfile so that it will get cleaned up on exit.
*
* In theory we could hold on to the tempfile and delete these as soon
* as we download the matching pack, but it would take a bit of
* refactoring. Leaving them until the process ends is probably OK.
*/
tmp = xstrfmt("%s/tmp_pack_%s.idx",
repo_get_object_directory(the_repository),
hash_to_hex(hash));
register_tempfile(tmp);

if (http_get_file(url, tmp, NULL) != HTTP_OK) {
error("Unable to get pack index %s", url);
Expand All @@ -2347,15 +2364,17 @@ static char *fetch_pack_index(unsigned char *hash, const char *base_url)
static int fetch_and_setup_pack_index(struct packed_git **packs_head,
unsigned char *sha1, const char *base_url)
{
struct packed_git *new_pack;
struct packed_git *new_pack, *p;
char *tmp_idx = NULL;
int ret;

if (has_pack_index(sha1)) {
new_pack = parse_pack_index(sha1, sha1_pack_index_name(sha1));
if (!new_pack)
return -1; /* parse_pack_index() already issued error message */
goto add_pack;
/*
* If we already have the pack locally, no need to fetch its index or
* even add it to list; we already have all of its objects.
*/
for (p = get_all_packs(the_repository); p; p = p->next) {
if (hasheq(p->hash, sha1, the_repository->hash_algo))
return 0;
}

tmp_idx = fetch_pack_index(sha1, base_url);
Expand All @@ -2371,15 +2390,12 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
}

ret = verify_pack_index(new_pack);
if (!ret) {
if (!ret)
close_pack_index(new_pack);
ret = finalize_object_file(tmp_idx, sha1_pack_index_name(sha1));
}
free(tmp_idx);
if (ret)
return -1;

add_pack:
new_pack->next = *packs_head;
*packs_head = new_pack;
return 0;
Expand Down Expand Up @@ -2507,7 +2523,8 @@ struct http_pack_request *new_direct_http_pack_request(

preq->url = url;

strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(packed_git_hash));
odb_pack_name(&preq->tmpfile, packed_git_hash, "pack");
strbuf_addstr(&preq->tmpfile, ".temp");
preq->packfile = fopen(preq->tmpfile.buf, "a");
if (!preq->packfile) {
error("Unable to open local file %s for pack",
Expand Down
22 changes: 18 additions & 4 deletions midx.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
uint32_t pack_int_id)
{
struct strbuf pack_name = STRBUF_INIT;
struct strbuf key = STRBUF_INIT;
struct packed_git *p;

pack_int_id = midx_for_pack(&m, pack_int_id);
Expand All @@ -455,16 +456,29 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
m->pack_names[pack_int_id]);

p = add_packed_git(pack_name.buf, pack_name.len, m->local);
/* pack_map holds the ".pack" name, but we have the .idx */
strbuf_addbuf(&key, &pack_name);
strbuf_strip_suffix(&key, ".idx");
strbuf_addstr(&key, ".pack");
p = hashmap_get_entry_from_hash(&r->objects->pack_map,
strhash(key.buf), key.buf,
struct packed_git, packmap_ent);
if (!p) {
p = add_packed_git(pack_name.buf, pack_name.len, m->local);
if (p) {
install_packed_git(r, p);
list_add_tail(&p->mru, &r->objects->packed_git_mru);
}
}

strbuf_release(&pack_name);
strbuf_release(&key);

if (!p)
return 1;

p->multi_pack_index = 1;
m->packs[pack_int_id] = p;
install_packed_git(r, p);
list_add_tail(&p->mru, &r->objects->packed_git_mru);

return 0;
}
Expand Down Expand Up @@ -973,7 +987,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
}

m_offset = e.offset;
p_offset = find_pack_entry_one(oid.hash, e.p);
p_offset = find_pack_entry_one(&oid, e.p);

if (m_offset != p_offset)
midx_report(_("incorrect object offset for oid[%d] = %s: %"PRIx64" != %"PRIx64),
Expand Down
4 changes: 2 additions & 2 deletions pack-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ static inline int bitmap_position_packfile(struct bitmap_index *bitmap_git,
const struct object_id *oid)
{
uint32_t pos;
off_t offset = find_pack_entry_one(oid->hash, bitmap_git->pack);
off_t offset = find_pack_entry_one(oid, bitmap_git->pack);
if (!offset)
return -1;

Expand Down Expand Up @@ -1609,7 +1609,7 @@ static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
if (bsearch_midx(&object->oid, bitmap_git->midx, NULL))
return 1;
} else {
if (find_pack_entry_one(object->oid.hash, bitmap_git->pack) > 0)
if (find_pack_entry_one(&object->oid, bitmap_git->pack) > 0)
return 1;
}
}
Expand Down
Loading

0 comments on commit 6978793

Please sign in to comment.