From patchwork Mon Dec 9 13:10:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11279367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5ABF2139A for ; Mon, 9 Dec 2019 13:10:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 394722077B for ; Mon, 9 Dec 2019 13:10:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pp22Ebwm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727403AbfLINKn (ORCPT ); Mon, 9 Dec 2019 08:10:43 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40419 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbfLINKn (ORCPT ); Mon, 9 Dec 2019 08:10:43 -0500 Received: by mail-pl1-f195.google.com with SMTP id g6so5792785plp.7 for ; Mon, 09 Dec 2019 05:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zjT/6rJDnAs2GlWdX8xKF++Y4AzU9qYkTwqgcLJMsto=; b=Pp22Ebwm9WTiLR+2ODEJ4y+rnzFVkStfySSn8iH7Y8OuqMOAmMnmc14r6uCTDonYQe DqL3Jcp2wp4Vy4llxlkjK8cvEfaJ7coFjCidRoo9mhyTU1iEqwl7lZXi89P1iRI/H4xd SWHjjagHwUvIUh5fqXHdCsV8m2qVisL2fLpSKjMcFYgpMq0YsvD7xmJjfsKhySlddqyl h1I6XRGNJB65hCmbdun32/JaHTwB4DPJ/ivx31SyIltltFhF6lFhGcj6xoBP01Npf2GH 0K8LozRSD8NpajONegcj2iDmmSqHqIw182Q4B4EHijLCP4Rq7vGz7ULYJj520zMhTMHw HMIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zjT/6rJDnAs2GlWdX8xKF++Y4AzU9qYkTwqgcLJMsto=; b=FuoyMcPWQVjdESv+i4m6+ZZ1xiDi6mOYDt20j6SBV3Yc1z041Fo/k2NQFGM+PLX91H iub5qJg3p6JnftyopOTHuOY31peRF98WaoDMDHGrzD5rXmiCkHjC+mL/QV4NyECDBrU4 7UB+MN7bnU/AAVj6q7JS9bb5ob/3+heqV4kzczxOwLmO9+6DEwQLeY6BFJovScW+fXDx NBJlsn+dvW05n2t9q5KOlIe7cQjPngPrbk/Tv4aPWoZ/x3YCyYGJ406ilnjJIaLDwRmy LKjZnc1bTw1gC/z4lfX7qkXEYndtBTpokI4ncRtXDVmXrw4m/qw4ISdGbPXu/cxQcWap rbMA== X-Gm-Message-State: APjAAAUcP9S9aKyhDziTpqza9s36pZ4g7TyNHwW2FUtSwphQdrptVfvM zPD1Pg9d5r4+1so68QMt0IiB4V0g X-Google-Smtp-Source: APXvYqw2sOkE4F3V8CX8bV5nJZKi4dVi9v4BrSLzXgX/bcmhUckb/gc2pLXD9tBxFvJ8JO/vr2D1/A== X-Received: by 2002:a17:902:d691:: with SMTP id v17mr19973256ply.150.1575897041362; Mon, 09 Dec 2019 05:10:41 -0800 (PST) Received: from generichostname ([2601:646:280:1b30:b0bc:639f:d5c8:2bcf]) by smtp.gmail.com with ESMTPSA id b65sm26451089pgc.18.2019.12.09.05.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 05:10:40 -0800 (PST) Date: Mon, 9 Dec 2019 05:10:39 -0800 From: Denton Liu To: Git Mailing List Cc: Elijah Newren , Junio C Hamano , Beat Bolli , Pavel Roskin Subject: [PATCH 1/5] notes: rename to load_display_notes() Message-ID: <4132d5bb7b354355a6dbe8049601f166b5de8fa8.1575896661.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org According to the function comment, init_display_notes() was supposed to "Load the notes machinery for displaying several notes trees." Rename this function to load_display_notes() so that its use is more accurately represented. This is done because, in a future commit, we will reuse the name init_display_notes(). Signed-off-by: Denton Liu --- builtin/log.c | 4 ++-- notes.c | 2 +- notes.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index dad63cffc6..622d6a6cb1 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -202,7 +202,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, if (!rev->show_notes_given && (!rev->pretty_given || w.notes)) rev->show_notes = 1; if (rev->show_notes) - init_display_notes(&rev->notes_opt); + load_display_notes(&rev->notes_opt); if ((rev->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) || rev->diffopt.filter || rev->diffopt.flags.follow_renames) @@ -1749,7 +1749,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.diffopt.flags.binary = 1; if (rev.show_notes) - init_display_notes(&rev.notes_opt); + load_display_notes(&rev.notes_opt); if (!output_directory && !use_stdout) output_directory = config_output_directory; diff --git a/notes.c b/notes.c index 532ec37865..fd6cef14a3 100644 --- a/notes.c +++ b/notes.c @@ -1039,7 +1039,7 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags) return trees; } -void init_display_notes(struct display_notes_opt *opt) +void load_display_notes(struct display_notes_opt *opt) { char *display_ref_env; int load_config_refs = 0; diff --git a/notes.h b/notes.h index 414bc6855a..1ce528442a 100644 --- a/notes.h +++ b/notes.h @@ -272,18 +272,18 @@ struct display_notes_opt { * - extra_notes_refs may contain a list of globs (in the same style * as notes.displayRef) where notes should be loaded from. */ -void init_display_notes(struct display_notes_opt *opt); +void load_display_notes(struct display_notes_opt *opt); /* * Append notes for the given 'object_sha1' from all trees set up by - * init_display_notes() to 'sb'. The 'flags' are a bitwise + * load_display_notes() to 'sb'. The 'flags' are a bitwise * combination of * * - NOTES_SHOW_HEADER: add a 'Notes (refname):' header * * - NOTES_INDENT: indent the notes by 4 places * - * You *must* call init_display_notes() before using this function. + * You *must* call load_display_notes() before using this function. */ void format_display_notes(const struct object_id *object_oid, struct strbuf *sb, const char *output_encoding, int raw); From patchwork Mon Dec 9 13:10:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11279369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A925139A for ; Mon, 9 Dec 2019 13:10:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE797207FF for ; Mon, 9 Dec 2019 13:10:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TxWwoHa4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbfLINKp (ORCPT ); Mon, 9 Dec 2019 08:10:45 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:43120 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbfLINKo (ORCPT ); Mon, 9 Dec 2019 08:10:44 -0500 Received: by mail-pj1-f65.google.com with SMTP id g4so5879164pjs.10 for ; Mon, 09 Dec 2019 05:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ks8eZSHvh7qET3gZ4zemF1h7mW7pJrNk+Ou3vtulXA4=; b=TxWwoHa4FgXxf6hVHt2mzsYii2FjO8aOMDic6coJR0P3gI+ayx8+oDwJh+XpYYdik4 gTvf8E+U1rKzcGWsNV+zZ5jXoifKPzobnDORHByPcFq26StSpKloD5/I0csyMhjPj7Oe kS+M58nGdbWNc9gXrn9A8QrKiOwdlKpmM+6bBzBV358GH3d/xeAtkC1LeREVZrnc1WMZ CwvN3Gfr3Na6vLhh4v159H2TJ7NzwrlIqca9nLdVCBSjJz+ghzp9Yc90s1nL/SleVZh5 X8vGsb2ZwaMZSUKKJDHoOju9/diobMmpCr7orW4QNVsxTH4L1PY6g21pJlnVEJxyqOZk FlaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ks8eZSHvh7qET3gZ4zemF1h7mW7pJrNk+Ou3vtulXA4=; b=C6P0EDelF+1G4xlGsZd9Q7pSQa8HSFSWVhDntTtdzQAzJ/F/cKcLvH9VyA7p/nZ/x4 rRzrClmnBiGqYptWN6yqYImjOFPvRj+YEyqoiK56hLYY0BNxfHfZLS/OwiSJBi/DT44D h2kDOWIT1S4R0k7GQwGJ2jAdlIddhcls4/KrcKHfEL53znqaYuHU+4KfzpUrG/igOc5l br6+6VSpZO+3454cahc3WdxAsCA8igqDJqLGUQ+K7FSmdlJvTsNhjebGVphSmkK0ARy2 pd/OM7z2yXxaLBLaWHM1A42ynjIa7WwH0M/rt//qSdS6fsEvTF6sQcJM8ITtaVQY9P++ tN3A== X-Gm-Message-State: APjAAAXMe0USb6QdE7O1oFjBBoZO+BoMQZ/OyotrGRSXZ2scR4ehY417 ySbK2uXIcru0ge3a5isfUMVV/GeS X-Google-Smtp-Source: APXvYqz1QTpzZQsk0WH4FkXqrGvVUPqCECPon8dhyO6zc/su588HzMSKRyrk+5kn5TUqA2ekzdkoew== X-Received: by 2002:a17:902:104:: with SMTP id 4mr30448398plb.130.1575897043925; Mon, 09 Dec 2019 05:10:43 -0800 (PST) Received: from generichostname ([2601:646:280:1b30:b0bc:639f:d5c8:2bcf]) by smtp.gmail.com with ESMTPSA id 2sm24813113pgo.79.2019.12.09.05.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 05:10:43 -0800 (PST) Date: Mon, 9 Dec 2019 05:10:41 -0800 From: Denton Liu To: Git Mailing List Cc: Elijah Newren , Junio C Hamano , Beat Bolli , Pavel Roskin Subject: [PATCH 2/5] notes: create init_display_notes() helper Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We currently open code the initialization for revs->notes_opt. Abstract this away into a helper function so that the logic can be reused in a future commit. This is slightly wasteful as we memset the struct twice but this is only run once so it shouldn't have any major effect. Signed-off-by: Denton Liu --- notes.c | 6 ++++++ notes.h | 5 +++++ revision.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/notes.c b/notes.c index fd6cef14a3..53d1e7767c 100644 --- a/notes.c +++ b/notes.c @@ -1039,6 +1039,12 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags) return trees; } +void init_display_notes(struct display_notes_opt *opt) +{ + memset(opt, 0, sizeof(*opt)); + opt->use_default_notes = -1; +} + void load_display_notes(struct display_notes_opt *opt) { char *display_ref_env; diff --git a/notes.h b/notes.h index 1ce528442a..c0b712371c 100644 --- a/notes.h +++ b/notes.h @@ -260,6 +260,11 @@ struct display_notes_opt { struct string_list extra_notes_refs; }; +/* + * Initialize a display_notes_opt to its default value. + */ +void init_display_notes(struct display_notes_opt *opt); + /* * Load the notes machinery for displaying several notes trees. * diff --git a/revision.c b/revision.c index d4aaf0ef25..24ad974590 100644 --- a/revision.c +++ b/revision.c @@ -1637,7 +1637,7 @@ void repo_init_revisions(struct repository *r, revs->diffopt.prefix_length = strlen(prefix); } - revs->notes_opt.use_default_notes = -1; + init_display_notes(&revs->notes_opt); } static void add_pending_commit_list(struct rev_info *revs, From patchwork Mon Dec 9 13:10:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11279371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E04D214B7 for ; Mon, 9 Dec 2019 13:10:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF5B5207FF for ; Mon, 9 Dec 2019 13:10:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aJT4gIty" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727578AbfLINKr (ORCPT ); Mon, 9 Dec 2019 08:10:47 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39993 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbfLINKr (ORCPT ); Mon, 9 Dec 2019 08:10:47 -0500 Received: by mail-pf1-f194.google.com with SMTP id q8so7215358pfh.7 for ; Mon, 09 Dec 2019 05:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XH/sgDUQtCXKlc9E4CK08KoTojOxZXbO6Z4gmwxFd7E=; b=aJT4gItyuANebFCv3KC/Bs49TiVIpjNkrjswOBsVKxmNBa0b4pk1LRvfm22nx51wUa GdPxB7ZBWhu3iLP7Z56BDBMtmkrfvo5YCVuYq6mItYvL8r5RTwO7fSxagHRHmEOQexyH +nswmSlj9N290Oocz7uxrB9IukL+bEwc3lD4QEYHHgmQmQkEVuaDzFkkhX9l+PuOC1TF YbNmv/YZ/QhzKxhEIAv/UNocR6UWn5vO+22m9muWBeLQRUI3NX92on6BrHKx7D/WAKme z4VW6HQD0xmTz87ewg+hOIbVf8QgFKAi5UgMBXy9NGP0e8Ka9bPdLwp9X84Vh6opJI58 Kziw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XH/sgDUQtCXKlc9E4CK08KoTojOxZXbO6Z4gmwxFd7E=; b=tSvdamiXHV2B0VF2hH/vuMsRVcdYGnwsbqDOTP6tmZFfLvfJzI/kJCBIg+IINfmTf+ lNcSc0iJo7bWvImB/EaZN2FVQsOV9rGDmo+sSqAQ/lnK5Vl52au2AH+b7fIRDl2b1Aw2 8rJrrLq3dNGtl8jD0iLQ5NENOCtxM0utMXKBcE0bnrHnViv7I3HcVnToPgClYDNoTqUB WcZAkOtjCmgUNbeyymezLZjmU7oiT0I8xUvoD8Owf57hFSfve3O6cvYI/xu3faJauzq6 zqc4hU1HssOlmwD2xbIL5smDsLMb9yQDqAqrg71HCiJLu9fZVncsBYaRBm4f99+s41bM ea5w== X-Gm-Message-State: APjAAAXWHe+SQbiU1DZ59HrMtqRk985iRo9Zjs99al4esLYTXQyEk8YB 1xTv+tIbXS/xDiQ+eE0Ima6aIm82 X-Google-Smtp-Source: APXvYqxfX08100/IODfaoEYHrG/Ux0pdvZRFwXkmJiGFyA0SaCTQqIf2mXg8JvNEtmF9wMztLchVUQ== X-Received: by 2002:a63:cb48:: with SMTP id m8mr19186840pgi.128.1575897046222; Mon, 09 Dec 2019 05:10:46 -0800 (PST) Received: from generichostname ([2601:646:280:1b30:b0bc:639f:d5c8:2bcf]) by smtp.gmail.com with ESMTPSA id q9sm12863173pgc.5.2019.12.09.05.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 05:10:45 -0800 (PST) Date: Mon, 9 Dec 2019 05:10:44 -0800 From: Denton Liu To: Git Mailing List Cc: Elijah Newren , Junio C Hamano , Beat Bolli , Pavel Roskin Subject: [PATCH 3/5] notes: extract logic into set_display_notes() Message-ID: <62543250c4ea0e0327f974cb90b294c60b525982.1575896661.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of open coding the logic that tweaks the variables in `struct display_notes_opt` within handle_revision_opt(), abstract away the logic into set_display_notes() so that it can be reused. Signed-off-by: Denton Liu --- notes.c | 24 ++++++++++++++++++++++++ notes.h | 10 ++++++++++ revision.c | 20 ++++---------------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/notes.c b/notes.c index 53d1e7767c..c93feff4ab 100644 --- a/notes.c +++ b/notes.c @@ -1045,6 +1045,30 @@ void init_display_notes(struct display_notes_opt *opt) opt->use_default_notes = -1; } +int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref) +{ + if (show_notes) { + if (opt_ref) { + struct strbuf buf = STRBUF_INIT; + strbuf_addstr(&buf, opt_ref); + expand_notes_ref(&buf); + string_list_append(&opt->extra_notes_refs, + strbuf_detach(&buf, NULL)); + } else { + opt->use_default_notes = 1; + } + } else { + opt->use_default_notes = -1; + /* we have been strdup'ing ourselves, so trick + * string_list into free()ing strings */ + opt->extra_notes_refs.strdup_strings = 1; + string_list_clear(&opt->extra_notes_refs, 0); + opt->extra_notes_refs.strdup_strings = 0; + } + + return !!show_notes; +} + void load_display_notes(struct display_notes_opt *opt) { char *display_ref_env; diff --git a/notes.h b/notes.h index c0b712371c..a476bfa066 100644 --- a/notes.h +++ b/notes.h @@ -265,6 +265,16 @@ struct display_notes_opt { */ void init_display_notes(struct display_notes_opt *opt); +/* + * Set a display_notes_opt to a given state. 'show_notes' is a boolean + * representing whether or not to show notes. 'opt_ref' points to a + * string for the notes ref, or is NULL if the default notes should be + * used. + * + * Return 'show_notes' normalized to 1 or 0. + */ +int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref); + /* * Load the notes machinery for displaying several notes trees. * diff --git a/revision.c b/revision.c index 24ad974590..c2d8d24939 100644 --- a/revision.c +++ b/revision.c @@ -2172,9 +2172,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg die("'%s': not a non-negative integer", arg); revs->expand_tabs_in_log = val; } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { - revs->show_notes = 1; + revs->show_notes = set_display_notes(&revs->notes_opt, 1, NULL); revs->show_notes_given = 1; - revs->notes_opt.use_default_notes = 1; } else if (!strcmp(arg, "--show-signature")) { revs->show_signature = 1; } else if (!strcmp(arg, "--no-show-signature")) { @@ -2189,25 +2188,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->track_first_time = 1; } else if (skip_prefix(arg, "--show-notes=", &optarg) || skip_prefix(arg, "--notes=", &optarg)) { - struct strbuf buf = STRBUF_INIT; - revs->show_notes = 1; - revs->show_notes_given = 1; if (starts_with(arg, "--show-notes=") && revs->notes_opt.use_default_notes < 0) revs->notes_opt.use_default_notes = 1; - strbuf_addstr(&buf, optarg); - expand_notes_ref(&buf); - string_list_append(&revs->notes_opt.extra_notes_refs, - strbuf_detach(&buf, NULL)); + revs->show_notes = set_display_notes(&revs->notes_opt, 1, optarg); + revs->show_notes_given = 1; } else if (!strcmp(arg, "--no-notes")) { - revs->show_notes = 0; + revs->show_notes = set_display_notes(&revs->notes_opt, 0, NULL); revs->show_notes_given = 1; - revs->notes_opt.use_default_notes = -1; - /* we have been strdup'ing ourselves, so trick - * string_list into free()ing strings */ - revs->notes_opt.extra_notes_refs.strdup_strings = 1; - string_list_clear(&revs->notes_opt.extra_notes_refs, 0); - revs->notes_opt.extra_notes_refs.strdup_strings = 0; } else if (!strcmp(arg, "--standard-notes")) { revs->show_notes_given = 1; revs->notes_opt.use_default_notes = 1; From patchwork Mon Dec 9 13:10:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11279375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F29F7112B for ; Mon, 9 Dec 2019 13:10:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D04C72077B for ; Mon, 9 Dec 2019 13:10:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mx0lFbm3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727604AbfLINKt (ORCPT ); Mon, 9 Dec 2019 08:10:49 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42280 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbfLINKt (ORCPT ); Mon, 9 Dec 2019 08:10:49 -0500 Received: by mail-pf1-f193.google.com with SMTP id 4so7209334pfz.9 for ; Mon, 09 Dec 2019 05:10:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ipfdo+UXPxR2f8Y3Obo0/L+qz+o3GhaT2oHjHu83tnk=; b=Mx0lFbm3lYpE+3qyf9izf6vZmGX0Chxe+rIBeIkP7ZD+GFxy0llQ+CfgBZl1sceOmu z5tBMiiXMTTQ8Rq5IDcwvjtiQkWu12jUC6IkSMqog8Q5gx3UlzW3kpAkKnksbJ5rr2/E y6wHycIJInk31jRVePoooWEpYd3ev3Dm0Cjml82HUVhvfPwizby9O11/ePiw6gTDaoZG OI//q1SuMLrRfg6mOmyOZZaXTL3Kp2sujENN2Fmi5dc25OIuvPO/7CJBofDyfw6TC9c0 XrgtPUeiGUXALdKgXUh6urjeoeW5AnEw7d9ZiCYgZF1/3R24mcJu4jtWeXafr2MpyySh aQ3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Ipfdo+UXPxR2f8Y3Obo0/L+qz+o3GhaT2oHjHu83tnk=; b=J96dNltxaNnU6RGxER2w/7v6iH+5RdSJjZAJCMmscm3nfE29f9WWfPLSorsjqoa9wY V1hLqQR6BzS2w/GJGSNI1HvUqHbyc2FPcz1wd4SoEKUbrb/LNj9nlVJAvrZPWG5sN59B zZ4BAOMa+8UiteGc77cj7U5XLtHVbEmFKwhzDdq8Ebq7mQiQtm69yuw/SgiSu9k3rVMN K/XFhIx2nunKjALQwNPXakhHNfpRqxzGVY1U6A+gX42HTqh82gykuvwNTxcTzjvWW0bM 6m0vPT7WJ8Fhf6kTE4C63/TjIAEdlcsH1CoAwJ2aEJuw6aT6qtTCDP++2x/wiN2omPpN jt+w== X-Gm-Message-State: APjAAAXYOgduNPVmQbnWp1Gd7l6hzoPIIwJ/41Wc3xxefTxMwV4HqT49 4J2xErXdJWmyrCC64PVMDFQ1PLno X-Google-Smtp-Source: APXvYqw3U2pj9jsYcvvp3r0PjrGQrnoQdgR8dwaQFmLD4oGRUu3uwmejTbF9G6BTf2xC6FFlreR39g== X-Received: by 2002:a62:bd08:: with SMTP id a8mr29101226pff.84.1575897048413; Mon, 09 Dec 2019 05:10:48 -0800 (PST) Received: from generichostname ([2601:646:280:1b30:b0bc:639f:d5c8:2bcf]) by smtp.gmail.com with ESMTPSA id r14sm27452280pfh.10.2019.12.09.05.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 05:10:48 -0800 (PST) Date: Mon, 9 Dec 2019 05:10:46 -0800 From: Denton Liu To: Git Mailing List Cc: Elijah Newren , Junio C Hamano , Beat Bolli , Pavel Roskin Subject: [PATCH 4/5] format-patch: use --notes behavior for format.notes Message-ID: <67c88a37d24c5481ff0fcc314368ad20c5ce65e4.1575896661.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we had multiple `format.notes` config values where we had ``, `false`, `` (in that order), then we would print out the notes for both `` and ``. This doesn't make sense, however, since we parse the config in a top-down manner and a `false` should be able to override previous configurations, just like how `--no-notes` will override previous `--notes`. Duplicate the logic that handles the `--[no-]notes[=]` option to `format.notes` for consistency. As a result, when parsing the config from top to bottom, `format.notes = true` will behave like `--notes`, `format.notes = ` will behave like `--notes=` and `format.notes = false` will behave like `--no-notes`. This change isn't strictly backwards compatible but since it is an edge case where a sane user would not mix notes refs with `false` and this feature is relatively new (released only in v2.23.0), this change should be harmless. Signed-off-by: Denton Liu --- builtin/log.c | 13 +------------ t/t4014-format-patch.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 622d6a6cb1..1f0405f72b 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -867,19 +867,8 @@ static int git_format_config(const char *var, const char *value, void *cb) return 0; } if (!strcmp(var, "format.notes")) { - struct strbuf buf = STRBUF_INIT; int b = git_parse_maybe_bool(value); - if (!b) - return 0; - rev->show_notes = 1; - if (b < 0) { - strbuf_addstr(&buf, value); - expand_notes_ref(&buf); - string_list_append(&rev->notes_opt.extra_notes_refs, - strbuf_detach(&buf, NULL)); - } else { - rev->notes_opt.use_default_notes = 1; - } + rev->show_notes = set_display_notes(&rev->notes_opt, b, b < 0 ? value : NULL); return 0; } diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 4d5719fe2c..5c40ea4397 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -808,6 +808,38 @@ test_expect_success 'format-patch with multiple notes refs' ' ! grep "this is note 2" out ' +test_expect_success 'format-patch with multiple notes refs in config' ' + test_when_finished "test_unconfig format.notes" && + + git notes --ref note1 add -m "this is note 1" HEAD && + test_when_finished git notes --ref note1 remove HEAD && + git notes --ref note2 add -m "this is note 2" HEAD && + test_when_finished git notes --ref note2 remove HEAD && + + git config format.notes note1 && + git format-patch -1 --stdout >out && + grep "this is note 1" out && + ! grep "this is note 2" out && + git config format.notes note2 && + git format-patch -1 --stdout >out && + ! grep "this is note 1" out && + grep "this is note 2" out && + git config --add format.notes note1 && + git format-patch -1 --stdout >out && + grep "this is note 1" out && + grep "this is note 2" out && + + git config --replace-all format.notes note1 && + git config --add format.notes false && + git format-patch -1 --stdout >out && + ! grep "this is note 1" out && + ! grep "this is note 2" out && + git config --add format.notes note2 && + git format-patch -1 --stdout >out && + ! grep "this is note 1" out && + grep "this is note 2" out +' + echo "fatal: --name-only does not make sense" > expect.name-only echo "fatal: --name-status does not make sense" > expect.name-status echo "fatal: --check does not make sense" > expect.check From patchwork Mon Dec 9 13:10:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11279377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEDB614B7 for ; Mon, 9 Dec 2019 13:10:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADB46207FF for ; Mon, 9 Dec 2019 13:10:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WYlPG89t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727638AbfLINKv (ORCPT ); Mon, 9 Dec 2019 08:10:51 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:46984 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbfLINKv (ORCPT ); Mon, 9 Dec 2019 08:10:51 -0500 Received: by mail-pj1-f65.google.com with SMTP id z21so5869725pjq.13 for ; Mon, 09 Dec 2019 05:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7Hs6iPjuAzxu1HDfiDVtnKiBpXM1/OYAobjKPOzsFkc=; b=WYlPG89txJcK3GvVMKFPxMab/DQaSeb78WbvGux1kUsMr99vqz7PEn+VYaSJ3JpGAL anrs5mLA2eo7LK32EsXmoo4Vpkepbz27yN3yC0RA1zbDGjXsQrIUoFz5Ms4EjMHoX9YF uURzYJ9N5N6URtaoJVudN+exLzgt5Q7Vjb3NiSY87WA7CZRp4+jIux8KT+t1UIHOfoY2 LWtvgqY5tfSC2fuxT2T3KT2IvsAcojeHgL+Ah4FFBDC6YrtJLKwB7Jc/XaFdJ90x8sRu UjreADkmDGtRHfoYj5U8HtSXESddoKeKd3C0NBTwMHs4mYM96zrOEdX0LMLf5pLCB61z rh6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7Hs6iPjuAzxu1HDfiDVtnKiBpXM1/OYAobjKPOzsFkc=; b=fqrBXkHBxXjuo0rS/bLwB0R67i+ylqq5zuyvycOadWzZeTb8gpiAgUY78PLHd/PJvG BFYWeS0zFvg2z5GBaTgK6BPX4OEEMypPVL5JUAX4t3a4Yq7tf6bfuIKoLBB73uFkChzP WbhkEQ0XLpTGNSxsKa7WsXMlUOcftKj354BPsmKMPJpY2RMZhx4UJe5PJjIVUx+9k6j8 K0qbjFgqafazdCdKetlHg+CproyhC9jqALls7vFtZWxR+kj9pALgL1jfTkj1yHkRs8wf SVZgXPZk6osVJjJwDpk9u8+d9bNcZHcORfzlKE+QFpabh2y3TUXP3BSar6uF+oydBOzT 2K/Q== X-Gm-Message-State: APjAAAXrfTfCKoYLUr2gsHud3xEbZrTo+22kdevTpYW9Lp3qDrX/6mPF P7xCuyuFJkhSmk4PdqzuVF60hALK X-Google-Smtp-Source: APXvYqwxnjn+InzGQnUFdBJXW/trDGtZDbzQxs9Wt3kkZnh6tkEs65dblV1xGvsBIcxCtZz/Dwxz1Q== X-Received: by 2002:a17:902:599a:: with SMTP id p26mr29388221pli.312.1575897050680; Mon, 09 Dec 2019 05:10:50 -0800 (PST) Received: from generichostname ([2601:646:280:1b30:b0bc:639f:d5c8:2bcf]) by smtp.gmail.com with ESMTPSA id n15sm25670970pgf.17.2019.12.09.05.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 05:10:50 -0800 (PST) Date: Mon, 9 Dec 2019 05:10:48 -0800 From: Denton Liu To: Git Mailing List Cc: Elijah Newren , Junio C Hamano , Beat Bolli , Pavel Roskin Subject: [PATCH 5/5] format-patch: move git_config() before repo_init_revisions() Message-ID: <709565e734820fcb6d5db027dcf644f53ce2d4c9.1575896661.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 13cdf78094 (format-patch: teach format.notes config option, 2019-05-16), the order in which git_config() and repo_init_revisions() were swapped so that `rev.notes_opt` would be initialized before git_config() was called. This is problematic, however, as git_config() should generally be called before repo_init_revisions(). Break this circular dependency by creating `show_notes` and `notes_opt` which git_config() reads into. Then, copy these values over to `rev.show_notes` and `rev.notes_opt` after repo_init_revisions() is called. Signed-off-by: Denton Liu --- builtin/log.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 1f0405f72b..4225615e7f 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -769,6 +769,8 @@ static const char *signature = git_version_string; static const char *signature_file; static int config_cover_letter; static const char *config_output_directory; +static int show_notes; +static struct display_notes_opt notes_opt; enum { COVER_UNSET, @@ -779,8 +781,6 @@ enum { static int git_format_config(const char *var, const char *value, void *cb) { - struct rev_info *rev = cb; - if (!strcmp(var, "format.headers")) { if (!value) die(_("format.headers without value")); @@ -868,7 +868,7 @@ static int git_format_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "format.notes")) { int b = git_parse_maybe_bool(value); - rev->show_notes = set_display_notes(&rev->notes_opt, b, b < 0 ? value : NULL); + show_notes = set_display_notes(¬es_opt, b, b < 0 ? value : NULL); return 0; } @@ -1624,8 +1624,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) extra_to.strdup_strings = 1; extra_cc.strdup_strings = 1; init_log_defaults(); + init_display_notes(¬es_opt); + git_config(git_format_config, NULL); repo_init_revisions(the_repository, &rev, prefix); - git_config(git_format_config, &rev); + rev.show_notes = show_notes; + memcpy(&rev.notes_opt, ¬es_opt, sizeof(notes_opt)); rev.commit_format = CMIT_FMT_EMAIL; rev.expand_tabs_in_log_default = 0; rev.verbose_header = 1;