"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
skipping the base object header in got_deltify()
To:
gameoftrees@openbsd.org
Date:
Thu, 17 Jun 2021 11:31:41 +0200

Download raw body.

Thread
  • Stefan Sperling:

    skipping the base object header in got_deltify()

Another change extracted from my packcreate branch:

Allow for skipping the base object header in got_deltify().

When we open a loose object in "raw" form, the object file will be
decompressed and written to a temporary file. This temporary file
now contains an object header followed by raw (unparsed) object data.

The object header is not relevant for deltification so we need to begin
deltification at the offset where the actual object data resides.
I missed handling this offset for the delta base file, which is fixed here.

(Packed objects don't have a header, so this offset will be zero if raw
object data was extracted from a pack file instead of a loose object file.)

ok?

diff fdf3c2d3876d076bf098461a4d147227126588b4 /home/stsp/src/got
blob - c6481fe4c01d6cc1e445a9f0f588ec77b8003d3f
file + lib/deltify.c
--- lib/deltify.c
+++ lib/deltify.c
@@ -354,7 +354,7 @@ const struct got_error *
 got_deltify(struct got_delta_instruction **deltas, int *ndeltas,
     FILE *f, off_t fileoffset, off_t filesize,
     struct got_delta_table *dt, FILE *basefile,
-    off_t basefile_size)
+    off_t basefile_offset0, off_t basefile_size)
 {
 	const struct got_error *err = NULL;
 	const off_t offset0 = fileoffset;
@@ -392,7 +392,8 @@ got_deltify(struct got_delta_instruction **deltas, int
 			    &blocklen);
 			if (err)
 				break;
-			emitdelta(deltas, ndeltas, 1, block->offset, blocklen);
+			emitdelta(deltas, ndeltas, 1,
+			    block->offset - basefile_offset0, blocklen);
 		} else {
 			/*
 			 * No match.
blob - 39069a604eca508347a2f734e6fe70185a3febea
file + lib/got_lib_deltify.h
--- lib/got_lib_deltify.h
+++ lib/got_lib_deltify.h
@@ -44,5 +44,6 @@ const struct got_error *got_deltify_init(struct got_de
     off_t fileoffset, off_t filesize);
 const struct got_error *got_deltify(struct got_delta_instruction **deltas,
     int *ndeltas, FILE *f, off_t fileoffset, off_t filesize,
-    struct got_delta_table *dt, FILE *basefile, off_t basefile_size);
+    struct got_delta_table *dt, FILE *basefile, off_t basefile_offset0,
+    off_t basefile_size);
 void got_deltify_free(struct got_delta_table *dt);
blob - 5fa89910676821b58b5c98fe4828ced3e50f3e97
file + regress/deltify/deltify_test.c
--- regress/deltify/deltify_test.c
+++ regress/deltify/deltify_test.c
@@ -85,7 +85,8 @@ deltify_abc_axc(void)
 	}
 
 	err = got_deltify(&deltas, &ndeltas, derived_file, 0,
-	    3 * GOT_DELTIFY_MAXCHUNK, dt, base_file, 3 * GOT_DELTIFY_MAXCHUNK);
+	    3 * GOT_DELTIFY_MAXCHUNK, dt, base_file, 0,
+	    3 * GOT_DELTIFY_MAXCHUNK);
 	if (err)
 		goto done;