Commit Diff


commit - be1adb68ca2a90d29b3e3af776e71bef197faf6d
commit + d8253374fe0c7ca9400fac9c446c8c227992ddee
blob - e11b3a0b3586e7aac0c6955aac2096e7dc6d7fe6
blob + 5278c5830ad6b4af4c8d43dbbe466b6a4851dd25
--- gotadmin/gotadmin.1
+++ gotadmin/gotadmin.1
@@ -96,7 +96,7 @@ work tree, use the repository path associated with thi
 .El
 .It Xo
 .Cm pack
-.Op Fl aq
+.Op Fl aDq
 .Op Fl r Ar repository-path
 .Op Fl x Ar reference
 .Op Ar reference ...
@@ -128,6 +128,10 @@ are as follows:
 Add objects to the generated pack file even if they are already packed
 in a different pack file.
 Unless this option is specified, only loose objects will be added.
+.It Fl D
+Force the use of ref-delta representation for deltified objects.
+If this option is not specified, offset-deltas will be used to represent
+deltified objects.
 .It Fl q
 Suppress progress reporting output.
 .It Fl r Ar repository-path
blob - 3aaef3cd2dd0fdb5d027a580537a9676d65237a8
blob + a7c0b49eb169b3371b17192a5ec228ef57483eb5
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -452,7 +452,7 @@ done:
 __dead static void
 usage_pack(void)
 {
-	fprintf(stderr, "usage: %s pack [-aq] [-r repository-path] "
+	fprintf(stderr, "usage: %s pack [-aDq] [-r repository-path] "
 	    "[-x reference] [reference ...]\n", getprogname());
 	exit(1);
 }
@@ -692,7 +692,7 @@ cmd_pack(int argc, char *argv[])
 	const struct got_error *error = NULL;
 	char *repo_path = NULL;
 	struct got_repository *repo = NULL;
-	int ch, i, loose_obj_only = 1, verbosity = 0;
+	int ch, i, loose_obj_only = 1, force_refdelta = 0, verbosity = 0;
 	struct got_object_id *pack_hash = NULL;
 	char *id_str = NULL;
 	struct got_pack_progress_arg ppa;
@@ -714,11 +714,14 @@ cmd_pack(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	while ((ch = getopt(argc, argv, "aqr:x:")) != -1) {
+	while ((ch = getopt(argc, argv, "aDqr:x:")) != -1) {
 		switch (ch) {
 		case 'a':
 			loose_obj_only = 0;
 			break;
+		case 'D':
+			force_refdelta = 1;
+			break;
 		case 'q':
 			verbosity = -1;
 			break;
@@ -802,7 +805,7 @@ cmd_pack(int argc, char *argv[])
 
 	error = got_repo_pack_objects(&packfile, &pack_hash,
 	    &include_refs, &exclude_refs, repo, loose_obj_only,
-	    pack_progress, &ppa, check_cancelled, NULL);
+	    force_refdelta, pack_progress, &ppa, check_cancelled, NULL);
 	if (error) {
 		if (ppa.printed_something)
 			printf("\n");
blob - 2caf2a94d4ed262a215863f07c9e967a8f052cc3
blob + 5ddd50191b8acfb903877b148bb856de99014b07
--- include/got_repository_admin.h
+++ include/got_repository_admin.h
@@ -34,7 +34,7 @@ const struct got_error *
 got_repo_pack_objects(FILE **packfile, struct got_object_id **pack_hash,
     struct got_reflist_head *include_refs,
     struct got_reflist_head *exclude_refs, struct got_repository *repo,
-    int loose_obj_only,
+    int loose_obj_only, int force_refdelta,
     got_pack_progress_cb progress_cb, void *progress_arg,
     got_cancel_cb cancel_cb, void *cancel_arg);
 
blob - 7a3c6579c0c3c5ab813f5c5cdb1093a791ac08b4
blob + a46287669ce58c4c526c341b77350db16c5fa714
--- lib/got_lib_pack_create.h
+++ lib/got_lib_pack_create.h
@@ -25,7 +25,7 @@ const struct got_error *got_pack_create(uint8_t *pack_
     FILE *delta_cache, struct got_object_id **theirs, int ntheirs,
     struct got_object_id **ours, int nours,
     struct got_repository *repo, int loose_obj_only, int allow_empty,
-    got_pack_progress_cb progress_cb, void *progress_arg,
+    int force_refdelta, got_pack_progress_cb progress_cb, void *progress_arg,
     struct got_ratelimit *, got_cancel_cb cancel_cb, void *cancel_arg);
 
 const struct got_error *
blob - c50c8a47f4f7de17370202ceff042e30a5adfeaa
blob + 1d2bcd07b13eee0369a1fdd6bcd48e349cd744b2
--- lib/pack_create.c
+++ lib/pack_create.c
@@ -1550,14 +1550,14 @@ packoff(char *hdr, off_t off)
 }
 
 static const struct got_error *
-deltahdr(off_t *packfile_size, SHA1_CTX *ctx, int packfd,
+deltahdr(off_t *packfile_size, SHA1_CTX *ctx, int packfd, int force_refdelta,
     struct got_pack_meta *m)
 {
 	const struct got_error *err;
 	char buf[32];
 	int nh;
 
-	if (m->prev->off != 0) {
+	if (m->prev->off != 0 && !force_refdelta) {
 		err = packhdr(&nh, buf, sizeof(buf),
 		    GOT_OBJ_TYPE_OFFSET_DELTA, m->delta_len);
 		if (err)
@@ -1590,7 +1590,7 @@ static const struct got_error *
 write_packed_object(off_t *packfile_size, int packfd,
     FILE *delta_cache, uint8_t *delta_cache_map, size_t delta_cache_size,
     struct got_pack_meta *m, int *outfd, SHA1_CTX *ctx,
-    struct got_repository *repo)
+    struct got_repository *repo, int force_refdelta)
 {
 	const struct got_error *err = NULL;
 	struct got_deflate_checksum csum;
@@ -1641,7 +1641,7 @@ write_packed_object(off_t *packfile_size, int packfd,
 		got_object_raw_close(raw);
 		raw = NULL;
 	} else if (m->delta_buf) {
-		err = deltahdr(packfile_size, ctx, packfd, m);
+		err = deltahdr(packfile_size, ctx, packfd, force_refdelta, m);
 		if (err)
 			goto done;
 		err = hwrite(packfd, m->delta_buf,
@@ -1652,7 +1652,7 @@ write_packed_object(off_t *packfile_size, int packfd,
 		free(m->delta_buf);
 		m->delta_buf = NULL;
 	} else if (delta_cache_map) {
-		err = deltahdr(packfile_size, ctx, packfd, m);
+		err = deltahdr(packfile_size, ctx, packfd, force_refdelta, m);
 		if (err)
 			goto done;
 		err = hcopy_mmap(delta_cache_map, delta_offset,
@@ -1666,7 +1666,7 @@ write_packed_object(off_t *packfile_size, int packfd,
 			err = got_error_from_errno("fseeko");
 			goto done;
 		}
-		err = deltahdr(packfile_size, ctx, packfd, m);
+		err = deltahdr(packfile_size, ctx, packfd, force_refdelta, m);
 		if (err)
 			goto done;
 		err = hcopy(delta_cache, packfd,
@@ -1686,7 +1686,7 @@ genpack(uint8_t *pack_sha1, int packfd, struct got_pac
     FILE *delta_cache, struct got_pack_meta **deltify, int ndeltify,
     struct got_pack_meta **reuse, int nreuse,
     int ncolored, int nfound, int ntrees, int nours,
-    struct got_repository *repo,
+    struct got_repository *repo, int force_refdelta,
     got_pack_progress_cb progress_cb, void *progress_arg,
     struct got_ratelimit *rl,
     got_cancel_cb cancel_cb, void *cancel_arg)
@@ -1750,7 +1750,7 @@ genpack(uint8_t *pack_sha1, int packfd, struct got_pac
 		m = deltify[i];
 		err = write_packed_object(&packfile_size, packfd,
 		    delta_cache, delta_cache_map, delta_cache_size,
-		    m, &outfd, &ctx, repo);
+		    m, &outfd, &ctx, repo, force_refdelta);
 		if (err)
 			goto done;
 	}
@@ -1779,7 +1779,7 @@ genpack(uint8_t *pack_sha1, int packfd, struct got_pac
 		m = reuse[i];
 		err = write_packed_object(&packfile_size, packfd,
 		    packfile, reuse_pack->map, reuse_pack->filesize,
-		    m, &outfd, &ctx, repo);
+		    m, &outfd, &ctx, repo, force_refdelta);
 		if (err)
 			goto done;
 	}
@@ -1826,7 +1826,7 @@ got_pack_create(uint8_t *packsha1, int packfd, FILE *d
     struct got_object_id **theirs, int ntheirs,
     struct got_object_id **ours, int nours,
     struct got_repository *repo, int loose_obj_only, int allow_empty,
-    got_pack_progress_cb progress_cb, void *progress_arg,
+    int force_refdelta, got_pack_progress_cb progress_cb, void *progress_arg,
     struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err;
@@ -1933,7 +1933,7 @@ got_pack_create(uint8_t *packsha1, int packfd, FILE *d
 
 	err = genpack(packsha1, packfd, reuse_pack, delta_cache, deltify.meta,
 	    deltify.nmeta, reuse.meta, reuse.nmeta, ncolored, nfound, ntrees,
-	    nours, repo, progress_cb, progress_arg, rl,
+	    nours, repo, force_refdelta, progress_cb, progress_arg, rl,
 	    cancel_cb, cancel_arg);
 	if (err)
 		goto done;
blob - c88a7edc73004236669568bde01f6d0e178ab81d
blob + 76b856371e7b492ce867b7dc85ea9aad5bf30125
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -141,7 +141,7 @@ const struct got_error *
 got_repo_pack_objects(FILE **packfile, struct got_object_id **pack_hash,
     struct got_reflist_head *include_refs,
     struct got_reflist_head *exclude_refs, struct got_repository *repo,
-    int loose_obj_only,
+    int loose_obj_only, int force_refdelta,
     got_pack_progress_cb progress_cb, void *progress_arg,
     got_cancel_cb cancel_cb, void *cancel_arg)
 {
@@ -205,8 +205,9 @@ got_repo_pack_objects(FILE **packfile, struct got_obje
 	}
 
 	err = got_pack_create((*pack_hash)->sha1, packfd, delta_cache,
-	    theirs, ntheirs, ours, nours, repo, loose_obj_only, 0,
-	    progress_cb, progress_arg, &rl, cancel_cb, cancel_arg);
+	    theirs, ntheirs, ours, nours, repo, loose_obj_only,
+	    0, force_refdelta, progress_cb, progress_arg, &rl,
+	    cancel_cb, cancel_arg);
 	if (err)
 		goto done;
 
blob - be435b3948bb0c087620071008e5aaef90565f6b
blob + bb4d82021965534663cafd60789dda2ed93c43eb
--- lib/send.c
+++ lib/send.c
@@ -642,7 +642,7 @@ got_send_pack(const char *remote_name, struct got_path
 		ppa.progress_cb = progress_cb;
 		ppa.progress_arg = progress_arg;
 		err = got_pack_create(packsha1, packfd, delta_cache,
-		    their_ids, ntheirs, our_ids, nours, repo, 0, 1,
+		    their_ids, ntheirs, our_ids, nours, repo, 0, 0, 1,
 		    pack_progress, &ppa, &rl, cancel_cb, cancel_arg);
 		if (err)
 			goto done;