From patchwork Fri Jan 18 07:47:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA4251580 for ; Fri, 18 Jan 2019 07:47:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D99C72A14F for ; Fri, 18 Jan 2019 07:47:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDB862A18B; Fri, 18 Jan 2019 07:47:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CBD72A158 for ; Fri, 18 Jan 2019 07:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbfARHrG (ORCPT ); Fri, 18 Jan 2019 02:47:06 -0500 Received: from mail-ed1-f44.google.com ([209.85.208.44]:35265 "EHLO mail-ed1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727349AbfARHrF (ORCPT ); Fri, 18 Jan 2019 02:47:05 -0500 Received: by mail-ed1-f44.google.com with SMTP id x30so10434226edx.2 for ; Thu, 17 Jan 2019 23:47:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=jWQp+OnjGGR/qjsHpDv/5/slcc6yYLWT9gs2Yk2rhoo=; b=K1b2Jk3fP4Y16b1Lt2WKjB2pqagKrg5mp+eEqM4p8GjhPejFf0JHhi6OZ29ICIertD 7px58X/x2WiTFM8ztM+Z8+BGGrwZbvyXSmbF/WAD0/btlZ5JhxOZ75rl9vhlYgXMMEjh CcFqfYLzuZA+gK+v14VDGa70kqoOAWuMWagKlbvhnMBsNi0ECuAe+dPS/G4GU0uCWsX8 K4ShcEg5dZpv5hP7bttG7rvQMoLaBgP3P/XeTz7t0b0UvNFeMrzSU3VgPKf0X4Na7GBW zjLvbZX5f/VGDEulYMGyelEzT7WQm+7FYjgKfJpGc65vUSapiLH8q9cIrlSnwduyovNc IY/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=jWQp+OnjGGR/qjsHpDv/5/slcc6yYLWT9gs2Yk2rhoo=; b=I0ph7zRUfYHMs35BhZ4xacUkcEy1x12eciwZehDXfdPBAO3Yl7FbmrkWoc5Ykuhp7E oS4HtARsIir1sf2ayovrw364PPd6LhEXyNQqS1d/Hb8bjVP3czzo2lkWGnNrd9cs8V4j dpdZHjQAtRSjPg4TYI6G0vuVDoupTdlrm6doaCYo9w4uGb3Y5uxOZ1KPWyxs9p4t+Skb sNED+WBvXFp/eLXeM+eiHd1++yYm9WzldSxjEYmcDhdr9++dfU5o2v970c515GTtJ7Pg gBVI2/gVhlemRviNfJzoOzGn89OD9TCsprGvOOUoQrQsLvgqlMTMQ0W/yR7vj3bKqVDD AEew== X-Gm-Message-State: AJcUukf5r8TQZkFFjYL250kTm3yqNGhAIVztdoRDD7unDxmYahLXXvqw d1HggK/8Y0yN4wFSXQXcLYLkIpmC X-Google-Smtp-Source: ALg8bN5oeQca+PgqpSlhOgYCxGCYc9Cwcu9mQo9nbpfye0yfpVD4rPRwx07unirOgOeX+W4KjxWVNQ== X-Received: by 2002:a50:8bc9:: with SMTP id n9mr14963193edn.41.1547797623276; Thu, 17 Jan 2019 23:47:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e51sm6893258edd.35.2019.01.17.23.47.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:02 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:02 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:46:54 GMT Message-Id: <737767b6f4e0367a7797020bd07a6b4357a47413.1547797620.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v2 1/7] diff: export diffstat interface Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Daniel Ferreira Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Ferreira Make the diffstat interface (namely, the diffstat_t struct and compute_diffstat) no longer be internal to diff.c and allow it to be used by other parts of git. This is helpful for code that may want to easily extract information from files using the diff machinery, while flushing it differently from how the show_* functions used by diff_flush() do it. One example is the builtin implementation of git-add--interactive's status. Signed-off-by: Daniel Ferreira Signed-off-by: Slavica Djukic --- diff.c | 36 ++++++++++++++---------------------- diff.h | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/diff.c b/diff.c index dc9965e836..46a7d8cf29 100644 --- a/diff.c +++ b/diff.c @@ -2421,22 +2421,6 @@ static void pprint_rename(struct strbuf *name, const char *a, const char *b) } } -struct diffstat_t { - int nr; - int alloc; - struct diffstat_file { - char *from_name; - char *name; - char *print_name; - const char *comments; - unsigned is_unmerged:1; - unsigned is_binary:1; - unsigned is_renamed:1; - unsigned is_interesting:1; - uintmax_t added, deleted; - } **files; -}; - static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat, const char *name_a, const char *name_b) @@ -5922,12 +5906,7 @@ void diff_flush(struct diff_options *options) dirstat_by_line) { struct diffstat_t diffstat; - memset(&diffstat, 0, sizeof(struct diffstat_t)); - for (i = 0; i < q->nr; i++) { - struct diff_filepair *p = q->queue[i]; - if (check_pair_status(p)) - diff_flush_stat(p, options, &diffstat); - } + compute_diffstat(options, &diffstat); if (output_format & DIFF_FORMAT_NUMSTAT) show_numstat(&diffstat, options); if (output_format & DIFF_FORMAT_DIFFSTAT) @@ -6227,6 +6206,19 @@ static int is_submodule_ignored(const char *path, struct diff_options *options) return ignored; } +void compute_diffstat(struct diff_options *options, struct diffstat_t *diffstat) +{ + int i; + struct diff_queue_struct *q = &diff_queued_diff; + + memset(diffstat, 0, sizeof(struct diffstat_t)); + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + if (check_pair_status(p)) + diff_flush_stat(p, options, diffstat); + } +} + void diff_addremove(struct diff_options *options, int addremove, unsigned mode, const struct object_id *oid, diff --git a/diff.h b/diff.h index ce5e8a8183..7809db3039 100644 --- a/diff.h +++ b/diff.h @@ -239,6 +239,22 @@ void diff_emit_submodule_error(struct diff_options *o, const char *err); void diff_emit_submodule_pipethrough(struct diff_options *o, const char *line, int len); +struct diffstat_t { + int nr; + int alloc; + struct diffstat_file { + char *from_name; + char *name; + char *print_name; + const char *comments; + unsigned is_unmerged:1; + unsigned is_binary:1; + unsigned is_renamed:1; + unsigned is_interesting:1; + uintmax_t added, deleted; + } **files; +}; + enum color_diff { DIFF_RESET = 0, DIFF_CONTEXT = 1, @@ -327,6 +343,8 @@ void diff_change(struct diff_options *, struct diff_filepair *diff_unmerge(struct diff_options *, const char *path); +void compute_diffstat(struct diff_options *options, struct diffstat_t *diffstat); + #define DIFF_SETUP_REVERSE 1 #define DIFF_SETUP_USE_SIZE_CACHE 4 From patchwork Fri Jan 18 07:47:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF92B1580 for ; Fri, 18 Jan 2019 07:47:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ECDF2A14F for ; Fri, 18 Jan 2019 07:47:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9310A2A18B; Fri, 18 Jan 2019 07:47:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 324162A14F for ; Fri, 18 Jan 2019 07:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbfARHrI (ORCPT ); Fri, 18 Jan 2019 02:47:08 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:34328 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727363AbfARHrG (ORCPT ); Fri, 18 Jan 2019 02:47:06 -0500 Received: by mail-ed1-f66.google.com with SMTP id b3so10466816ede.1 for ; Thu, 17 Jan 2019 23:47:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=6Y2WvcczK8cknroo/M285WWWCxDBVS1J4gBLizPfG74=; b=Txaonq5RtxxuWIHIAwRiMtVG53vFtIKCqysmc36AoNPVIHXrYI7jJH+vBj8KvrPdi1 l36dpl1Qq8aMZMheZH5oROV+Jxy8sTZK7/1S/bMJ6yZRU6/G4c5oDhR90pf6mLeZ1pGN jtB6fnMzaVYGw/PEmSPc8Aku0+TkH6zBQlnMKO8fCrdaEvBWhdwp5I4UxYtsPOPd2xNA id4OnCUUrc+Y+JH5iXqdYntgJNP5Hjr6OY0Tq+lvRoB73RwkTo8lI1pDcud4KFBirmuW 8kRdwRsJscnPTzKHYwBZ3i582jtZ7Zhoitqg/NHEKQ95Jajuye9dAVGvB08HfsJJlW21 zDoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=6Y2WvcczK8cknroo/M285WWWCxDBVS1J4gBLizPfG74=; b=GdAZKB8G5/x9nGjfJ8Q1sSc65UzX6G6lPaBqJbmXB3LuINfvNT6hE6gZb45eDAPRKo DYl689Edxkm1yhmb7PmTd5nxYkNyNrgEeqbn9ovU5Jhqymy2rEgRIVFez0TDFB7X4WCe PPhDLwB+/NYYojanZef4juORoJCCyPSfVvVl80RI28n9SDNZWEe7CFCKYX/FX+3oZxpR WUmsPkKSmtuUcmW9TI8BQfb+Otwl6Slzemy4LMRhpWwIQg2XAgqediGTgNuyb5g114z0 ZuhSc8L2AkqcWaUsG219dYIt5pDz5V1ebZ0RbipnYewbyGQLm4fSCQw1Ey9fl7hbCYbc C0BA== X-Gm-Message-State: AJcUukfyPB2HomiCowdXUzbuHslhJsq1NhQCJnxrzup71ET6+ViDPVQs 8URcu5mBACD4TNR/14U0ahiZby+i X-Google-Smtp-Source: ALg8bN6t8YEwuieYG19C0TMAgzxWfxDrhRDa2EwDS2rh7f7p+B5LOm+1qfwDqZ6/WI4AmfrmEm026g== X-Received: by 2002:a17:906:20c2:: with SMTP id c2-v6mr13645864ejc.241.1547797624210; Thu, 17 Jan 2019 23:47:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x38sm7124165edx.24.2019.01.17.23.47.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:03 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:03 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:46:55 GMT Message-Id: <91b1963125f7dfdd46fe5166125ee59ef2557b13.1547797620.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v2 2/7] add--helper: create builtin helper for interactive add Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Daniel Ferreira Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Ferreira Create a builtin helper for git-add--interactive, which right now is not able to do anything. This is the first step in an effort to convert git-add--interactive.perl to a C builtin, in search for better portability, expressibility and performance (specially on non-POSIX systems like Windows). Additionally, an eventual complete port of git-add--interactive would remove the last "big" Git script to have Perl as a dependency, allowing most Git users to have a NOPERL build running without big losses. Signed-off-by: Daniel Ferreira Signed-off-by: Slavica Djukic --- .gitignore | 1 + Makefile | 1 + builtin.h | 1 + builtin/add--helper.c | 6 ++++++ git.c | 1 + 5 files changed, 10 insertions(+) create mode 100644 builtin/add--helper.c diff --git a/.gitignore b/.gitignore index 0d77ea5894..2ee71ed217 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /git /git-add /git-add--interactive +/git-add--helper /git-am /git-annotate /git-apply diff --git a/Makefile b/Makefile index 1a44c811aa..9c84b80739 100644 --- a/Makefile +++ b/Makefile @@ -1023,6 +1023,7 @@ LIB_OBJS += xdiff-interface.o LIB_OBJS += zlib.o BUILTIN_OBJS += builtin/add.o +BUILTIN_OBJS += builtin/add--helper.o BUILTIN_OBJS += builtin/am.o BUILTIN_OBJS += builtin/annotate.o BUILTIN_OBJS += builtin/apply.o diff --git a/builtin.h b/builtin.h index 6538932e99..dd811ef7d5 100644 --- a/builtin.h +++ b/builtin.h @@ -128,6 +128,7 @@ extern void setup_auto_pager(const char *cmd, int def); extern int is_builtin(const char *s); extern int cmd_add(int argc, const char **argv, const char *prefix); +extern int cmd_add__helper(int argc, const char **argv, const char *prefix); extern int cmd_am(int argc, const char **argv, const char *prefix); extern int cmd_annotate(int argc, const char **argv, const char *prefix); extern int cmd_apply(int argc, const char **argv, const char *prefix); diff --git a/builtin/add--helper.c b/builtin/add--helper.c new file mode 100644 index 0000000000..6a97f0e191 --- /dev/null +++ b/builtin/add--helper.c @@ -0,0 +1,6 @@ +#include "builtin.h" + +int cmd_add__helper(int argc, const char **argv, const char *prefix) +{ + return 0; +} diff --git a/git.c b/git.c index 2f604a41ea..5507591f2e 100644 --- a/git.c +++ b/git.c @@ -443,6 +443,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) static struct cmd_struct commands[] = { { "add", cmd_add, RUN_SETUP | NEED_WORK_TREE }, + { "add--helper", cmd_add__helper, RUN_SETUP | NEED_WORK_TREE }, { "am", cmd_am, RUN_SETUP | NEED_WORK_TREE }, { "annotate", cmd_annotate, RUN_SETUP | NO_PARSEOPT }, { "apply", cmd_apply, RUN_SETUP_GENTLY }, From patchwork Fri Jan 18 07:47:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2653613BF for ; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 125A32A14F for ; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0666F2A18B; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48A762A14F for ; Fri, 18 Jan 2019 07:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727428AbfARHrK (ORCPT ); Fri, 18 Jan 2019 02:47:10 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42204 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727349AbfARHrI (ORCPT ); Fri, 18 Jan 2019 02:47:08 -0500 Received: by mail-ed1-f66.google.com with SMTP id y20so10378154edw.9 for ; Thu, 17 Jan 2019 23:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=gJ9EZ6s2ppCMotQCwIgSQOgE/iuUG1zHvEyrNQD0AEU=; b=AI9h8hjNxGw8TM9Ed0azA8nHmBxJUMRzSMEIMsGFoj/KkobMyCKtpTJ8PN8rwCeuq+ tVcvBS1xeOsHr8kfNr32oSCjPL2ZJ7/2jXBoxi/4/A9y6B2S/te9lNoMWPOTPHp7uk5J 9Db3FewcZ3Y7Wo7d5GtKSn2O9jD6ZKAi18j3hPubaQJXAGtnkiPuTtoE49kfxIWcjnI7 fj1zP5zyxc46iOOMMrKcC3kVfxv4YYOotE4pxsMO1/MYziSLTxYcvNpxy0nIWHW/nicU AOLtE3UvLIY0YHbxHZx0Abl8R+5pvspCAR5k8HQd0zRa4cb+ZIGFOi8+brY3qHrKH9PE iR2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=gJ9EZ6s2ppCMotQCwIgSQOgE/iuUG1zHvEyrNQD0AEU=; b=jddA9tOZ9F3kFrNpUs10FLlbgFE7m6xAOhe/bpoKxhCqFG7qeOqMMzd41MB+XhUnmE jtgT9wxR1fZ58Dkn8AE4Ns5ACyo7VNjYXoW7OR4qzcXTzwn5mjSPo4BMoicdBMvrsAPL yVAajqJnWwEnBZrmxzLX5wAq8TX2PFgQV9yaMPzGIs8EqZUH8Q+o5mFzek4Uu5EQG4z9 5dO62VKW5mkfYhHYJCCU6XBxIeQU7wwmS7SOHC/0kd5+XKqnsj6oNWJF4n6dtIpBywsT OsBSKx4a+/N1TDeQQerVARHt7LWFj07Y3HHmMeuI69E66+xcn5Xq30n70mf5s9XBtC2r 9UTg== X-Gm-Message-State: AJcUukc5AM1bgItYgiAtMg0I8N2qXSULIha3JTrS8vTERcJD5eH6lUHx 1MAzUFpzyopyfuIrMX3t5iDCfexo X-Google-Smtp-Source: ALg8bN4tvF6hTHT5vAZ1Ms+bsOFplqM+XUuE2TCZpjWjG8KXD/zNhWlUDYumkqURKN3CZ9kQ2wmAzg== X-Received: by 2002:a17:906:b387:: with SMTP id o7-v6mr13923463ejz.124.1547797625105; Thu, 17 Jan 2019 23:47:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l20-v6sm3831188eja.18.2019.01.17.23.47.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:04 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:04 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:46:56 GMT Message-Id: In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v2 3/7] add-interactive.c: implement status command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Daniel Ferreira Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Ferreira Add new files: add-interactive.c and add-interactive.h, which will be used for implementing "application logic" of git add -i, whereas add--helper.c will be used mostly for parsing the command line. We're a bit lax with the command-line parsing, as the command is intended to be called only by one internal user: the add--interactive script. Implement add --interactive's status command in add-interactive.c and use it in builtin add--helper.c. It prints a numstat comparing changed files between a) the worktree and the index; b) the index and the HEAD. To do so, we use run_diff_index() and run_diff_files() to get changed files, use the diffstat API on them to get the numstat and use a combination of a hashmap and qsort() to print the result in O(n) + O(n lg n) complexity. This is the first interactive add command implemented in C of those anticipated by the previous commit, which introduced the add--helper built-in. Signed-off-by: Daniel Ferreira Signed-off-by: Slavica Djukic --- Makefile | 1 + add-interactive.c | 246 ++++++++++++++++++++++++++++++++++++++++++ add-interactive.h | 8 ++ builtin/add--helper.c | 32 ++++++ 4 files changed, 287 insertions(+) create mode 100644 add-interactive.c create mode 100644 add-interactive.h diff --git a/Makefile b/Makefile index 9c84b80739..2a4a5cc37b 100644 --- a/Makefile +++ b/Makefile @@ -827,6 +827,7 @@ LIB_H = $(shell $(FIND) . \ -name '*.h' -print) LIB_OBJS += abspath.o +LIB_OBJS += add-interactive.o LIB_OBJS += advice.o LIB_OBJS += alias.o LIB_OBJS += alloc.o diff --git a/add-interactive.c b/add-interactive.c new file mode 100644 index 0000000000..c55d934186 --- /dev/null +++ b/add-interactive.c @@ -0,0 +1,246 @@ +#include "add-interactive.h" +#include "cache.h" +#include "commit.h" +#include "color.h" +#include "config.h" +#include "diffcore.h" +#include "revision.h" + +#define HEADER_INDENT " " + +enum collection_phase { + WORKTREE, + INDEX +}; + +struct file_stat { + struct hashmap_entry ent; + struct { + uintmax_t added, deleted; + } index, worktree; + char name[FLEX_ARRAY]; +}; + +struct collection_status { + enum collection_phase phase; + + const char *reference; + struct pathspec pathspec; + + struct hashmap file_map; +}; + +static int use_color = -1; +enum color_add_i { + COLOR_PROMPT, + COLOR_HEADER, + COLOR_HELP, + COLOR_ERROR +}; + +static char colors[][COLOR_MAXLEN] = { + GIT_COLOR_BOLD_BLUE, /* Prompt */ + GIT_COLOR_BOLD, /* Header */ + GIT_COLOR_BOLD_RED, /* Help */ + GIT_COLOR_BOLD_RED /* Error */ +}; + +static const char *get_color(enum color_add_i ix) +{ + if (want_color(use_color)) + return colors[ix]; + return ""; +} + +static int parse_color_slot(const char *slot) +{ + if (!strcasecmp(slot, "prompt")) + return COLOR_PROMPT; + if (!strcasecmp(slot, "header")) + return COLOR_HEADER; + if (!strcasecmp(slot, "help")) + return COLOR_HELP; + if (!strcasecmp(slot, "error")) + return COLOR_ERROR; + + return -1; +} + +int add_i_config(const char *var, + const char *value, void *cbdata) +{ + const char *name; + + if (!strcmp(var, "color.interactive")) { + use_color = git_config_colorbool(var, value); + return 0; + } + + if (skip_prefix(var, "color.interactive.", &name)) { + int slot = parse_color_slot(name); + if (slot < 0) + return 0; + if (!value) + return config_error_nonbool(var); + return color_parse(value, colors[slot]); + } + + return git_default_config(var, value, cbdata); +} + +static int hash_cmp(const void *unused_cmp_data, const void *entry, + const void *entry_or_key, const void *keydata) +{ + const struct file_stat *e1 = entry, *e2 = entry_or_key; + const char *name = keydata ? keydata : e2->name; + + return strcmp(e1->name, name); +} + +static int alphabetical_cmp(const void *a, const void *b) +{ + struct file_stat *f1 = *((struct file_stat **)a); + struct file_stat *f2 = *((struct file_stat **)b); + + return strcmp(f1->name, f2->name); +} + +static void collect_changes_cb(struct diff_queue_struct *q, + struct diff_options *options, + void *data) +{ + struct collection_status *s = data; + struct diffstat_t stat = { 0 }; + int i; + + if (!q->nr) + return; + + compute_diffstat(options, &stat); + + for (i = 0; i < stat.nr; i++) { + struct file_stat *entry; + const char *name = stat.files[i]->name; + unsigned int hash = strhash(name); + + entry = hashmap_get_from_hash(&s->file_map, hash, name); + if (!entry) { + FLEX_ALLOC_STR(entry, name, name); + hashmap_entry_init(entry, hash); + hashmap_add(&s->file_map, entry); + } + + if (s->phase == WORKTREE) { + entry->worktree.added = stat.files[i]->added; + entry->worktree.deleted = stat.files[i]->deleted; + } else if (s->phase == INDEX) { + entry->index.added = stat.files[i]->added; + entry->index.deleted = stat.files[i]->deleted; + } + } +} + +static void collect_changes_worktree(struct collection_status *s) +{ + struct rev_info rev; + + s->phase = WORKTREE; + + init_revisions(&rev, NULL); + setup_revisions(0, NULL, &rev, NULL); + + rev.max_count = 0; + + rev.diffopt.flags.ignore_dirty_submodules = 1; + rev.diffopt.output_format = DIFF_FORMAT_CALLBACK; + rev.diffopt.format_callback = collect_changes_cb; + rev.diffopt.format_callback_data = s; + + run_diff_files(&rev, 0); +} + +static void collect_changes_index(struct collection_status *s) +{ + struct rev_info rev; + struct setup_revision_opt opt = { 0 }; + + s->phase = INDEX; + + init_revisions(&rev, NULL); + opt.def = s->reference; + setup_revisions(0, NULL, &rev, &opt); + + rev.diffopt.output_format = DIFF_FORMAT_CALLBACK; + rev.diffopt.format_callback = collect_changes_cb; + rev.diffopt.format_callback_data = s; + + run_diff_index(&rev, 1); +} + +void add_i_print_modified(void) +{ + int i = 0; + struct collection_status s; + /* TRANSLATORS: you can adjust this to align "git add -i" status menu */ + const char *modified_fmt = _("%12s %12s %s"); + const char *header_color = get_color(COLOR_HEADER); + struct object_id sha1; + + struct hashmap_iter iter; + struct file_stat **files; + struct file_stat *entry; + + if (read_cache() < 0) + return; + + s.reference = !get_oid("HEAD", &sha1) ? "HEAD": empty_tree_oid_hex(); + hashmap_init(&s.file_map, hash_cmp, NULL, 0); + + collect_changes_worktree(&s); + collect_changes_index(&s); + + if (hashmap_get_size(&s.file_map) < 1) { + printf("\n"); + return; + } + + printf(HEADER_INDENT); + color_fprintf(stdout, header_color, modified_fmt, _("staged"), + _("unstaged"), _("path")); + printf("\n"); + + hashmap_iter_init(&s.file_map, &iter); + + files = xcalloc(hashmap_get_size(&s.file_map), sizeof(struct file_stat *)); + while ((entry = hashmap_iter_next(&iter))) { + files[i++] = entry; + } + QSORT(files, hashmap_get_size(&s.file_map), alphabetical_cmp); + + for (i = 0; i < hashmap_get_size(&s.file_map); i++) { + struct file_stat *f = files[i]; + + char worktree_changes[50]; + char index_changes[50]; + + if (f->worktree.added || f->worktree.deleted) + snprintf(worktree_changes, 50, "+%"PRIuMAX"/-%"PRIuMAX, f->worktree.added, + f->worktree.deleted); + else + snprintf(worktree_changes, 50, "%s", _("nothing")); + + if (f->index.added || f->index.deleted) + snprintf(index_changes, 50, "+%"PRIuMAX"/-%"PRIuMAX, f->index.added, + f->index.deleted); + else + snprintf(index_changes, 50, "%s", _("unchanged")); + + printf(" %2d: ", i + 1); + printf(modified_fmt, index_changes, worktree_changes, f->name); + printf("\n"); + } + printf("\n"); + + free(files); + hashmap_free(&s.file_map, 1); +} diff --git a/add-interactive.h b/add-interactive.h new file mode 100644 index 0000000000..1f4747553c --- /dev/null +++ b/add-interactive.h @@ -0,0 +1,8 @@ +#ifndef ADD_INTERACTIVE_H +#define ADD_INTERACTIVE_H + +int add_i_config(const char *var, const char *value, void *cbdata); + +void add_i_print_modified(void); + +#endif \ No newline at end of file diff --git a/builtin/add--helper.c b/builtin/add--helper.c index 6a97f0e191..43545d9af5 100644 --- a/builtin/add--helper.c +++ b/builtin/add--helper.c @@ -1,6 +1,38 @@ +#include "add-interactive.h" #include "builtin.h" +#include "config.h" +#include "revision.h" + +static const char * const builtin_add_helper_usage[] = { + N_("git add-interactive--helper "), + NULL +}; + +enum cmd_mode { + DEFAULT = 0, + STATUS +}; int cmd_add__helper(int argc, const char **argv, const char *prefix) { + enum cmd_mode mode = DEFAULT; + + struct option options[] = { + OPT_CMDMODE(0, "status", &mode, + N_("print status information with diffstat"), STATUS), + OPT_END() + }; + + git_config(add_i_config, NULL); + argc = parse_options(argc, argv, NULL, options, + builtin_add_helper_usage, + PARSE_OPT_KEEP_ARGV0); + + if (mode == STATUS) + add_i_print_modified(); + else + usage_with_options(builtin_add_helper_usage, + options); + return 0; } From patchwork Fri Jan 18 07:47:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 184D013B5 for ; Fri, 18 Jan 2019 07:47:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0752A2A14F for ; Fri, 18 Jan 2019 07:47:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F00812A158; Fri, 18 Jan 2019 07:47:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABF4A2A284 for ; Fri, 18 Jan 2019 07:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727415AbfARHrI (ORCPT ); Fri, 18 Jan 2019 02:47:08 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:45293 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727396AbfARHrH (ORCPT ); Fri, 18 Jan 2019 02:47:07 -0500 Received: by mail-ed1-f66.google.com with SMTP id d39so10349663edb.12 for ; Thu, 17 Jan 2019 23:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=a60PDB/sFGZbiveurPxw6uMN1zI85wNCHnWFU/k8O74=; b=X65fUxC9IIXWT8Zp+IPZRlYs3ioJhyEtd6AVMhAqQDuiFBPbmusrylAI94/7CohV3m NK9qDXNMyD8nVuU2lcAWAoU8JNaUzM1eVMjG2wGmHZA0g94NBYj69kt55a5TCwWYIICm NKYXkAVBUEXty8is73x9ErgkfAa8jJ55bOPc+JjY2nHR2k7QsVMDcuyS+hYTEw95tyIr WLRrI9NV4joyFPQvCPeK4LPYaeV8gn9SDC/W0dLMu/DVdVvOOdoaZ6fSKdSGhqOzSwSm A3S4YDLBwwBNIjMQ9KVdLJE920gByNjJHynN+xPU23quOWGpWD/w5suMgaZamTMakrf0 V6MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=a60PDB/sFGZbiveurPxw6uMN1zI85wNCHnWFU/k8O74=; b=uGA/RG6Dpto0bmmliIwFICLiTZ8MOQoeSzhdqqHGn7K4wGCOE/MygoZObrh4AW3mIB 9um9Y4i0npCKIUzXLG8/+u1XtJgruZ9s/LYZT9HlPZVgV2nhKoQbpt/+g/N1mSIXxM+9 XN5RQDo54yVXUhd7kDynQYdxr+NLbnLNAfwObkdWGBqGmoE6X7shmKaE0Ej6TR3uWseK EAJLmE5K6k8aT/m9XCI2TF0vw7Zlf39RvkfPcqOetRo8Nwg/GhA4SkzksVE1FkhKcX45 rnNTvR0DOpM3UkRwcTH6TUuZIS4fWz7ltR48htddENVHg2I9a4dAhB09OFEmG/xqpGzO AHUg== X-Gm-Message-State: AJcUukfv025PfZCrm7xajbw3QktghaEwDfOLfwN0qWi60aYtxtLaB+zT autZbDc/OXMACdf6PHJweTl5GJOX X-Google-Smtp-Source: ALg8bN5ohLhU1540D56escgA6zv8A7bKsLzqY66EsK7hgLGIKsZoc/pExeIgRjaNtie1IyvTP+83nw== X-Received: by 2002:a17:906:14d8:: with SMTP id y24-v6mr13530231ejc.216.1547797625853; Thu, 17 Jan 2019 23:47:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 24sm7094733eds.97.2019.01.17.23.47.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:05 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:05 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:46:57 GMT Message-Id: <4950c889aacd869a8f4fd30b8d5cde4b43957347.1547797620.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v2 4/7] add--interactive.perl: use add--helper --status for status_cmd Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Daniel Ferreira Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Ferreira Call the newly introduced add--helper builtin on status_cmd() instead of relying on add--interactive's Perl functions to build print the numstat. Signed-off-by: Daniel Ferreira Signed-off-by: Slavica Djukic --- git-add--interactive.perl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 20eb81cc92..a6536f9cf3 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -597,9 +597,7 @@ sub prompt_help_cmd { } sub status_cmd { - list_and_choose({ LIST_ONLY => 1, HEADER => $status_head }, - list_modified()); - print "\n"; + system(qw(git add--helper --status)); } sub say_n_paths { From patchwork Fri Jan 18 07:47:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A32D13B5 for ; Fri, 18 Jan 2019 07:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69FC82A14F for ; Fri, 18 Jan 2019 07:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E8452A18B; Fri, 18 Jan 2019 07:47:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDB5D2A14F for ; Fri, 18 Jan 2019 07:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727423AbfARHrK (ORCPT ); Fri, 18 Jan 2019 02:47:10 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:44389 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727404AbfARHrI (ORCPT ); Fri, 18 Jan 2019 02:47:08 -0500 Received: by mail-ed1-f68.google.com with SMTP id y56so10363499edd.11 for ; Thu, 17 Jan 2019 23:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=d7U7T5sEAfWL6DSSMOOF1JfJchy4XqNd3KtgPqPBD+M=; b=mIdY69zRnWJyk/8fMlGf1/ciOPHHVvodPa8fWtk9RCRVlC1mX1pNrSuZLua3JLIuYl iUt5jhlcrHKOnYKObJZyTHud4mgSoN6bqA55cCI3keDoSaxrXbI3aTvCF+3Xc8FhFNyH gh7gJdbOUCKYZOGQgVdeYgmKCcJIvnT3uNNGiQEh/hCq+FCMpf/Bmq5k8vv6seUHt3c4 jZXh7R7r2D3WR9K1g1DBz8PB66FT3ZVSOeok4GGLgwCdW+AOlJvT/eMrfXZCYXry+GIJ mo/vNrLdaYjeplXKkb3d8kJ16gXBhA4LB/6RiUEZuOgyhMF03H28YA3vIApag2axN6+g ol3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=d7U7T5sEAfWL6DSSMOOF1JfJchy4XqNd3KtgPqPBD+M=; b=rYO4JMnBw0O2VevT1eVZX0lvzKRbMh+A+gxYMKjoNieCe/CakegnJ5bVhrJ3avC65B 9/mRLxEVy3foXlXEtLSGF3H6aivtTKnUH9LhLMRSfaioYvPvdrnxtPjGL8vYQe24nIFt 0R1038b51Lx0366EqRxPASD0ywYj7S7JIb0DXs6EjzvhUT/Xdf1aY8GxxneO51vqckH5 jjHgkogVxAY1VTzT2LkdhiSe/zjp8HSMrgZ3GMed+/LilN3md2yd/NN3XVRjeoJWhjAO VxOosZHLAWll9E0h+U85GqpL1xIAqwBaM9bj6Fg8ve1yhs9d96JaQQxM7URADTBX4epR aHVg== X-Gm-Message-State: AJcUukdjtFu1g2IOALXitOAumcZAl+vU2ZaP/2ARki/+D0WMXcXYKsaU JncxBUimoRcSjIMqhu743Lfb4Mxt X-Google-Smtp-Source: ALg8bN7HwCRm5qeEuVHlXyB4JbtrTtq8NS9Yhcwv6bslHrPO3ZsxO+DReRbIE1MxnaleGbDIYYF9iw== X-Received: by 2002:a17:906:4f04:: with SMTP id t4-v6mr13393012eju.153.1547797626708; Thu, 17 Jan 2019 23:47:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c12sm6679876edi.52.2019.01.17.23.47.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:06 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:06 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:46:58 GMT Message-Id: In-Reply-To: References: From: "Slavica Djukic via GitGitGadget" Subject: [PATCH v2 5/7] add-interactive.c: implement show-help command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Slavica Djukic Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Slavica Djukic Implement show-help command in add-interactive.c and use it in builtin add--helper.c. Use command name "show-help" instead of "help": add--helper is builtin, hence add--helper --help would be intercepted by handle_builtin and re-routed to the help command, without ever calling cmd_add__helper(). Signed-off-by: Slavica Djukic --- add-interactive.c | 23 +++++++++++++++++++++++ add-interactive.h | 4 +++- builtin/add--helper.c | 7 ++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/add-interactive.c b/add-interactive.c index c55d934186..76c3f4c3eb 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -244,3 +244,26 @@ void add_i_print_modified(void) free(files); hashmap_free(&s.file_map, 1); } + +void add_i_show_help(void) +{ + const char *help_color = get_color(COLOR_HELP); + color_fprintf(stdout, help_color, "%s%s", _("status"), + N_(" - show paths with changes")); + printf("\n"); + color_fprintf(stdout, help_color, "%s%s", _("update"), + N_(" - add working tree state to the staged set of changes")); + printf("\n"); + color_fprintf(stdout, help_color, "%s%s", _("revert"), + N_(" - revert staged set of changes back to the HEAD version")); + printf("\n"); + color_fprintf(stdout, help_color, "%s%s", _("patch"), + N_(" - pick hunks and update selectively")); + printf("\n"); + color_fprintf(stdout, help_color, "%s%s", _("diff"), + N_(" - view diff between HEAD and index")); + printf("\n"); + color_fprintf(stdout, help_color, "%s%s", _("add untracked"), + N_(" - add contents of untracked files to the staged set of changes")); + printf("\n"); +} diff --git a/add-interactive.h b/add-interactive.h index 1f4747553c..46e17c5c71 100644 --- a/add-interactive.h +++ b/add-interactive.h @@ -5,4 +5,6 @@ int add_i_config(const char *var, const char *value, void *cbdata); void add_i_print_modified(void); -#endif \ No newline at end of file +void add_i_show_help(void); + +#endif diff --git a/builtin/add--helper.c b/builtin/add--helper.c index 43545d9af5..a3b3a68b68 100644 --- a/builtin/add--helper.c +++ b/builtin/add--helper.c @@ -10,7 +10,8 @@ static const char * const builtin_add_helper_usage[] = { enum cmd_mode { DEFAULT = 0, - STATUS + STATUS, + HELP }; int cmd_add__helper(int argc, const char **argv, const char *prefix) @@ -20,6 +21,8 @@ int cmd_add__helper(int argc, const char **argv, const char *prefix) struct option options[] = { OPT_CMDMODE(0, "status", &mode, N_("print status information with diffstat"), STATUS), + OPT_CMDMODE(0, "show-help", &mode, + N_("show help"), HELP), OPT_END() }; @@ -30,6 +33,8 @@ int cmd_add__helper(int argc, const char **argv, const char *prefix) if (mode == STATUS) add_i_print_modified(); + else if (mode == HELP) + add_i_show_help(); else usage_with_options(builtin_add_helper_usage, options); From patchwork Fri Jan 18 07:47:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2983113BF for ; Fri, 18 Jan 2019 07:47:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 192A42A14F for ; Fri, 18 Jan 2019 07:47:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D6D22A18B; Fri, 18 Jan 2019 07:47:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A14472A14F for ; Fri, 18 Jan 2019 07:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbfARHrO (ORCPT ); Fri, 18 Jan 2019 02:47:14 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:37714 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbfARHrJ (ORCPT ); Fri, 18 Jan 2019 02:47:09 -0500 Received: by mail-ed1-f65.google.com with SMTP id h15so10419451edb.4 for ; Thu, 17 Jan 2019 23:47:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=j+7JffoxNBIVZ3QpeyLd0isG5DGXw98QOCaM9TGCpzo=; b=t8cyPbP+Rc4EjIqgInvD8e0fMlIZk+bJ8iTMydA+TyJwmBCfO/Ob77qC169NDxoj5v xpidha/CwQKdLozQu7hLxzm1t86c1ta9UB/R2RwfFuD/vrEEk5t5TXk2Pb75Vqlo9q2p EzuALh6wIEwSgmF3of6Ah+hsYnj+13eNdrIiRsgj/vYNVV67ESpe24QLyk9bxSiq8y7W n/ifCQCHDHUPOmBCqufRi765CLdn+wr6SIACT2FEAaJLEHlEH4VI4In8l3K9SksxB33g ZsN/SMbQZVCcql9HzwFdLEaRdjDsRv8TkN99P7InQfelW8+69lJCLC2ctjBqTgXaIbqX M+RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=j+7JffoxNBIVZ3QpeyLd0isG5DGXw98QOCaM9TGCpzo=; b=Z59WTz11o4g2pGKiRt+eZ5fa1sDmh9fO5dW5pfXNPtVVhA3RvtXE+jFvWnvxuxMagH 5M+el5PSLUcdIuwEKqB/0QiTpO6Nej9/3pC7c9uJzrZgoJ74Sc9OMpygpj4wtEOXqZz4 x1uvpgME/HLKbEWoXVug5Mpdv5SxklBK1odoZc5hdes8TG71yAoPLy+Dpf6FCR0OukcC M7IInH1IIrWgqiRbYvYTEi/bsj+9wAB3QruqQieIgWcwytkq1Qu9NEQlBEjwrbBkyU9c 4YS/oCzBDtOd7+JESRYlo8KUOk+KPvUpq+rgY7ZqN4H7qdBFqEscdX2vOjvSDeLuirJM aObg== X-Gm-Message-State: AJcUukcdU1M3DtQsrkT4TjCDRCsvU2YG1FGOMbWT2HmrRyU0EbhgYhvN LpP6YmiqElV6JkijDzBcSsiDVARI X-Google-Smtp-Source: ALg8bN7bkvqgN7FkJCS0A6tLu3Oj1lEahBpFCxHOSzUOf8lxni4ffV3qNa3pTdRHpqKpmrypn5GM+w== X-Received: by 2002:a17:906:6b99:: with SMTP id l25-v6mr13708188ejr.154.1547797627726; Thu, 17 Jan 2019 23:47:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p22-v6sm3863141ejf.48.2019.01.17.23.47.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:06 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:06 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:46:59 GMT Message-Id: <2b4714b8d04f98a6d35f3f4f15881406fa87c320.1547797620.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Slavica Djukic via GitGitGadget" Subject: [PATCH v2 6/7] t3701-add-interactive: test add_i_show_help() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Slavica Djukic Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Slavica Djukic Add test to t3701-add-interactive to verify that add_i_show_help() outputs expected content. Also, add it before changing git-add--interactive.perl's help_cmd to demonstrate that there are no changes introduced by the conversion to C. Prefix git add -i call with GIT_PAGER_IN_USE=true TERM=vt100 to force colored output on Windows. Signed-off-by: Slavica Djukic --- t/t3701-add-interactive.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 65dfbc033a..14e3286995 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -639,4 +639,28 @@ test_expect_success 'add -p patch editing works with pathological context lines' test_cmp expected-2 actual ' +test_expect_success 'show help from add--helper' ' + git reset --hard && + cat >expect <<-\EOF && + + *** 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_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored && + test_decode_color actual && + test_i18ncmp expect actual +' + test_done From patchwork Fri Jan 18 07:47:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 10769513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A66651580 for ; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 971EA2A14F for ; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B6F92A18B; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4233D2A14F for ; Fri, 18 Jan 2019 07:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727433AbfARHrM (ORCPT ); Fri, 18 Jan 2019 02:47:12 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:33040 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727396AbfARHrK (ORCPT ); Fri, 18 Jan 2019 02:47:10 -0500 Received: by mail-ed1-f67.google.com with SMTP id p6so10450197eds.0 for ; Thu, 17 Jan 2019 23:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Eiglx/ZyLaUkVeXKBevUQCRjAV8+UqPW2VxjNNLfegc=; b=E+7PwsvHXgSXbd8G2Gdv4ODq0BKEHfxzZ0qHjS5ucp2Vf33ObXwlpf5r6Uh1OXwlHq NNkDT7/8p0ToXv4Uo8zolxoz6RXARDxbB72btg+QC1syD9nUqrjhe7K6L/TUJ2iUkb24 tzmJuYGEmRFLjqeF7PzlYsFEq7kUH2OHbhlK/FJ5ucpN4cGf9IRZW+5fek1fiXNl/32S 2ARortkcExLCeTsQeV5kvqnLG0D36ZEdvCWL5R4QjmPL+PW4iehK5Dy58LuHEbBECf// IGtuncHZy8jwHzb+5IF4PaWq5GI5JP7o0h73YEvtyY8p1SaiBFY5518nIOdL9ItoHhcs e2OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Eiglx/ZyLaUkVeXKBevUQCRjAV8+UqPW2VxjNNLfegc=; b=JJfjLIzT/XAX8oly6YK7owDPQvovti5MzHPzADynxH0nZMoXJZfIV4m3ME4V2qRk8B Pk6QjOc5SAQn7uuQoGmX5NfdBf7DK+inoUjSqnP01u1DFNbq1TVwSLhjtSKaSbpizfHu FF+769Q/HtJ5rrxFknhDkyMUlfcagvaHJnGYj7D5hUlI3YPPY98aKSBZpZ03HRQ09dlZ H2eJEjXyyEucnug/3mDGfraf18QSGgMyKindBTpe/eLInF5zXDNxNO/LEE66bOVzJmRa jHCA8lPIDxUXSrp/7zyJ3tRN9DhJU4JbVWCSC/kTbkaUtqaVfVaY1B5thA+ZNHYMtOwc vlRg== X-Gm-Message-State: AJcUukcfEUMm60MLjDbuFMR3813VVZOoWBLQCZCcfYzu7WsMOvnnbMgt e5Qp9DZ55cWBceWefYL1HThzLL93 X-Google-Smtp-Source: ALg8bN5R4Cpq/FB6vYcTOHPOE0EFQ8fB2X2Pows7bH1d1/5uqWxSnLfpZkf0/e0ro1ejyBGIWboinw== X-Received: by 2002:a50:acc3:: with SMTP id x61mr14650359edc.76.1547797628652; Thu, 17 Jan 2019 23:47:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k32sm7014167edb.42.2019.01.17.23.47.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 23:47:07 -0800 (PST) Date: Thu, 17 Jan 2019 23:47:07 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 07:47:00 GMT Message-Id: <6ede6d92511d372eb30a78d59912135faad069aa.1547797620.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Slavica Djukic via GitGitGadget" Subject: [PATCH v2 7/7] add--interactive.perl: use add--helper --show-help for help_cmd Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Slavica Djukic Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Slavica Djukic Change help_cmd sub in git-add--interactive.perl to use show-help command from builtin add--helper. Signed-off-by: Slavica Djukic --- git-add--interactive.perl | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index a6536f9cf3..32ee729a58 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -1717,16 +1717,7 @@ sub quit_cmd { } sub help_cmd { -# TRANSLATORS: please do not translate the command names -# 'status', 'update', 'revert', etc. - print colored $help_color, __ <<'EOF' ; -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 -EOF + system(qw(git add--helper --show-help)); } sub process_args {