Skip to content

Commit b74fce1

Browse files
Nicolas Pitregitster
authored andcommitted
allow OFS_DELTA objects during a push
The fetching of OFS_DELTA objects has been negotiated between both peers since git version 1.4.4. However, this was missing from the push side where every OFS_DELTA objects were always converted to REF_DELTA objects causing an increase in transferred data. To fix this, both the client and the server processes have to be modified: the former to invoke pack-objects with --delta-base-offset when the server provides the ofs-delta capability, and the later to send that capability when OFS_DELTA objects are allowed as already indicated by the repack.usedeltabaseoffset config variable which is TRUE by default since git v1.6.0. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75b4406 commit b74fce1

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

builtin-receive-pack.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ static int receive_unpack_limit = -1;
2727
static int transfer_unpack_limit = -1;
2828
static int unpack_limit = 100;
2929
static int report_status;
30+
static int prefer_ofs_delta = 1;
3031
static const char *head_name;
31-
32-
static char capabilities[] = " report-status delete-refs ";
33-
static int capabilities_sent;
32+
static char *capabilities_to_send;
3433

3534
static enum deny_action parse_deny_action(const char *var, const char *value)
3635
{
@@ -84,24 +83,29 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
8483
return 0;
8584
}
8685

86+
if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
87+
prefer_ofs_delta = git_config_bool(var, value);
88+
return 0;
89+
}
90+
8791
return git_default_config(var, value, cb);
8892
}
8993

9094
static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
9195
{
92-
if (capabilities_sent)
96+
if (!capabilities_to_send)
9397
packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
9498
else
9599
packet_write(1, "%s %s%c%s\n",
96-
sha1_to_hex(sha1), path, 0, capabilities);
97-
capabilities_sent = 1;
100+
sha1_to_hex(sha1), path, 0, capabilities_to_send);
101+
capabilities_to_send = NULL;
98102
return 0;
99103
}
100104

101105
static void write_head_info(void)
102106
{
103107
for_each_ref(show_ref, NULL);
104-
if (!capabilities_sent)
108+
if (capabilities_to_send)
105109
show_ref("capabilities^{}", null_sha1, 0, NULL);
106110

107111
}
@@ -687,6 +691,10 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
687691
else if (0 <= receive_unpack_limit)
688692
unpack_limit = receive_unpack_limit;
689693

694+
capabilities_to_send = (prefer_ofs_delta) ?
695+
" report-status delete-refs ofs-delta " :
696+
" report-status delete-refs ";
697+
690698
add_alternate_refs();
691699
write_head_info();
692700
clear_extra_refs();

builtin-send-pack.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
4343
"--stdout",
4444
NULL,
4545
NULL,
46+
NULL,
4647
};
4748
struct child_process po;
4849
int i;
4950

51+
i = 4;
5052
if (args->use_thin_pack)
51-
argv[4] = "--thin";
53+
argv[i++] = "--thin";
54+
if (args->use_ofs_delta)
55+
argv[i++] = "--delta-base-offset";
5256
memset(&po, 0, sizeof(po));
5357
po.argv = argv;
5458
po.in = -1;
@@ -315,6 +319,8 @@ int send_pack(struct send_pack_args *args,
315319
ask_for_status_report = 1;
316320
if (server_supports("delete-refs"))
317321
allow_deleting_refs = 1;
322+
if (server_supports("ofs-delta"))
323+
args->use_ofs_delta = 1;
318324

319325
if (!remote_refs) {
320326
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"

send-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct send_pack_args {
66
send_mirror:1,
77
force_update:1,
88
use_thin_pack:1,
9+
use_ofs_delta:1,
910
dry_run:1;
1011
};
1112

0 commit comments

Comments
 (0)