int transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags) { verify_remote_names(refspec_nr, refspec); if (transport->push) return transport->push(transport, refspec_nr, refspec, flags); if (transport->push_refs) { struct ref *remote_refs = transport->get_refs_list(transport, 1); struct ref *local_refs = get_local_heads(); int match_flags = MATCH_REFS_NONE; int verbose = flags & TRANSPORT_PUSH_VERBOSE; int ret; if (flags & TRANSPORT_PUSH_ALL) match_flags |= MATCH_REFS_ALL; if (flags & TRANSPORT_PUSH_MIRROR) match_flags |= MATCH_REFS_MIRROR; if (match_refs(local_refs, &remote_refs, refspec_nr, refspec, match_flags)) { return -1; } ret = transport->push_refs(transport, remote_refs, flags); print_push_status(transport->url, remote_refs, verbose); if (!(flags & TRANSPORT_PUSH_DRY_RUN)) { struct ref *ref; for (ref = remote_refs; ref; ref = ref->next) update_tracking_ref(transport->remote, ref, verbose); } if (!ret && !refs_pushed(remote_refs)) fprintf(stderr, "Everything up-to-date\n"); return ret; } return 1; }
int cmd_send_pack(int argc, const char **argv, const char *prefix) { int i, nr_refspecs = 0; const char **refspecs = NULL; const char *remote_name = NULL; struct remote *remote = NULL; const char *dest = NULL; int fd[2]; struct child_process *conn; struct extra_have_objects extra_have; struct ref *remote_refs, *local_refs; int ret; int send_all = 0; const char *receivepack = "git-receive-pack"; int flags; argv++; for (i = 1; i < argc; i++, argv++) { const char *arg = *argv; if (*arg == '-') { if (!prefixcmp(arg, "--receive-pack=")) { receivepack = arg + 15; continue; } if (!prefixcmp(arg, "--exec=")) { receivepack = arg + 7; continue; } if (!prefixcmp(arg, "--remote=")) { remote_name = arg + 9; continue; } if (!strcmp(arg, "--all")) { send_all = 1; continue; } if (!strcmp(arg, "--dry-run")) { args.dry_run = 1; continue; } if (!strcmp(arg, "--mirror")) { args.send_mirror = 1; continue; } if (!strcmp(arg, "--force")) { args.force_update = 1; continue; } if (!strcmp(arg, "--verbose")) { args.verbose = 1; continue; } if (!strcmp(arg, "--thin")) { args.use_thin_pack = 1; continue; } usage(send_pack_usage); } if (!dest) { dest = arg; continue; } refspecs = (const char **) argv; nr_refspecs = argc - i; break; } if (!dest) usage(send_pack_usage); /* * --all and --mirror are incompatible; neither makes sense * with any refspecs. */ if ((refspecs && (send_all || args.send_mirror)) || (send_all && args.send_mirror)) usage(send_pack_usage); if (remote_name) { remote = remote_get(remote_name); if (!remote_has_url(remote, dest)) { die("Destination %s is not a uri for %s", dest, remote_name); } } conn = git_connect(fd, dest, receivepack, args.verbose ? CONNECT_VERBOSE : 0); memset(&extra_have, 0, sizeof(extra_have)); get_remote_heads(fd[0], &remote_refs, 0, NULL, REF_NORMAL, &extra_have); verify_remote_names(nr_refspecs, refspecs); local_refs = get_local_heads(); flags = MATCH_REFS_NONE; if (send_all) flags |= MATCH_REFS_ALL; if (args.send_mirror) flags |= MATCH_REFS_MIRROR; /* match them up */ if (match_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags)) return -1; ret = send_pack(&args, fd, conn, remote_refs, &extra_have); close(fd[1]); close(fd[0]); ret |= finish_connect(conn); print_push_status(dest, remote_refs); if (!args.dry_run && remote) { struct ref *ref; for (ref = remote_refs; ref; ref = ref->next) update_tracking_ref(remote, ref); } if (!ret && !refs_pushed(remote_refs)) fprintf(stderr, "Everything up-to-date\n"); return ret; }