Commit c336f88938f60b7e0ec2b0200d9c901ddeeec114

Stefan Sperling 2018-07-23T10:53:49

don't store copies of packfile paths in each delta

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;
 }