git@vger.kernel.org mailing list mirror (one of many)
 help / 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 v2 1/2] submodule: port set_name_rev from shell to C
Date: Mon, 5 Jun 2017 15:50:22 -0700
Message-ID: <CAGZ79kZv_Jw1n6z=5sDOtiJecyJmQ-NEzYN6kPL_uCCHTKE0bg@mail.gmail.com> (raw)
In-Reply-To: <20170605202529.22959-1-pc44800@gmail.com>

On Mon, Jun 5, 2017 at 1:25 PM, Prathamesh Chavan <pc44800@gmail.com> wrote:
> Since later on we want to port submodule subcommand status, and since
> set_name_rev is part of cmd_status, hence this function is ported. It
> has been ported to function print_name_rev in C, which calls get_name_rev
> to get the revname, and after formatting it, print_name_rev prints it.
> And hence in this way, the command `git submodule--helper print-name-rev
> "sm_path" "sha1"` sets value of revname in git-submodule.sh
>
> The function get_name_rev returns the stdout of the git describe
> commands. Since there are four different git-describe commands used for
> generating the name rev, four child_process are introduced, each successive
> child process running only when previous has no stdout. The order of these
> four git-describe commands is maintained the same as it was in the function
> set_name_rev() in shell script.
>
> 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 | 67 +++++++++++++++++++++++++++++++++++++++++++++
>  git-submodule.sh            | 16 ++---------
>  2 files changed, 69 insertions(+), 14 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 566a5b6a6..3022118d1 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -219,6 +219,72 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
>         return 0;
>  }
>
> +enum describe_step {
> +       step_bare = 0,

Do we rely on step_bare to be equal to 0?
(This is the hint I am reading from '=0' here.
If we do not, please omit.)

> +       step_tags,
> +       step_contains,
> +       step_all_always,
> +       step_end
> +};
> +
> +static char *get_name_rev(int argc, const char **argv, const char *prefix)

So we split up the functionality into two functions.
get_name_rev, which does the heavy lifting work, and
print_name_rev, that is a wrapper around having to deal with
going from shell to C and back.

One of C strength' compared to shell is type safety,
so maybe we can tighten the contract that get_name_rev
offers to its callers and make it

  get_name_rev(const char *sub_path, const char *object_id / sha1)

and then have print_name_rev call it via

  get_name_rev (argv[1], argv[2])

(which coincidentally is right after checking for
argc != 3, which reinforces that the contract of the
wrapper is "just making sure we have valid input" and
this function "just does heavy lifting, assuming input
is valid".

> +{
> +       struct child_process cp;
> +       struct strbuf sb = STRBUF_INIT;
> +       enum describe_step cur_step;
> +
> +       for (cur_step = step_bare; cur_step < step_end; cur_step++) {
> +               child_process_init(&cp);

(minor nit, personal opinion, feel free to ignore:)
Alternatively, you could declare cp inside the loop assigned to
CHILD_PROCESS_INIT.
Same for strbuf sb as well, such that you only declare the iterator
variable outside the loop.

> +               prepare_submodule_repo_env(&cp.env_array);
> +               cp.dir = argv[1];
> +               cp.no_stderr = 1;

cp.git_cmd = 1; as well?

Thanks,
Stefan

  parent reply index

Thread overview: 9+ messages in thread (expand / mbox.gz / Atom feed / [top])
2017-05-21 12:27 [GSoC][PATCH v1 1/2] submodule: port set_name_rev from shell to C Prathamesh Chavan
2017-05-21 12:27 ` [GSoC][PATCH v1 2/2] submodule: port submodule subcommand status Prathamesh Chavan
2017-05-22 21:28   ` Stefan Beller
2017-06-05 20:25     ` Prathamesh Chavan
2017-06-05 20:25       ` [GSoC][PATCH v2 2/2] submodule: port submodule subcommand status Prathamesh Chavan
2017-06-05 23:12         ` Stefan Beller
2017-06-06  4:24         ` Christian Couder
2017-06-05 22:50       ` Stefan Beller [this message]
2017-06-05 23:20       ` Brandon Williams

Reply instructions:

You may reply publically 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 to all the recipients using the --to, --cc,
  and --in-reply-to switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGZ79kZv_Jw1n6z=5sDOtiJecyJmQ-NEzYN6kPL_uCCHTKE0bg@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

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox