From: Christian Couder <christian.couder@gmail.com>
To: Prathamesh Chavan <pc44800@gmail.com>
Cc: git <git@vger.kernel.org>, Stefan Beller <sbeller@google.com>,
Brandon Williams <bmwill@google.com>
Subject: Re: [GSoC][PATCH v2 08/13] submodule: port submodule subcommand 'summary' from shell to C
Date: Sun, 30 Jul 2017 07:28:45 +0200 [thread overview]
Message-ID: <CAP8UFD2XWm-m1CZoX121mhQ+WunCRTMJT5RjrZAXKBY3axcSJQ@mail.gmail.com> (raw)
In-Reply-To: <20170729222401.12381-9-pc44800@gmail.com>
On Sun, Jul 30, 2017 at 12:23 AM, Prathamesh Chavan <pc44800@gmail.com> wrote:
> +static int module_summary(int argc, const char **argv, const char *prefix)
> +{
> + struct summary_cb info = SUMMARY_CB_INIT;
> + int cached = 0;
> + char *diff_cmd = "diff-index";
> + int for_status = 0;
> + int quiet = 0;
> + int files = 0;
> + int summary_limits = -1;
> + struct child_process cp_rev = CHILD_PROCESS_INIT;
> + char *head;
> + struct strbuf sb = STRBUF_INIT;
> + int ret;
> +
> + struct option module_summary_options[] = {
> + OPT__QUIET(&quiet, N_("Suppress output for initializing a submodule")),
> + OPT_BOOL(0, "cached", &cached, N_("Use the commit stored in the index instead of the submodule HEAD")),
> + OPT_BOOL(0, "files", &files, N_("To compares the commit in the index with that in the submodule HEAD")),
> + OPT_BOOL(0, "for-status", &for_status, N_("Skip submodules with 'all' ignore_config value")),
> + OPT_INTEGER('n', "summary-limits", &summary_limits, N_("Limit the summary size")),
> + OPT_END()
> + };
> +
> + const char *const git_submodule_helper_usage[] = {
> + N_("git submodule--helper summary [<options>] [--] [<path>]"),
> + NULL
> + };
> +
> + argc = parse_options(argc, argv, prefix, module_summary_options,
> + git_submodule_helper_usage, 0);
> +
> + if (!summary_limits)
> + return 0;
> +
> + cp_rev.git_cmd = 1;
> + argv_array_pushl(&cp_rev.args, "rev-parse", "-q", "--verify",
> + argc ? argv[0] : "HEAD", NULL);
> +
> + if (!capture_command(&cp_rev, &sb, 0)) {
> + strbuf_strip_suffix(&sb, "\n");
> + if (argc) {
> + argv++;
> + argc--;
> + }
> + } else if (!argc || !strcmp(argv[0], "HEAD")) {
> + /* before the first commit: compare with an empty tree */
> + struct stat st;
> + struct object_id oid;
> + if (fstat(0, &st) < 0 || index_fd(oid.hash, 0, &st, 2, prefix, 3))
> + die("Unable to add %s to database", oid.hash);
> + strbuf_addstr(&sb, oid_to_hex(&oid));
> + if (argc) {
> + argv++;
> + argc--;
> + }
> + } else {
> + strbuf_addstr(&sb, "HEAD");
> + }
> +
> + head = strbuf_detach(&sb, NULL);
I am not sure this "head" variable is really needed.
> + if (files) {
> + if (cached)
> + die(_("The --cached option cannot be used with the --files option"));
> + diff_cmd = "diff-files";
> +
> + free(head);
> +
> + head = NULL;
If "head" isn't used, "strbuf_reset(&sb)" could be used instead.
If "head" is still needed, "FREE_AND_NULL(head)" could be used.
> + }
> +
> + info.argc = argc;
> + info.argv = argv;
> + info.prefix = prefix;
> + info.cached = !!cached;
> + info.for_status = !!for_status;
> + info.quiet = quiet;
> + info.files = files;
> + info.summary_limits = summary_limits;
> + info.diff_cmd = diff_cmd;
> +
> + ret = compute_summary_module_list(head, &info);
> + if (head)
> + free(head);
"sb.buf" could be passed to compute_summary_module_list() instead of
"head". In this case that function should check that head is not an
empty string before using it.
If "head" is not used then strbuf_release(&sb) can be used to free any
memory sb still holds.
If "head" is still used, "if (head)" can be removed before
"free(head)" as free() already checks if its argument is NULL.
> + return ret;
> +
Spurious new line.
> +}
next prev parent reply other threads:[~2017-07-30 5:28 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-24 20:34 [GSoC][PATCH 00/13] Update: Week 10 Prathamesh Chavan
2017-07-24 20:34 ` [GSoC][PATCH 01/13] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-07-24 20:34 ` [GSoC][PATCH 02/13] submodule--helper: introduce for_each_submodule_list() Prathamesh Chavan
2017-07-24 20:34 ` [GSoC][PATCH 03/13] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-07-24 20:54 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 04/13] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-07-24 21:30 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 05/13] submodule: port submodule subcommand 'sync' " Prathamesh Chavan
2017-07-24 21:52 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 06/13] submodule: port submodule subcommand 'deinit' " Prathamesh Chavan
2017-07-24 23:03 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 07/13] diff: change scope of the function count_lines() Prathamesh Chavan
2017-07-24 20:34 ` [GSoC][PATCH 08/13] submodule: port submodule subcommand 'summary' from shell to C Prathamesh Chavan
2017-07-25 0:09 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 09/13] submodule foreach: correct '$path' in nested submodules from a subdirectory Prathamesh Chavan
2017-07-25 0:13 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 10/13] submodule foreach: document '$sm_path' instead of '$path' Prathamesh Chavan
2017-07-25 0:15 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 11/13] submodule foreach: clarify the '$toplevel' variable documentation Prathamesh Chavan
2017-07-24 20:34 ` [GSoC][PATCH 12/13] submodule foreach: document variable '$displaypath' Prathamesh Chavan
2017-07-25 0:16 ` Brandon Williams
2017-07-24 20:34 ` [GSoC][PATCH 13/13] submodule: port submodule subcommand 'foreach' from shell to C Prathamesh Chavan
2017-07-25 0:29 ` Brandon Williams
2017-07-29 22:23 ` [GSoC][PATCH v2 00/13] Update: Week 10 Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 01/13] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 02/13] submodule--helper: introduce for_each_submodule_list() Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 03/13] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 04/13] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-07-30 5:35 ` Christian Couder
2017-07-29 22:23 ` [GSoC][PATCH v2 05/13] submodule: port submodule subcommand 'sync' " Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 06/13] submodule: port submodule subcommand 'deinit' " Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 07/13] diff: change scope of the function count_lines() Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 08/13] submodule: port submodule subcommand 'summary' from shell to C Prathamesh Chavan
2017-07-30 5:28 ` Christian Couder [this message]
2017-07-30 6:33 ` Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 09/13] submodule foreach: correct '$path' in nested submodules from a subdirectory Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 10/13] submodule foreach: document '$sm_path' instead of '$path' Prathamesh Chavan
2017-07-29 22:23 ` [GSoC][PATCH v2 11/13] submodule foreach: clarify the '$toplevel' variable documentation Prathamesh Chavan
2017-07-29 22:24 ` [GSoC][PATCH v2 12/13] submodule foreach: document variable '$displaypath' Prathamesh Chavan
2017-07-29 22:24 ` [GSoC][PATCH v2 13/13] submodule: port submodule subcommand 'foreach' from shell to C Prathamesh Chavan
2017-07-31 20:28 ` [GSoC][PATCH v2 00/13] Update: Week 10 Brandon Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP8UFD2XWm-m1CZoX121mhQ+WunCRTMJT5RjrZAXKBY3axcSJQ@mail.gmail.com \
--to=christian.couder@gmail.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=pc44800@gmail.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).