From patchwork Fri Jan 24 09:25:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3667117EF for ; Fri, 24 Jan 2020 09:25:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01D38214AF for ; Fri, 24 Jan 2020 09:25:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="aTbNOYmo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730373AbgAXJZd (ORCPT ); Fri, 24 Jan 2020 04:25:33 -0500 Received: from mail-wm1-f45.google.com ([209.85.128.45]:52084 "EHLO mail-wm1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728939AbgAXJZc (ORCPT ); Fri, 24 Jan 2020 04:25:32 -0500 Received: by mail-wm1-f45.google.com with SMTP id t23so983805wmi.1 for ; Fri, 24 Jan 2020 01:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sCK1M6XYbZYN8AO5fuXYUV2/8jZqq1qwxiW1947lphs=; b=aTbNOYmoLMWpnPOdXQ825OAodTFBfMfHyNSmbpk6uFAuYEPOk/kuWMWtn61rwLtX3r dQjeS7BnV/jb1WhuaZZUntFASax2EsTJ/9uRhQJS8bzfMM3kPwD/ihbYMuvGPnOaoovs sywoZGZCp6WUbS1rKcxsgPUo/AEXzQvtYdC17e2iZzZuTWFJNXBuQYL8NP4lMLYOX1KM hE7MuVAW4cH9S8lIrXOlMJGCtqyZJBQBk6TE4QkhZyMeRVyxD9Q4HxI292Wb4SFAnucR KaJX88pwgJ9ZPIefIu1b9OcA3dY2LJKsuK24o5Uwd4PSm2u0x8yVZGBBjGeO2tGiz45t hczQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sCK1M6XYbZYN8AO5fuXYUV2/8jZqq1qwxiW1947lphs=; b=SBD4EKHzD1Wja+pFQ+YwB/dUiuldqLUoWbKxw/Ju5LOwn9kDKpidcrmjtodRER4Q5A rwpq1hsHuLJuWj4CznC2roxJLWoPO7VavJTABd1hLFloy/ZtAk532llAIJ54hn483tXC SadmHxc/RVNP/UZmm3oSt8f2WT8ZLeldNGMjBy+n9fVkA7MIlN6qkJV5cuqI8ybo3JvM Gn3UdiF01zoxr+p+YK/d8b+9Zyaf0p2bVT3HfN1/ldDYI9YjAVUvbwNBRbIo6gC02v1r PpL7ZGJFfo4XFiOpkqsY3YkmVvh/Q9BSjuQ+4F1IHR09H0rLrmwF6LCjQOer9oPSfqHK mo4g== X-Gm-Message-State: APjAAAUITbyfNPy5rH7kNlahdcIbnqKLhnoq48nTdJOpI/X5vGrkOmBU YQjZwlknrFG26seKfso= X-Google-Smtp-Source: APXvYqzkWUyg6vs5F7UxIG+0XoZhuhaR8RUnWt8LqHJ3YdC5d56v3AytojA80YjF5q2ShFNH7ysYTw== X-Received: by 2002:a7b:c317:: with SMTP id k23mr2386965wmj.75.1579857930155; Fri, 24 Jan 2020 01:25:30 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id q6sm7132757wrx.72.2020.01.24.01.25.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:29 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 1/7] pull --rebase/remote rename: document and honor single-letter abbreviations rebase types Date: Fri, 24 Jan 2020 10:25:21 +0100 Message-Id: <803d3aa1162da020b3e284be04de6ebad88935aa.1579857394.git.bert.wesarg@googlemail.com> X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When 46af44b07d (pull --rebase=: allow single-letter abbreviations for the type, 2018-08-04) landed in Git, it had the side effect that not only 'pull --rebase=' accepted the single-letter abbreviations but also the 'pull.rebase' and 'branch..rebase' configurations. However, 'git remote rename' did not honor these single-letter abbreviations when reading the 'branch.*.rebase' configurations. We now document the single-letter abbreviations and both code places share a common function to parse the values of 'git pull --rebase=*', 'pull.rebase', and 'branches.*.rebase'. The only functional change is the handling of the `branch_info::rebase` value. Before it was an unsigned enum, thus the truth value could be checked with `branch_info::rebase != 0`. But `enum rebase_type` is signed, thus the truth value must now be checked with `branch_info::rebase >= REBASE_TRUE` Signed-off-by: Bert Wesarg --- Changes since v1: * Add comment that 'git remote rename' considers unknown `.rebase' values as false Cc: Johannes Schindelin Cc: Junio C Hamano --- Documentation/config/branch.txt | 7 ++++--- Documentation/config/pull.txt | 7 ++++--- Makefile | 1 + builtin/pull.c | 29 ++++----------------------- builtin/remote.c | 30 +++++++++++----------------- rebase.c | 35 +++++++++++++++++++++++++++++++++ rebase.h | 15 ++++++++++++++ 7 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 rebase.c create mode 100644 rebase.h diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt index a592d522a7..cc5f3249fc 100644 --- a/Documentation/config/branch.txt +++ b/Documentation/config/branch.txt @@ -81,15 +81,16 @@ branch..rebase:: "git pull" is run. See "pull.rebase" for doing this in a non branch-specific manner. + -When `merges`, pass the `--rebase-merges` option to 'git rebase' +When `merges` (or just 'm'), pass the `--rebase-merges` option to 'git rebase' so that the local merge commits are included in the rebase (see linkgit:git-rebase[1] for details). + -When `preserve` (deprecated in favor of `merges`), also pass +When `preserve` (or just 'p', deprecated in favor of `merges`), also pass `--preserve-merges` along to 'git rebase' so that locally committed merge commits will not be flattened by running 'git pull'. + -When the value is `interactive`, the rebase is run in interactive mode. +When the value is `interactive` (or just 'i'), the rebase is run in interactive +mode. + *NOTE*: this is a possibly dangerous operation; do *not* use it unless you understand the implications (see linkgit:git-rebase[1] diff --git a/Documentation/config/pull.txt b/Documentation/config/pull.txt index b87cab31b3..5404830609 100644 --- a/Documentation/config/pull.txt +++ b/Documentation/config/pull.txt @@ -14,15 +14,16 @@ pull.rebase:: pull" is run. See "branch..rebase" for setting this on a per-branch basis. + -When `merges`, pass the `--rebase-merges` option to 'git rebase' +When `merges` (or just 'm'), pass the `--rebase-merges` option to 'git rebase' so that the local merge commits are included in the rebase (see linkgit:git-rebase[1] for details). + -When `preserve` (deprecated in favor of `merges`), also pass +When `preserve` (or just 'p', deprecated in favor of `merges`), also pass `--preserve-merges` along to 'git rebase' so that locally committed merge commits will not be flattened by running 'git pull'. + -When the value is `interactive`, the rebase is run in interactive mode. +When the value is `interactive` (or just 'i'), the rebase is run in interactive +mode. + *NOTE*: this is a possibly dangerous operation; do *not* use it unless you understand the implications (see linkgit:git-rebase[1] diff --git a/Makefile b/Makefile index 09f98b777c..96ced97bff 100644 --- a/Makefile +++ b/Makefile @@ -954,6 +954,7 @@ LIB_OBJS += quote.o LIB_OBJS += range-diff.o LIB_OBJS += reachable.o LIB_OBJS += read-cache.o +LIB_OBJS += rebase.o LIB_OBJS += rebase-interactive.o LIB_OBJS += reflog-walk.o LIB_OBJS += refs.o diff --git a/builtin/pull.c b/builtin/pull.c index d25ff13a60..888181c07c 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -15,6 +15,7 @@ #include "sha1-array.h" #include "remote.h" #include "dir.h" +#include "rebase.h" #include "refs.h" #include "refspec.h" #include "revision.h" @@ -26,15 +27,6 @@ #include "commit-reach.h" #include "sequencer.h" -enum rebase_type { - REBASE_INVALID = -1, - REBASE_FALSE = 0, - REBASE_TRUE, - REBASE_PRESERVE, - REBASE_MERGES, - REBASE_INTERACTIVE -}; - /** * Parses the value of --rebase. If value is a false value, returns * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is @@ -45,22 +37,9 @@ enum rebase_type { static enum rebase_type parse_config_rebase(const char *key, const char *value, int fatal) { - int v = git_parse_maybe_bool(value); - - if (!v) - return REBASE_FALSE; - else if (v > 0) - return REBASE_TRUE; - else if (!strcmp(value, "preserve") || !strcmp(value, "p")) - return REBASE_PRESERVE; - else if (!strcmp(value, "merges") || !strcmp(value, "m")) - return REBASE_MERGES; - else if (!strcmp(value, "interactive") || !strcmp(value, "i")) - return REBASE_INTERACTIVE; - /* - * Please update _git_config() in git-completion.bash when you - * add new rebase modes. - */ + enum rebase_type v = rebase_parse_value(value); + if (v != REBASE_INVALID) + return v; if (fatal) die(_("Invalid value for %s: %s"), key, value); diff --git a/builtin/remote.c b/builtin/remote.c index 96bbe828fe..6802765e73 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -6,6 +6,7 @@ #include "string-list.h" #include "strbuf.h" #include "run-command.h" +#include "rebase.h" #include "refs.h" #include "refspec.h" #include "object-store.h" @@ -248,9 +249,7 @@ static int add(int argc, const char **argv) struct branch_info { char *remote_name; struct string_list merge; - enum { - NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE, REBASE_MERGES - } rebase; + enum rebase_type rebase; }; static struct string_list branch_list = STRING_LIST_INIT_NODUP; @@ -305,17 +304,12 @@ static int config_read_branches(const char *key, const char *value, void *cb) space = strchr(value, ' '); } string_list_append(&info->merge, xstrdup(value)); - } else { - int v = git_parse_maybe_bool(value); - if (v >= 0) - info->rebase = v; - else if (!strcmp(value, "preserve")) - info->rebase = NORMAL_REBASE; - else if (!strcmp(value, "merges")) - info->rebase = REBASE_MERGES; - else if (!strcmp(value, "interactive")) - info->rebase = INTERACTIVE_REBASE; - } + } else + /* + * Consider invalid values as false and check the + * truth value with >= REBASE_TRUE. + */ + info->rebase = rebase_parse_value(value); } return 0; } @@ -943,7 +937,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb return 0; if ((n = strlen(branch_item->string)) > show_info->width) show_info->width = n; - if (branch_info->rebase) + if (branch_info->rebase >= REBASE_TRUE) show_info->any_rebase = 1; item = string_list_insert(show_info->list, branch_item->string); @@ -960,16 +954,16 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data) int width = show_info->width + 4; int i; - if (branch_info->rebase && branch_info->merge.nr > 1) { + if (branch_info->rebase >= REBASE_TRUE && branch_info->merge.nr > 1) { error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"), item->string); return 0; } printf(" %-*s ", show_info->width, item->string); - if (branch_info->rebase) { + if (branch_info->rebase >= REBASE_TRUE) { const char *msg; - if (branch_info->rebase == INTERACTIVE_REBASE) + if (branch_info->rebase == REBASE_INTERACTIVE) msg = _("rebases interactively onto remote %s"); else if (branch_info->rebase == REBASE_MERGES) msg = _("rebases interactively (with merges) onto " diff --git a/rebase.c b/rebase.c new file mode 100644 index 0000000000..f8137d859b --- /dev/null +++ b/rebase.c @@ -0,0 +1,35 @@ +#include "rebase.h" +#include "config.h" + +/* + * Parses textual value for pull.rebase, branch..rebase, etc. + * Unrecognised value yields REBASE_INVALID, which traditionally is + * treated the same way as REBASE_FALSE. + * + * The callers that care if (any) rebase is requested should say + * if (REBASE_TRUE <= rebase_parse_value(string)) + * + * The callers that want to differenciate an unrecognised value and + * false can do so by treating _INVALID and _FALSE differently. + */ +enum rebase_type rebase_parse_value(const char *value) +{ + int v = git_parse_maybe_bool(value); + + if (!v) + return REBASE_FALSE; + else if (v > 0) + return REBASE_TRUE; + else if (!strcmp(value, "preserve") || !strcmp(value, "p")) + return REBASE_PRESERVE; + else if (!strcmp(value, "merges") || !strcmp(value, "m")) + return REBASE_MERGES; + else if (!strcmp(value, "interactive") || !strcmp(value, "i")) + return REBASE_INTERACTIVE; + /* + * Please update _git_config() in git-completion.bash when you + * add new rebase modes. + */ + + return REBASE_INVALID; +} diff --git a/rebase.h b/rebase.h new file mode 100644 index 0000000000..cc723d4748 --- /dev/null +++ b/rebase.h @@ -0,0 +1,15 @@ +#ifndef REBASE_H +#define REBASE_H + +enum rebase_type { + REBASE_INVALID = -1, + REBASE_FALSE = 0, + REBASE_TRUE, + REBASE_PRESERVE, + REBASE_MERGES, + REBASE_INTERACTIVE +}; + +enum rebase_type rebase_parse_value(const char *value); + +#endif /* REBASE */ From patchwork Fri Jan 24 09:25:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86F68921 for ; Fri, 24 Jan 2020 09:25:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 652C820838 for ; Fri, 24 Jan 2020 09:25:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="cQ+TSAiU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730376AbgAXJZd (ORCPT ); Fri, 24 Jan 2020 04:25:33 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:32794 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728928AbgAXJZc (ORCPT ); Fri, 24 Jan 2020 04:25:32 -0500 Received: by mail-wm1-f66.google.com with SMTP id m10so3118430wmc.0 for ; Fri, 24 Jan 2020 01:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DyHHivxss+vJsvXP+/tp2pYiIergF+KDNzC01hr3fTU=; b=cQ+TSAiUs6lbnGYSI34+PiRrmX650aCZtgA5n5SluPVyU5NOHXNUfodhdpf2ffEm5p 8do7ZelIDkX5D/T5BkvqB7NmEOZosy1AsAs3ERY0ydgSkiZhzEEBsH36FSykLE2QXEj7 IJgyyPdypT7R7C6v/K9IfMyGlM2dTvyyDYcSL09ngN10XxcyV8eCGr0gLMD4P9vla0js 6L9r60v0yAHqzHm2tREzAnna1zhymMbkRnx32UFYLg9CJLa3MyDzni8m+C/S+7B11RrN Fkvw7OKPKGxgT9DZ3WA/hl51rFA+/wF/wUZkaBiZrdLZZdUNs7ZnR5fBX6oNgnllSAKW sPcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DyHHivxss+vJsvXP+/tp2pYiIergF+KDNzC01hr3fTU=; b=REmdpcseQCWw7BS2oh9Y58qt23hUNmAzpx18Gi5CH4nEVeLeXoIykA93cpDAog/tAf AqCddWwIrgBX4bBI3ls8QarPQ1IQxKiFOBpB1Qb3YPKrUwQTmgiSXu1DwZS+GkvNbwIB /Db1LfI2sQg8kD9qtgK0pv9bcHnvqmqnYEUzxaDnkLDhwYkfp4YlupKFun7pgr6UfujZ 6Ho5l2lFxnKOIGTXPFcmpfZAcYS7mQtwDBihqLRwT/dxZV2JYcllrSE5WzUi0fbDjxhE 3sA3VOMcCLGtE1snT6by5eba5r8fh2/GbI6cxPOy+pTrCY2wnFThJHP1FHgDruOreMLR p4ew== X-Gm-Message-State: APjAAAWmI8RupFuuZmjh5Hu1/ZHiVoVotocMrx6s6EmLU2dWczErNiL9 +eTL7T5HYhO+2YAmtZ0= X-Google-Smtp-Source: APXvYqz4ymWx1Y58Pt7lNO3r6zlZTRh7J/sHOccJ1JfemQAMMi19gaWFlLphngPOxI1Sq6CyTb8TEQ== X-Received: by 2002:a1c:5448:: with SMTP id p8mr2543805wmi.159.1579857931256; Fri, 24 Jan 2020 01:25:31 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id q6sm7132821wrx.72.2020.01.24.01.25.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:30 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Junio C Hamano Subject: [PATCH v2 2/7] remote: clean-up by returning early to avoid one indentation Date: Fri, 24 Jan 2020 10:25:22 +0100 Message-Id: X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Bert Wesarg --- Changes since v1: * avoid mixed declarations and statements Cc: Junio C Hamano --- builtin/remote.c | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 6802765e73..4cf929bfc6 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -263,54 +263,56 @@ static const char *abbrev_ref(const char *name, const char *prefix) static int config_read_branches(const char *key, const char *value, void *cb) { - if (starts_with(key, "branch.")) { - const char *orig_key = key; - char *name; - struct string_list_item *item; - struct branch_info *info; - enum { REMOTE, MERGE, REBASE } type; - size_t key_len; - - key += 7; - if (strip_suffix(key, ".remote", &key_len)) { - name = xmemdupz(key, key_len); - type = REMOTE; - } else if (strip_suffix(key, ".merge", &key_len)) { - name = xmemdupz(key, key_len); - type = MERGE; - } else if (strip_suffix(key, ".rebase", &key_len)) { - name = xmemdupz(key, key_len); - type = REBASE; - } else - return 0; + const char *orig_key = key; + char *name; + struct string_list_item *item; + struct branch_info *info; + enum { REMOTE, MERGE, REBASE } type; + size_t key_len; - item = string_list_insert(&branch_list, name); + if (!starts_with(key, "branch.")) + return 0; + + key += 7; + if (strip_suffix(key, ".remote", &key_len)) { + name = xmemdupz(key, key_len); + type = REMOTE; + } else if (strip_suffix(key, ".merge", &key_len)) { + name = xmemdupz(key, key_len); + type = MERGE; + } else if (strip_suffix(key, ".rebase", &key_len)) { + name = xmemdupz(key, key_len); + type = REBASE; + } else + return 0; + + item = string_list_insert(&branch_list, name); + + if (!item->util) + item->util = xcalloc(1, sizeof(struct branch_info)); + info = item->util; + if (type == REMOTE) { + if (info->remote_name) + warning(_("more than one %s"), orig_key); + info->remote_name = xstrdup(value); + } else if (type == MERGE) { + char *space = strchr(value, ' '); + value = abbrev_branch(value); + while (space) { + char *merge; + merge = xstrndup(value, space - value); + string_list_append(&info->merge, merge); + value = abbrev_branch(space + 1); + space = strchr(value, ' '); + } + string_list_append(&info->merge, xstrdup(value)); + } else + /* + * Consider invalid values as false and check the + * truth value with >= REBASE_TRUE. + */ + info->rebase = rebase_parse_value(value); - if (!item->util) - item->util = xcalloc(1, sizeof(struct branch_info)); - info = item->util; - if (type == REMOTE) { - if (info->remote_name) - warning(_("more than one %s"), orig_key); - info->remote_name = xstrdup(value); - } else if (type == MERGE) { - char *space = strchr(value, ' '); - value = abbrev_branch(value); - while (space) { - char *merge; - merge = xstrndup(value, space - value); - string_list_append(&info->merge, merge); - value = abbrev_branch(space + 1); - space = strchr(value, ' '); - } - string_list_append(&info->merge, xstrdup(value)); - } else - /* - * Consider invalid values as false and check the - * truth value with >= REBASE_TRUE. - */ - info->rebase = rebase_parse_value(value); - } return 0; } From patchwork Fri Jan 24 09:25:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CD45921 for ; Fri, 24 Jan 2020 09:25:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77F242087E for ; Fri, 24 Jan 2020 09:25:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="P8FpdOQl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730390AbgAXJZf (ORCPT ); Fri, 24 Jan 2020 04:25:35 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34094 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730364AbgAXJZe (ORCPT ); Fri, 24 Jan 2020 04:25:34 -0500 Received: by mail-wr1-f67.google.com with SMTP id t2so1120335wrr.1 for ; Fri, 24 Jan 2020 01:25:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RoY/pvI4yAWUXsyXH8Nid9Dt9ncDunTF8PBKcVdpJIE=; b=P8FpdOQl9LuUGUQ5xZtsSB9fy52mXqqalh62eo8gQeaPoT9Sv0YakKezsYYFpd04s6 rgbLP+0sxLsZLiGRyIcJbYJC5Gm3T1hI3Sg7B4iGN7Uy6b9o6akoISdxxrURU4hQeWeT zCjXXSQxpZn7CwrBmDrSEDITy63dEZ3Phlj+PzzWOM8pBdqiFnPgNe2ntw2l9XtblrQT +NbeQtJEL/tv+MTeU20K4K3tlSyTIg6ak/6x8gm+RtxhG/1TGnla4B47As+Af8PgPexG daqLw3iSHDZwvPnx/ofTvM++tZtxuMXJ3Q86vRePUoQk7imdKnVhFdL0TBNjnUBDBUqe jzYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RoY/pvI4yAWUXsyXH8Nid9Dt9ncDunTF8PBKcVdpJIE=; b=TN+EjACeMe1pPYvKSrq74hm1HlSkLIulHN3b6CwWu7awE1kHxei6yb32q9JQuwYva5 ozmX9SC4iNm+GA1XwiDPrMOsLvzeKvz32XPXRs0h1sg7jI/vSprzdT/dE/Iq4dP4aVGR dUCUsesjJHyxWd89wiRZGSIcSS5iAS6gFkC1EWsSv/SrwPAfpl2VVUGkEOl7Qa9vTQda iZVOXdeL1vpBr3beUkhQ3fGvyE4MYLonCTzTU7BBdN18p/ENiiFzHywhTEx1OD2pJblI UglAS3T25HtL97NmbY1y4o7O4/xHMEPHL5x7JqaMOGI3lIv/eDvpbDsFsToNM3WPYpjf +Drw== X-Gm-Message-State: APjAAAXX2LzdyUeKoqPJPFVxzS5wCXiiNjeS8xo69WlO3+P+souXRJRs Js2Hd0CQS/AHVjfE264= X-Google-Smtp-Source: APXvYqz9/J6cix7cT0UmMDdp4Z4R3dUZ8VlxmjfzG4e7sGhOznmdJrhwFuV7lTXBz4H1lHY3NFYIpg== X-Received: by 2002:a05:6000:11c3:: with SMTP id i3mr3129422wrx.244.1579857932311; Fri, 24 Jan 2020 01:25:32 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id b128sm6055600wmb.25.2020.01.24.01.25.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:31 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Junio C Hamano , Johannes Schindelin Subject: [PATCH 3/7] remote: clean-up config callback Date: Fri, 24 Jan 2020 10:25:23 +0100 Message-Id: X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Some minor clean-ups in function `config_read_branches`: * remove hardcoded length in `key += 7` * call `xmemdupz` only once * use a switch to handle the configuration type and add a `BUG()` Suggested-by: Junio C Hamano Signed-off-by: Bert Wesarg --- Cc: Johannes Schindelin --- builtin/remote.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 4cf929bfc6..9ee44c9f6c 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -273,29 +273,29 @@ static int config_read_branches(const char *key, const char *value, void *cb) if (!starts_with(key, "branch.")) return 0; - key += 7; - if (strip_suffix(key, ".remote", &key_len)) { - name = xmemdupz(key, key_len); + key += strlen("branch."); + if (strip_suffix(key, ".remote", &key_len)) type = REMOTE; - } else if (strip_suffix(key, ".merge", &key_len)) { - name = xmemdupz(key, key_len); + else if (strip_suffix(key, ".merge", &key_len)) type = MERGE; - } else if (strip_suffix(key, ".rebase", &key_len)) { - name = xmemdupz(key, key_len); + else if (strip_suffix(key, ".rebase", &key_len)) type = REBASE; - } else + else return 0; + name = xmemdupz(key, key_len); item = string_list_insert(&branch_list, name); if (!item->util) item->util = xcalloc(1, sizeof(struct branch_info)); info = item->util; - if (type == REMOTE) { + switch (type) { + case REMOTE: if (info->remote_name) warning(_("more than one %s"), orig_key); info->remote_name = xstrdup(value); - } else if (type == MERGE) { + break; + case MERGE: { char *space = strchr(value, ' '); value = abbrev_branch(value); while (space) { @@ -306,12 +306,18 @@ static int config_read_branches(const char *key, const char *value, void *cb) space = strchr(value, ' '); } string_list_append(&info->merge, xstrdup(value)); - } else + break; + } + case REBASE: /* * Consider invalid values as false and check the * truth value with >= REBASE_TRUE. */ info->rebase = rebase_parse_value(value); + break; + default: + BUG("unexpected type=%d", type); + } return 0; } From patchwork Fri Jan 24 09:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 418F8924 for ; Fri, 24 Jan 2020 09:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 205012087E for ; Fri, 24 Jan 2020 09:25:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="JbS2Ta5h" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730407AbgAXJZj (ORCPT ); Fri, 24 Jan 2020 04:25:39 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38245 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730379AbgAXJZf (ORCPT ); Fri, 24 Jan 2020 04:25:35 -0500 Received: by mail-wr1-f66.google.com with SMTP id y17so1106416wrh.5 for ; Fri, 24 Jan 2020 01:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D6TDBqYHH2nVMXOOZqKEGbpyRYQDDl87BGG8RFhwR7I=; b=JbS2Ta5h8o1Ieje71CfkWnN0ULUgLi8/DNz/k+EwiZwRMeKFNKfr6biYpLsjCZd11u vcRiQRy9ExU/7BeMiHkvAXt3rQ3+7eBwSfAccTmP+ZnAY3ahmYo/Jo0f8VQasxGZRJ/Q YZhUBEIuqOV2KgT68tteHKUdlGbejKplpM6evcFePV7qGSX464lo72h2Z5PQ/SAmFefQ Oi9NmpiYXZwt6zy4Q6ohn/EAXHV7Or2QgcQDre4ewvZYD1Q6pr9BqxB1cpFtZCKYQrru dqR2o2qQDtYnOtu1WqvEqOaPwu3Q6JElilwRVuz0lJcuEuMA2QmxXvMNlMRtOVVyxs6r RKTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D6TDBqYHH2nVMXOOZqKEGbpyRYQDDl87BGG8RFhwR7I=; b=fxl0ZjVQSsKpMq9iDDWz96kucHr/3GDLX/GFjw6iy6+3ziEIhIFjYoxSPyHi9iuY3G 5ktbaYbmf6Plcp5NMDsQ9ad8HqJU7qb/MpBJx0tg5fC+f0y+bnaGFX5EUWCyASEuvJa/ lW1NvB0jGO0VneEHXCe1lW9bc8pPIFGl09AHF7fdE5Ay5oz9GU9pMdwtT0ZjG0r2P/Ej oYPapADWbkYzuOpZVlEOJA/9rWLaOe+aN8o1yzMghDIUyIi7oBrPCF4bK5s9P3C57mf5 GX3VIiuMcmQh6F6HRg2JGPRoVpHv4TLTcJcjHuJHl/qWD+GbjtOGpaNvFJJIt1Q5DnZm 9Bww== X-Gm-Message-State: APjAAAVPh38a7EwqDnbEUoWBtBAPhMarjGYEUfD+7N3UvBHM78ppTfhq iuYKg4vNC+rbQ54iNWM= X-Google-Smtp-Source: APXvYqzr2RM4IpOQDQrHczTC/TEzZrESjBHrNFfSH9CK4davOH7JVVJB+RRkX0OkjeJ/aZYELvl4yg== X-Received: by 2002:adf:fe50:: with SMTP id m16mr3320459wrs.217.1579857933306; Fri, 24 Jan 2020 01:25:33 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id n187sm6200792wme.28.2020.01.24.01.25.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:32 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Junio C Hamano , Johannes Schindelin Subject: [PATCH v4 4/7] remote rename/remove: handle branch..pushRemote config values Date: Fri, 24 Jan 2020 10:25:24 +0100 Message-Id: <9c2110eda64ab7bf0cb780dafe1f13b28fee5ca0.1579857394.git.bert.wesarg@googlemail.com> X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When renaming or removing a remote with git remote rename X Y git remote remove X Git already renames/removes any config values from branch..remote = X to branch..remote = Y As branch..pushRemote also names a remote, it now also renames or removes these config values from branch..pushRemote = X to branch..pushRemote = Y Signed-off-by: Bert Wesarg --- Changes since v3: * handle also 'git remote remove' Cc: Junio C Hamano Cc: Johannes Schindelin --- builtin/remote.c | 22 +++++++++++++++++++++- t/t5505-remote.sh | 16 +++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 9ee44c9f6c..a2379a14bf 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -250,6 +250,7 @@ struct branch_info { char *remote_name; struct string_list merge; enum rebase_type rebase; + char *push_remote_name; }; static struct string_list branch_list = STRING_LIST_INIT_NODUP; @@ -267,7 +268,7 @@ static int config_read_branches(const char *key, const char *value, void *cb) char *name; struct string_list_item *item; struct branch_info *info; - enum { REMOTE, MERGE, REBASE } type; + enum { REMOTE, MERGE, REBASE, PUSH_REMOTE } type; size_t key_len; if (!starts_with(key, "branch.")) @@ -280,6 +281,8 @@ static int config_read_branches(const char *key, const char *value, void *cb) type = MERGE; else if (strip_suffix(key, ".rebase", &key_len)) type = REBASE; + else if (strip_suffix(key, ".pushremote", &key_len)) + type = PUSH_REMOTE; else return 0; name = xmemdupz(key, key_len); @@ -315,6 +318,11 @@ static int config_read_branches(const char *key, const char *value, void *cb) */ info->rebase = rebase_parse_value(value); break; + case PUSH_REMOTE: + if (info->push_remote_name) + warning(_("more than one %s"), orig_key); + info->push_remote_name = xstrdup(value); + break; default: BUG("unexpected type=%d", type); } @@ -682,6 +690,11 @@ static int mv(int argc, const char **argv) strbuf_addf(&buf, "branch.%s.remote", item->string); git_config_set(buf.buf, rename.new_name); } + if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) { + strbuf_reset(&buf); + strbuf_addf(&buf, "branch.%s.pushremote", item->string); + git_config_set(buf.buf, rename.new_name); + } } if (!refspec_updated) @@ -783,6 +796,13 @@ static int rm(int argc, const char **argv) die(_("could not unset '%s'"), buf.buf); } } + if (info->push_remote_name && !strcmp(info->push_remote_name, remote->name)) { + strbuf_reset(&buf); + strbuf_addf(&buf, "branch.%s.pushremote", item->string); + result = git_config_set_gently(buf.buf, NULL); + if (result && result != CONFIG_NOTHING_SET) + die(_("could not unset '%s'"), buf.buf); + } } /* diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 883b32efa0..082042b05a 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -737,12 +737,14 @@ test_expect_success 'rename a remote' ' git clone one four && ( cd four && + git config branch.master.pushRemote origin && git remote rename origin upstream && test -z "$(git for-each-ref refs/remotes/origin)" && test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" && test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" && test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && - test "$(git config branch.master.remote)" = "upstream" + test "$(git config branch.master.remote)" = "upstream" && + test "$(git config branch.master.pushRemote)" = "upstream" ) ' @@ -784,6 +786,18 @@ test_expect_success 'rename succeeds with existing remote..prune' ' git -C four.four remote rename origin upstream ' +test_expect_success 'remove a remote' ' + git clone one four.five && + ( + cd four.five && + git config branch.master.pushRemote origin && + git remote remove origin && + test -z "$(git for-each-ref refs/remotes/origin)" && + test_must_fail git config branch.master.remote && + test_must_fail git config branch.master.pushRemote + ) +' + cat >remotes_origin < X-Patchwork-Id: 11349993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 302AD921 for ; Fri, 24 Jan 2020 09:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E2C420838 for ; Fri, 24 Jan 2020 09:25:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="dA7cx6/n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730493AbgAXJZj (ORCPT ); Fri, 24 Jan 2020 04:25:39 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39323 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730407AbgAXJZh (ORCPT ); Fri, 24 Jan 2020 04:25:37 -0500 Received: by mail-wm1-f65.google.com with SMTP id c84so117920wme.4 for ; Fri, 24 Jan 2020 01:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8g88UAKgVv3SFFuCppcJ8SYygP9Rl3QVIODohy+UUug=; b=dA7cx6/nWNV+FpbXYluMCJHOxrw/gZiH5fIuHCm0TOLX/4F/funfu+IxzxXMo8UNNz eswsOGkMrjwmooYANkFXuNWbIbSsvGhvQ+9PNsXhiHhwSa1+Z1wzAM7+ZVXE4Nxu4Ue/ c4/gIut0zQpJJyB32Q6lwd1kU3QRc0PTGsh7ArXbN0oaNFSnFQshxRUcEEc9h36UISCM 8h4rA3zUU/AHz8FHWLmBDTzOZyUedZ4oOtc9QIlk7ZFmHudl+qfBES+iSKbXkApxCivR c3OJnGiTeS15O/iMtqE30eOueK8JPYY+Qycq8fHLv1B1DspRDwQykVy58Ctcm8PQ8VcC CNHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8g88UAKgVv3SFFuCppcJ8SYygP9Rl3QVIODohy+UUug=; b=NRiY2WUukVjn8EyfAsoPZO3LYUhoUcdtgDaMf0lx0FLbEj/YWY19Ptf/uSbXPrKH60 58wVpL2Rb/A9nA0xD1FUCN+ZS/SLtl6HsOs8gVGMaWNjwgJFUgrjpgDUlP6KvXzY2QvQ zNDNWutnm8F49mPXib3yHpSRmqcw0mlobVkQc3Tgo11FwS+mRS7mHQMA7XLK0Fpm8F3t AJkS9JhKOWRniIb2ZYbT1HJtWSmzCQ7RZXFEVwzC98Mv3uOKsy51+6LV3bDpttxBx3Zs h1GMNog2SRq5EifyPC/9314YnqWGhQgdT3Y02DzBP9cDjtuj9pMY3AycYWrFNjrheM4i c36A== X-Gm-Message-State: APjAAAXfMriCB1312ohhjIejAewyco5YNyifpqM7wr41z9DZony++ATi xmV5xN8No55Kz3a0cDg= X-Google-Smtp-Source: APXvYqxZQcOdWYY0HCxCrEYjdZNW4+UsuxwdKaXqLOfxJQigmw9VDFaGx5gkC/0b02B9+dCzgj2Ozg== X-Received: by 2002:a05:600c:2042:: with SMTP id p2mr2502679wmg.79.1579857934500; Fri, 24 Jan 2020 01:25:34 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id f16sm6740918wrm.65.2020.01.24.01.25.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:34 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Matthew Rogers Subject: [RFC PATCH 5/7] config: make `scope_name` global as `config_scope_name` Date: Fri, 24 Jan 2020 10:25:25 +0100 Message-Id: <00742e5cd2d5b44c256be3b14fd2dd07e306ffdf.1579857394.git.bert.wesarg@googlemail.com> X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Bert Wesarg --- Will be replaced by Matthew Rogers. Cc: Matthew Rogers --- config.c | 16 ++++++++++++++++ config.h | 1 + t/helper/test-config.c | 17 +---------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/config.c b/config.c index d75f88ca0c..4c461bb7a3 100644 --- a/config.c +++ b/config.c @@ -3317,6 +3317,22 @@ enum config_scope current_config_scope(void) return current_parsing_scope; } +const char *config_scope_name(enum config_scope scope) +{ + switch (scope) { + case CONFIG_SCOPE_SYSTEM: + return "system"; + case CONFIG_SCOPE_GLOBAL: + return "global"; + case CONFIG_SCOPE_REPO: + return "repo"; + case CONFIG_SCOPE_CMDLINE: + return "cmdline"; + default: + return "unknown"; + } +} + int lookup_config(const char **mapping, int nr_mapping, const char *var) { int i; diff --git a/config.h b/config.h index 91fd4c5e96..c063f33ff6 100644 --- a/config.h +++ b/config.h @@ -301,6 +301,7 @@ enum config_scope { CONFIG_SCOPE_REPO, CONFIG_SCOPE_CMDLINE, }; +const char *config_scope_name(enum config_scope scope); enum config_scope current_config_scope(void); const char *current_config_origin_type(void); diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 214003d5b2..1e3bc7c8f4 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -37,21 +37,6 @@ * */ -static const char *scope_name(enum config_scope scope) -{ - switch (scope) { - case CONFIG_SCOPE_SYSTEM: - return "system"; - case CONFIG_SCOPE_GLOBAL: - return "global"; - case CONFIG_SCOPE_REPO: - return "repo"; - case CONFIG_SCOPE_CMDLINE: - return "cmdline"; - default: - return "unknown"; - } -} static int iterate_cb(const char *var, const char *value, void *data) { static int nr; @@ -63,7 +48,7 @@ static int iterate_cb(const char *var, const char *value, void *data) printf("value=%s\n", value ? value : "(null)"); printf("origin=%s\n", current_config_origin_type()); printf("name=%s\n", current_config_name()); - printf("scope=%s\n", scope_name(current_config_scope())); + printf("scope=%s\n", config_scope_name(current_config_scope())); return 0; } From patchwork Fri Jan 24 09:25:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B8AA921 for ; Fri, 24 Jan 2020 09:25:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDF962087E for ; Fri, 24 Jan 2020 09:25:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="lYD/SrKz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730487AbgAXJZi (ORCPT ); Fri, 24 Jan 2020 04:25:38 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35444 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730422AbgAXJZh (ORCPT ); Fri, 24 Jan 2020 04:25:37 -0500 Received: by mail-wm1-f67.google.com with SMTP id p17so1012374wmb.0 for ; Fri, 24 Jan 2020 01:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wawsmq1he+hSgRdUpR4y74QZa+9pSBu3ypishV7dzzE=; b=lYD/SrKz+aVOvB1pJ2K8/2WEwfqTT3ei17pminsPEv/zxh5OtwiYolGBkCSew1bu2g yq/NEXjNEcv7iGBTn/JYo5xWHEG9c8zH3ayOCZAiD5s9NF+8H89be6ibzxXT8JVzYclL HZMs8rVcWkmpI1v+0Ep/kQ6XSXRvimUoyT7JGmMwc3YQSNLFBCIk0r6nLNS4e5+MginV MYicomJu8GETELZs80zlTWqQsrdHHrAZyUtq/Ll39POQAJHx2KgOpJpggErmcGe9y57N EQBQtMkH2plzBwXwYm4ZgxR+d3I7nYS1w2gl3icV+LS3JwcwddOYgFm1ER5MheOfmeKL g5GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wawsmq1he+hSgRdUpR4y74QZa+9pSBu3ypishV7dzzE=; b=W1ryxiM1QqYS2qBQdgxlYeRpOGcVUAKcP51WTJo0h48nj4CjH9aWexrRVFSXT2uFzA l5AN33cpGvgaEmhmtpzb5jMgTve2AgEGNjEgWLIkoqIuSXHdfASqd6MuJ7yDW/br6M9Q 717hxLy0hxmvnbMDACImXtFW13s4/w0YgR5+y8wdr/Yur1PL+XEC9lRrTq+APYqpJ5V1 A1f/alLJjZOB31mXSecUSGq9Pzac1c5xSmq39Gxk7l3/hAS0B82XsL4FCUe3UkTFWbHl 6DrPItbTa9bD167PlyqZsujpTzUip57DMEP3BTG3sQEQUmlPIjvpzhHyUDJVzbfyGXFN WtMQ== X-Gm-Message-State: APjAAAV2ZtRXda6bTaMqFRVnLdDedQv5psbzuj7izfJYxzV2e0qhkvuI NFl9bn/w8d/9fvQKmwc= X-Google-Smtp-Source: APXvYqxaEl/PjpK6D58V7Zbzn/tWza+7ctVgEy7KSWAy9TbUZsj8OPYOvbbNwZ5ZnBJOirsyZQEYSw== X-Received: by 2002:a05:600c:218b:: with SMTP id e11mr2543936wme.121.1579857935546; Fri, 24 Jan 2020 01:25:35 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id j12sm7258685wrw.54.2020.01.24.01.25.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:35 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg Subject: [PATCH 6/7] config: provide access to the current line number Date: Fri, 24 Jan 2020 10:25:26 +0100 Message-Id: <2442c6d6b7d12d73f98ba1c11d3f62915fa124e6.1579857394.git.bert.wesarg@googlemail.com> X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Users are nowadays trained to see message from CLI tools in the form :: … To be able to give such messages when notifying the user about configurations in any config file, it is currently only possible to get the file name (if the value originates from a file to begin with) via `current_config_name()`. Now it is also possible to query the current line number for the configuration. Signed-off-by: Bert Wesarg --- config.c | 8 ++++++++ config.h | 1 + t/helper/test-config.c | 1 + t/t1308-config-set.sh | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 4c461bb7a3..5d1d6b5871 100644 --- a/config.c +++ b/config.c @@ -3333,6 +3333,14 @@ const char *config_scope_name(enum config_scope scope) } } +int current_config_line(void) +{ + if (current_config_kvi) + return current_config_kvi->linenr; + else + return cf->linenr; +} + int lookup_config(const char **mapping, int nr_mapping, const char *var) { int i; diff --git a/config.h b/config.h index c063f33ff6..371f7f2dd0 100644 --- a/config.h +++ b/config.h @@ -306,6 +306,7 @@ const char *config_scope_name(enum config_scope scope); enum config_scope current_config_scope(void); const char *current_config_origin_type(void); const char *current_config_name(void); +int current_config_line(void); /** * Include Directives diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 1e3bc7c8f4..234c722b48 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -48,6 +48,7 @@ static int iterate_cb(const char *var, const char *value, void *data) printf("value=%s\n", value ? value : "(null)"); printf("origin=%s\n", current_config_origin_type()); printf("name=%s\n", current_config_name()); + printf("lno=%d\n", current_config_line()); printf("scope=%s\n", config_scope_name(current_config_scope())); return 0; diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 7b4e1a63eb..9e36e7a590 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -238,8 +238,8 @@ test_expect_success 'error on modifying repo config without repo' ' cmdline_config="'foo.bar=from-cmdline'" test_expect_success 'iteration shows correct origins' ' - echo "[foo]bar = from-repo" >.git/config && - echo "[foo]bar = from-home" >.gitconfig && + printf "[ignore]\n\tthis = please\n[foo]bar = from-repo\n" >.git/config && + printf "[foo]\n\tbar = from-home\n" >.gitconfig && if test_have_prereq MINGW then # Use Windows path (i.e. *not* $HOME) @@ -253,18 +253,28 @@ test_expect_success 'iteration shows correct origins' ' value=from-home origin=file name=$HOME_GITCONFIG + lno=2 scope=global + key=ignore.this + value=please + origin=file + name=.git/config + lno=2 + scope=repo + key=foo.bar value=from-repo origin=file name=.git/config + lno=3 scope=repo key=foo.bar value=from-cmdline origin=command line name= + lno=-1 scope=cmdline EOF GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config iterate >actual && From patchwork Fri Jan 24 09:25:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Wesarg X-Patchwork-Id: 11349997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79830924 for ; Fri, 24 Jan 2020 09:25:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EB1B208C4 for ; Fri, 24 Jan 2020 09:25:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=googlemail.com header.i=@googlemail.com header.b="OGcIF6FB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730497AbgAXJZk (ORCPT ); Fri, 24 Jan 2020 04:25:40 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42662 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730443AbgAXJZi (ORCPT ); Fri, 24 Jan 2020 04:25:38 -0500 Received: by mail-wr1-f68.google.com with SMTP id q6so1089482wro.9 for ; Fri, 24 Jan 2020 01:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PXqzKYCM93B+OFfZqNOaYnQpMhd6zfOAEEX76utp1is=; b=OGcIF6FBgxZYoWS4hbmmS975dqoxbVC0OJN6TriYihq6wCCO2XMVsulpSnX1eMbvO/ d1ke3KOfXgB8cyTvbTJ5YkM0fLtmSBgQ0a4zsOa+f44u8DHFrAGUgj5+hS1Yb/XWuYvf eybYVi2Jxghrn3qJQoMB1M+O93I8pCQvATs3iVeeAQmy8bzRxZaPx69mzW0lIWmQLJ7J RmAUDHCHkn0jjp+hZxTzDyew40GAcbAF3SDz1+TXtqmAxP7ZHLJML3R+U2hRqkhyVBgN KjiO2rcTc+D4vuO38f9iv1k+D7fmkH3JKvkZD0eh1ZF2TW4CASYjMJ0D/wm673LzN4e5 J4hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PXqzKYCM93B+OFfZqNOaYnQpMhd6zfOAEEX76utp1is=; b=NvG7/3ZLJCPd4INCyhFgglV9J2hoFCcidUm/H1bbv/dR4BZAl3Hk5bPVfxEXQP/tPn 6CNYdcPE/sFsCcBjKHN2zyPJpmShjgOUNxC/V3nBbg1AcXn9KcBa/1TceN1MMbnRYQo6 1bz3NYfCoi0tsn23ZKujYQDaNgmJnuJHtZl2G/7+bz99PUrn7wjP5Om0EmSGQHiF4jK8 6QqKhzCb2kA+YpOrwW/9CCP9Xhr+r/QtCR8YaS1sAGDoBsxvIUdSJF5OcoI+v9ER1XKV FCqTD0wToev3Z65HwQpiXMyrBw78zxvIpVW7Wc9O/5JZwvM1ClcBM1TTL7wLa6TptYwn to0Q== X-Gm-Message-State: APjAAAWa3elaAw85k6LN4z84UHcy84sYYodB42Q7FNKqGc/kFey093zN Djnfj9bRPPmMEjbxS3A= X-Google-Smtp-Source: APXvYqwTKqhJUNYpbtb2uLKzxeVtOoAdHzsloTf9NhGRZtHM6MN8t2biCGilr+9fSBaC4B92WxCH2g== X-Received: by 2002:a5d:484d:: with SMTP id n13mr3105448wrs.420.1579857936613; Fri, 24 Jan 2020 01:25:36 -0800 (PST) Received: from localhost (m221.zih.tu-dresden.de. [141.30.68.221]) by smtp.gmail.com with ESMTPSA id f207sm7220789wme.9.2020.01.24.01.25.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jan 2020 01:25:36 -0800 (PST) From: Bert Wesarg To: git@vger.kernel.org Cc: Bert Wesarg , Junio C Hamano , Johannes Schindelin , Matthew Rogers Subject: [PATCH v2 7/7] remote rename/remove: gently handle remote.pushDefault config Date: Fri, 24 Jan 2020 10:25:27 +0100 Message-Id: X-Mailer: git-send-email 2.24.1.497.g9abd7b20b4.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When renaming a remote with git remote rename X Y git remote remove X Git already renames or removes any branch..remote and branch..pushRemote configurations if their value is X. However remote.pushDefault needs a more gentle approach, as this may be set in a non-repo configuration file. In such a case only a warning is printed, such as: warning: The global configuration remote.pushDefault in: $HOME/.gitconfig:35 now names the non-existent remote origin It is changed to remote.pushDefault = Y or removed when set in a repo configuration though. Signed-off-by: Bert Wesarg --- Matthew, you are in Cc because of your current work 'config: allow user to know scope of config options'. I think I'm correct to assuming an ordering of the enum config_scope. Changes since v1: * handle also 'git remote remove' Cc: Junio C Hamano Cc: Johannes Schindelin Cc: Matthew Rogers --- builtin/remote.c | 54 +++++++++++++++++++++++++++++++++ t/t5505-remote.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index a2379a14bf..7404e50c13 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -615,6 +615,55 @@ static int migrate_file(struct remote *remote) return 0; } +struct push_default_info +{ + const char *old_name; + enum config_scope scope; + struct strbuf origin; + int linenr; +}; + +static int config_read_push_default(const char *key, const char *value, + void *cb) +{ + struct push_default_info* info = cb; + if (strcmp(key, "remote.pushdefault") || strcmp(value, info->old_name)) + return 0; + + info->scope = current_config_scope(); + strbuf_reset(&info->origin); + strbuf_addstr(&info->origin, current_config_name()); + info->linenr = current_config_line(); + + return 0; +} + +static void handle_push_default(const char* old_name, const char* new_name) +{ + struct push_default_info push_default = { + old_name, CONFIG_SCOPE_UNKNOWN, STRBUF_INIT, -1 }; + git_config(config_read_push_default, &push_default); + if (push_default.scope >= CONFIG_SCOPE_CMDLINE) + ; /* pass */ + else if (push_default.scope >= CONFIG_SCOPE_REPO) { + int result = git_config_set_gently("remote.pushDefault", + new_name); + if (new_name && result && result != CONFIG_NOTHING_SET) + die(_("could not set '%s'"), "remote.pushDefault"); + else if (!new_name && result && result != CONFIG_NOTHING_SET) + die(_("could not unset '%s'"), "remote.pushDefault"); + } else if (push_default.scope >= CONFIG_SCOPE_SYSTEM) { + /* warn */ + warning(_("The %s configuration remote.pushDefault in:\n" + "\t%s:%d\n" + "now names the non-existent remote '%s'"), + config_scope_name(push_default.scope), + push_default.origin.buf, push_default.linenr, + old_name); + } +} + + static int mv(int argc, const char **argv) { struct option options[] = { @@ -750,6 +799,9 @@ static int mv(int argc, const char **argv) die(_("creating '%s' failed"), buf.buf); } string_list_clear(&remote_branches, 1); + + handle_push_default(rename.old_name, rename.new_name); + return 0; } @@ -835,6 +887,8 @@ static int rm(int argc, const char **argv) strbuf_addf(&buf, "remote.%s", remote->name); if (git_config_rename_section(buf.buf, NULL) < 1) return error(_("Could not remove config section '%s'"), buf.buf); + + handle_push_default(remote->name, NULL); } return result; diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 082042b05a..bbff8c5770 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -737,6 +737,7 @@ test_expect_success 'rename a remote' ' git clone one four && ( cd four && + test_config_global remote.pushDefault origin && git config branch.master.pushRemote origin && git remote rename origin upstream && test -z "$(git for-each-ref refs/remotes/origin)" && @@ -744,7 +745,42 @@ test_expect_success 'rename a remote' ' test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" && test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && test "$(git config branch.master.remote)" = "upstream" && - test "$(git config branch.master.pushRemote)" = "upstream" + test "$(git config branch.master.pushRemote)" = "upstream" && + test "$(git config --global remote.pushDefault)" = "origin" + ) +' + +test_expect_success 'rename a remote renames repo remote.pushDefault' ' + git clone one four.1 && + ( + cd four.1 && + git config remote.pushDefault origin && + git remote rename origin upstream && + test "$(git config --local remote.pushDefault)" = "upstream" + ) +' + +test_expect_success 'rename a remote renames repo remote.pushDefault but ignores global' ' + git clone one four.2 && + ( + cd four.2 && + test_config_global remote.pushDefault other && + git config remote.pushDefault origin && + git remote rename origin upstream && + test "$(git config --global remote.pushDefault)" = "other" && + test "$(git config --local remote.pushDefault)" = "upstream" + ) +' + +test_expect_success 'rename a remote renames repo remote.pushDefault but keeps global' ' + git clone one four.3 && + ( + cd four.3 && + test_config_global remote.pushDefault origin && + git config remote.pushDefault origin && + git remote rename origin upstream && + test "$(git config --global remote.pushDefault)" = "origin" && + test "$(git config --local remote.pushDefault)" = "upstream" ) ' @@ -790,11 +826,47 @@ test_expect_success 'remove a remote' ' git clone one four.five && ( cd four.five && + test_config_global remote.pushDefault origin && git config branch.master.pushRemote origin && git remote remove origin && test -z "$(git for-each-ref refs/remotes/origin)" && test_must_fail git config branch.master.remote && - test_must_fail git config branch.master.pushRemote + test_must_fail git config branch.master.pushRemote && + test "$(git config --global remote.pushDefault)" = "origin" + ) +' + +test_expect_success 'remove a remote removes repo remote.pushDefault' ' + git clone one four.five.1 && + ( + cd four.five.1 && + git config remote.pushDefault origin && + git remote remove origin && + test_must_fail git config --local remote.pushDefault + ) +' + +test_expect_success 'remove a remote removes repo remote.pushDefault but ignores global' ' + git clone one four.five.2 && + ( + cd four.five.2 && + test_config_global remote.pushDefault other && + git config remote.pushDefault origin && + git remote remove origin && + test "$(git config --global remote.pushDefault)" = "other" && + test_must_fail git config --local remote.pushDefault + ) +' + +test_expect_success 'remove a remote removes repo remote.pushDefault but keeps global' ' + git clone one four.five.3 && + ( + cd four.five.3 && + test_config_global remote.pushDefault origin && + git config remote.pushDefault origin && + git remote remove origin && + test "$(git config --global remote.pushDefault)" = "origin" && + test_must_fail git config --local remote.pushDefault ) '