simplify more code which assumed deltas could span mulitple packs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
diff --git a/lib/pack.c b/lib/pack.c
index 0e92eab..61b8394 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -708,7 +708,7 @@ parse_offset_delta(off_t *base_offset, int fd, off_t offset)
static const struct got_error *
resolve_delta_chain(struct got_delta_chain *, struct got_repository *,
- struct got_packidx *, int, size_t, const char *, off_t, size_t, int,
+ struct got_packidx *, struct got_pack *, off_t, size_t, int,
size_t, unsigned int);
static const struct got_error *
@@ -731,9 +731,9 @@ add_delta(struct got_delta_chain *deltas, const char *path_packfile,
static const struct got_error *
resolve_offset_delta(struct got_delta_chain *deltas,
- struct got_repository *repo, struct got_packidx *packidx, int fd,
- size_t packfile_size, const char *path_packfile, off_t delta_offset,
- size_t tslen, int delta_type, size_t delta_size, unsigned int recursion)
+ struct got_repository *repo, struct got_packidx *packidx,
+ struct got_pack *pack, off_t delta_offset, size_t tslen,
+ int delta_type, size_t delta_size, unsigned int recursion)
{
const struct got_error *err;
@@ -745,42 +745,41 @@ resolve_offset_delta(struct got_delta_chain *deltas,
uint8_t *delta_buf;
size_t delta_len;
- err = parse_offset_delta(&base_offset, fd, delta_offset);
+ err = parse_offset_delta(&base_offset, pack->fd, delta_offset);
if (err)
return err;
- delta_data_offset = lseek(fd, 0, SEEK_CUR);
+ delta_data_offset = lseek(pack->fd, 0, SEEK_CUR);
if (delta_data_offset == -1)
return got_error_from_errno();
- err = got_inflate_to_mem_fd(&delta_buf, &delta_len, fd);
+ err = got_inflate_to_mem_fd(&delta_buf, &delta_len, pack->fd);
if (err)
return err;
- err = add_delta(deltas, path_packfile, delta_offset, tslen,
+ err = add_delta(deltas, pack->path_packfile, delta_offset, tslen,
delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
if (err)
return err;
/* An offset delta must be in the same packfile. */
- if (base_offset >= packfile_size)
+ if (base_offset >= pack->filesize)
return got_error(GOT_ERR_PACK_OFFSET);
- if (lseek(fd, base_offset, SEEK_SET) == -1)
+ if (lseek(pack->fd, base_offset, SEEK_SET) == -1)
return got_error_from_errno();
err = parse_object_type_and_size(&base_type, &base_size, &base_tslen,
- fd);
+ pack->fd);
if (err)
return err;
- return resolve_delta_chain(deltas, repo, packidx, fd, packfile_size,
- path_packfile, base_offset, base_tslen, base_type, base_size,
- recursion - 1);
+ return resolve_delta_chain(deltas, repo, packidx, pack, base_offset,
+ base_tslen, base_type, base_size, recursion - 1);
}
static const struct got_error *
resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
- struct got_packidx *packidx, int fd, const char *path_packfile,
+ struct got_packidx *packidx, struct got_pack *pack,
off_t delta_offset, size_t tslen, int delta_type, size_t delta_size,
unsigned int recursion)
{
@@ -792,27 +791,25 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
uint64_t base_size;
size_t base_tslen;
ssize_t n;
- char *path_base_packfile;
- struct got_pack *base_pack;
off_t delta_data_offset;
uint8_t *delta_buf;
size_t delta_len;
- n = read(fd, &id, sizeof(id));
+ n = read(pack->fd, &id, sizeof(id));
if (n < 0)
return got_error_from_errno();
if (n != sizeof(id))
return got_error(GOT_ERR_BAD_PACKFILE);
- delta_data_offset = lseek(fd, 0, SEEK_CUR);
+ delta_data_offset = lseek(pack->fd, 0, SEEK_CUR);
if (delta_data_offset == -1)
return got_error_from_errno();
- err = got_inflate_to_mem_fd(&delta_buf, &delta_len, fd);
+ err = got_inflate_to_mem_fd(&delta_buf, &delta_len, pack->fd);
if (err)
return err;
- err = add_delta(deltas, path_packfile, delta_offset, tslen,
+ err = add_delta(deltas, pack->path_packfile, delta_offset, tslen,
delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
if (err)
return err;
@@ -827,44 +824,30 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
return got_error(GOT_ERR_BAD_PACKIDX);
}
- err = get_packfile_path(&path_base_packfile, repo, packidx);
- if (err)
- return err;
-
- base_pack = get_cached_pack(path_base_packfile, repo);
- if (base_pack == NULL) {
- err = cache_pack(&base_pack, path_base_packfile, NULL, repo);
- if (err)
- goto done;
- }
-
- if (base_offset >= base_pack->filesize) {
+ if (base_offset >= pack->filesize) {
err = got_error(GOT_ERR_PACK_OFFSET);
goto done;
}
- if (lseek(base_pack->fd, base_offset, SEEK_SET) == -1) {
+ if (lseek(pack->fd, base_offset, SEEK_SET) == -1) {
err = got_error_from_errno();
goto done;
}
err = parse_object_type_and_size(&base_type, &base_size, &base_tslen,
- base_pack->fd);
+ pack->fd);
if (err)
goto done;
- err = resolve_delta_chain(deltas, repo, packidx, base_pack->fd,
- base_pack->filesize, path_base_packfile, base_offset,
+ err = resolve_delta_chain(deltas, repo, packidx, pack, base_offset,
base_tslen, base_type, base_size, recursion - 1);
done:
- free(path_base_packfile);
return err;
}
static const struct got_error *
resolve_delta_chain(struct got_delta_chain *deltas, struct got_repository *repo,
- struct got_packidx *packidx, int fd, size_t packfile_size,
- const char *path_packfile, off_t delta_offset, size_t tslen,
- int delta_type, size_t delta_size, unsigned int recursion)
+ struct got_packidx *packidx, struct got_pack *pack, off_t delta_offset,
+ size_t tslen, int delta_type, size_t delta_size, unsigned int recursion)
{
const struct got_error *err = NULL;
@@ -877,18 +860,16 @@ resolve_delta_chain(struct got_delta_chain *deltas, struct got_repository *repo,
case GOT_OBJ_TYPE_BLOB:
case GOT_OBJ_TYPE_TAG:
/* Plain types are the final delta base. Recursion ends. */
- err = add_delta(deltas, path_packfile, delta_offset, tslen,
- delta_type, delta_size, 0, NULL, 0);
+ err = add_delta(deltas, pack->path_packfile, delta_offset,
+ tslen, delta_type, delta_size, 0, NULL, 0);
break;
case GOT_OBJ_TYPE_OFFSET_DELTA:
- err = resolve_offset_delta(deltas, repo, packidx, fd,
- packfile_size, path_packfile, delta_offset, tslen,
- delta_type, delta_size, recursion - 1);
+ err = resolve_offset_delta(deltas, repo, packidx, pack,
+ delta_offset, tslen, delta_type, delta_size, recursion - 1);
break;
case GOT_OBJ_TYPE_REF_DELTA:
- err = resolve_ref_delta(deltas, repo, packidx, fd,
- path_packfile, delta_offset, tslen, delta_type,
- delta_size, recursion - 1);
+ err = resolve_ref_delta(deltas, repo, packidx, pack,
+ delta_offset, tslen, delta_type, delta_size, recursion - 1);
break;
default:
return got_error(GOT_ERR_OBJ_TYPE);
@@ -899,8 +880,8 @@ resolve_delta_chain(struct got_delta_chain *deltas, struct got_repository *repo,
static const struct got_error *
open_delta_object(struct got_object **obj, struct got_repository *repo,
- struct got_packidx *packidx, const char *path_packfile, int fd,
- size_t packfile_size, struct got_object_id *id, off_t offset, size_t tslen,
+ struct got_packidx *packidx, struct got_pack *pack,
+ struct got_object_id *id, off_t offset, size_t tslen,
int delta_type, size_t delta_size)
{
const struct got_error *err = NULL;
@@ -916,7 +897,7 @@ open_delta_object(struct got_object **obj, struct got_repository *repo,
memcpy(&(*obj)->id, id, sizeof((*obj)->id));
(*obj)->pack_offset = offset + tslen;
- (*obj)->path_packfile = strdup(path_packfile);
+ (*obj)->path_packfile = strdup(pack->path_packfile);
if ((*obj)->path_packfile == NULL) {
err = got_error_from_errno();
goto done;
@@ -926,9 +907,8 @@ open_delta_object(struct got_object **obj, struct got_repository *repo,
SIMPLEQ_INIT(&(*obj)->deltas.entries);
(*obj)->flags |= GOT_OBJ_FLAG_DELTIFIED;
- err = resolve_delta_chain(&(*obj)->deltas, repo, packidx, fd,
- packfile_size, path_packfile, offset, tslen, delta_type, delta_size,
- GOT_DELTA_CHAIN_RECURSION_MAX);
+ err = resolve_delta_chain(&(*obj)->deltas, repo, packidx, pack, offset,
+ tslen, delta_type, delta_size, GOT_DELTA_CHAIN_RECURSION_MAX);
if (err)
goto done;
@@ -998,8 +978,8 @@ open_packed_object(struct got_object **obj, struct got_repository *repo,
case GOT_OBJ_TYPE_OFFSET_DELTA:
case GOT_OBJ_TYPE_REF_DELTA:
- err = open_delta_object(obj, repo, packidx, path_packfile,
- pack->fd, pack->filesize, id, offset, tslen, type, size);
+ err = open_delta_object(obj, repo, packidx, pack, id, offset,
+ tslen, type, size);
break;
default: