commit - 040bf4a1507fed89b06cff95edf9f230ebc32ed2
commit + 72eb343178e036e8e57e1991ef5c4a99ca020ef4
blob - e9f8bccaba3a5b29967825d40d6983546b54dc61
blob + af295fc40438bb0ead909df0299dc917f29ea676
--- lib/delta.c
+++ lib/delta.c
if (delta == NULL)
return NULL;
+ delta->path_packfile = strdup(path_packfile);
+ if (delta->path_packfile == NULL) {
+ free(delta);
+ return NULL;
+ }
delta->type = type;
delta->offset = offset;
delta->tslen = tslen;
void
got_delta_close(struct got_delta *delta)
{
+ free(delta->path_packfile);
free(delta->delta_buf);
free(delta);
}
blob - bc986fd9f13fbac49dfd74e76e0039dea07c5f74
blob + ada9bf24224874127a2434200404a4aa622396ff
--- lib/got_lib_delta.h
+++ lib/got_lib_delta.h
struct got_delta {
SIMPLEQ_ENTRY(got_delta) entry;
+ char *path_packfile;
off_t offset;
size_t tslen;
int type;
blob - 10708fc5990cd0278bf912f985c9d3f289af2553
blob + 43b6e180a1c7bf8a46d512b4008713108df58f76
--- lib/pack.c
+++ lib/pack.c
return (off_t)(offset & GOT_PACKIDX_OFFSET_VAL_MASK);
}
+static const struct got_error *
+get_packfile_path(char **path_packfile, struct got_repository *repo,
+ struct got_packidx_v2_hdr *packidx);
+
static int
-get_object_idx(struct got_packidx_v2_hdr *packidx, struct got_object_id *id)
+get_object_idx(struct got_packidx_v2_hdr *packidx, struct got_object_id *id, struct got_repository *repo)
{
u_int8_t id0 = id->sha1[0];
uint32_t totobj = betoh32(packidx->fanout_table[0xff]);
int i = 0;
+ char hex[SHA1_DIGEST_STRING_LENGTH];
+ char *sha1str = got_sha1_digest_to_str(id->sha1, hex, sizeof(hex));
if (id0 > 0)
i = betoh32(packidx->fanout_table[id0 - 1]);
struct got_object_id *oid = &packidx->sorted_ids[i];
int cmp = got_object_id_cmp(id, oid);
- if (cmp == 0)
+ if (cmp == 0) {
+ char *path_packfile = NULL;
+ const struct got_error *err;
+ err = get_packfile_path(&path_packfile, repo, packidx);
+ if (err) {
+ printf("get_packfile_path: %s\n", err->msg);
+ } else {
+ if (strcmp(sha1str, "b3197d9ea53a42fc1632369008b8f3a085dcd205") == 0) {
+ printf("Found %s in %s\n", sha1str, path_packfile);
+ }
+ }
+ free(path_packfile);
return i;
+ }
i++;
}
for (i = 0; i < nitems(repo->packidx_cache); i++) {
if (repo->packidx_cache[i] == NULL)
break;
- *idx = get_object_idx(repo->packidx_cache[i], id);
+ *idx = get_object_idx(repo->packidx_cache[i], id, repo);
if (*idx != -1) {
*packidx = repo->packidx_cache[i];
return NULL;
if (err)
goto done;
- *idx = get_object_idx(*packidx, id);
+ *idx = get_object_idx(*packidx, id, repo);
if (*idx != -1) {
err = NULL; /* found the object */
cache_packidx(*packidx, repo);
static const struct got_error *
dump_delta_chain_to_file(size_t *result_size, struct got_delta_chain *deltas,
- FILE *outfile, struct got_pack *pack, struct got_repository *repo)
+ FILE *outfile, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_delta *delta;
/* Deltas are ordered in ascending order. */
SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
if (n == 0) {
+ struct got_pack *pack;
size_t base_len;
/* Plain object types are the delta base. */
goto done;
}
+ pack = get_cached_pack(delta->path_packfile, repo);
+ if (pack == NULL) {
+ err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
+ goto done;
+ }
+
if (fseeko(pack->packfile, delta->offset + delta->tslen,
SEEK_SET) != 0) {
err = got_error_from_errno();
static const struct got_error *
dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
- struct got_delta_chain *deltas, struct got_pack *pack,
- struct got_repository *repo)
+ struct got_delta_chain *deltas, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_delta *delta;
/* Deltas are ordered in ascending order. */
SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
if (n == 0) {
+ struct got_pack *pack;
size_t base_len;
/* Plain object types are the delta base. */
goto done;
}
+ pack = get_cached_pack(delta->path_packfile, repo);
+ if (pack == NULL) {
+ err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
+ goto done;
+ }
+
if (fseeko(pack->packfile, delta->offset + delta->tslen,
SEEK_SET) != 0) {
err = got_error_from_errno();
struct got_repository *repo)
{
const struct got_error *err = NULL;
- struct got_pack *pack;
if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0)
return got_error(GOT_ERR_OBJ_NOT_PACKED);
- pack = get_cached_pack(obj->path_packfile, repo);
- if (pack == NULL) {
- err = cache_pack(&pack, obj->path_packfile, NULL, repo);
- if (err)
- goto done;
- }
-
*f = got_opentemp();
if (*f == NULL) {
err = got_error(GOT_ERR_FILE_OPEN);
}
if ((obj->flags & GOT_OBJ_FLAG_DELTIFIED) == 0) {
+ struct got_pack *pack;
+
+ pack = get_cached_pack(obj->path_packfile, repo);
+ if (pack == NULL) {
+ err = cache_pack(&pack, obj->path_packfile, NULL, repo);
+ if (err)
+ goto done;
+ }
+
if (fseeko(pack->packfile, obj->pack_offset, SEEK_SET) != 0) {
err = got_error_from_errno();
goto done;
}
+
err = got_inflate_to_file(&obj->size, pack->packfile, *f);
} else
err = dump_delta_chain_to_file(&obj->size, &obj->deltas, *f,
- pack, repo);
+ repo);
done:
if (err && *f) {
fclose(*f);
struct got_object *obj, struct got_repository *repo)
{
const struct got_error *err = NULL;
- FILE *packfile = NULL;
- struct got_pack *pack;
if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0)
return got_error(GOT_ERR_OBJ_NOT_PACKED);
- pack = get_cached_pack(obj->path_packfile, repo);
- if (pack == NULL) {
- err = cache_pack(&pack, obj->path_packfile, NULL, repo);
- if (err)
- goto done;
- }
-
if ((obj->flags & GOT_OBJ_FLAG_DELTIFIED) == 0) {
+ struct got_pack *pack;
+
+ pack = get_cached_pack(obj->path_packfile, repo);
+ if (pack == NULL) {
+ err = cache_pack(&pack, obj->path_packfile, NULL, repo);
+ if (err)
+ goto done;
+ }
+
if (fseeko(pack->packfile, obj->pack_offset, SEEK_SET) != 0) {
err = got_error_from_errno();
goto done;
err = got_inflate_to_mem(buf, len, pack->packfile);
} else
- err = dump_delta_chain_to_mem(buf, len, &obj->deltas, pack,
- repo);
+ err = dump_delta_chain_to_mem(buf, len, &obj->deltas, repo);
done:
- if (packfile)
- fclose(packfile);
return err;
}