On Mon, Aug 21, 2017 at 09:45:14PM +0530, Prathamesh Chavan wrote:
> 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.cou...@gmail.com>
> Mentored-by: Stefan Beller <sbel...@google.com>
> Signed-off-by: Prathamesh Chavan <pc44...@gmail.com>
> ---
>  builtin/submodule--helper.c | 63 
> +++++++++++++++++++++++++++++++++++++++++++++
>  git-submodule.sh            | 16 ++----------
>  2 files changed, 65 insertions(+), 14 deletions(-)
> 
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 7803457ba..a4bff3f38 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c

[...]

> @@ -1242,6 +1304,7 @@ static struct cmd_struct commands[] = {
>       {"relative-path", resolve_relative_path, 0},
>       {"resolve-relative-url", resolve_relative_url, 0},
>       {"resolve-relative-url-test", resolve_relative_url_test, 0},
> +     {"print-name-rev", print_name_rev, 0},

I see the function in git-submodule.sh was named kind of reverse. How
about we do it more naturally here and call this 'rev-name' instead?
That makes is more clear to me and is also similar to the used variable
name 'revname'.

I would also prefix it differently like 'get' or 'calculate' instead of
'print' since it tries to find a name and is not just a simple lookup.

So in summary I would prefer something like 'get-rev-name' as a name for
the subcommand here.

>       {"init", module_init, SUPPORT_SUPER_PREFIX},
>       {"remote-branch", resolve_remote_submodule_branch, 0},
>       {"push-check", push_check, 0},
> diff --git a/git-submodule.sh b/git-submodule.sh
> index e131760ee..e988167e0 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -759,18 +759,6 @@ cmd_update()
>       }
>  }
>  
> -set_name_rev () {
> -     revname=$( (
> -             sanitize_submodule_env
> -             cd "$1" && {
> -                     git describe "$2" 2>/dev/null ||
> -                     git describe --tags "$2" 2>/dev/null ||
> -                     git describe --contains "$2" 2>/dev/null ||
> -                     git describe --all --always "$2"
> -             }
> -     ) )
> -     test -z "$revname" || revname=" ($revname)"
> -}
>  #
>  # Show commit summary for submodules in index or working tree
>  #
> @@ -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
>  
> -- 
> 2.13.0
> 

Reply via email to