@matheusbsbs / matheus-bagliano / commits / b74fce16fa
Fork 0

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 <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed May 1, 2009 at 16:56 UTC b74fce16fa51362d4a3875d46e488006c3ad5371
3 files changed +23 -8
builtin-receive-pack.c
+15 -7
@@ -27,10 +27,9 @@ static int receive_unpack_limit = -1;
27 static int transfer_unpack_limit = -1;
28 static int unpack_limit = 100;
29 static int report_status;
30 +static int prefer_ofs_delta = 1;
31 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;
33
34 static enum deny_action parse_deny_action(const char *var, const char *value)
35 {
@@ -84,24 +83,29 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
83 return 0;
84 }
85
86 + if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
87 + prefer_ofs_delta = git_config_bool(var, value);
88 + return 0;
89 + }
90 +
91 return git_default_config(var, value, cb);
92 }
93
94 static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
95 {
92 - if (capabilities_sent)
96 + if (!capabilities_to_send)
97 packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
98 else
99 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;
102 return 0;
103 }
104
105 static void write_head_info(void)
106 {
107 for_each_ref(show_ref, NULL);
104 - if (!capabilities_sent)
108 + if (capabilities_to_send)
109 show_ref("capabilities^{}", null_sha1, 0, NULL);
110
111 }
@@ -687,6 +691,10 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
691 else if (0 <= receive_unpack_limit)
692 unpack_limit = receive_unpack_limit;
693
694 + capabilities_to_send = (prefer_ofs_delta) ?
695 + " report-status delete-refs ofs-delta " :
696 + " report-status delete-refs ";
697 +
698 add_alternate_refs();
699 write_head_info();
700 clear_extra_refs();
builtin-send-pack.c
+7 -1
@@ -43,12 +43,16 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
43 "--stdout",
44 NULL,
45 NULL,
46 + NULL,
47 };
48 struct child_process po;
49 int i;
50
51 + i = 4;
52 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";
56 memset(&po, 0, sizeof(po));
57 po.argv = argv;
58 po.in = -1;
@@ -315,6 +319,8 @@ int send_pack(struct send_pack_args *args,
319 ask_for_status_report = 1;
320 if (server_supports("delete-refs"))
321 allow_deleting_refs = 1;
322 + if (server_supports("ofs-delta"))
323 + args->use_ofs_delta = 1;
324
325 if (!remote_refs) {
326 fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
send-pack.h
+1
@@ -6,6 +6,7 @@ struct send_pack_args {
6 send_mirror:1,
7 force_update:1,
8 use_thin_pack:1,
9 + use_ofs_delta:1,
10 dry_run:1;
11 };
12