From patchwork Tue Sep 10 20:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13799302 Received: from aib29agh122.zrh1.oracleemaildelivery.com (aib29agh122.zrh1.oracleemaildelivery.com [192.29.178.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5AD6176252 for ; Tue, 10 Sep 2024 20:44:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726001080; cv=none; b=nmJVzaxX+8aqXVGNkiI5vpctBd4fix5gfe5BvsIloo4rErNegn45JPwPxRh6Y6Yw+okZvo5kLuygTHqx2EAgszDvZxZzEq1rTJJ/ni20SRShAqXEE83dT6rdlO2r/OF95pqrSUuFzVyEbdD9qHSfRi6FReOGDEmF2Oye/BpjbgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726001080; c=relaxed/simple; bh=QZBCqw2G82OdN2aDRIhGTS893iPwEWAjoCSNC2nDoS0=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=Y/iwyEV8bK+bEbooDG4tZ+w+gs1A7epP0E0Z+xfXwgzvfwUBSDDX3UfUVQhKK08fFtvKqVH7Nr0ZDVLd2k+RIW8HRADLrzp1RMrSJjrCsNl+G3AgLlhF7p7POf+r0+l/NHfup0It7OSWMVU7DQ3KSNfuoiXqfPUcKSFM6BRRJqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=FWRBIni0; arc=none smtp.client-ip=192.29.178.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="FWRBIni0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=R1YrB40qO3JlgrgVOKo9miaDmh2216DNGKIvrWEzizs=; b=FWRBIni0SLL13qloeXKjbj/5emta/gNs+K95NlY4cViAfNzWyf4KoS2sagRYUM9xvMUl1DO1ceYV ahV/hS/fsUYBOZeBmH5st94PuTilV3ug1k/EXscfXrqLSB05MNmZCiCHM1QGbz8gmm4JZLwzYEMN FHhid+c0QBUdwtavGYU5eQLMEpApIVAOnFKJoTHFlfk6eCjm+XigYKAI2jXAnSKxaHzoFL0T5+Ka JrYKfsLgoA0TG2rulbo6ey+J2Mlje0oZy789IPxy8OvrPWcJfmsfNU2c2S9Sn44LlbDB/5gVVgVM dtw5YX39QOeXBk4VCYkB6MHzDlfmYouhun63nQ== Received: by omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240709 64bit (built Jul 9 2024)) with ESMTPS id <0SJM008G96PR7A30@omta-ad1-fd1-401-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Tue, 10 Sep 2024 20:39:27 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , Patrick Steinhardt , =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Bence Ferdinandy Subject: [RFC PATCH v2 1/2] fetch: set-head with --set-head option Date: Tue, 10 Sep 2024 22:37:13 +0200 Message-id: <20240910203835.2288291-2-bence@ferdinandy.com> In-reply-to: <20240910203835.2288291-1-bence@ferdinandy.com> References: <20240910203835.2288291-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAGJ6/mkol+Ap++/pEyqGNeGu9zVxxvhfnzcW8vd2ea3WUcu9RlcMLRcPbzoE7zE zntPrxyZWTntUgHFoc9mRXJKx8oyEPMPhSmhjBFgMB4+Y0mzwqE5Lx6cd4A4OO3R k9REjBb/BwsPqgXxrR+N/2DO7NL1+lguSXSIoXmxblOuSajSnfpv2kmxWtGB4b5N 82yRAQJCI3HOZB1619aG62Gb5dZcQ0niZT9gDVbllBvItwKjCpnLI4nMV/EksuyI roqewYhbsCgfPdv/BctAX3kAdKMX1S81seq9uKe2lCNASnUcQu/FKsd6wC5dLHwj gCgFPuCkqTQtX359u5ry3KRUT7/e1uPr0HiSXhGp/pAjxpuA5Qo1jmNbiS90utbP 20LF19AnUmNoavCJqegNySOEfVSHU5gzFaNGKf1gV35ZBx8eyTrWHe8OsHRfgJW1 tR0amDq2py+uWZbaCUDa+poioTNUM+sAEXr37LtWw7738Zcy9DgSYDiJ When cloning a repository refs/remotes/origin/HEAD is set automatically. In contrast, when using init, remote add and fetch to set a remote, one needs to call remote set-head --auto to achieve the same result. Add a --set-head option to git fetch to automatically set heads on remotes. Signed-off-by: Bence Ferdinandy --- builtin/fetch.c | 29 ++++++++++++++++++++++++----- builtin/remote.c | 5 +++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index b2b5aee5bf..6392314c6a 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1961,8 +1961,19 @@ static int fetch_finished(int result, struct strbuf *out, return 0; } -static int fetch_multiple(struct string_list *list, int max_children, - const struct fetch_config *config) +static int run_set_head(const char *name) +{ + struct child_process cmd = CHILD_PROCESS_INIT; + strvec_push(&cmd.args, "remote"); + strvec_push(&cmd.args, "set-head"); + strvec_push(&cmd.args, "--auto"); + strvec_push(&cmd.args, name); + cmd.git_cmd = 1; + return run_command(&cmd); +} + +static int fetch_multiple(struct string_list *list, int max_children, int set_head, + const struct fetch_config *config) { int i, result = 0; struct strvec argv = STRVEC_INIT; @@ -2014,6 +2025,8 @@ static int fetch_multiple(struct string_list *list, int max_children, error(_("could not fetch %s"), name); result = 1; } + if (set_head && run_set_head(name)) + result = 1; } strvec_clear(&argv); @@ -2062,7 +2075,7 @@ static inline void fetch_one_setup_partial(struct remote *remote) } static int fetch_one(struct remote *remote, int argc, const char **argv, - int prune_tags_ok, int use_stdin_refspecs, + int prune_tags_ok, int set_head, int use_stdin_refspecs, const struct fetch_config *config) { struct refspec rs = REFSPEC_INIT_FETCH; @@ -2135,9 +2148,12 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, refspec_clear(&rs); transport_disconnect(gtransport); gtransport = NULL; + if (set_head && run_set_head(remote -> name)) + exit_code = 1; return exit_code; } + int cmd_fetch(int argc, const char **argv, const char *prefix) { struct fetch_config config = { @@ -2154,6 +2170,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) struct string_list list = STRING_LIST_INIT_DUP; struct remote *remote = NULL; int all = -1, multiple = 0; + int set_head = 0; int result = 0; int prune_tags_ok = 1; int enable_auto_gc = 1; @@ -2171,6 +2188,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) OPT__VERBOSITY(&verbosity), OPT_BOOL(0, "all", &all, N_("fetch from all remotes")), + OPT_BOOL(0, "set-head", &set_head, + N_("auto set remote HEAD")), OPT_BOOL(0, "set-upstream", &set_upstream, N_("set upstream for git pull/fetch")), OPT_BOOL('a', "append", &append, @@ -2436,7 +2455,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) trace2_region_leave("fetch", "setup-partial", the_repository); } trace2_region_enter("fetch", "fetch-one", the_repository); - result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs, + result = fetch_one(remote, argc, argv, prune_tags_ok, set_head, stdin_refspecs, &config); trace2_region_leave("fetch", "fetch-one", the_repository); } else { @@ -2459,7 +2478,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) /* TODO should this also die if we have a previous partial-clone? */ trace2_region_enter("fetch", "fetch-multiple", the_repository); - result = fetch_multiple(&list, max_children, &config); + result = fetch_multiple(&list, max_children, set_head, &config); trace2_region_leave("fetch", "fetch-multiple", the_repository); } diff --git a/builtin/remote.c b/builtin/remote.c index 0acc547d69..35c54dd103 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1536,9 +1536,12 @@ static int get_remote_default(const char *key, const char *value UNUSED, static int update(int argc, const char **argv, const char *prefix) { int i, prune = -1; + int set_head = 0; struct option options[] = { OPT_BOOL('p', "prune", &prune, N_("prune remotes after fetching")), + OPT_BOOL(0, "set-head", &set_head, + N_("auto set remote HEAD")), OPT_END() }; struct child_process cmd = CHILD_PROCESS_INIT; @@ -1552,6 +1555,8 @@ static int update(int argc, const char **argv, const char *prefix) if (prune != -1) strvec_push(&cmd.args, prune ? "--prune" : "--no-prune"); + if (set_head) + strvec_push(&cmd.args, "--set-head"); if (verbose) strvec_push(&cmd.args, "-v"); strvec_push(&cmd.args, "--multiple"); From patchwork Tue Sep 10 20:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bence Ferdinandy X-Patchwork-Id: 13799303 Received: from aib29agh127.zrh1.oracleemaildelivery.com (aib29agh127.zrh1.oracleemaildelivery.com [192.29.178.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E325176252 for ; Tue, 10 Sep 2024 20:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.29.178.127 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726001088; cv=none; b=GvEEqxQR/kTSq1wabIrIVgtqV30Fod58RLaNEgAoBvpxCU7p5WWTo81Gzd8tLjZ/4Bq0sRzWusaXBCOqTBUTJDpFCSTBdKNsiWd3gI6g11zvQJepZTBv6Dbrs6sXicKZN1avl1FHRk7I2hgrIPR9wvupA1SYOTe6fBvS3YPM5f8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726001088; c=relaxed/simple; bh=b5NrbsBixKD2I1DrQJ1TlOrzd6gVpzK7pQW9yz0tf+o=; h=From:To:Cc:Subject:Date:Message-id:In-reply-to:References: MIME-version; b=jiIxvrBPDrP0evUlYOo/QctfcV4cow3HqqIriyh20WC7eKrXO1chCF55ZmwrxXO38mzVrjXMeWM/v3W9jrrTd02jd8QaEZmEGO/MwK2tAlhG7w0fgOKeQVS/I58yGoxiIGqv0jB5gGeSxBUSP9wsOQ5oMteBNIBLjglzXTMstLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b=nqnJuJTN; arc=none smtp.client-ip=192.29.178.127 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ferdinandy.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zrh1.rp.oracleemaildelivery.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zrh1.rp.oracleemaildelivery.com header.i=@zrh1.rp.oracleemaildelivery.com header.b="nqnJuJTN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=prod-zrh-20200406; d=zrh1.rp.oracleemaildelivery.com; h=Date:To:From:Subject:Message-Id:MIME-Version:Sender:List-Unsubscribe:List-Unsubscribe-Post; bh=6U7X65IS9yvt5ArGE0vZuKwRwAVma+9LaJi7Q8pWPzQ=; b=nqnJuJTNzql3qYiQL237Dqd9brNIq9W54pyWyQv+b9B2krX4FaPCN6DT/fAuwverZA5ngqryH9fd NQntR0l1KjoINPzeeaCyDPPhCGJMgqNwhCpuTw/3NukGSsCYBimuUiO5qFiHN71RH/kIo3KuIp/b 1fvycWKioCI98SHyPyidSfUgA2tSR6/ZdSaSSBrB7ekvkgMqNHnWCMVuiLhhxvoP8GSJueLEE60j 4WtJAr8hehCkL4eY4PpBJbJ831PNGCOpe8ntJWKxJJtM+N0k5qhwWRwaBbpMniom15pZpwGzsunF aNUCKZVZElo0MOmRzcfXUrxh94eG+SZC24/ruw== Received: by omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com (Oracle Communications Messaging Server 8.1.0.1.20240709 64bit (built Jul 9 2024)) with ESMTPS id <0SJM00F9W6Q09650@omta-ad1-fd3-402-eu-zurich-1.omtaad1.vcndpzrh.oraclevcn.com> for git@vger.kernel.org; Tue, 10 Sep 2024 20:39:36 +0000 (GMT) List-Unsubscribe-Post: List-Unsubscribe=One-Click From: Bence Ferdinandy To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , Patrick Steinhardt , =?utf-8?q?Ren=C3=A9_Scharfe?= , Johannes Schindelin , Bence Ferdinandy Subject: [RFC PATCH v2 2/2] set-head: do not update if there is no change Date: Tue, 10 Sep 2024 22:37:14 +0200 Message-id: <20240910203835.2288291-3-bence@ferdinandy.com> In-reply-to: <20240910203835.2288291-1-bence@ferdinandy.com> References: <20240910203835.2288291-1-bence@ferdinandy.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-transfer-encoding: 8bit Reporting-Meta: AAHIA+iLW4+N8FNUHnoGYkiKLbs40IIVsmNPEs115GzgtOnvxOAVQo5dP7oU0E8L 5HrmiweWSocxnOTcAeMz4JOUZCPureDjUHq0lD5oSUxf2fmQN14iKA7v1SJMfweX K1DWQiYie6CMSge1Z1G+aB4xP7uTH6Q8suIBUjNwj6N1PcWPpsWHgq/vTPmWgvRa mMly2lDNdrQ9un5CoohhCvoNwntFnPcfMQ21Yp0A85wFFAJQmvnq5QJ5l6VoRdx4 j3CRqfyY1MK5z739vd5aAzlsahAJE2wGWm6NUaUlVsJYTUZIV8A2Jy7YdKcN5XyF mEy/gTKRBrCgTArhOY+1JA5FPaaZk28/cEViPSjy0e2OrtEgo2uroEtDScuRJ1h8 jNX3hwpTBBoxcYyhpWzAPtrMOJi26Hk2QKcRrEP4rUOtANzXANWuElgoUfF0FldD qBaz1shwxEJHnJjP3rnkVbnQYRyyLAojZPtGcBGsk3vePM85lua+r57z Currently, even if there is no actual change to remote/HEAD calling remote set-head will overwrite the appropriate file and if set to --auto will also print a message saying "remote/HEAD set to branch", which implies something was changed. In contrast, on a nil operation e.g. pull will clearly state that nothing was done, while fetch will not output anything. Change the behaviour of remote set-head so that the reference is only updated if it actually needs to change. Since set-head --auto is essentially a fetch-like operation, align it's behaviour with fetch and only print output if something was actually done. Signed-off-by: Bence Ferdinandy --- builtin/remote.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 35c54dd103..e220e51b84 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1400,8 +1400,8 @@ static int show(int argc, const char **argv, const char *prefix) static int set_head(int argc, const char **argv, const char *prefix) { - int i, opt_a = 0, opt_d = 0, result = 0; - struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; + int i, opt_a = 0, opt_d = 0, is_ref_changed = 0, result = 0; + struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT; char *head_name = NULL; struct option options[] = { @@ -1440,12 +1440,14 @@ static int set_head(int argc, const char **argv, const char *prefix) if (head_name) { strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name); + refs_read_symbolic_ref(get_main_ref_store(the_repository),buf.buf,&buf3); + is_ref_changed = strcmp(buf2.buf,buf3.buf); /* make sure it's valid */ if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf)) result |= error(_("Not a valid ref: %s"), buf2.buf); - else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head")) + else if (is_ref_changed && refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head")) result |= error(_("Could not setup %s"), buf.buf); - else if (opt_a) + else if (opt_a && is_ref_changed) printf("%s/HEAD set to %s\n", argv[0], head_name); free(head_name); }