From patchwork Mon Nov 16 16:08: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: 11909669 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 4A3F9C61DD8 for ; Mon, 16 Nov 2020 16:08:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CB1D20729 for ; Mon, 16 Nov 2020 16:08:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZIFfmU7X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731635AbgKPQIg (ORCPT ); Mon, 16 Nov 2020 11:08:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728858AbgKPQIg (ORCPT ); Mon, 16 Nov 2020 11:08:36 -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 1B1A3C0613CF for ; Mon, 16 Nov 2020 08:08:36 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id 23so19238413wrc.8 for ; Mon, 16 Nov 2020 08:08: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=js8oUsMHl21kgw69PYKoHcc81MiST6F1XqDnN0kNdcM=; b=ZIFfmU7X4eeH3Itq/a2AXgbmYbsAgRJSJDbp2W5f08pSF5nPjjuhBzNo6PYgnkiOKZ iD56OS4Yaxbw/XC/xdk6/Xsvjvi6Q/kJi0hO/qLrT2NXXL0NQl2ZFpWsQIJoJ5LixNlw 3CJEslG92swnCLT5YBvwSyRfgC+ZJB1hPsziENfHrgmQZ7edwQKWDw7INYsUIUHsGzqq SmmUp969VpD6hszIxLnuBIvVicg2n1jNQLSiMwZV4MMnBMGOveSkn0fwTTKxpG7w0Cqj GTlGUASbDDkGT5Xhq1e2Yw1JM0zQcbcPikpMQo6JBTpeWnHVsN6CMJncvzE7+RYxRgtp PX6Q== 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=cnkgQ7Pnmei2x6YA9Fgd/Ky+UkzaW2s5f8dDGZxRdetsmk1Vp/lurZAdQkxywXOJq1 JQPoVC1FQzmhBvuB3Ldf928LDeNz73/cWNPUXzzXntNjVXc6e3kpI/P6oYkI/1i1ZINJ WzjHMPvX++csqFvZ1lOmsBcd25n2mAmgNekWOmPdO8g7rFN1i16OCNhasQNiyv5UnFLK I5dChzKM2/JNjxH7N7RFd9i7WvcSjkDp/xQUiVp45jkV9Wa5XPIWd7XoEwcN74w/XsW4 SWzIWP/gEJyra2inx8HtEuUC5kUQUUN+HN0ZNrHWFgzqBYMl4d0KNj5ZX+DHF5CTY+D2 2M2g== X-Gm-Message-State: AOAM533iXhZ+TkgvZKax1Tnjz1CJpjAQpoBYDmyqQmIt/5EWkjBNuKKJ k8srunpmisDin2WydgHcLGpGTgGBYJA= X-Google-Smtp-Source: ABdhPJxAnmhb6Uwt2ECP7kBVYAU6AeCVAULzlNW169/nfy8Hcc+hjTvqnWQoH0yZ2Bs1S74N2JK39w== X-Received: by 2002:adf:fd85:: with SMTP id d5mr12265895wrr.99.1605542914713; Mon, 16 Nov 2020 08:08:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o197sm19720452wme.17.2020.11.16.08.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:34 -0800 (PST) Message-Id: <6152122c04aacf8c3e3f1aae7b73995da6b9e354.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:22 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 Mon Nov 16 16:08: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: 11909681 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 6A1E1C4742C for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30E1020729 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FQWBBcdw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731663AbgKPQIi (ORCPT ); Mon, 16 Nov 2020 11:08:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731658AbgKPQIh (ORCPT ); Mon, 16 Nov 2020 11:08:37 -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 09D86C0613CF for ; Mon, 16 Nov 2020 08:08:37 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id h21so3329094wmb.2 for ; Mon, 16 Nov 2020 08:08: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=dpll76Bt0FuWoTL59TONqXQ0KGL2T+WUdIsjig1jOUg=; b=FQWBBcdwKCARAq/cLY0Ed5g/F+XkhkMo/bNDPJgxX4md/xpgy/bAaEbWb0q83NhySV cc8euxmPgvefEPfYPgxK6Vih1WlyIKblfUneB77HfM7MEd7B2Tym2GxWK5rPF+aAozPj Riff2Tn+RclBJLT9ixAbRqUyw8JTUf9FLJMJX/9tMmouv6XBnmCVfIf8W0a99o2jqaTO JAl0Cu7GMgpKEIve28IGLuq7swJbCi6s22KhtSuE56F04OTEAPDCaqPj4FCHwEJdJQIG wh4OVFynccDyqzC6IYrG/uUFXnoBbEiOZPerbkyVVa4bKNGNRMFjTYy1NhT7qh5ruPHr Xf/A== 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=UdCamG5OjvQ744bvrhfs8kzKiFKc1LXnFEC1baxCqJ69SlQTyi+Iqj8pD63Rz3ameb UpUlCKtSbZ3C2mh3p6QAwQ+5qJ9co0x9fkzMtmEuyhHUXhVhuPcvvJomMzxCMkLTKmej x8m0hlbcaQ9ehz7ex3h37znr4hEJWxjguvA1LH18qmmCPsR9TQGj56CdaatTSHgM90Qf f4X9PFqguVroM69JNdRHzP+++dbvsBefW2kuoiAKlwXYbkCMU8G1fnP9pngLzz13madE QC/51hU1XGVzrnhYVfougVmBJLSjV5lGQgHaOm+Xr5v3NCTL80rDKm6eTeR4lslfyLb2 UCow== X-Gm-Message-State: AOAM530iB0Z4zdJZei/aK8O7wQn3sbvPb0ZhF8LfQXQczdSPj1H/Hx2y 1u7lM9CmkbHCndr9RsOphbx+GTkmIic= X-Google-Smtp-Source: ABdhPJwL5ANPWD4SMNw26Z5WriL9Y7TEd9ZhWQqZu3cS9ilWZ/X0tgXNZ8KRjWkyIngJsog3+K36uw== X-Received: by 2002:a1c:93:: with SMTP id 141mr3353897wma.52.1605542915617; Mon, 16 Nov 2020 08:08:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f18sm9747811wru.42.2020.11.16.08.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:35 -0800 (PST) Message-Id: <068813912b9e5133f9d9bbacb239f7954788bf53.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:23 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 Mon Nov 16 16:08: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: 11909679 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 91BDDC61DD8 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56B8A221F9 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sVmvEjOr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731691AbgKPQIi (ORCPT ); Mon, 16 Nov 2020 11:08:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731658AbgKPQIi (ORCPT ); Mon, 16 Nov 2020 11:08:38 -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 F34EFC0613CF for ; Mon, 16 Nov 2020 08:08:37 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id l1so19252142wrb.9 for ; Mon, 16 Nov 2020 08:08:37 -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=sVmvEjOrfiQ72g4ptzgbVRwIktv2ALrkds1QgWASNCYKtYPeJnziWQ5JgvokPx8e7L E+cl1vMufRsN0SuF+B9p7/PV8hKc5Mbd2ImQSewfbbA+/MXmrHXv92wsyGuRJ29HxjDA MMSJIq6bM0AAUxxfsMoCRqr17Mpfc6rz5+wxY3kcY8KnwCX40xJ7mC+bM+31/5sCm+yt K9zH4MXG0MW/9Xai0dMTVYX3wl9zfz8AmzsQAT+gYY/aqZiCnei7fXKuI8u2DamOs9jE v3ocGfs5bbxYblU9YWK5gVM0SUTgmnYSZukB5NX9pQwlW5RyqwRfYThxasofNm/VxZ5m lBwA== 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=XO+5ihtgcq6EuTDesezelxXpjwKdxOcC8hwQGSDgFniIokoGlxF7YEanJCaYdwfJgM pkBqiKdG0GV03uZt/e65DrNujk//L9WlY5GGmB1ICG+DBFORB3jyFUfYXJcFObyxvaEu yUGPV42HuRSVu/FujHAvhTFENko9HiKxR867wcn/6Z4ua961+ZjvY8P5oOh6okKnPqeP C0yELdGgHYjnPpzrM7Qqe2trPWVV/0KCyc+638CkMQqPP7v6gbaxtv5b9Y5w+zn14gvR uOUoWuep9a7xVUqpl2XpyN/6Qhckd2AmJJN0Jl7oT3k+L1DHnFiunr/4G7z2TGq+257p zcNQ== X-Gm-Message-State: AOAM530E4pNqv0/jvT4gc08TrbckT5pDChKmyLE6+KWHswmUuEOq7PGh /jr2S7/whyodKYW2FoPOTFEVzDELwn4= X-Google-Smtp-Source: ABdhPJwMduVXgsGH+XeWyZ6jK9MGUOSBJAz7P4DtfPzMcqqfXX1ZRD+r5QRqbCIWeoa+Yo/ggmZ0Jw== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr15930655wrv.29.1605542916574; Mon, 16 Nov 2020 08:08:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k3sm3349509wrn.81.2020.11.16.08.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:36 -0800 (PST) Message-Id: <98deb538d91ba0ab485fa8d97cc6062bcc680938.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:24 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 Mon Nov 16 16:08:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909683 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 B4840C5519F for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A90A20729 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JxiyaF+M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731695AbgKPQIj (ORCPT ); Mon, 16 Nov 2020 11:08:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731658AbgKPQIj (ORCPT ); Mon, 16 Nov 2020 11:08:39 -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 D3F8EC0613CF for ; Mon, 16 Nov 2020 08:08:38 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id s8so19244111wrw.10 for ; Mon, 16 Nov 2020 08:08:38 -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=JxiyaF+MT1qlLD4RBZZLKCpM7RECE/A13cPVRMLLrwO7RIQbK2ruugT/isfR8cQaYy ynbcK5UrQocqFRmcfqIXIkc5jVg5pJxEhPbliwkFtiXKg7GzzB2ijeMdwZCCClYJqnxj r0J6vo0sTniYzM6q7KA4UfxexPs2V2A3AOJ41t/Xx/C1dGADm6t7emFNGKOxMz4z3cAy v1AmPOyYhFpNj5MKWHYX8i4vjBLU28q8FHJkuCkNjODIs4X3hacKmte6eQFI8jUm/OET WFLUY2ReEw1n8so7cTrlBVTF1tEKq2KsDDlfJkTTAjn2lgRWF5HCxhiI4DtJl2PSZt+o cuwQ== 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=ESruqPADWY2vB0YJNGCCYUQAcR9KW6kjG4cSCfoLYhPYSDKl0ip4otmmOSwwoOYrue PiQGKFZiU3pkEZYPLfoCw0auB3ym3DqZiZ6ZDf+ebN7WztsKKVi0GEz+EdeUek7oZ62V RoG7nIRDcGQoaf7r+e2wgOW6puHxlkaLB1qiOtLpsMf41wQ90/U903NKNYogdN2MDYya n38PQ8OMu6hUKTFTtNCaa2nCMMnbF+2CMnTaoXkMqA/VwYLsoGIqNBu+7ajFYQiPoUbv K2NnVGig2/37Iw5/N4FHT9F91mJs4Q7dTj9qeXoPLYGED7C2rFQAbVMWxhwQrPq6sAsO Kv7A== X-Gm-Message-State: AOAM533ylEe4NTQMbnKyRNr4BBDuThQnhVVKA3RtiX0l8/A9leoIhXwY FTy8AK5YxtDLnzTIly9Vo8bHMDvlS5g= X-Google-Smtp-Source: ABdhPJzzThqnOpVde1YUomNpii1L/l2D5f866VluYqPcjFXuYu5ysiKgMm80csk/d0XXq0p2yqQXIQ== X-Received: by 2002:a5d:44cf:: with SMTP id z15mr19886479wrr.353.1605542917528; Mon, 16 Nov 2020 08:08:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v2sm23011170wrm.96.2020.11.16.08.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:36 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:25 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 Mon Nov 16 16:08:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909675 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 DE8DBC63699 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4125221F9 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vhU+sIOy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731701AbgKPQIl (ORCPT ); Mon, 16 Nov 2020 11:08:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731696AbgKPQIl (ORCPT ); Mon, 16 Nov 2020 11:08:41 -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 97704C0613CF for ; Mon, 16 Nov 2020 08:08:39 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id r17so19294962wrw.1 for ; Mon, 16 Nov 2020 08:08:39 -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=vhU+sIOyivkFmIVtrwYZXHEBtZBZruPFG2lT4ZfKpaqfxoV2E6MwsQhz91DCWsogtx 96M52ySrjk7sbsPoswYsDznLakmIzQjqp+q4gLeqEVxz4YawEr/S4AJoI30HkdHZO31Z 39S4rYiy90/TPlfX1A8aSlKdlreylsJqzZiu1FDymUtWfTgcunu1zbXQj/7fzvBEFdkf E1NcVDBIUADeBiQS4a7OEFmnsGOFBx7ILQgA1BQhapsLQVZqnzpra3PGNi4vAHJwHdrO Wxas3uD8N7AiBGYrMuzwmWXmtMh1ID4k58KDg+BLQON8Tkl+cuBaw/K1kGhtnzaxqHCh 7xzA== 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=BVISMQywvokaZY0/bxihZGbqELEtKO40dn8P16OqUa1w7SY4MKVOHIkF/xRC2LyyFw R+76o8Amu9wBwvzEXmulGV0P8dowUbFC99F1ino7zN82xjuIjIxGTNXLr7h0g8wGK4Rr 9/JnTQFdU9Uw5MVas26ff6rSbYYjKq01itl0VbUrImNKciQkxFiRIfqYvfXZo4zQC34l k3U/tmM8r7atB7KhWnPdRBYhFoNTzBnrnllgsma+8OjomKzh5dVl7XWxq8SoNgzA9wmI kiBSsWkulORim5IDNgIRUovXdGWZsRmusd4F+Q6YP9KOyed6cnxevl7/JQnsvQf+Qzih laCQ== X-Gm-Message-State: AOAM53362VnDUCwdC7Mb95SVC/4CVjLig8yFxfSu5WjWp6he8Vyk5Iv5 VU0M6guOo26bxPPW4Az00nEBvMo2D18= X-Google-Smtp-Source: ABdhPJxAwpKLZxOOpkI7lihTQ3EOGD7nYb3x9FPq2ya874qDGTRvhn/wiDbLw2oBPRxPy5/A4mb3zQ== X-Received: by 2002:a5d:66cd:: with SMTP id k13mr20146127wrw.365.1605542918277; Mon, 16 Nov 2020 08:08:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m3sm19422006wrv.6.2020.11.16.08.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:37 -0800 (PST) Message-Id: <337b45cad8b876e1811099f398bf0a05ade21acf.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:26 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 Mon Nov 16 16:08:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909671 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 3B28DC6369E for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3121221F9 for ; Mon, 16 Nov 2020 16:09:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QZcQRcPp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731704AbgKPQIm (ORCPT ); Mon, 16 Nov 2020 11:08:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731696AbgKPQIl (ORCPT ); Mon, 16 Nov 2020 11:08:41 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF01C0613CF for ; Mon, 16 Nov 2020 08:08:41 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id 23so206721wmg.1 for ; Mon, 16 Nov 2020 08:08:41 -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=/1KLgV2xLIpkunGyPrrCfBxphaLP2gFzSlc7IzvFqQk=; b=QZcQRcPpx1nfUheI61X6Q8m+SYmRNiZ9CUair5twlaSBdYc5VBUcjAuSZax2J1p1cV +v/I/BsHn61ouAjdHur9W3K4GFpvhtjmkgKH4wSbQ3KA8Zs0MbX3WFNMeSNa0I/T9tNd g0uKduw6nnd3XcgCQ79ZGcphpfOn3qcwfNkQlJSQTltVS007tuVUHrC4Zd3oNr+sJ+Q2 k572o6G6YNBfjQBn76FiMEroJltfZumFtIjGZ0tITuTI4MNglGMec1aAwuSIRdRZuCkL zE2qTQEy4u+cYR25OLJBaoQNxhLU4x0g2nHM1Hncx1Q5krDMgbwlP27SOk2OBtXgZXIj rSAw== 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=/1KLgV2xLIpkunGyPrrCfBxphaLP2gFzSlc7IzvFqQk=; b=LWZuf6kXtaxNirK2SRmpcENLc/sJNB+6zcr+7ozNm+xQzBW1TVO/WuYMl9ym5qXZBS 8M0rBxjJviqHLWrhoABSNYdW1P4JioFI4f1f09I/1k1zxm2FCps7XAYjHgxpGG7iWeL5 Cn0RZjIJ3iJyQeqDj481jGcGvZsrQgxWzJIm4jH3stwTSG7fP5jVfoQCuWTBXSu7KXXL xWfw+kHO9lTyfz3vzrpPEPFyI60spl8JK11bjCAs2MAwN/G4dVbdKTsZmTWaKjEIYT38 vzt+dvbpEWZg7assnAU3+dR22Xj1tXbPpgsH2sQm0QB1VimlZ66p64MbIaIVzle1QnAv lNlQ== X-Gm-Message-State: AOAM531uD7xCGj0A9cjJGa+lhPqYCF1K0hngMwlaoMQKkFFdmEr0YcID cV2h5DefYWZJRSbP0/91DZtbY65CJIE= X-Google-Smtp-Source: ABdhPJxOVzy8GK2kRZQZXQeM96VHz9KV5FwiHE1WOqu6WTvaKRKGIB2j3TavuzSO9vyXnQYpY3zkkg== X-Received: by 2002:a1c:2d93:: with SMTP id t141mr16272443wmt.104.1605542920222; Mon, 16 Nov 2020 08:08:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r9sm25337197wrg.59.2020.11.16.08.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:39 -0800 (PST) Message-Id: <6a68bc5511a72d25b84a243dd5d8019f81cee610.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:28 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 so that the same upcoming test (which will compare the output of `git add -p` against a known-good version) will pass both for the Perl version as well as for 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 Mon Nov 16 16:08:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909677 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 611F8C63798 for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27FAD20729 for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TKLTo7E9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731707AbgKPQIn (ORCPT ); Mon, 16 Nov 2020 11:08:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731696AbgKPQIm (ORCPT ); Mon, 16 Nov 2020 11:08:42 -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 4BAF9C0613CF for ; Mon, 16 Nov 2020 08:08:42 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id w24so24098786wmi.0 for ; Mon, 16 Nov 2020 08:08:42 -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=TKLTo7E98m+TxRmHL+8anhQKoWj/NJnv2qadJWLPYj/7oRmxbYu6S8Zrd2RNlDRHnj t6DIXQdmNvZjGnvEgezvW/CAOnsRMNQf1JtqdipebCgjl4yeuJaSFaPCNB0RHoEwbuYG BEJQLnvqYvHNSGqz79pJbctZ+v41GWh9BVjJPPfDQH9SmyqRQnJPh5hDqc0NnPrTgtnR uTX+GGE1I9B+UdFxuz+0hIiphDk44xx+oeNPl8KJX3hjzGEZG5hcq4SvxCldI8LodQ9U MkXLCJ3FQ45kV7TVsJDlzzrJvvT+h4ylbt7SAxHK9XI8TDbz1ttYBFrdMQ66Tzp809bM aGQg== 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=VTglABCrsOUEMNWACET9US0vhgOwzYFmlN9Tz2yMOYc3UTMwH54QxxguyBplxu29Ys ws3i+MMBBz9mW98DbjnlpQ6dRREpexQiMtp8jVYHMaTzZLXTZl/wZxHsffBJ6k0kg+RJ RtEZJPhe4wC8I5R1u2ydlmTGQCgPDQI2ZD2kUNTCtJ7rSioZpm7STR1X1YQWxmB59Q+h wyAp+qw1nNFnPMr9DNwrX6ss7+sGI4JDtrIl0dgzrOsQLuGNot+602zl39OF+JL+tZ9j cl88GHdRBb137k6m9u2QnEA+CjB7H+Fn6QqSg2CgMKNIWEt3Wbp06NT9zKkJHp3Nxfgo z5IQ== X-Gm-Message-State: AOAM531nkQzFqPgzybMY/Oaqpvz4/FmPImncIn7a+FXJ9k9i4zyNijNj JcEpZM0+A1mz3kyjejjehJbaa0O2AQc= X-Google-Smtp-Source: ABdhPJzYrpQigh68ZfYnyX4QmzQ0WL9VAYBp49XsrzOWmhSX3IW15iNQYLnZKQnNUGmeRzeDDrV/mg== X-Received: by 2002:a1c:328a:: with SMTP id y132mr16012529wmy.134.1605542920953; Mon, 16 Nov 2020 08:08:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s8sm23621235wrn.33.2020.11.16.08.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:40 -0800 (PST) Message-Id: <168891f9f8b61f958b7a32ab2bb744563d086357.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:29 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 Mon Nov 16 16:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909687 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 850D6C6379D for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50337221F9 for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QQGpX5Yv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731710AbgKPQIo (ORCPT ); Mon, 16 Nov 2020 11:08:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731696AbgKPQIn (ORCPT ); Mon, 16 Nov 2020 11:08:43 -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 56D3AC0613CF for ; Mon, 16 Nov 2020 08:08:43 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id s8so19244393wrw.10 for ; Mon, 16 Nov 2020 08:08:43 -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=Z0intue/lSwO9yFM240zAhjoEqzGBf2u2fwvfA8xtN0=; b=QQGpX5YviIBltB9B1HSETMKJ7cPULX8nt1bCnvxB1jPx0B5e065BOowKVUqNLocMa8 6mzcmOkoOzeRAoeAJsO5PMsJBNhXOUy9OSnX6LJt1ySpbFc/hWnwEXvwEOBmBzEtspYT a47QXOKXwsKpzU4guSpsjZqgKY6Ox8DomHc2OpevvG/lkcldAnWm0j3vkGt24e1v/Y3p 1X56ojpCMgk8Jqz6WYi0Nofiil1pn9Tjz4DIwyuKMJY+INYUO0f/fvXGnRzESaO9dX6u wGJPfweARTyiBTBYg/eE4IYcXT9FmIT0w2iIqcsrkwj59BYnQn22ZYuJa6YjZOv4QjfQ O0Eg== 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=Z0intue/lSwO9yFM240zAhjoEqzGBf2u2fwvfA8xtN0=; b=VMG1Gg7FuC2eKim2uRnQCo9hHdxtzuVOiKwg6Y098rHVCSR9xcz81kj1eVObv/lYkU zIDmcPgvrvRb/SdOY5rPuaDO5SNxusRTvga1a4dVyCRHvKqwHck7PmqhZjI/kM5xbxOK cXhrhLDRpwAhbWtDVRr3ssJMCeMVWQBqKZiXyNwvWb0ymGtOgYQkNZ6GvXyrB6CQSapu aS8kAuW/uN67jpIbWFBhhyUdAiowWTiO47gWK18mSGJqOFjcVihP8PO2BQwL2E7onzqZ V7wRm+UZLlPtBeAtt45S4nQERCzjHQKmy2ssFK4kw2bgN04N8S4JUQNe+hvR6YtFotrf flyw== X-Gm-Message-State: AOAM530esQ+2R4trlU4MZEOLCFNuLqm9F9CSKC2JB5z+zhjCCci2mxju wkdbevn0RGbffkukK6WBEJe4wBu6dGM= X-Google-Smtp-Source: ABdhPJxBGcBA6I9yUXSRnKza1gzon6ozbjbCvzUt9HSiRcFtN9bTlTRd5pVHYcmz4sYna6dTAjo1gg== X-Received: by 2002:adf:9e07:: with SMTP id u7mr19237301wre.47.1605542921953; Mon, 16 Nov 2020 08:08:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e3sm6820210wro.90.2020.11.16.08.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:41 -0800 (PST) Message-Id: <094a4ad90ced8756ded9a225d2fd3886574ef6fc.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:30 +0000 Subject: [PATCH v3 09/11] add -i (Perl version): color header to match the C version Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Jeff King , Johannes Schindelin , Phillip Wood , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Both versions of `add -i` indent non-flat lists by five spaces. However when using color the C version prints these spaces after the ANSI color codes whereas the Perl version prints them before the color codes. Change the Perl version to match the C version to allow for introducing a test that verifies that both versions produce the exact same output. 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 Mon Nov 16 16:08:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909689 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 A4827C6379F for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7382E20729 for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qmINwcmG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731713AbgKPQIq (ORCPT ); Mon, 16 Nov 2020 11:08:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731696AbgKPQIp (ORCPT ); Mon, 16 Nov 2020 11:08:45 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23130C0613CF for ; Mon, 16 Nov 2020 08:08:44 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id p1so19230374wrf.12 for ; Mon, 16 Nov 2020 08:08:44 -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=Al/BEw1HlTzADw13DfXHg15dSSfmpzE7jxEGknssPgI=; b=qmINwcmG9abD2EDd1BqmuKGLGKNkNh+J6VLNJVC9kvusXwJLmT4crnKjxygKga75Wk xfEW+B7vY+LdqUe89kTECfN8E8Z0s2W7fSC6gqMB8zp+Fu8c9PE5CKla+5pNHobnYCkY PatviHc8IMjxzjPrCcOr2e+aRr+3CgCEL/QHaYsuzV08QE3OGB7ecUYPZtrhU2TnzuW9 M9CHdfngqGzkOLXaB/PHx/M88KKs3KhGojU9f5JqflX13jpQ/dP+ncVjOxfusopC08pl Vzif9JnBvxwT1wMuWqj7RkD60MiY3gyD8dEiuZ0w8o6pv++nefp5Cd2U98TPY9Bjewu4 f0BA== 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=Al/BEw1HlTzADw13DfXHg15dSSfmpzE7jxEGknssPgI=; b=YNILqUVNss4AyG0br979PYfwfiIpLgMCeYAEVusZZT2DsXil+VXzquNNchfsiHtDdX PC/H0MgfFqrRggtVw8TXjPPK9qmoPVRPHqsuA05RG8FFdEg3B1g1wtJEE6zr8WNA4tNY SVbqnncm1mv/q99tS2oFuMO4JpnNYkw2jX1MGb/44vBBnawFGVv6J8gSPFHck3SBJI4J 6p/LLNOPLG+uImeDaUlC7Z2X59kXQtOVz4rm2q98VzDRayaFHIoZJrVYTbtbq2uRmvEB 2LK2Sarx+8MUynhRHzduG2m7AnU3mJpGlpJh7hmY96XQDf243KASLEvzPF7RhQBY7Tnv 382g== X-Gm-Message-State: AOAM531WRS1CiAiDQH0JL38jDSMBrD/sLKzfCBiXOb4uQKL+Z/G1YJkE V2UAkoS8s/TZGcRjvrzsxdzLmZTHhSU= X-Google-Smtp-Source: ABdhPJzgNzyLa459Hzw/nJ/kznPo6d1een5CUGGrzaD/+GgwBqSpdOik3HusOHAy6xxivZ0yd/5Hsw== X-Received: by 2002:adf:b186:: with SMTP id q6mr21577577wra.53.1605542922774; Mon, 16 Nov 2020 08:08:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x63sm21410243wmb.48.2020.11.16.08.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:42 -0800 (PST) Message-Id: <9a4d2a33b50344e97e2bc47e5aeb0d3fcbc18a6c.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:31 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 leads 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 Mon Nov 16 16:08:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11909685 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 D1245C64E75 for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A87C221F9 for ; Mon, 16 Nov 2020 16:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q4fXo8Ur" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731716AbgKPQIs (ORCPT ); Mon, 16 Nov 2020 11:08:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731696AbgKPQIq (ORCPT ); Mon, 16 Nov 2020 11:08:46 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34668C0613D1 for ; Mon, 16 Nov 2020 08:08:45 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id l1so19252627wrb.9 for ; Mon, 16 Nov 2020 08:08:45 -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=q4fXo8Ur41fPR1ivbsjo2qAcGG5zSJ6KpssR3Ryp05el/UVRE8VjtnnhMKxfmreIkt gIWf5yGY194ylFQRs59emTrD5uD2hLjs4bCzdgvJaWKwkyEKWy3W+U1Wfk1ylyghP1tP DbIuju5tvyZX/eKz0Wyg4HNYslqQiIHmNK5lJcc+a/r6HicK6PPFk/SkPTGUbyrYRbFW Ng35wgpnNuwpJrxwcuITAfGLRLfpIMOj8htDMiEyWa4Ink6KCv+d5BpX0Hf+WHCoJL6t gckwUj40c0hGLxQ2WRV9ZtXBoQYMO1i0uM1bKBH8Is5PIXIIb2OZuQIxoPCx+p9CMCyT WiWA== 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=b8VKedrPeF99YwKFajGZj7HU6St2N73TITbYEBXE8g0Z4JZrxuhNep0MaqdDMkgT3S YJAuXjjkyuUnHfpW1w3EJnfnd/RCnD8RgcWypO/6ZLt/7XhVi8vSRwEAnvM5X6KXUl5h j/ZHWvIMcTtijS/iSJM6BfuIhdbTMUx8gORSVvF3cHnHx7Hiju08OXqP23MGG2sfN2OJ xlkuy56dDSdxN4DSkxNd2K4ZCrfVzL0RuTqyGUp14sKyMyRolUFDSh04niYKbYk5OKdR 5TKkk0PpYDXZcrOH4NUvFughDNXaMUtTWFSU9vWvy2OCOBU2ongoHGg7nPinRVZL2sUD R0Dg== X-Gm-Message-State: AOAM533U427B+2pPxbiEJHmy6CJMR/caql3YIX31KwsaiI81+f46Ic9E jA08EHEgqWGih+rkQSzVq+lF0ZojV8k= X-Google-Smtp-Source: ABdhPJzpfko9d9mncfT49ir+9j4nmm3Xkps77UQI3tNxOZPLjK6BzeHAzLmBGrypsmg/4khfFRKqag== X-Received: by 2002:adf:b74d:: with SMTP id n13mr3176658wre.101.1605542923706; Mon, 16 Nov 2020 08:08:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w10sm24099417wra.34.2020.11.16.08.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:08:43 -0800 (PST) Message-Id: <492f46833a3fee22cef4e1ecfb341f20b5471e9c.1605542912.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 16 Nov 2020 16:08:32 +0000 Subject: [PATCH v3 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 , Phillip Wood , 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 &&