From patchwork Wed Nov 11 12:28:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67EC5C56201 for ; Wed, 11 Nov 2020 12:28:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 030C520829 for ; Wed, 11 Nov 2020 12:28:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G2Qk3E6y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726595AbgKKM2c (ORCPT ); Wed, 11 Nov 2020 07:28:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbgKKM22 (ORCPT ); Wed, 11 Nov 2020 07:28:28 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CADCC0613D4 for ; Wed, 11 Nov 2020 04:28:28 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id 10so2104225wml.2 for ; Wed, 11 Nov 2020 04:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=js8oUsMHl21kgw69PYKoHcc81MiST6F1XqDnN0kNdcM=; b=G2Qk3E6yMszllmLDrZ8b7zhQrb2FM6lBbCkzpPFWcBC219yALjOe2tAcoSerW4LN/b kCeBXumrcHLHyrXSeQ2tAa/EeLgpjoGAaOt/l0Pv7BRt6ndKFBMuY+mlYixiafzDNDCn u6ySwaaZML6A0wWvlfEsCq7dtJD4V/LRXEPFu5+O7AcK3/tl8I0JslxfHT7+cGRepFR5 u2rR7NswZckY+aPBgm2mMQBZDOJeaUs+sHGAPt6Rt1bW+TfwelEqSls1isHwoo0hVIb3 5v01cCS6DHzxXu+gf7CTDWg9NHegwOIdKaUcdt5SaTt2j06uY+/8VonfHcPtsXyiDVkm bF6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=js8oUsMHl21kgw69PYKoHcc81MiST6F1XqDnN0kNdcM=; b=OtUQpIY0yu199bW40MeNI90aWKUDZWubMIkf8sYWqYUejeBxpq9gWYwqLGDLKYncGK CxcWynNKLyol5gCkqAj9Zp8GBZOIjkp6ySY8xQSDy1zPpPhY94k3LuhbQaxL4blpe9vL swb9qKYqBHWBfg0N01mdJ+htT3Bc+QJTQ/3xKfWtKWbHmCUsbAQFTpxvwoa/c18Z9tb6 1QQLBZEv+aVfLhHSDJjKBbQOVZrFvcKxs/cTIC8P+g87Xmq5Mr7+z0G6sVPNIAjoAEei 1pNfmWpYxv3pTt394Y5hSnCv3vlbJztjil+w5UGR0lliQGoG1HZ4MtALWto52y/T5ycK GG1w== X-Gm-Message-State: AOAM53378RM5POHuvt8PeIdhRV8+LF7kSG5sqR/jdXrp3HZMF0qk7VXj xwuxJ7CumVeTjOC8AeSK7xkiKFqLy9g= X-Google-Smtp-Source: ABdhPJy2zQQweM1RVanVNWADbd4YDj/3QeRifS/ElPjwSW3PCUbePOr/e5yMyU3T9fhk4liQ5j7S1Q== X-Received: by 2002:a1c:bd08:: with SMTP id n8mr3847908wmf.136.1605097706634; Wed, 11 Nov 2020 04:28:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s202sm2386861wme.39.2020.11.11.04.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:26 -0800 (PST) Message-Id: <6152122c04aacf8c3e3f1aae7b73995da6b9e354.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:14 +0000 Subject: [PATCH v2 01/11] add -i (built-in): do show an error message for incorrect inputs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin There is a neat feature in `git add -i` where it allows users to select items via unique prefixes. In the built-in version of `git add -i`, we specifically sort the items (unless they are already sorted) and then perform a binary search to figure out whether the input constitutes a unique prefix. Unfortunately, by mistake this code misidentifies matches even if the input string is not actually a prefix of any item. For example, in the initial menu, where there is a `status` and an `update` command, the input `tadaa` was mistaken as a prefix of `update`. Let's fix this by looking a bit closer whether the input is actually a prefix of the item at the found insert index. Signed-off-by: Johannes Schindelin --- add-interactive.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/add-interactive.c b/add-interactive.c index 555c4abf32..8ca503d803 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -194,7 +194,8 @@ static ssize_t find_unique(const char *string, struct prefix_item_list *list) else if (index + 1 < list->sorted.nr && starts_with(list->sorted.items[index + 1].string, string)) return -1; - else if (index < list->sorted.nr) + else if (index < list->sorted.nr && + starts_with(list->sorted.items[index].string, string)) item = list->sorted.items[index].util; else return -1; From patchwork Wed Nov 11 12:28:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46960C388F9 for ; Wed, 11 Nov 2020 12:28:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E344B207BB for ; Wed, 11 Nov 2020 12:28:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SLJ4my2b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726774AbgKKM2w (ORCPT ); Wed, 11 Nov 2020 07:28:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbgKKM23 (ORCPT ); Wed, 11 Nov 2020 07:28:29 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C658FC0613D6 for ; Wed, 11 Nov 2020 04:28:28 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id d12so2306018wrr.13 for ; Wed, 11 Nov 2020 04:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dpll76Bt0FuWoTL59TONqXQ0KGL2T+WUdIsjig1jOUg=; b=SLJ4my2ba994nD76xmDnmA999YufP9qjgNUBCrSTalSmlVtPwGpkttbKY5Phb8B3gC mE560W7aRMeRuw3SminCxsZ0Gj2+70NiJMClotzJJGWrMki2epoa8nFXE7ZTz6gk8/Iq lyE75wfAj80F3+flyJMdl7fk7ICsPGQRmsTrcrm3xTEJa9OS6dGhJGdR1IT7/D1JNN4V 2JE7iRbjyq8mUIyLhJeL5E0pw8FI5VAanybfvE8Qb7zUJKntqqM60vUvwua1zyzNtYtl otXkP47zONMAcZzN+6svRqZa8q4E4yB/NyJl+JtpgiRzw5SbWUxp5hQMhqAy/PYneZWU TE6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dpll76Bt0FuWoTL59TONqXQ0KGL2T+WUdIsjig1jOUg=; b=n/2qWgntibF+swDtSnub5s7oBKU6gMnLl56SAwkWPKLiqza114So1HzP6MrimSEgzw 0Aa9icPEHaAvHOvDKCAZVXZLbsQhCc7p97gWpX1iR4QwsIzDOqj4cRuCmJ798C+5TVdG I320ICWhHFJ8XKvHzdpyYz3GgCISA8V5C2rfIgLUoMii3bHciHYDzjs/h+UpoI3uqDEm 9vfwRiERpc6liYUYjhw+O0Z12U4gZtqoeRk3EzHZLLgJ4+OxRSrhG1+cBn13C8S6fJQE uSg1kqzP1LzIMii+2YlEmyqI63Vi3lR3H9wTroDYXWoumyEyZcm3zZSAm/Mr72uVMQ/D y3RQ== X-Gm-Message-State: AOAM5307UyL5lVe9HevBL8f6DqA5MPCOpqVo3Jl3V6CK1JwSt8RO4zpq kW32b2sBBlU+8u8O2wMK7LLuWfD4Ai4= X-Google-Smtp-Source: ABdhPJyhhD6t4F6BS43eLmO/jVhjUu+nINcxZP2QC85XP3SZnQHgeWWLULrF698ajXRigdb4XL9stw== X-Received: by 2002:a5d:6447:: with SMTP id d7mr28906118wrw.96.1605097707402; Wed, 11 Nov 2020 04:28:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a12sm2344695wrr.31.2020.11.11.04.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:27 -0800 (PST) Message-Id: <068813912b9e5133f9d9bbacb239f7954788bf53.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:15 +0000 Subject: [PATCH v2 02/11] add -i (built-in): send error messages to stderr Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The Perl version of that command already does that since a301973641f (add -p: print errors in separate color, 2009-02-05). The built-in version's development started by reimplementing the initial version from 5cde71d64af (git-add --interactive, 2006-12-10) for simplicity, though, which still printed error messages to stdout. Let's fix that by imitating the Perl version's behavior in the built-in version of that command. Signed-off-by: Johannes Schindelin --- add-interactive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-interactive.c b/add-interactive.c index 8ca503d803..0f24992ca4 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -365,7 +365,7 @@ static ssize_t list_and_choose(struct add_i_state *s, if (from < 0 || from >= items->items.nr || (singleton && from + 1 != to)) { - color_fprintf_ln(stdout, s->error_color, + color_fprintf_ln(stderr, s->error_color, _("Huh (%s)?"), p); break; } else if (singleton) { From patchwork Wed Nov 11 12:28:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8276DC5517A for ; Wed, 11 Nov 2020 12:28:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D0A220829 for ; Wed, 11 Nov 2020 12:28:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NlGeh3z8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbgKKM2v (ORCPT ); Wed, 11 Nov 2020 07:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgKKM2a (ORCPT ); Wed, 11 Nov 2020 07:28:30 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86451C0617A6 for ; Wed, 11 Nov 2020 04:28:29 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id d12so2306062wrr.13 for ; Wed, 11 Nov 2020 04:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=I45Wez2549eUcVcvjzTBIh58pyxNIL9ydV8QhHpZrSs=; b=NlGeh3z8EQcJvNhAz4Xik48igb/CiGEubywqovfn38xD+2x+pw/KuY3F376fhVGJDH gJMsFgTIoIcn87BkETkKGtTZaRBC6P1OvIR33t37zrwT2uEHGQ+x6dDOz/hI3jJVhaKX A0QN0YMAz8YyWz16lWxQ0IUiFjFyKO5FDyHUYbe2YQDtoASGCKJyFGEjWJ198FnDhsk/ JrdQAXvQC2Qun9+7Eqq/g6J30VGlTeauGIhQgM7HrYcgEDBuMHnvqGzg7VtXrWuo2c4u ShmdH2QYgDgRp9QIERbeBW/+ACxdFSOa2j69tiLEjztwmc4PuB7MLgYmXwv/F5TSAL1l lj7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=I45Wez2549eUcVcvjzTBIh58pyxNIL9ydV8QhHpZrSs=; b=ehf9Ppujv/itDGzbysudcE3ex6vLuNeu7cqFcuvtB/LFHbHHadsP6nRE9SN7tMdvmm HFllfsimJHmAWzosUhwWv8d957WGz51uTUeSWMMfMEherd5WaGV7REYknSsV7euPHrCd oOSNmZvDxqNLGQDEGnfaxVolF/2UxOhZP6tFKGHjHWz+whpG5Q2kyGYqL7UfF8YthRcT d0QmdoXHiE1hPzuuu0OL+GC1ioL7nkeZbcdoZAmvyadb7NZL55yw8yW4CN/kvDupTC1G ASYmcoyGJy5PQiqxVpbicIYS1sN9WSJQSSSy2I6qWVlxzmejoWMR6wU0wua7BWnLE4V4 V16g== X-Gm-Message-State: AOAM533nnfa7FC1q1A1f6sg4Xv11HjQSIkEE4Q3fFn7wITeQwoAPZgLh rq2JmzZbNADrARyFwx7ztcf7LwNGK6U= X-Google-Smtp-Source: ABdhPJwQnV6r8kKonI7gFv89ovFGL8F+MvYWjIVDvG0Ra4zwWRNtMkDe8acN5V4N8wSpPcTzJOhcSQ== X-Received: by 2002:adf:f2c7:: with SMTP id d7mr26246001wrp.142.1605097708170; Wed, 11 Nov 2020 04:28:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q7sm2536656wrg.95.2020.11.11.04.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:27 -0800 (PST) Message-Id: <98deb538d91ba0ab485fa8d97cc6062bcc680938.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:16 +0000 Subject: [PATCH v2 03/11] add -p (built-in): imitate `xdl_format_hunk_hdr()` generating hunk headers Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In libxdiff, imitating GNU diff, the hunk headers only show the line count if it is different from 1. When splitting hunks, the Perl version of `git add -p` already imitates this. Let's do the same in the built-in version of said command. Signed-off-by: Johannes Schindelin --- add-patch.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/add-patch.c b/add-patch.c index be4cf6e9e5..b6d53229bb 100644 --- a/add-patch.c +++ b/add-patch.c @@ -661,9 +661,14 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, else new_offset += delta; - strbuf_addf(out, "@@ -%lu,%lu +%lu,%lu @@", - old_offset, header->old_count, - new_offset, header->new_count); + strbuf_addf(out, "@@ -%lu", old_offset); + if (header->old_count != 1) + strbuf_addf(out, ",%lu", header->old_count); + strbuf_addf(out, " +%lu", new_offset); + if (header->new_count != 1) + strbuf_addf(out, ",%lu", header->new_count); + strbuf_addstr(out, " @@"); + if (len) strbuf_add(out, p, len); else if (colored) From patchwork Wed Nov 11 12:28:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBBB2C56202 for ; Wed, 11 Nov 2020 12:28:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A5AF207BB for ; Wed, 11 Nov 2020 12:28:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oipXyuQi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbgKKM2u (ORCPT ); Wed, 11 Nov 2020 07:28:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726384AbgKKM2a (ORCPT ); Wed, 11 Nov 2020 07:28:30 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84917C0617A7 for ; Wed, 11 Nov 2020 04:28:30 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id 19so2115930wmf.1 for ; Wed, 11 Nov 2020 04:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=AzgWnmI3Bhq6k5C1tKCzYRk5JHhlQy9Xx+1Yk/wajuk=; b=oipXyuQi9SYPa5C+l2M8qSRca9H5rLdJjkaVrjs33ZX+ZXVdPK0EoMoMo6RP7xycdN OjGBvBPEZE06pWLNV1PbM3Wm7KvE9asRxmQySRt11xPr2kOMaMFjdje92NW6CNo+XW/U UMdMu153WHMhkc/WzpFaGA8lzIJWAIfP6ja54n0SeOX6mHuB14DfmXGzhWa73afx4pQi pJLwLaQpuERIZ9mTEpK1CL6w3Q+eNcUqofrlYHBM+vNrtQA3f9egtggJaGetCIHX2u2L K3SZPp4NLVES+3HRSfWO1zuU2SMc+Qb7GIglaBlMXEd3lsWH3icXRY6g7aGnTpbUxuzU ZTYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=AzgWnmI3Bhq6k5C1tKCzYRk5JHhlQy9Xx+1Yk/wajuk=; b=LrGyTfKPS1FCmSvTuPoHPACEzl1H0uHox1Uu7dL9wCwDy9ZvETdyIFSLsrF51jLGnu 2t06eQ5ItJA+Ep0T4QV6yw4ivn8owFKpYOu3ofXaYKngn9riMto3Y+W2JeHp14C9LU78 uN5jHft/tpAwBG1x7mrMfakbg/RfiN3fX3LfUWYq054l6NPu2z+MxLOGVECDvOk2nx0A 8JkmYxKpaY1JV7W2CXS/NADpjQ2c7aUggEALgKv6y+Civ3YCzDbSiY5F40n6MUuVcntC 6v8ik84WmRIXbPS/vpphdX7DB/yXHwLxRBUtV31pOFz218GeGQlEtwVLDnSZ0VHXLpKe YRTg== X-Gm-Message-State: AOAM530qH2lWKQh3BZJl57YkfmeOpYLwq/4GZcJdNcMQ4Aej0K5SzqSc obtbNXVNbKIk3w9jQ2cou90K2O8OCoE= X-Google-Smtp-Source: ABdhPJzKyVhKBIG+hGI7FlakOT5N4/oxyQJpJTMAJ4QAPqsh1lZYINcZf05kr6KW6RLyj+VUvAnyOw== X-Received: by 2002:a1c:7213:: with SMTP id n19mr3782038wmc.36.1605097708904; Wed, 11 Nov 2020 04:28:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j71sm2613344wmj.10.2020.11.11.04.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:28 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:17 +0000 Subject: [PATCH v2 04/11] add -i: use `reset_color` consistently Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin We already maintain a list of colors in the `add_i_state`, therefore we should use them. Signed-off-by: Johannes Schindelin --- add-patch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add-patch.c b/add-patch.c index b6d53229bb..bf89c43145 100644 --- a/add-patch.c +++ b/add-patch.c @@ -672,7 +672,7 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, if (len) strbuf_add(out, p, len); else if (colored) - strbuf_addf(out, "%s\n", GIT_COLOR_RESET); + strbuf_addf(out, "%s\n", s->s.reset_color); else strbuf_addch(out, '\n'); } @@ -1065,7 +1065,7 @@ static void recolor_hunk(struct add_p_state *s, struct hunk *hunk) s->s.file_new_color : s->s.context_color); strbuf_add(&s->colored, plain + current, eol - current); - strbuf_addstr(&s->colored, GIT_COLOR_RESET); + strbuf_addstr(&s->colored, s->s.reset_color); if (next > eol) strbuf_add(&s->colored, plain + eol, next - eol); current = next; From patchwork Wed Nov 11 12:28:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E77C56201 for ; Wed, 11 Nov 2020 12:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 285B3207BB for ; Wed, 11 Nov 2020 12:28:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PdA/tOGO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725965AbgKKM2f (ORCPT ); Wed, 11 Nov 2020 07:28:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbgKKM2b (ORCPT ); Wed, 11 Nov 2020 07:28:31 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17203C0613D1 for ; Wed, 11 Nov 2020 04:28:31 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id c9so2074751wml.5 for ; Wed, 11 Nov 2020 04:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=wqcvrpnp66411xzdRYT+v8cQp9rgUou7SRfzShsgUY0=; b=PdA/tOGOE4Pl5Cue2jJ/I7Y8ABSWSozxIyc9o1W5WGjgyfNaJM6sp6YFK8T0gFeXxI VKZUtByMyn0mZgrQwATZJs/nQxNP883BDxnjmLGi/p91cG0dUV7JXyKZiSQGusBycuTu arPlqQcq3xh5ayv7p3fnyEj7BAm9J04YVKjujzraV3p4Vuz/C8V/trnzTUhg+ESjtwLe YE+GJPDGm1xP6jwVrl/Loca8jrUxCAkPseZ8cjf2PDbcDzaqUnbaJayTtOXQE7qWShKe z9dcFBh2oOM2B1DgDlDthEhNzfejXvxPYxNynBG6ElHBC/oVOzkWvcnuP7LXLR8YO4IX yvmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=wqcvrpnp66411xzdRYT+v8cQp9rgUou7SRfzShsgUY0=; b=dvmuNwsh2jtrRWCZjXIowuJRHjG+EtUm04Z6jf8ZKxWdDyzA5x9e8AJRucLmKsOOtn F8+pFINJmXOH+vYK5+u2188aD+4kJxG9Z2v/DPZDQIgMNe5vTOTvjiW+YHG+8LefqrJM FaItAMm1zkYGqQngF5yT1H9fWjojeBbGt6mtp/hQZMhMVX0Ni2LopSXJrRrPn3GxU1Ps K3x0KD3uchTTFmm9YL5hAXJ8SBSEaN9HQ3mjikE0WOrEZyfJ1D1kjVHfmsRoZ4ogyhEn 3lQ0yOOhLNkFdWmyHJB65H7tgqwEMs4eI8ExoP2KouvGUTpZ2iEmgmbbMsIZe3PRUTwB DVAg== X-Gm-Message-State: AOAM532KNsmMIRjkQsb/fSvKg46Zvp8lTXZfopSdvpOAtxOjiyW8+gVY M7gdRiCMB9KseTTWQ1wcY+JXO+qsOtw= X-Google-Smtp-Source: ABdhPJzWs9ASL/TZf613+AOXg97nQqy1d3m9GQR0z65csdlr3gjbCU8HimWPexR8TfGXnb4Jx4gLhw== X-Received: by 2002:a1c:e90a:: with SMTP id q10mr3730038wmc.57.1605097709758; Wed, 11 Nov 2020 04:28:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p4sm2625729wmc.46.2020.11.11.04.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:29 -0800 (PST) Message-Id: <337b45cad8b876e1811099f398bf0a05ade21acf.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:18 +0000 Subject: [PATCH v2 05/11] add -i (built-in): prevent the `reset` "color" from being configured Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The Perl version of that command sneakily uses `git config --get-color` to figure out the ANSI sequence to reset the color, but passes the empty string and therefore cannot actually match any config entry. This was missed when re-implementing the command as a built-in command. Let's fix this, preventing the `reset` sequence from being overridden via the config. Signed-off-by: Johannes Schindelin --- add-interactive.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/add-interactive.c b/add-interactive.c index 0f24992ca4..f3a1d7456e 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -44,7 +44,6 @@ void init_add_i_state(struct add_i_state *s, struct repository *r) init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED); init_color(r, s, "prompt", s->prompt_color, GIT_COLOR_BOLD_BLUE); init_color(r, s, "error", s->error_color, GIT_COLOR_BOLD_RED); - init_color(r, s, "reset", s->reset_color, GIT_COLOR_RESET); init_color(r, s, "fraginfo", s->fraginfo_color, diff_get_color(s->use_color, DIFF_FRAGINFO)); init_color(r, s, "context", s->context_color, @@ -54,6 +53,9 @@ void init_add_i_state(struct add_i_state *s, struct repository *r) init_color(r, s, "new", s->file_new_color, diff_get_color(s->use_color, DIFF_FILE_NEW)); + strlcpy(s->reset_color, + s->use_color ? GIT_COLOR_RESET : "", COLOR_MAXLEN); + FREE_AND_NULL(s->interactive_diff_filter); git_config_get_string("interactive.difffilter", &s->interactive_diff_filter); From patchwork Wed Nov 11 12:28:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26E80C56201 for ; Wed, 11 Nov 2020 12:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC45220795 for ; Wed, 11 Nov 2020 12:28:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EZQzjgTP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgKKM2h (ORCPT ); Wed, 11 Nov 2020 07:28:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbgKKM2c (ORCPT ); Wed, 11 Nov 2020 07:28:32 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D04C0613D4 for ; Wed, 11 Nov 2020 04:28:31 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id k2so2367957wrx.2 for ; Wed, 11 Nov 2020 04:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IfewZDe6pyLTRvzVboxTA78Zdq0TjQvvkV3C3VOSFME=; b=EZQzjgTP+yDuoZazyM1CiiEPmnRPFX/7prVbuKTKvzyH5mAjLOW1q8G3XKTbFI+Qt8 2wb06AL+ieIum2gfW9OZqtT321kEQIn1nv06DZaxej+nBYbq5tTnb+bu1BA6RC6JL5P/ mtNOgB/q+CjYqtHavQTW3Fn9R6pSTAIFfzYi/rmwmjmYE01ejK14v5VkM7HDfXyV6c5F b9zonrpNt5HD/b8L4hou1lZtLvAUm7LGQlb4yl5tx8X9pU0XV/2h2FjBZIE38i1fjp2z OOj2jPCDYnVB6NUmcyITt4zdH+Menk1vXSdR8fQG0BCd1ckveS3rnXLqvKPVt0o3/qxR SbSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IfewZDe6pyLTRvzVboxTA78Zdq0TjQvvkV3C3VOSFME=; b=FbzCtUavt2o348G5iT56Iv+ig8pKIkmXmDKkry+EyI8L/EL90UfBrRuBsQoTZ3URfZ Ho9CY0FDmmqPgFEOWGXux6w3fJdU0SEUNpBagsxlrPvF8YEmt7azUdDZaeZzaB1J6/dT /h+sxWRNb3N9tMiTOMxL3yVpIkHG+Fy0VKYXu+Fkko5mZr0sNQKb7WVyXQp2iATBvmok N9bPqsJoLseAamsxqdF7lX7M5lRUj31IY5wy8FUmh8eBQhIRk6ly9hkHQOs1qaq9K1DB mf/h40k6aJ1l7XsjMNxRs5uC9tcg2rVwXrXyhYP/5oxyGmGzmUNRBYblBPhk3BaHI2UZ 7tbg== X-Gm-Message-State: AOAM5325kCz6kRn/WW05uhFH9Syg596mUCCq+mTCLD/jbJETNpR+2KOm 5hXt+lKJXjgWr/4N6s5JlZO1KOtFn+k= X-Google-Smtp-Source: ABdhPJz2xfdpabHhqPc9W8xilPwRMWBJ9EkOFtrI33VHnb0edjEcexwfO70WazB61hiMP9wXDqPfgA== X-Received: by 2002:adf:8465:: with SMTP id 92mr28063078wrf.50.1605097710495; Wed, 11 Nov 2020 04:28:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x63sm2588653wmb.48.2020.11.11.04.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:30 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:19 +0000 Subject: [PATCH v2 06/11] add -i (built-in): use correct names to load color.diff.* config Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The builtin version of add-interactive mistakenly loads diff colors from color.interactive.* instead of color.diff.*. It also accidentally spells `frag` as `fraginfo`. Let's fix that. Note also that we don't respect the historical `diff.color.*`. The perl version never did, and those have been deprecated since 2007. Reported-by: Philippe Blain Co-authored-by: Jeff King Signed-off-by: Johannes Schindelin --- add-interactive.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/add-interactive.c b/add-interactive.c index f3a1d7456e..9126684348 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -12,10 +12,10 @@ #include "prompt.h" static void init_color(struct repository *r, struct add_i_state *s, - const char *slot_name, char *dst, + const char *section_and_slot, char *dst, const char *default_color) { - char *key = xstrfmt("color.interactive.%s", slot_name); + char *key = xstrfmt("color.%s", section_and_slot); const char *value; if (!s->use_color) @@ -40,17 +40,20 @@ void init_add_i_state(struct add_i_state *s, struct repository *r) git_config_colorbool("color.interactive", value); s->use_color = want_color(s->use_color); - init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD); - init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED); - init_color(r, s, "prompt", s->prompt_color, GIT_COLOR_BOLD_BLUE); - init_color(r, s, "error", s->error_color, GIT_COLOR_BOLD_RED); - init_color(r, s, "fraginfo", s->fraginfo_color, + init_color(r, s, "interactive.header", s->header_color, GIT_COLOR_BOLD); + init_color(r, s, "interactive.help", s->help_color, GIT_COLOR_BOLD_RED); + init_color(r, s, "interactive.prompt", s->prompt_color, + GIT_COLOR_BOLD_BLUE); + init_color(r, s, "interactive.error", s->error_color, + GIT_COLOR_BOLD_RED); + + init_color(r, s, "diff.frag", s->fraginfo_color, diff_get_color(s->use_color, DIFF_FRAGINFO)); - init_color(r, s, "context", s->context_color, + init_color(r, s, "diff.context", s->context_color, diff_get_color(s->use_color, DIFF_CONTEXT)); - init_color(r, s, "old", s->file_old_color, + init_color(r, s, "diff.old", s->file_old_color, diff_get_color(s->use_color, DIFF_FILE_OLD)); - init_color(r, s, "new", s->file_new_color, + init_color(r, s, "diff.new", s->file_new_color, diff_get_color(s->use_color, DIFF_FILE_NEW)); strlcpy(s->reset_color, From patchwork Wed Nov 11 12:28:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA626C5517A for ; Wed, 11 Nov 2020 12:28:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84A4C20795 for ; Wed, 11 Nov 2020 12:28:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GvFqk13n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbgKKM2g (ORCPT ); Wed, 11 Nov 2020 07:28:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbgKKM2d (ORCPT ); Wed, 11 Nov 2020 07:28:33 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87663C0613D6 for ; Wed, 11 Nov 2020 04:28:32 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id s8so2326843wrw.10 for ; Wed, 11 Nov 2020 04:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=wtwRH7d2asDdW9AzKlKoJolSKk1x7GDxEy0Ku/21dzU=; b=GvFqk13n38L5la6CacNLN99fg7J/Pd7Kmd4gIZVV5fXob/89bi7pgVCg5F+ft9YzGG 8v9NXF1eAs291tagPzd04rNLMBlPwIqQzEVJlV60T8t44PL9p1gE3z9XHvmoI82rna+N raF38snf/ua+hZuA7R95DS5FXK3e3OKEmtKNers4yRo0OjgtL9/Ka6765ycBCUEvzA2y PyyDSbyC2TegQYbMpRR6p8su4T8g9oTxzvDaUErWPsGWjGMHIemsALJALE420/b5c7sb vabr8+Zfoints76JIoSATeNrz6TiE4MQWEJlei7qtxJkaGEkulms18vFyB0+rHlj8Znc 0xMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=wtwRH7d2asDdW9AzKlKoJolSKk1x7GDxEy0Ku/21dzU=; b=Eyo5/YeiazX46g4PMMll3iJIUieHDI6Z/Mlz746VWPEsqm0zt8O4mFbiRnpVu5Uo1T gFx27kq5XjkMGpKFnl6uWziBJRlI2o15wo3+j/fkksVC+mflk63keu1O8SNuUL5+N6mo dIn0ic+V70ow+xv8kcldxzVKykR6xi7LIcK+QG2BvcGCy+nsbfKytI1t+mJ7nBzCT9V8 J8rFwBy1DbRVOikVIv8FRTYalEu8n8Awmg+mc0GVAriuBsOUicTS5MclRFhDto94DhR9 MGFuc7SoQFDwKmgY16HlOFLuOBdrOW2Sf308EOjXSOANfW2MqubU4sSIqDk4M7uFCZwK Wi4Q== X-Gm-Message-State: AOAM530BEwBXNVmgYvFYRZqsRTxnSvBkthmzvSeGG/5Ox0VjcUixJfye 4yddvFQAAn/c9+8jnK+3oa+IoAb66CY= X-Google-Smtp-Source: ABdhPJyDkocbQ+XVY7mYYReIJRYvjvdmr7gXHkTsXpmdGewB8g29a2qquz++o8Fg6FmRQPVCeDGiDA== X-Received: by 2002:a05:6000:1006:: with SMTP id a6mr20646140wrx.367.1605097711188; Wed, 11 Nov 2020 04:28:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b14sm2273287wrq.47.2020.11.11.04.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:30 -0800 (PST) Message-Id: <73b6d60a801766605cde9403d7a9e8451ef99e11.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:20 +0000 Subject: [PATCH v2 07/11] add -p (built-in): do not color the progress indicator separately Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The Perl version of this command colors the progress indicator and the prompt message in one go, let's do the same in the built-in version. Signed-off-by: Johannes Schindelin --- add-patch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/add-patch.c b/add-patch.c index bf89c43145..2fad92ca37 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1461,15 +1461,15 @@ static int patch_update_file(struct add_p_state *s, else prompt_mode_type = PROMPT_HUNK; - color_fprintf(stdout, s->s.prompt_color, - "(%"PRIuMAX"/%"PRIuMAX") ", + printf("%s(%"PRIuMAX"/%"PRIuMAX") ", s->s.prompt_color, (uintmax_t)hunk_index + 1, (uintmax_t)(file_diff->hunk_nr ? file_diff->hunk_nr : 1)); - color_fprintf(stdout, s->s.prompt_color, - _(s->mode->prompt_mode[prompt_mode_type]), - s->buf.buf); + printf(_(s->mode->prompt_mode[prompt_mode_type]), + s->buf.buf); + if (*s->s.reset_color) + fputs(s->s.reset_color, stdout); fflush(stdout); if (read_single_character(s) == EOF) break; From patchwork Wed Nov 11 12:28:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16981C5517A for ; Wed, 11 Nov 2020 12:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0CBA206FB for ; Wed, 11 Nov 2020 12:28:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UBeX4WOd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgKKM2k (ORCPT ); Wed, 11 Nov 2020 07:28:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbgKKM2d (ORCPT ); Wed, 11 Nov 2020 07:28:33 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D516C0617A6 for ; Wed, 11 Nov 2020 04:28:33 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id d12so2306233wrr.13 for ; Wed, 11 Nov 2020 04:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=9tX+jisZnF8QKIRir0GzdfsvhwQEBVAh2/i2Bt96TTA=; b=UBeX4WOdEt8+UG7iY33GzAK6JEwdBaMZl/1jCJeof2K2NtJj94JP4uEzJrFFK9ERQv dJ8Tsz4CsezE9ssOb3goaKxRiClqPqzZtycBUz7wRwrp+rfPxmJZhKP+4uuAVZeRX/MN djZKDqrzz4Pa44tHqcSu2PIAruvX5hRfhJHehzUzKwokmEg+9WxUFijRtmNJgwPb5n5g UtFeYSlMsbGjMP1QfeMk3qEf+EW9iPN9gm+MEMEcVn1vXbdzIvVMafsHl7qP1BvQwpR3 etMqkq7iwUUOq+vVcxn9IQOX0NCyYb0w/1TzbjsAQh1WM6Oabrol7amMqUoxFfh6aMe2 KoTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=9tX+jisZnF8QKIRir0GzdfsvhwQEBVAh2/i2Bt96TTA=; b=WiNm4HAZW0Ld2S8f/NXdOW238iEmVlJBSnmabObXP4fws3fqs/JVPddtltjW255tEZ SJ6IQy9WXmADcJ4g+HDmkMLMlkwkl1HKEuOWrIZHC08Rr5+QSTOP9FXXWjgcIQW3TDSM s34E1qGcDVXC1Rc8KJWRW0FSDmG12XKXFGuvS0hBxtoIV9CYBZ83r18TCLPyigOX/QVp uUr11h9ORg+33QAmhHl/+Y6PAu6El5ccGGth0+77rOt0tdWJ8fs9GKHbtggcESAK9wcP 1+hs05uBrSCMUg/uFQTlkbZ1eC6iG0esbAQWr1YG2SzFSti4H5p2PZvdZUUY+sl2luIN nVRw== X-Gm-Message-State: AOAM531xAwhq5eCKMQ7EKG8qxaLGM6Gr6oeWGUAdP9yUyZw05Pzb3xTO VvLb7OHKMrSRdksrWIjwRIGP6VX7asc= X-Google-Smtp-Source: ABdhPJzx8OmL2M2QdWlirlWub1VBjlICfC+9On3SLk7v8VM2N0/xhyiN45csKS+jGb52nPB/30L8zQ== X-Received: by 2002:adf:e789:: with SMTP id n9mr20176237wrm.211.1605097711923; Wed, 11 Nov 2020 04:28:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n8sm2214470wmc.11.2020.11.11.04.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:31 -0800 (PST) Message-Id: <91ded2fbbe7197d8ad46005ff3eadeb2a5a69e18.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:21 +0000 Subject: [PATCH v2 08/11] add -i (built-in): use the same indentation as the Perl version Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When copying the spaces used to indent non-flat lists in `git add -i`, one space was appended by mistake. This makes the output of the built-in version of `git add -i` inconsistent with the Perl version. Let's adjust the built-in version to produce the same output as the Perl version. Signed-off-by: Johannes Schindelin --- add-interactive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-interactive.c b/add-interactive.c index 9126684348..c298a8b80f 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -1137,7 +1137,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps) print_file_item_data.color = data.color; print_file_item_data.reset = data.reset; - strbuf_addstr(&header, " "); + strbuf_addstr(&header, " "); strbuf_addf(&header, print_file_item_data.modified_fmt, _("staged"), _("unstaged"), _("path")); opts.list_opts.header = header.buf; From patchwork Wed Nov 11 12:28:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EEF5C5517A for ; Wed, 11 Nov 2020 12:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33C1E2084C for ; Wed, 11 Nov 2020 12:28:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d/foLPxc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgKKM2l (ORCPT ); Wed, 11 Nov 2020 07:28:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgKKM2e (ORCPT ); Wed, 11 Nov 2020 07:28:34 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECCC9C0617A7 for ; Wed, 11 Nov 2020 04:28:33 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id c17so2315557wrc.11 for ; Wed, 11 Nov 2020 04:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=xkBYrD8bcxEnHBhLHEAXw4mp/SsWUlfPpyOGpP9cIBM=; b=d/foLPxcCNwbrAwuZwF39jOy/IPCSpiJ1MFxZQeUtRkEkEaaLwJfH81wImlrDAe5QS 2GcQ/z7mcgRIvCrPQoFoz006jRKUGlgq1Oe0oLU/nXAeqodE9Vl4ROBaXlZjBNp3vgRg 27f/wcXEdCENqDVL4l98/kvZun0P703hMh7SL8hrjo9rKXfECBUk3WaYNEcs0O1/u0cw syAX7bdsfNb4KR+/ths6UDkl0H9lbc4THtF/6n4gfQyponY4lQcUwyBUcJ/yQYFEHMDi QWAwzSyoYZqS7U4Pme2c5OBvtfJj6Ou1zXGhplPzcwFufPoplgxUsB1GwTeXJeCg648A qCdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=xkBYrD8bcxEnHBhLHEAXw4mp/SsWUlfPpyOGpP9cIBM=; b=BurIQ1A88rKDrP4Ks8WwbLr5SRvVQOYkniSP8GxkToBpRdhDBDlmwKNrVHmARfaQ4r SW3y8HRUQrcpbn2HgJW1kZGkxElcBAhDmEa7mx6PM0Xe5PIEGj1U4SBbyrUDyX2O65MG N4U9fh1/Za79icMYdkgiBhO0KbT2EE0+niZcfHT9weNdI2iqWcmy23XAv3irkt5s/4ae 03TsBRBSOJivQgoHkJ0HKbWUFVK2vmpmkLnAr78uGBHDB2VrAIZOwHp+fv4xCf74+gY3 4OqwclZ/WVUtGi8UxP+dclrG7Kcfr4nBomxQRiLXS6KGeTcp3PVfpzpHhDSIy03n3HB5 u51A== X-Gm-Message-State: AOAM5337XKBQNnVFYnIYeyXzU5TQY/fg+OfPzgyVDunAgg5giQMxw7Ii SBoTxyV1TZ31KQEVU75H3u8n856vxHo= X-Google-Smtp-Source: ABdhPJw1FC6hu/3SWyio8ByVs+gbFW+NcJr/sn7rsHtlgmuKweopn68BRWSfUWWIf26cIZxu4Tc4OA== X-Received: by 2002:a5d:4cca:: with SMTP id c10mr2499402wrt.372.1605097712619; Wed, 11 Nov 2020 04:28:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q7sm2536969wrg.95.2020.11.11.04.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:32 -0800 (PST) Message-Id: <304614751ea1b1db80fbbbdc909b3d198c20313e.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:22 +0000 Subject: [PATCH v2 09/11] add -i (Perl version): include indentation in the colored header Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The header is formatted by padding each column heading with spaces up to the length of 12 characters. These padding spaces are naturally included when coloring the entire header. However, the preceding five spaces indentation for non-flat lists were _not_ included in the Perl version, but _were_ included in the built-in version. Let's adjust the former to align with the latter's behavior. Signed-off-by: Johannes Schindelin --- git-add--interactive.perl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index e713fe3d02..adbac2bc6d 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -483,10 +483,8 @@ sub list_and_choose { my $last_lf = 0; if ($opts->{HEADER}) { - if (!$opts->{LIST_FLAT}) { - print " "; - } - print colored $header_color, "$opts->{HEADER}\n"; + my $indent = $opts->{LIST_FLAT} ? "" : " "; + print colored $header_color, "$indent$opts->{HEADER}\n"; } for ($i = 0; $i < @stuff; $i++) { my $chosen = $chosen[$i] ? '*' : ' '; From patchwork Wed Nov 11 12:28:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50D81C388F9 for ; Wed, 11 Nov 2020 12:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2042207BB for ; Wed, 11 Nov 2020 12:28:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vgOSM7Gd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726769AbgKKM2m (ORCPT ); Wed, 11 Nov 2020 07:28:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726722AbgKKM2h (ORCPT ); Wed, 11 Nov 2020 07:28:37 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8095C0613D4 for ; Wed, 11 Nov 2020 04:28:36 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id c9so2074937wml.5 for ; Wed, 11 Nov 2020 04:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=fWhYFLm87UYuCIjPFgBzbh9jSW2xTQmwaysBZzk2pPU=; b=vgOSM7GdJFI/edG9ytpa6fHyi70JclBo/2dy70/JkU0AZzXBJxn6LZjOGs8ZA5/Vdy DyrGc36c8fTPloXLhGbtgqRWw8OOekCwELkfIQLCVZA0rbiWoHI1BKfv0owfIWWo7ZER 3jjVe6RYS11nMpU0TM7/RrqzwiwFUmbX7KBz5ZaQWBx0zr28a+ma6ZwQFnYn/PvGgtMP 6Lo6ZrKGfusclMJZWdaK64VPXAYR/J2vWnFk1Ocl2XHvVDhxYISRlu0Hbww2OnjmVbd2 Y7oGx8aO17WE/FfBr9GOHc2+MI3AT8tNHydvSegpYJBwm0Keb1cRjwcKM2aV/JsRUmxt rxIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=fWhYFLm87UYuCIjPFgBzbh9jSW2xTQmwaysBZzk2pPU=; b=BvqbcFRiBe0DBQVvlJMwxolsvRnyulOIyvdL+N8HoiR/wlN5aYB9KtSagtFGICrIg9 iPknY/j6m9xiIBsMHP2PZOuTJEl3jIm167IhFb6qFf1dcMPoocZ/MEzJoHxHo2Qpsp7L uSfRr6soQlLf7KFwEVWEYS2j7IzgrDQNqulhEpNcBT65S8ilAiyxxqsy4Mos+R6jxxVp QcNdtCsryDovdBuhOXbklcoCImFNg+N2bN7wl7Mooe3dw+7SeAqKuARVP/8RQoAUM7Oy QjgswdKK/BQtR7KK3oqoSo6jFPwEl2EsvDr0rhiA7x+4O6A8rWN+cdd4Qtr24J0wBad7 g8dA== X-Gm-Message-State: AOAM530aywktKBlfOjapqYBl0J5ldNIHE82gWC3xdUolDitGx5GXwqLE PYkF5kDtguQNMgQ9BMpw30zkVk2Ovho= X-Google-Smtp-Source: ABdhPJxKmSaEFmeNy1E+2v16kxrH8PafjhMR2y2Y/o08C9rcB3sle7tzPAvUaHt6FCrrAxcRzfQJNw== X-Received: by 2002:a7b:c4c3:: with SMTP id g3mr3699067wmk.127.1605097713387; Wed, 11 Nov 2020 04:28:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f5sm2392130wmh.16.2020.11.11.04.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:32 -0800 (PST) Message-Id: <48d8e0badfec5f0e576868f7a406ed7ede6c7200.1605097704.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:23 +0000 Subject: [PATCH v2 10/11] add -p: prefer color.diff.context over color.diff.plain Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Git's diff machinery allows users to override the colors to use in diffs, even the plain-colored context lines. As of 8dbf3eb6850 (diff.h: rename DIFF_PLAIN color slot to DIFF_CONTEXT, 2015-05-27), the preferred name of the config setting is `color.diff.context`, although Git still allows `color.diff.plain`. In the context of `git add -p`, this logic is a bit hard to replicate: `git_diff_basic_config()` reads all config values sequentially and if it sees _any_ `color.diff.context` or `color.diff.plain`, it accepts the new color. The Perl version of `git add -p` needs to go through `git config --get-color`, though, which allows only one key to be specified. The same goes for the built-in version of `git add -p`, which has to go through `repo_config_get_value()`. The best we can do here is to look for `.context` and if none is found, fall back to looking for `.plain`, and if still not found, fall back to the hard-coded default (which in this case is simply the empty string, as context lines are typically rendered without colored). This still needs to inconsistencies when both config names are used: the initial diff will be colored by the diff machinery. Once edited by a user, a hunk has to be re-colored by `git add -p`, though, which would then use the other setting to color the context lines. In practice, this is not _all_ that bad. The `git config` manual says this in the `color.diff.`: `context` (context text - `plain` is a historical synonym) We should therefore assume that users use either one or the other, but not both names. Besides, it is relatively uncommon to look at a hunk after editing it because it is immediately staged by default. Signed-off-by: Johannes Schindelin --- add-interactive.c | 6 ++++-- git-add--interactive.perl | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/add-interactive.c b/add-interactive.c index c298a8b80f..54dfdc56f5 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -49,8 +49,10 @@ void init_add_i_state(struct add_i_state *s, struct repository *r) init_color(r, s, "diff.frag", s->fraginfo_color, diff_get_color(s->use_color, DIFF_FRAGINFO)); - init_color(r, s, "diff.context", s->context_color, - diff_get_color(s->use_color, DIFF_CONTEXT)); + init_color(r, s, "diff.context", s->context_color, "fall back"); + if (!strcmp(s->context_color, "fall back")) + init_color(r, s, "diff.plain", s->context_color, + diff_get_color(s->use_color, DIFF_CONTEXT)); init_color(r, s, "diff.old", s->file_old_color, diff_get_color(s->use_color, DIFF_FILE_OLD)); init_color(r, s, "diff.new", s->file_new_color, diff --git a/git-add--interactive.perl b/git-add--interactive.perl index adbac2bc6d..bc3a1e8eff 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -30,9 +30,9 @@ $diff_use_color ? ( $repo->get_color('color.diff.frag', 'cyan'), ) : (); -my ($diff_plain_color) = +my ($diff_context_color) = $diff_use_color ? ( - $repo->get_color('color.diff.plain', ''), + $repo->get_color($repo->config('color.diff.context') ? 'color.diff.context' : 'color.diff.plain', ''), ) : (); my ($diff_old_color) = $diff_use_color ? ( @@ -1046,7 +1046,7 @@ sub color_diff { colored((/^@/ ? $fraginfo_color : /^\+/ ? $diff_new_color : /^-/ ? $diff_old_color : - $diff_plain_color), + $diff_context_color), $_); } @_; } From patchwork Wed Nov 11 12:28:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11897525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0462FC388F9 for ; Wed, 11 Nov 2020 12:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92719207BB for ; Wed, 11 Nov 2020 12:28:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bTdtkYzP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbgKKM2r (ORCPT ); Wed, 11 Nov 2020 07:28:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbgKKM2f (ORCPT ); Wed, 11 Nov 2020 07:28:35 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92863C0613D1 for ; Wed, 11 Nov 2020 04:28:35 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id h2so2128968wmm.0 for ; Wed, 11 Nov 2020 04:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ZZUqMQkE4pHLIgP6YPbr6smpy1FSBQAOH0ZoELDA6jk=; b=bTdtkYzPXOn53jBF9UIxbV7LQB+SNc6OEBVSev0zgrSnuHvBoi/c2ikx2c5876lbWR uIfLJSlkKpPQrzX+hXGsG6whcQHB0tpWSxfW7f/uBY+81h0s4zdvm4QSMlyprS+FNWx6 84qKpVarRK8olvw+dh/Nm1K8ksnq+XFs5GsMVu4n3szQDH5WsdW+4S3+x5cqvyjS2Hfs p5TmnqbRdIl+oNUarV6uhRhL1M05ZbVurhCfYOILmvlNWnyxWklyNaiC4D2ID66qalkF XYhbhzfnq9hAhmglko2yHKKQHzHx+9UVsNMgVLtU0eaVhzwVDYvlEzcyCLdTncvdfFi9 YDIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ZZUqMQkE4pHLIgP6YPbr6smpy1FSBQAOH0ZoELDA6jk=; b=rRVUKuptFEFw2SPzuFe5XyBUFfTtCjCeaxPCeMIJJh3z8EJdxzY1Sglel6efvCjcKy S+1uiz/lFH9W/o/3re5wDTbnAAoYgODakVCJEYXluPSZyrJiQM20ibNsQibJyyuhAQoX +y9w+Z7wIUTBhOAn4GSnzUAvQUJgkot31Jm3TU9IYzPrA75s0qlTlt05rV5+LQkhzHuk gNyWrlGbrlf4IEVO+t6S1sWDbgQhkyyNsfsHncM0RUf81lbvX8fsJrXYlZXHSJ12QtSd V9iIHX4sHyc/aa9LDGb+0AxMiKxrYP3IKSZMN/On5bLQ3p3TTeLrxPNXaohfAJQscGzf h1iw== X-Gm-Message-State: AOAM530OjfCKMcofqUBdQRbbKHvcLThzRSItDKNTn2BoIp3i/Zu2jowR U7C8d2OKhlHnC36etD5iHco8dTUtViQ= X-Google-Smtp-Source: ABdhPJyr5QCn0R48HrQ23k7U3LfTJuAmgiEUpcFzrycH5Rbn3f6VnFq/bw1p4qjvF9zqNOpWWlY5wQ== X-Received: by 2002:a1c:7e8e:: with SMTP id z136mr4013338wmc.46.1605097714104; Wed, 11 Nov 2020 04:28:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g131sm2531486wma.35.2020.11.11.04.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 04:28:33 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 11 Nov 2020 12:28:24 +0000 Subject: [PATCH v2 11/11] add -i: verify in the tests that colors can be overridden Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Now that the Perl version produces the same output as the built-in version (mostly fixing bugs in the latter), let's add a regression test to verify that it stays this way. Note that we only `grep` for the colored error message instead of verifying that the entire `stderr` consists of just this one line: when running the test script using the `-x` option to trace the commands, the sub-shell in `force_color` causes those commands to be traced into `err.raw` (unless running in Bash where we set the `BASH_XTRACEFD` variable to avoid that). Also note that the color reset in the `+new` line might look funny and unnecessary, as the corresponding `old` line does not reset the color after the diff marker only to turn the color back on right away. However, this is a (necessary) side effect of the white-space check: in `emit_line_ws_markup()`, we first emit the diff marker via `emit_line_0()` and then the rest of the line via `ws_check_emit()`. To leave them somewhat decoupled, the color has to be reset after the diff marker to allow for the rest of the line to start with another color (or inverted, in case of white-space issues). Finally, we have to simulate hunk editing: the `git add -p` command cannot rely on the internal diff machinery for coloring after letting the user edit a hunk; It has to "re-color" the edited hunk. This is the primary reason why that command is interested in the exact values of the `color.diff.*` settings in the first place. To test this re-coloring, we therefore have to pretend to edit a hunk and then show that hunk in the regression test. Co-authored-by: Jeff King Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index ca04fac417..cc3f434a97 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -589,6 +589,90 @@ test_expect_success 'diffs can be colorized' ' grep "$(printf "\\033")" output ' +test_expect_success 'colors can be overridden' ' + git reset --hard && + test_when_finished "git rm -f color-test" && + test_write_lines context old more-context >color-test && + git add color-test && + test_write_lines context new more-context another-one >color-test && + + echo trigger an error message >input && + force_color git \ + -c color.interactive.error=blue \ + add -i 2>err.raw err && + grep "Huh (trigger)?" err && + + test_write_lines help quit >input && + force_color git \ + -c color.interactive.header=red \ + -c color.interactive.help=green \ + -c color.interactive.prompt=yellow \ + add -i >actual.raw actual && + cat >expect <<-\EOF && + staged unstaged path + 1: +3/-0 +2/-1 color-test + + *** Commands *** + 1: status 2: update 3: revert 4: add untracked + 5: patch 6: diff 7: quit 8: help + What now> status - show paths with changes + update - add working tree state to the staged set of changes + revert - revert staged set of changes back to the HEAD version + patch - pick hunks and update selectively + diff - view diff between HEAD and index + add untracked - add contents of untracked files to the staged set of changes + *** Commands *** + 1: status 2: update 3: revert 4: add untracked + 5: patch 6: diff 7: quit 8: help + What now> Bye. + EOF + test_cmp expect actual && + + : exercise recolor_hunk by editing and then look at the hunk again && + test_write_lines s e K q >input && + force_color git \ + -c color.interactive.prompt=yellow \ + -c color.diff.meta=italic \ + -c color.diff.frag=magenta \ + -c color.diff.context=cyan \ + -c color.diff.old=bold \ + -c color.diff.new=blue \ + -c core.editor=touch \ + add -p >actual.raw actual.decoded && + sed "s/index [0-9a-f]*\\.\\.[0-9a-f]* 100644//" actual && + cat >expect <<-\EOF && + diff --git a/color-test b/color-test + + --- a/color-test + +++ b/color-test + @@ -1,3 +1,4 @@ + context + -old + +new + more-context + +another-one + (1/1) Stage this hunk [y,n,q,a,d,s,e,?]? Split into 2 hunks. + @@ -1,3 +1,3 @@ + context + -old + +new + more-context + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? @@ -3 +3,2 @@ + more-context + +another-one + (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? @@ -1,3 +1,3 @@ + context + -old + +new + more-context + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? + EOF + test_cmp expect actual +' + test_expect_success 'colorized diffs respect diff.wsErrorHighlight' ' git reset --hard &&