don't store copies of packfile paths in each delta
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
diff --git a/lib/delta.c b/lib/delta.c
index 4b51bee..b04d85e 100644
--- a/lib/delta.c
+++ b/lib/delta.c
@@ -36,9 +36,8 @@
#endif
struct got_delta *
-got_delta_open(const char *path_packfile, off_t offset, size_t tslen,
- int type, size_t size, off_t data_offset, uint8_t *delta_buf,
- size_t delta_len)
+got_delta_open(off_t offset, size_t tslen, int type, size_t size,
+ off_t data_offset, uint8_t *delta_buf, size_t delta_len)
{
struct got_delta *delta;
@@ -46,11 +45,6 @@ got_delta_open(const char *path_packfile, off_t offset, size_t tslen,
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;
@@ -64,7 +58,6 @@ got_delta_open(const char *path_packfile, off_t offset, size_t tslen,
void
got_delta_close(struct got_delta *delta)
{
- free(delta->path_packfile);
free(delta->delta_buf);
free(delta);
}
diff --git a/lib/got_lib_delta.h b/lib/got_lib_delta.h
index 91fd446..6f61627 100644
--- a/lib/got_lib_delta.h
+++ b/lib/got_lib_delta.h
@@ -16,7 +16,6 @@
struct got_delta {
SIMPLEQ_ENTRY(got_delta) entry;
- char *path_packfile;
off_t offset;
size_t tslen;
int type;
@@ -33,8 +32,8 @@ struct got_delta_chain {
#define GOT_DELTA_CHAIN_RECURSION_MAX 500
-struct got_delta *got_delta_open(const char *, off_t, size_t, int, size_t,
- off_t, uint8_t *, size_t);
+struct got_delta *got_delta_open(off_t, size_t, int, size_t, off_t,
+ uint8_t *, size_t);
void got_delta_close(struct got_delta *);
const struct got_error *got_delta_chain_get_base_type(int *,
struct got_delta_chain *);
diff --git a/lib/pack.c b/lib/pack.c
index 9aa5fdb..440b49e 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -890,14 +890,14 @@ resolve_delta_chain(struct got_delta_chain *, struct got_repository *,
size_t, unsigned int);
static const struct got_error *
-add_delta(struct got_delta_chain *deltas, const char *path_packfile,
- off_t delta_offset, size_t tslen, int delta_type, size_t delta_size,
- size_t delta_data_offset, uint8_t *delta_buf, size_t delta_len)
+add_delta(struct got_delta_chain *deltas, off_t delta_offset, size_t tslen,
+ int delta_type, size_t delta_size, size_t delta_data_offset,
+ uint8_t *delta_buf, size_t delta_len)
{
struct got_delta *delta;
- delta = got_delta_open(path_packfile, delta_offset, tslen,
- delta_type, delta_size, delta_data_offset, delta_buf,
+ delta = got_delta_open(delta_offset, tslen, delta_type, delta_size,
+ delta_data_offset, delta_buf,
delta_len);
if (delta == NULL)
return got_error_from_errno();
@@ -951,8 +951,8 @@ resolve_offset_delta(struct got_delta_chain *deltas,
return err;
}
- err = add_delta(deltas, pack->path_packfile, delta_offset, tslen,
- delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
+ err = add_delta(deltas, delta_offset, tslen, delta_type, delta_size,
+ delta_data_offset, delta_buf, delta_len);
if (err)
goto done;
@@ -1024,8 +1024,8 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
goto done;
}
- err = add_delta(deltas, pack->path_packfile, delta_offset, tslen,
- delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
+ err = add_delta(deltas, delta_offset, tslen, delta_type, delta_size,
+ delta_data_offset, delta_buf, delta_len);
if (err)
goto done;
@@ -1076,8 +1076,8 @@ 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, pack->path_packfile, delta_offset,
- tslen, delta_type, delta_size, 0, NULL, 0);
+ err = add_delta(deltas, delta_offset, tslen, delta_type,
+ delta_size, 0, NULL, 0);
break;
case GOT_OBJ_TYPE_OFFSET_DELTA:
err = resolve_offset_delta(deltas, repo, packidx, pack,
@@ -1249,7 +1249,7 @@ get_delta_chain_max_size(uint64_t *max_size, struct got_delta_chain *deltas)
static const struct got_error *
dump_delta_chain_to_file(size_t *result_size, struct got_delta_chain *deltas,
- FILE *outfile, struct got_repository *repo)
+ const char *path_packfile, FILE *outfile, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_delta *delta;
@@ -1301,7 +1301,7 @@ dump_delta_chain_to_file(size_t *result_size, struct got_delta_chain *deltas,
goto done;
}
- pack = get_cached_pack(delta->path_packfile, repo);
+ pack = get_cached_pack(path_packfile, repo);
if (pack == NULL) {
err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
goto done;
@@ -1405,7 +1405,8 @@ done:
static const struct got_error *
dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
- struct got_delta_chain *deltas, struct got_repository *repo)
+ struct got_delta_chain *deltas, const char *path_packfile,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_delta *delta;
@@ -1443,7 +1444,7 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
goto done;
}
- pack = get_cached_pack(delta->path_packfile, repo);
+ pack = get_cached_pack(path_packfile, repo);
if (pack == NULL) {
err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
goto done;
@@ -1555,7 +1556,7 @@ got_packfile_extract_object(FILE **f, struct got_object *obj,
}
} else
err = dump_delta_chain_to_file(&obj->size,
- &obj->deltas, *f, repo);
+ &obj->deltas, obj->path_packfile, *f, repo);
done:
if (err && *f) {
fclose(*f);
@@ -1599,7 +1600,8 @@ got_packfile_extract_object_to_mem(uint8_t **buf, size_t *len,
err = got_inflate_to_mem_fd(buf, len, pack->fd);
}
} else
- err = dump_delta_chain_to_mem(buf, len, &obj->deltas, repo);
+ err = dump_delta_chain_to_mem(buf, len, &obj->deltas,
+ obj->path_packfile, repo);
done:
return err;
}