From patchwork Mon Jan 21 09:13:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773365 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 E36C514E5 for ; Mon, 21 Jan 2019 09:13:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D276829D5D for ; Mon, 21 Jan 2019 09:13:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C694C29E10; Mon, 21 Jan 2019 09:13:46 +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 4CCB129D5D for ; Mon, 21 Jan 2019 09:13:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726857AbfAUJNo (ORCPT ); Mon, 21 Jan 2019 04:13:44 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:45928 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726058AbfAUJNn (ORCPT ); Mon, 21 Jan 2019 04:13:43 -0500 Received: by mail-ed1-f65.google.com with SMTP id d39so15918209edb.12 for ; Mon, 21 Jan 2019 01:13:42 -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=RD6lMHtHtxa/EEcLNFkYVrxoxqRM9ppOopDk1lZs6ddfOQi6VITQMz24PUFtBVUKv8 NB/FJo7M8qOgf1ogY0TpcHuRp7lIigopSqYiKcLeT0+mDcS5Qccmf/r6djE2ITAx8i6P UOZg3j5pMKXo1eX5Ob7I71SRg5qQle6sEbF6QElqqAYA9QZGr338GK8HEM3nTUp+Se2k VNy9vezQ88cEVpm/PQ2jQK0BymXhNkaxtyyrdWPdRDi9s40QdmeVQZ+78yHWjbP1lbJ/ c0bSNr6RZsLEG7843jMPkxY64wflX9UYxRL7GWds/8/DuLu1oxPpw8rsi+NG8z0e6sJO 2aMg== 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=JkI62ywmJuSm25/rpXhHHgKFPBG7r37XiXng9J8SOUd1Hvw8IvX+3gT/09t1nx8Y8n 7A07gIp8sbbPaN5iWqin3a8c16Suw4i4oS2eLVTSly3lm6a8aHei7T6A4MWYAl/Oq1Gs udj+2QRupj+OIhfQyT3vBnQWxQYTadwr3ThD3nMY8WfVUvWdUDzARV/JQYJQLqHauHSm zG6I1obuJhbC15gBj1GPv3RhiYmxr+OzIJ6hn3lhCFaY7pau7tlWs7fh7XdISt7ATRdt Omz+i+JUrPUyQgt3NM5a7F4iITKa+/tgdJlQlQHkHfKOvjklcK8BPgpweXTyoUZkUg3v lM5g== X-Gm-Message-State: AJcUukdLgtGhossj38yCx20pcz5WDBIQ9eYDW1j/Nvw8c2GnOiwRENkC cWuXTEAPr1DlfyOySma/rlY82wk2 X-Google-Smtp-Source: ALg8bN7IaDHQQHaRT/1bmUvmPEc+IMKwOzlzdyJKCekio6qENt+jKw0N97DAaqOIEazN+xnyw8PwKA== X-Received: by 2002:a50:82c7:: with SMTP id 65mr26292930edg.94.1548062021540; Mon, 21 Jan 2019 01:13:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c53sm9684613ede.26.2019.01.21.01.13.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:40 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:40 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:33 GMT Message-Id: <737767b6f4e0367a7797020bd07a6b4357a47413.1548062019.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v3 1/7] diff: export diffstat interface Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , 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 Mon Jan 21 09:13:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773367 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 0F2C6746 for ; Mon, 21 Jan 2019 09:13:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F089F29D5A for ; Mon, 21 Jan 2019 09:13:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2F2629D5E; Mon, 21 Jan 2019 09:13:47 +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 8227829D5D for ; Mon, 21 Jan 2019 09:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbfAUJNq (ORCPT ); Mon, 21 Jan 2019 04:13:46 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:39974 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726030AbfAUJNo (ORCPT ); Mon, 21 Jan 2019 04:13:44 -0500 Received: by mail-ed1-f65.google.com with SMTP id g22so15964629edr.7 for ; Mon, 21 Jan 2019 01:13:43 -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=Lsw6ShRKDh1OEa8+DmKB5b4HtGLQvpWWRJfDYkoOg/EXPe3yJIg+/x+IqCdtd0l3uV nphIyt+Bws+xBh3k+A+mCv5JlWrPY/kU3JyH4oCPdLOMk3sRrfFCV/cMX24rajZEDXsS 3CoaW8hlqPhHj0Eles6FtoFpuz/SzUE2vriMoI9z7Ll0LnxS/ceZVaTQbREUrse3q4ca qK5x+kTSLCca3GO/H9AKxLSjz8GoDpIA5V2FjyfsQ4q24cawSpg9q3gH3EiIaSuqa25X cqTOTem7omrhAH4jt9Scd59XLTPExwCCHKZmVap97BgHJCrDPkoy98JVytwinB1emmPG fsCQ== 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=O9iKdiSu5E57XlDoDv8ez1Vphm0PGtoEH/gny3LxKv2zfXhOY9yJCdoopwHvB1prIc FckEvlai/d4cDa2uSUAMATF4J0qsdp551JhDzhPUMq2p0blq2AYazT2Ty/2Cp5iN9gcH hK2k5oAvCVGjwJec1L4ufHVkTNldcBStJMDAzpi0HhJXhDKHM5Udy0Z4yfMoT1VLF64M c2k3yli33LIjVTXcLLHkMRbSOZ06hLJdhajooLKb3jJf9uQiFQfNtddwkwXx7cG86wMX jIHq5fXjqCczfU541r5EETQkJGnj6JFcLfBIbfN7m6KJMkMTfGTJGEmHXbwbZkJQ9Xp/ WEKA== X-Gm-Message-State: AJcUukfy1LzXIeY0POQVagpEylPFZbHxCRilxX0lMJd6X0VkgfqBa2lo 5gPB2kg0XpS6E59m9ON3jDFQplwP X-Google-Smtp-Source: ALg8bN4sw8wlkNmookemkZ0sxk2G7RKJ1sSLasHDkmNb2JYV373dsaJ0+9laiOaFxdGWOBOaxdSFGw== X-Received: by 2002:a50:a3d1:: with SMTP id t17mr26712811edb.238.1548062022596; Mon, 21 Jan 2019 01:13:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ga24-v6sm4916692ejb.72.2019.01.21.01.13.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:42 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:42 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:34 GMT Message-Id: <91b1963125f7dfdd46fe5166125ee59ef2557b13.1548062019.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v3 2/7] add--helper: create builtin helper for interactive add Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , 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 Mon Jan 21 09:13:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773379 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 A744B14E5 for ; Mon, 21 Jan 2019 09:13:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95ED92654B for ; Mon, 21 Jan 2019 09:13:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A46A28449; Mon, 21 Jan 2019 09:13:55 +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 B9E9B2654B for ; Mon, 21 Jan 2019 09:13:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727589AbfAUJNx (ORCPT ); Mon, 21 Jan 2019 04:13:53 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:46209 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726058AbfAUJNp (ORCPT ); Mon, 21 Jan 2019 04:13:45 -0500 Received: by mail-ed1-f68.google.com with SMTP id o10so15925014edt.13 for ; Mon, 21 Jan 2019 01:13:44 -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=alN0MpDaQnTyvIOpqJ8h+3z9CJgkeV/Gm8JkfbfdM7xEjmyq20IbX7OUlw05p17Qe6 0GUD2wpDG7czfhWifg6AmJjD2dNof8EnmP6gZiwb6/Xgq1QqMVaKnVswjV4L3aodyHoR cRd17E3o5FvFI3E4yCOo0vw54vl5aprsp6AM+ZkK1aRzoCPcQcQml7Oe3I93ole3dYPR oQcWZhewlfGY3XG/IqXtAZPYuaaQ6OWIASRMPtC2SwTMZu2wQSErKVWYvaQ5dl3fX3bO 59E45RlDxOHaJzlxepdytuzBlLk8YZP0vebCS+zN845gn7/TuDB/aIO4apkNB8CTKjFD ymhA== 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=DNqY2AkylyQ/aZ9Fnk4xV9mKtrJX5UfZMoDfeVRjQz95CUZeQFzX6Jp3FXFKrOklAU IX2Z39D7HTya/QagVgmOI8viXgOoYvxfek9i/Ry6PpmghDlPddJfvBwtSv85jLusuDCV yKKmk9z2uNBbpfbLtnU+1Pps2heL5CQ7LZL6UlhQBl9tHjlBnh3epoKhGzdrx0/3k0m1 P0GMMc3lDYUZApjxvZczuppFvMA3hA+01qkt0d5rzojF/SFgwNjib6TJuEYlLq/qk2pa hdZnLLGGOw7e1mU0PXJn4hoY0fD1EYe70aOt2MaTY4mKAb3b8ZErmPWMW3mYdxO3TGam C4Yw== X-Gm-Message-State: AJcUukeshuIIaO35eaKnP5CONGjYCpogtkFLh223P+M1KyIDesBfx5PB fMpjWmpIQzRvh2gZQPQf2BXSEyPQ X-Google-Smtp-Source: ALg8bN7qJ+6yfftfrK4EyegiMjDsGBtD1PqkZlMp7v9xuuHnW3H+i33KD5GsmeQVucCKrOehiKdnCg== X-Received: by 2002:a17:906:314a:: with SMTP id e10-v6mr16863996eje.227.1548062023562; Mon, 21 Jan 2019 01:13:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f35sm9242862edd.80.2019.01.21.01.13.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:42 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:42 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:35 GMT Message-Id: In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v3 3/7] add-interactive.c: implement status command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , 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 Mon Jan 21 09:13:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773371 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 5AAB114E5 for ; Mon, 21 Jan 2019 09:13:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 471442654B for ; Mon, 21 Jan 2019 09:13:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 372DF28449; Mon, 21 Jan 2019 09:13:49 +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 E2C5E2654B for ; Mon, 21 Jan 2019 09:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727591AbfAUJNs (ORCPT ); Mon, 21 Jan 2019 04:13:48 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:45934 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbfAUJNq (ORCPT ); Mon, 21 Jan 2019 04:13:46 -0500 Received: by mail-ed1-f68.google.com with SMTP id d39so15918319edb.12 for ; Mon, 21 Jan 2019 01:13:45 -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=XfNPR+IBWfE1Hq5vIs0cylQM37vOJ3njUrMFL4rI0m773VHUQrXzxsJswuxTQeHe5N rLQ5yBHM51d2KYFsXUxgX5OQau8JdCPeGLGUbWtfQ1WCvAIjSzGzi7hSWU5EDXgXXtf2 ggpBiWQAbpwX5EW+yxjDFiLG1E5+gF19UobneYcaDHyKa0abS37xkbKrmQS8fl5vg76W fnSQwrvJoI37asSP11BMgyc7OVbKfQniNlRd7MI0bYXPlJqZpa0UrcA/AgXKZGCVKMnf 5KZtAJGDLCemPQbXRVZUWNRIZ1raxOGzYnlRRxL/azqE+Y2rL94KNg8JUtpv3D5FQrxv zB1A== 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=q7e2kLGiyOk34sGWRBGYxAwGSeRxFtDfMcFQpSuOI3+E2cOCsgyphMRUynEPz8SbLr zBoi+sFDmYbpSv0qIwlwMY/BvOVuqmPmWEvrQuELsbvY3mBzEREOOrMrp/fareqSlTZe IPTkMSzdmpwQFAkkz6v6L+PrCelwOQzkNxZTbbwfhTMJde/7khhM0nUkQapPhnNkNh5z FyufBjyvuab8hLRORKfXiwRs3Nd4G1v7BFV8HWbVCOYteovTKkp6TpZYn8Kpgxjz0VGJ /fKxrj+soa/9i+ErsazrtqVMQN3qeOG4l2aOgHNb5TeEG43Vsi0e7o1EVUrG4AJp2H0t SHSw== X-Gm-Message-State: AJcUukcwIoHKU04g/pS5XyAItL1zbCgDkVQeMfOH/Tid45sZMxjqKyoH cbZtMvK1hVBBckC+vccnJ1vHelvu X-Google-Smtp-Source: ALg8bN5LGXHJGdFyB6e8yb6Etpy4eSb0bFTJHigmra3vYAfH3XxnbJHZYizyadC/WnrGbGIFRFKljw== X-Received: by 2002:a50:b32f:: with SMTP id q44mr26174027edd.70.1548062024259; Mon, 21 Jan 2019 01:13:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c30sm8952587edc.70.2019.01.21.01.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:43 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:43 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:36 GMT Message-Id: <4950c889aacd869a8f4fd30b8d5cde4b43957347.1548062019.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Daniel Ferreira via GitGitGadget" Subject: [PATCH v3 4/7] add--interactive.perl: use add--helper --status for status_cmd Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , 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 Mon Jan 21 09:13:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773373 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 1900C746 for ; Mon, 21 Jan 2019 09:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 090852654B for ; Mon, 21 Jan 2019 09:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F18D428449; Mon, 21 Jan 2019 09:13:49 +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 92DF02654B for ; Mon, 21 Jan 2019 09:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727597AbfAUJNs (ORCPT ); Mon, 21 Jan 2019 04:13:48 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:44504 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727176AbfAUJNr (ORCPT ); Mon, 21 Jan 2019 04:13:47 -0500 Received: by mail-ed1-f65.google.com with SMTP id y56so15926556edd.11 for ; Mon, 21 Jan 2019 01:13:45 -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=c0HymROOdhLPhJ4ItXr0cvQM8M8lupIo2/ijvNiLxeg=; b=jwlMIg6NYr2UjkQCMAzBKIuMD3pLFP3D79XnGWf6bxc8BUuyOJ7mMj+T4wqQAZgsvZ XqvWiD42wDPQ9ps8EELX8Zi67X8HH6hiiBnp5/GVsa/o8aOv8464l5K9W6ukxqvqezOz uEvq4I6lAzdd8Rb9AZlCELoH6GQOh6GJ9goDoYhge8oWYKTIe8rGidLse1XYrsPzUFsE +UnFJ4fn4pMACghLtPJyM6LPyeGcsLQLt9dB6k71KE0ED658R7jsMFReRGypNDHIgsYU Ti/3dHWAQIiMXo2pSYzDPqsx9Wk8ZlZZFO8dcpGVEluzB2/Gd3MrvKAALfERvHxm5CkZ cvhg== 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=c0HymROOdhLPhJ4ItXr0cvQM8M8lupIo2/ijvNiLxeg=; b=Utm2n05bhi1ij3fl6TUQh/ACKF9i12yWkRZVLo80AKZHXGZFOyc/7POpSkDMwrL5WE LuxPpTqnvqfDVt5ZMP1Y6tw1pv3507p4sTHjK/FvJbih9JxpjW0aCmqhj1W1naenWV05 IRHHhiWmKtyY7WF1YL8ZYgeJtO1Myo+9rL6jy3l8xois0Qx3tfCUaIZbSDfUmKZVv80W Dhi0ktQOxrT3z4JulUdo7xNcUw+vsCxIm0n9EbrzmxSa/vHx0henFYtB9JaCYiVFsANY Q4csinCSYF6NVAykkhDvoLUatP/VRPHs6bh7rMmkz9PmaNb7DX2Mw7CjkoGi/l+XzBH0 N91A== X-Gm-Message-State: AJcUukeFqgShm4iSbkD13K5VLIcj6scXbF5XNmTBv8IZazfNwhg/V7/B YJ6sE1rMKITCNbzyFb+JNgRDJV3z X-Google-Smtp-Source: ALg8bN7UNadCgViF+kTrMlM3iVNBHmVr1b+4B9zCgF+dbrmm4nrHdqpqnzdE6/GefccdcuZUP7EKGA== X-Received: by 2002:a17:906:c5a:: with SMTP id t26-v6mr23338363ejf.140.1548062025034; Mon, 21 Jan 2019 01:13:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h51sm9771473edh.17.2019.01.21.01.13.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:44 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:44 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:37 GMT Message-Id: <581b108c9c3a090660ee655263c4639d1bf409d6.1548062019.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Slavica Djukic via GitGitGadget" Subject: [PATCH v3 5/7] add-interactive.c: implement show-help command Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , 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 | 17 +++++++++++++++++ add-interactive.h | 4 +++- builtin/add--helper.c | 7 ++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/add-interactive.c b/add-interactive.c index c55d934186..d239037bc1 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -244,3 +244,20 @@ 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_ln(stdout, help_color, "status - %s", + _("show paths with changes")); + color_fprintf_ln(stdout, help_color, "update - %s", + _("add working tree state to the staged set of changes")); + color_fprintf_ln(stdout, help_color, "revert - %s", + _("revert staged set of changes back to the HEAD version")); + color_fprintf_ln(stdout, help_color, "patch - %s", + _("pick hunks and update selectively")); + color_fprintf_ln(stdout, help_color, "diff - %s", + _("view diff between HEAD and index")); + color_fprintf_ln(stdout, help_color, "add untracked - %s", + _("add contents of untracked files to the staged set of changes")); +} 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 Mon Jan 21 09:13:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773375 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 3FA1E746 for ; Mon, 21 Jan 2019 09:13:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F5E12654B for ; Mon, 21 Jan 2019 09:13:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23BEA28449; Mon, 21 Jan 2019 09:13:51 +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 BA74D2654B for ; Mon, 21 Jan 2019 09:13:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727600AbfAUJNt (ORCPT ); Mon, 21 Jan 2019 04:13:49 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42223 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbfAUJNs (ORCPT ); Mon, 21 Jan 2019 04:13:48 -0500 Received: by mail-ed1-f66.google.com with SMTP id y20so15941628edw.9 for ; Mon, 21 Jan 2019 01:13:47 -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=gCbGc/U+I/5kaeGSbwWdZW4qY++54YBHSZTlYpNWEKEAtuEqrmKjZav0qdwrifk+6w /zpVEpV4yHVDSbC9nVpYGMsX2EpmQNCrCs98UM8eYnCtEOcuSr0U7IGYyZVA3lRyJk06 SMVCjfTeXQz3zpNRRJ1MijBgzGOK03/RmvLsSGzFL546YWlYHgRadc+ZsrHKR00JLA7/ XQDU6TUURF3E4sg99aAKl2m7G3JWRo0xHv2CMKX4x5cWhHXakoMPam0u3QIDEKuQfKX3 pLnPo/4vNt0mz82V/tAJDVmQVbCLje2Y3Hsbv2nPvlKGR9vPlYrCtxT2hBmW4mpxJVOe z06g== 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=Yfol8B81GEmNQk0Xya9gEA+ByRB0QMHlp/w4OCyTLL3k+3dd2uXPY+ynbQF6EuO4W3 WvPuSiUzO0a0v4JVJ5Wi485MOflgHe2QSlc2Lwk/i2zAU0QcCArYGKzFpDkJeHoB/wTJ mUC1lbMPeMNoaXwwh+zRBQtoGNo8fJUdB2WQukon8jO3LVW8nNCwJnu3Ut3lhY6+hOJf zURzEQHs1/g0+T1R8Pxs2OanAFNJN5BVaKLWFsLJ7zjR6RZ319aCQJe1/9yK3qOwXQ/n WEnLZg8OU/oNmIeuxJNaNFA26X+JA+2m/U0aBz56sIjohFAcCqO/+b5mucpTRTapOOjC HEeg== X-Gm-Message-State: AJcUukfoHk6qjfjjL5uMdDrtvh16fV0nQWQ8mCP+eVx0s5IDZShJfqzR CDXsZlrQTS9/1j20hxqfNujqG3J/ X-Google-Smtp-Source: ALg8bN5k0/5wB3bsqIV8Oxxe3k2HtQZdOSxJG+tSNl+FQQRCXvmbIbPZs0McWvIfCYbkeW3gguO5KA== X-Received: by 2002:a50:ccdd:: with SMTP id b29mr25930358edj.102.1548062026205; Mon, 21 Jan 2019 01:13:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t24sm8913874edb.7.2019.01.21.01.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:45 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:45 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:38 GMT Message-Id: In-Reply-To: References: From: "Slavica Djukic via GitGitGadget" Subject: [PATCH v3 6/7] t3701-add-interactive: test add_i_show_help() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , 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 Mon Jan 21 09:13:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10773377 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 CABB0746 for ; Mon, 21 Jan 2019 09:13:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BACA12654B for ; Mon, 21 Jan 2019 09:13:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEF2F28449; Mon, 21 Jan 2019 09:13:52 +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 638512654B for ; Mon, 21 Jan 2019 09:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbfAUJNu (ORCPT ); Mon, 21 Jan 2019 04:13:50 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:43218 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727589AbfAUJNt (ORCPT ); Mon, 21 Jan 2019 04:13:49 -0500 Received: by mail-ed1-f67.google.com with SMTP id f9so15943746eds.10 for ; Mon, 21 Jan 2019 01:13:47 -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=OnJWvQmLMmrEHVF8kFk5aARb7xShyD9bGHiXVDccGnWCyPmL/IKqcuthjelsdwDDgs QnQu7DrM0DG+YCvObn0e3bfmkySaccs1rBf63pX2w809AOde4Z0DRv7TKAiuOVHqutDA H9cF0MeG9wWF25VQHlD2oFtnz9pvrhVo8zKlJaRy1LT4qSZx14FSlDo929XY7rqVgyHj MJCVkF9Szgvmphh1ENZRfREV9+FeUpQ+SQS3FYGnZaBy6pfxRir/v60icEEsVBFgRHsg 2aXNrLRVZo+C3qROpoQnDGpXtKICDchAIAkto6x65OBLuV2E/ZUKHvDq1zO9KXvBSUu9 5sRQ== 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=HVIQ5MA1tRGJRXqMbU0JoqTvw+rJiUA73+5vQ/Vk+md2JuTm9cJ2YfoO8OMMFOdYPA jgBCxUKYg+R0UI5MjeJO7qbYLDsdtHRSRY5WPwOX7x8wHJx7DGdDfmUcbnMohML/FKhz Yx2y1TdyryuK0wBzbdoUqwOLkumLjXDFiR7zJwcqgY32+dboNFDq5HBtUd7gpTB9CbZC gi636YwOpHErCs8MdDeelQ6lyUV6P1GbfE0Wlfp5IhBlSDGtruhyp6npJVUbHwLvfGgE mFD1RspzoUDRZ1ms3eIS73Z/4EpohDmTXtSHQ0sqIX2mHTjlibXCjcc++lCuZPgyhrot 7bkw== X-Gm-Message-State: AJcUukd6LHK565HrtdBKQsqjyP40MoTpYEFBtEOY96oqOMv+9w0Gxwsp Y9F0isGmKzg64YVCKfGngsuNYp9g X-Google-Smtp-Source: ALg8bN4drJ9rggGdMZQ5qzf1M7lINKXpUVL9RYhu3KZMsJYooDbl7Xh3+5F3DT9TkzDdvG6mvfWFtQ== X-Received: by 2002:a17:906:b1b:: with SMTP id u27-v6mr23740801ejg.67.1548062027106; Mon, 21 Jan 2019 01:13:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 24sm9082516eds.97.2019.01.21.01.13.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 01:13:46 -0800 (PST) Date: Mon, 21 Jan 2019 01:13:46 -0800 (PST) X-Google-Original-Date: Mon, 21 Jan 2019 09:13:39 GMT Message-Id: In-Reply-To: References: From: "Slavica Djukic via GitGitGadget" Subject: [PATCH v3 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: Phillip Wood , 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 {