@matheusbsbs / matheus-bagliano / commits / 40c155ff14
Fork 0

push: prepare sender to receive extended ref information from the receiver

"git push" enhancement allows the receiving end to report not only its own refs but refs in repositories it borrows from via the alternate object store mechanism. By telling the sender that objects reachable from these extra refs are already complete in the receiving end, the number of objects that need to be transfered can be cut down. These entries are sent over the wire with string ".have", instead of the actual names of the refs. This string was chosen so that they are ignored by older programs at the sending end. If we sent some random but valid looking refnames for these entries, "matching refs" rule (triggered when running "git push" without explicit refspecs, where the sender learns what refs the receiver has, and updates only the ones with the names of the refs the sender also has) and "delete missing" rule (triggered when "git push --mirror" is used, where the sender tells the receiver to delete the refs it itself does not have) would try to update/delete them, which is not what we want. This prepares the send-pack (and "push" that runs native protocol) to accept extended existing ref information and make use of it. The ".have" entries are excluded from ref matching rules, and are exempt from deletion rule while pushing with --mirror option, but are still used for pack generation purposes by providing more "bottom" range commits. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 9, 2008 at 01:27 UTC 40c155ff14c8b313d408f2e51a55c881ce082e4e
5 files changed +39 -10
builtin-fetch-pack.c
+1 -1
@@ -735,7 +735,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
735 conn = git_connect(fd, (char *)dest, args.uploadpack,
736 args.verbose ? CONNECT_VERBOSE : 0);
737 if (conn) {
738 - get_remote_heads(fd[0], &ref, 0, NULL, 0);
738 + get_remote_heads(fd[0], &ref, 0, NULL, 0, NULL);
739
740 ref = fetch_pack(&args, fd, conn, ref, dest, nr_heads, heads, NULL);
741 close(fd[0]);
builtin-send-pack.c
+16 -5
@@ -18,7 +18,7 @@ static struct send_pack_args args = {
18 /*
19 * Make a pack stream and spit it out into file descriptor fd
20 */
21 -static int pack_objects(int fd, struct ref *refs)
21 +static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra)
22 {
23 /*
24 * The child becomes pack-objects --revs; we feed
@@ -34,6 +34,8 @@ static int pack_objects(int fd, struct ref *refs)
34 NULL,
35 };
36 struct child_process po;
37 + int i;
38 + char buf[42];
39
40 if (args.use_thin_pack)
41 argv[4] = "--thin";
@@ -49,9 +51,15 @@ static int pack_objects(int fd, struct ref *refs)
51 * We feed the pack-objects we just spawned with revision
52 * parameters by writing to the pipe.
53 */
52 - while (refs) {
53 - char buf[42];
54 + for (i = 0; i < extra->nr; i++) {
55 + memcpy(buf + 1, sha1_to_hex(&extra->array[i][0]), 40);
56 + buf[0] = '^';
57 + buf[41] = '\n';
58 + if (!write_or_whine(po.in, buf, 42, "send-pack: send refs"))
59 + break;
60 + }
61
62 + while (refs) {
63 if (!is_null_sha1(refs->old_sha1) &&
64 has_sha1_file(refs->old_sha1)) {
65 memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
@@ -381,14 +389,17 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
389 int expect_status_report = 0;
390 int flags = MATCH_REFS_NONE;
391 int ret;
392 + struct extra_have_objects extra_have;
393
394 + memset(&extra_have, 0, sizeof(extra_have));
395 if (args.send_all)
396 flags |= MATCH_REFS_ALL;
397 if (args.send_mirror)
398 flags |= MATCH_REFS_MIRROR;
399
400 /* No funny business with the matcher */
391 - remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL);
401 + remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL,
402 + &extra_have);
403 get_local_heads();
404
405 /* Does the other end support the reporting? */
@@ -496,7 +507,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
507
508 packet_flush(out);
509 if (new_refs && !args.dry_run) {
499 - if (pack_objects(out, remote_refs) < 0)
510 + if (pack_objects(out, remote_refs, &extra_have) < 0)
511 return -1;
512 }
513 else
cache.h
+5 -1
@@ -709,7 +709,11 @@ extern struct child_process *git_connect(int fd[2], const char *url, const char
709 extern int finish_connect(struct child_process *conn);
710 extern int path_match(const char *path, int nr, char **match);
711 extern int get_ack(int fd, unsigned char *result_sha1);
712 -extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags);
712 +struct extra_have_objects {
713 + int nr, alloc;
714 + unsigned char (*array)[20];
715 +};
716 +extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags, struct extra_have_objects *);
717 extern int server_supports(const char *feature);
718
719 extern struct packed_git *parse_pack_index(unsigned char *sha1);
connect.c
+15 -1
@@ -41,12 +41,20 @@ int check_ref_type(const struct ref *ref, int flags)
41 return check_ref(ref->name, strlen(ref->name), flags);
42 }
43
44 +static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1)
45 +{
46 + ALLOC_GROW(extra->array, extra->nr + 1, extra->alloc);
47 + hashcpy(&(extra->array[extra->nr][0]), sha1);
48 + extra->nr++;
49 +}
50 +
51 /*
52 * Read all the refs from the other end
53 */
54 struct ref **get_remote_heads(int in, struct ref **list,
55 int nr_match, char **match,
49 - unsigned int flags)
56 + unsigned int flags,
57 + struct extra_have_objects *extra_have)
58 {
59 *list = NULL;
60 for (;;) {
@@ -72,6 +80,12 @@ struct ref **get_remote_heads(int in, struct ref **list,
80 server_capabilities = xstrdup(name + name_len + 1);
81 }
82
83 + if (extra_have &&
84 + name_len == 5 && !memcmp(".have", name, 5)) {
85 + add_extra_have(extra_have, old_sha1);
86 + continue;
87 + }
88 +
89 if (!check_ref(name, name_len, flags))
90 continue;
91 if (nr_match && !path_match(name, nr_match, match))
transport.c
+2 -2
@@ -619,7 +619,7 @@ static struct ref *get_refs_via_connect(struct transport *transport)
619 struct ref *refs;
620
621 connect_setup(transport);
622 - get_remote_heads(data->fd[0], &refs, 0, NULL, 0);
622 + get_remote_heads(data->fd[0], &refs, 0, NULL, 0, NULL);
623
624 return refs;
625 }
@@ -652,7 +652,7 @@ static int fetch_refs_via_pack(struct transport *transport,
652
653 if (!data->conn) {
654 connect_setup(transport);
655 - get_remote_heads(data->fd[0], &refs_tmp, 0, NULL, 0);
655 + get_remote_heads(data->fd[0], &refs_tmp, 0, NULL, 0, NULL);
656 }
657
658 refs = fetch_pack(&args, data->fd, data->conn,