From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Subject: [PATCH v3 4/6] push --force-with-lease: implement logic to populate old_sha1_expect[] Date: Mon, 22 Jul 2013 23:43:18 -0700 Message-ID: <1374561800-938-5-git-send-email-gitster@pobox.com> References: <1374561800-938-1-git-send-email-gitster@pobox.com> To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Jul 23 08:44:00 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V1WKF-0002l7-Eb for gcvg-git-2@plane.gmane.org; Tue, 23 Jul 2013 08:43:59 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753928Ab3GWGno (ORCPT ); Tue, 23 Jul 2013 02:43:44 -0400 Received: from b-pb-sasl-quonix.pobox.com ([208.72.237.35]:51356 "EHLO smtp.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752470Ab3GWGnb (ORCPT ); Tue, 23 Jul 2013 02:43:31 -0400 Received: from smtp.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 329C324A15 for ; Tue, 23 Jul 2013 06:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references; s=sasl; bh=nSGp +9sRdyQGOUIx6eLR4Upfu78=; b=f1PdNY+ofP8kuuF/urui3J0jum4Hbmsb4khv VzIusbx43VGaJsvFy/SdUaSJ775pv9K4eHlsA9v7an91xXncejxT4emWAbH4VmPT 281KkRGHZzNyPRD8D+VSeIb/IddHlkmtF8gayhx3HdaqfPf6tXT9Ipo43TRNHZ+S vLewsQs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references; q=dns; s=sasl; b=m0RzV1 ZEsHoeOjMjhAXMz9xR7b6PV98mO63aqv0AU1FG1Pk7Xqe/NvUXu3G1eMOLpkkG+W 29COm1zpFXjk9WmDQuYq1EXqGPJRMhRSs/zhcwUoRfiWpJGPMgjGTe9c+cTMDW7U UnZoYby6AGHQWIeNVdpL11vqWgMnAMFQ7eHko= Received: from b-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by b-sasl-quonix.pobox.com (Postfix) with ESMTP id 2936324A14 for ; Tue, 23 Jul 2013 06:43:31 +0000 (UTC) Received: from pobox.com (unknown [50.161.4.97]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by b-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 4E68224A13 for ; Tue, 23 Jul 2013 06:43:30 +0000 (UTC) X-Mailer: git-send-email 1.8.3.4-985-g5661af8 In-Reply-To: <1374561800-938-1-git-send-email-gitster@pobox.com> X-Pobox-Relay-ID: 2FC542BA-F363-11E2-AB37-E84251E3A03C-77302942!b-pb-sasl-quonix.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This plugs the push_cas_option data collected by the command line option parser to the transport system with a new function apply_push_cas(), which is called after match_push_refs() has already been called. At this point, we know which remote we are talking to, and what remote refs we are going to update, so we can fill in the details that may have been missing from the command line, such as (1) what abbreviated refname the user gave us matches the actual refname at the remote; and (2) which remote-tracking branch in our local repository to read the value of the object to expect at the remote. to populate the old_sha1_expect[] field of each of the remote ref. As stated in the documentation, the use of remote-tracking branch as the default is a tentative one, and we may come up with a better logic as we gain experience. Still nobody uses this information, which is the topic of the next patch. Signed-off-by: Junio C Hamano --- builtin/push.c | 7 ++++++ builtin/send-pack.c | 3 +++ remote.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ remote.h | 6 ++++++ transport.c | 6 ++++++ transport.h | 4 ++++ 6 files changed, 87 insertions(+) diff --git a/builtin/push.c b/builtin/push.c index 31a5ba0..2fd0a70 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -299,6 +299,13 @@ static int push_with_options(struct transport *transport, int flags) if (thin) transport_set_option(transport, TRANS_OPT_THIN, "yes"); + if (!is_empty_cas(&cas)) { + if (!transport->smart_options) + die("underlying transport does not support --%s option", + CAS_OPT_NAME); + transport->smart_options->cas = &cas; + } + if (verbosity > 0) fprintf(stderr, _("Pushing to %s\n"), transport->url); err = transport_push(transport, refspec_nr, refspec, flags, diff --git a/builtin/send-pack.c b/builtin/send-pack.c index a23b26d..6027ead 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -242,6 +242,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags)) return -1; + if (!is_empty_cas(&cas)) + apply_push_cas(&cas, remote, remote_refs); + set_ref_status_for_push(remote_refs, args.send_mirror, args.force_update); diff --git a/remote.c b/remote.c index 0d38353..52e3a12 100644 --- a/remote.c +++ b/remote.c @@ -1978,3 +1978,64 @@ int parseopt_push_cas_option(const struct option *opt, const char *arg, int unse { return parse_push_cas_option(opt->value, arg, unset); } + +int is_empty_cas(const struct push_cas_option *cas) +{ + return !cas->use_tracking_for_rest && !cas->nr; +} + +/* + * Look at remote.fetch refspec and see if we have a remote + * tracking branch for the refname there. Fill its current + * value in sha1[]. + * If we cannot do so, return negative to signal an error. + */ +static int remote_tracking(struct remote *remote, const char *refname, + unsigned char sha1[20]) +{ + char *dst; + + dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname); + if (!dst) + return -1; /* no tracking ref for refname at remote */ + if (read_ref(dst, sha1)) + return -1; /* we know what the tracking ref is but we cannot read it */ + return 0; +} + +static void apply_cas(struct push_cas_option *cas, + struct remote *remote, + struct ref *ref) +{ + int i; + + /* Find an explicit --