• S
    submodule: port init from shell to C · 3604242f
    Stefan Beller 提交于
    By having the `submodule init` functionality in C, we can reference it
    easier from other parts in the code in later patches. The code is split
    up to have one function to initialize one submodule and a calling function
    that takes care of the rest, such as argument handling and translating the
    arguments to the paths of the submodules.
    
    This is the first submodule subcommand that is fully converted to C
    except for the usage string, so this is actually removing a call to
    the `submodule--helper list` function, which is supposed to be used in
    this transition. Instead we'll make a direct call to `module_list_compute`.
    
    An explanation why we need to edit the prefixes in cmd_update in
    git-submodule.sh in this patch:
    
    By having no processing in the shell part, we need to convey the notion
    of wt_prefix and prefix to the C parts, which former patches punted on
    and did the processing of displaying path in the shell.
    
    `wt_prefix` used to hold the path from the repository root to the current
    directory, e.g. wt_prefix would be t/ if the user invoked the
    `git submodule` command in ~/repo/t and ~repo is the GIT_DIR.
    
    `prefix` used to hold the relative path from the repository root to the
    operation, e.g. if you have recursive submodules, the shell script would
    modify the `prefix` in each recursive step by adding the submodule path.
    
    We will pass `wt_prefix` into the C helper via `git -C <dir>` as that
    will setup git in the directory the user actually called git-submodule.sh
    from. The `prefix` will be passed in via the `--prefix` option.
    
    Having `prefix` and `wt_prefix` relative to the GIT_DIR of the
    calling superproject is unfortunate with this patch as the C code doesn't
    know about a possible recursion from a superproject via `submodule update
    --init --recursive`.
    
    To fix this, we change the meaning of `wt_prefix` to point to the current
    project instead of the superproject and `prefix` to include any relative
    paths issues in the superproject. That way `prefix` will become the leading
    part for displaying paths and `wt_prefix` will be empty in recursive
    calls for now.
    
    The new notion of `wt_prefix` and `prefix` still allows us to reconstruct
    the calling directory in the superproject by just traveling reverse of
    `prefix`.
    Signed-off-by: NStefan Beller <sbeller@google.com>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    3604242f
git-submodule.sh 26.3 KB