All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Prathamesh Chavan <pc44800@gmail.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	Christian Couder <christian.couder@gmail.com>
Subject: Re: [GSoC][PATCH 4/8] submodule: port submodule subcommand 'status' from shell to C
Date: Tue, 18 Jul 2017 14:39:39 -0700	[thread overview]
Message-ID: <CAGZ79kb48kNggPv64ubbBNK-Sk8AW4eXxhZt=PZZCPKr9OiuLQ@mail.gmail.com> (raw)
In-Reply-To: <20170718204904.3768-5-pc44800@gmail.com>

On Tue, Jul 18, 2017 at 1:49 PM, Prathamesh Chavan <pc44800@gmail.com> wrote:
> This aims to make git-submodule 'status' a built-in. Hence, the function
> cmd_status() is ported from shell to C. This is done by introducing
> three functions: module_status(), submodule_status() and print_status().
>
> The function module_status() acts as the front-end of the subcommand.
> It parses subcommand's options and then calls the function
> module_list_compute() for computing the list of submodules. Then
> this functions calls for_each_submodule_list() looping through the
> list obtained.
>
> Then for_each_submodule_list() calls submodule_status() for each of the
> submodule in its list. The function submodule_status() is responsible
> for generating the status each submodule it is called for, and
> then calls print_status().
>
> Finally, the function print_status() handles the printing of submodule's
> status.
>
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Stefan Beller <sbeller@google.com>
> Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
> ---
>  builtin/submodule--helper.c | 146 ++++++++++++++++++++++++++++++++++++++++++++
>  git-submodule.sh            |  49 +--------------
>  2 files changed, 147 insertions(+), 48 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 80f744407..9c1630495 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -560,6 +560,151 @@ static int module_init(int argc, const char **argv, const char *prefix)
>         return 0;
>  }
>
> +struct status_cb {
> +       const char *prefix;
> +       unsigned int quiet: 1;
> +       unsigned int recursive: 1;
> +       unsigned int cached: 1;
> +};
> +#define STATUS_CB_INIT { NULL, 0, 0, 0 }
> +
> +static void print_status(struct status_cb *info, char state, const char *path,
> +                        char *sub_sha1, char *displaypath)
> +{
> +       if (info->quiet)
> +               return;
> +
> +       printf("%c%s %s", state, sub_sha1, displaypath);
> +
> +       if (state == ' ' || state == '+') {
> +               struct argv_array name_rev_args = ARGV_ARRAY_INIT;
> +
> +               argv_array_pushl(&name_rev_args, "print-name-rev",
> +                                path, sub_sha1, NULL);
> +               print_name_rev(name_rev_args.argc, name_rev_args.argv,
> +                              info->prefix);
> +       } else {
> +               printf("\n");
> +       }
> +}
> +
> +static int handle_submodule_head_ref(const char *refname,
> +                                    const struct object_id *oid, int flags,
> +                                    void *cb_data)
> +{
> +       struct strbuf *output = cb_data;
> +       if (oid)
> +               strbuf_addstr(output, oid_to_hex(oid));
> +       return 0;
> +}
> +
> +static void status_submodule(const struct cache_entry *list_item, void *cb_data)
> +{
> +       struct status_cb *info = cb_data;
> +       char *sub_sha1 = xstrdup(oid_to_hex(&list_item->oid));
> +       char *displaypath;
> +       struct stat st;
> +
> +       if (!submodule_from_path(null_sha1, list_item->name))
> +               die(_("no submodule mapping found in .gitmodules for path '%s'"),
> +                     list_item->name);
> +
> +       displaypath = get_submodule_displaypath(list_item->name, info->prefix);
> +
> +       if (list_item->ce_flags) {
> +               print_status(info, 'U', list_item->name,
> +                            sha1_to_hex(null_sha1), displaypath);
> +               goto cleanup;
> +       }
> +
> +       if (!is_submodule_active(the_repository, list_item->name)) {
> +               print_status(info, '-', list_item->name, sub_sha1, displaypath);
> +               goto cleanup;
> +       }
> +
> +       if (!lstat(list_item->name, &st) && !ce_match_stat(list_item, &st, 0)) {
> +               print_status(info, ' ', list_item->name, sub_sha1, displaypath);

The question from the last round still stands
https://public-inbox.org/git/CAGZ79kb18z5zc9iu3Vv5aVZWJmoZzmwbMVpy89VC-t-ei2M+bw@mail.gmail.com/

  I am not an expert in the diff area  and wonder how
  the cmd_diff_files functionality is achieved with just a stat call
  and then comparing it to  ce_match_stat. 'Using "dirty" ignores
  all changes to the work tree of submodules, only changes to the
  commits stored in the superproject are shown.' So I'd have
  expected ce->oid to be compared (is there an index entry differing,
  i.e. more than one stage?)

  reply	other threads:[~2017-07-18 21:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 20:48 [GSoC][PATCH 0/8] Update: Week 9 Prathamesh Chavan
2017-07-18 20:48 ` [GSoC][PATCH 1/8] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-07-18 20:48 ` [GSoC][PATCH 2/8] submodule--helper: introduce for_each_submodule_list() Prathamesh Chavan
2017-07-18 20:48 ` [GSoC][PATCH 3/8] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-07-18 20:49 ` [GSoC][PATCH 4/8] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-07-18 21:39   ` Stefan Beller [this message]
2017-07-18 22:32     ` Junio C Hamano
2017-07-18 22:44       ` Stefan Beller
2017-07-18 22:47         ` Junio C Hamano
2017-07-18 20:49 ` [GSoC][PATCH 5/8] submodule: port submodule subcommand 'sync' " Prathamesh Chavan
2017-07-18 22:23   ` Stefan Beller
2017-07-20 19:36     ` Prathamesh Chavan
2017-07-20 19:57       ` Stefan Beller
2017-07-18 20:49 ` [GSoC][PATCH 6/8] submodule: port submodule subcommand 'deinit' " Prathamesh Chavan
2017-07-19 14:04   ` Christian Couder
2017-07-18 20:49 ` [GSoC][PATCH 7/8] diff: change scope of the function count_lines() Prathamesh Chavan
2017-07-18 20:49 ` [GSoC][PATCH 8/8] submodule: port submodule subcommand 'summary' from shell to C Prathamesh Chavan
2017-07-19 14:53   ` Christian Couder
  -- strict thread matches above, loose matches on Subject: below --
2017-07-10 22:45 [GSoC] Update: Week 8 Prathamesh Chavan
2017-07-10 22:54 ` [GSoC][PATCH 1/8] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-07-10 22:54   ` [GSoC][PATCH 4/8] submodule: port submodule subcommand 'status' from shell to C Prathamesh Chavan
2017-07-10 23:38     ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGZ79kb48kNggPv64ubbBNK-Sk8AW4eXxhZt=PZZCPKr9OiuLQ@mail.gmail.com' \
    --to=sbeller@google.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pc44800@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.