From: Junio C Hamano <gitster@pobox•com>
To: Prathamesh Chavan <pc44800@gmail•com>
Cc: git@vger•kernel.org, sbeller@google•com, christian.couder@gmail•com
Subject: Re: [GSoC][PATCH 3/5 v3] submodule: port set_name_rev() from shell to C
Date: Fri, 30 Jun 2017 15:49:23 -0700 [thread overview]
Message-ID: <xmqqbmp5ozv0.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170630194727.29787-3-pc44800@gmail.com> (Prathamesh Chavan's message of "Sat, 1 Jul 2017 01:17:25 +0530")
Prathamesh Chavan <pc44800@gmail•com> writes:
> Function set_name_rev() is ported from git-submodule to the
> submodule--helper builtin. The function get_name_rev() generates the
> value of the revision name as required, and the function
> print_name_rev() handles the formating and printing of the obtained
> revision name.
>
> 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 | 69 +++++++++++++++++++++++++++++++++++++++++++++
> git-submodule.sh | 16 ++---------
> 2 files changed, 71 insertions(+), 14 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index c4286aac5..4103e40e4 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -244,6 +244,74 @@ static char *get_submodule_displaypath(const char *path, const char *prefix)
> }
> }
>
> +enum describe_step {
> + step_bare,
> + step_tags,
> + step_contains,
> + step_all_always,
> + step_end
> +};
Hmph.
The only difference between the steps being what subcommand is run,
a better implementation might be to do
static const char *describe_bare[] = {
NULL
};
...
static const char **describe_argv[] = {
describe_bare, describe_tags, describe_contains,
describe_all_always, NULL
};
const char ***d;
for (d = describe_argv; *d; d++) {
argv_array_pushl(&cp.args, "describe");
argv_array_pushv(&cp.args, *d);
... do the thing ...
}
but unfortunately C is a bit klunky to do so; we cannot easily make
the contents of describe_argv[] as anonymous arrays. An otherwise
useless enum stil bothers me, but I do not think of anything better
offhand.
> +
> +static char *get_name_rev(const char *sub_path, const char* object_id)
> +{
> + struct strbuf sb = STRBUF_INIT;
> + enum describe_step cur_step;
> +
> + for (cur_step = step_bare; cur_step < step_end; cur_step++) {
> + struct child_process cp = CHILD_PROCESS_INIT;
> + prepare_submodule_repo_env(&cp.env_array);
> + cp.dir = sub_path;
> + cp.git_cmd = 1;
> + cp.no_stderr = 1;
> +
> + switch (cur_step) {
> + case step_bare:
> + argv_array_pushl(&cp.args, "describe",
> + object_id, NULL);
> + break;
> + case step_tags:
> + argv_array_pushl(&cp.args, "describe",
> + "--tags", object_id, NULL);
> + break;
> + case step_contains:
> + argv_array_pushl(&cp.args, "describe",
> + "--contains", object_id,
> + NULL);
> + break;
> + case step_all_always:
> + argv_array_pushl(&cp.args, "describe",
> + "--all", "--always",
> + object_id, NULL);
> + break;
> + default:
> + BUG("unknown describe step '%d'", cur_step);
> + }
Dedent the body of switch() by one level, i.e.
switch (var) {
case val1:
do_this();
break;
case val2:
do_that();
...
}
Otherwise looking good.
> @@ -1042,14 +1030,14 @@ cmd_status()
> fi
> if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path"
> then
> - set_name_rev "$sm_path" "$sha1"
> + revname=$(git submodule--helper print-name-rev "$sm_path" "$sha1")
> say " $sha1 $displaypath$revname"
> else
> if test -z "$cached"
> then
> sha1=$(sanitize_submodule_env; cd "$sm_path" && git rev-parse --verify HEAD)
> fi
> - set_name_rev "$sm_path" "$sha1"
> + revname=$(git submodule--helper print-name-rev "$sm_path" "$sha1")
> say "+$sha1 $displaypath$revname"
> fi
next prev parent reply other threads:[~2017-06-30 22:49 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-26 23:09 [GSoC] Update: Week 6 Prathamesh Chavan
2017-06-26 23:11 ` [GSoC][PATCH 1/6 v2] submodule--helper: introduce for_each_submodule_list Prathamesh Chavan
2017-06-26 23:11 ` [GSoC][PATCH 2/6 v2] submodule: port subcommand foreach from shell to C Prathamesh Chavan
2017-06-27 6:06 ` Christian Couder
2017-06-26 23:11 ` [GSoC][PATCH 3/6 v2] submodule: port set_name_rev " Prathamesh Chavan
2017-06-26 23:11 ` [GSoC][PATCH 4/6 v2] submodule: port submodule subcommand status Prathamesh Chavan
2017-06-26 23:11 ` [GSoC][PATCH 5/6 v2] submodule: port submodule subcommand sync from shell to C Prathamesh Chavan
2017-06-27 6:37 ` Christian Couder
2017-06-26 23:11 ` [GSoC][PATCH 6/6 v2] submodule: port submodule subcommand 'deinit' " Prathamesh Chavan
2017-06-27 7:18 ` Christian Couder
2017-06-28 19:53 ` [GSoC][PATCH 1/6 v2] submodule--helper: introduce for_each_submodule_list Junio C Hamano
2017-06-29 11:47 ` Prathamesh Chavan
2017-06-30 19:47 ` [GSoC][PATCH 1/5 v3] submodule--helper: introduce get_submodule_displaypath() Prathamesh Chavan
2017-06-30 19:47 ` [GSoC][PATCH 2/5 v3] submodule--helper: introduce for_each_submodule_list() Prathamesh Chavan
2017-06-30 19:47 ` [GSoC][PATCH 3/5 v3] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-06-30 22:49 ` Junio C Hamano [this message]
2017-06-30 19:47 ` [GSoC][PATCH 4/5 v3] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-06-30 23:08 ` Junio C Hamano
2017-06-30 19:47 ` [GSoC][PATCH 5/5 v3] submodule: port submodule subcommand 'sync' " Prathamesh Chavan
2017-06-30 20:11 ` Stefan Beller
2017-06-30 23:19 ` Junio C Hamano
2017-06-30 22:37 ` [GSoC][PATCH 1/5 v3] submodule--helper: introduce get_submodule_displaypath() Junio C Hamano
2017-07-13 20:05 ` [GSoC][PATCH 1/5 v4] " Prathamesh Chavan
2017-07-13 20:05 ` [GSoC][PATCH 2/5 v4] submodule--helper: introduce for_each_submodule_list() Prathamesh Chavan
2017-07-13 20:05 ` [GSoC][PATCH 3/5 v4] submodule: port set_name_rev() from shell to C Prathamesh Chavan
2017-07-13 20:05 ` [GSoC][PATCH 4/5 v4] submodule: port submodule subcommand 'status' " Prathamesh Chavan
2017-07-13 22:44 ` Stefan Beller
2017-07-13 20:05 ` [GSoC][PATCH 5/5 v4] submodule: port submodule subcommand 'sync' " Prathamesh Chavan
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=xmqqbmp5ozv0.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=christian.couder@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=pc44800@gmail$(echo .)com \
--cc=sbeller@google$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox