X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=builtin-send-pack.c;h=a9fdbf9d45ddd84e6397ab3e559b06e105c52a19;hb=6e13921b4f7adcc7316a76c0c4955b85b1589a65;hp=2af9f2934142f55858f4b5c76deb6397ac74b9f8;hpb=a1e3c2c1986e688bbef38ad573970dacd4a5899f;p=git.git diff --git a/builtin-send-pack.c b/builtin-send-pack.c index 2af9f2934..a9fdbf9d4 100644 --- a/builtin-send-pack.c +++ b/builtin-send-pack.c @@ -18,7 +18,7 @@ static struct send_pack_args args = { /* * Make a pack stream and spit it out into file descriptor fd */ -static int pack_objects(int fd, struct ref *refs) +static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra) { /* * The child becomes pack-objects --revs; we feed @@ -34,6 +34,8 @@ static int pack_objects(int fd, struct ref *refs) NULL, }; struct child_process po; + int i; + char buf[42]; if (args.use_thin_pack) argv[4] = "--thin"; @@ -49,9 +51,15 @@ static int pack_objects(int fd, struct ref *refs) * We feed the pack-objects we just spawned with revision * parameters by writing to the pipe. */ - while (refs) { - char buf[42]; + for (i = 0; i < extra->nr; i++) { + memcpy(buf + 1, sha1_to_hex(&extra->array[i][0]), 40); + buf[0] = '^'; + buf[41] = '\n'; + if (!write_or_whine(po.in, buf, 42, "send-pack: send refs")) + break; + } + while (refs) { if (!is_null_sha1(refs->old_sha1) && has_sha1_file(refs->old_sha1)) { memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40); @@ -132,7 +140,13 @@ static struct ref *remote_refs, **remote_tail; static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { struct ref *ref; - int len = strlen(refname) + 1; + int len; + + /* we already know it starts with refs/ to get here */ + if (check_ref_format(refname + 5)) + return 0; + + len = strlen(refname) + 1; ref = xcalloc(1, sizeof(*ref) + len); hashcpy(ref->new_sha1, sha1); memcpy(ref->name, refname, len); @@ -216,7 +230,7 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref) { struct refspec rs; - if (ref->status != REF_STATUS_OK) + if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE) return; rs.src = ref->name; @@ -226,7 +240,7 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref) if (args.verbose) fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst); if (ref->deletion) { - delete_ref(rs.dst, NULL); + delete_ref(rs.dst, NULL, 0); } else update_ref("update by push", rs.dst, ref->new_sha1, NULL, 0, 0); @@ -381,14 +395,17 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest int expect_status_report = 0; int flags = MATCH_REFS_NONE; int ret; + struct extra_have_objects extra_have; + memset(&extra_have, 0, sizeof(extra_have)); if (args.send_all) flags |= MATCH_REFS_ALL; if (args.send_mirror) flags |= MATCH_REFS_MIRROR; /* No funny business with the matcher */ - remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL); + remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL, + &extra_have); get_local_heads(); /* Does the other end support the reporting? */ @@ -418,24 +435,19 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest */ new_refs = 0; for (ref = remote_refs; ref; ref = ref->next) { - const unsigned char *new_sha1; - - if (!ref->peer_ref) { - if (!args.send_mirror) - continue; - new_sha1 = null_sha1; - } - else - new_sha1 = ref->peer_ref->new_sha1; + if (ref->peer_ref) + hashcpy(ref->new_sha1, ref->peer_ref->new_sha1); + else if (!args.send_mirror) + continue; - ref->deletion = is_null_sha1(new_sha1); + ref->deletion = is_null_sha1(ref->new_sha1); if (ref->deletion && !allow_deleting_refs) { ref->status = REF_STATUS_REJECT_NODELETE; continue; } if (!ref->deletion && - !hashcmp(ref->old_sha1, new_sha1)) { + !hashcmp(ref->old_sha1, ref->new_sha1)) { ref->status = REF_STATUS_UPTODATE; continue; } @@ -463,14 +475,13 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest !ref->deletion && !is_null_sha1(ref->old_sha1) && (!has_sha1_file(ref->old_sha1) - || !ref_newer(new_sha1, ref->old_sha1)); + || !ref_newer(ref->new_sha1, ref->old_sha1)); if (ref->nonfastforward && !ref->force && !args.force_update) { ref->status = REF_STATUS_REJECT_NONFASTFORWARD; continue; } - hashcpy(ref->new_sha1, new_sha1); if (!ref->deletion) new_refs++; @@ -496,7 +507,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest packet_flush(out); if (new_refs && !args.dry_run) { - if (pack_objects(out, remote_refs) < 0) + if (pack_objects(out, remote_refs, &extra_have) < 0) return -1; } else