submodule: implement `list` as a builtin helper
PATCH v4 1/3 submodule: implement `list` as a builtin helper
In reply to a message not in the archiveMost of the submodule operations work on a set of submodules. Calculating and using this set is usually done via:
module_list "$@" | {
while read mode sha1 stage sm_path
do
# the actual operation
done
}
Currently the function module_list is implemented in the git-submodule.sh as a shell script wrapping a perl script. The rewrite is in C, such that it is faster and can later be easily adapted when other functions are rewritten in C.
git-submodule.sh, similar to the builtin commands, will navigate to the top-most directory of the repository and keep the subdirectory as a variable. As the helper is called from within the git-submodule.sh script, we are already navigated to the root level, but the path arguments are still relative to the subdirectory we were in when calling git-submodule.sh. That's why there is a --prefix option pointing to an alternative path which to anchor relative path arguments.
--- .gitignore | 1 + Makefile | 1 + builtin.h | 1 + builtin/submodule--helper.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ git-submodule.sh | 54 ++--------------- git.c | 1 + 6 files changed, 147 insertions(+), 48 deletions(-) create mode 100644 builtin/submodule--helper.c
.gitignore +1 -0
@@ -155,6 +155,7 @@ /git-status /git-stripspace /git-submodule +/git-submodule--helper /git-svn /git-symbolic-ref /git-tag
Makefile +1 -0
@@ -901,6 +901,7 @@ BUILTIN_OBJS += builtin/shortlog.o BUILTIN_OBJS += builtin/show-branch.o BUILTIN_OBJS += builtin/show-ref.o BUILTIN_OBJS += builtin/stripspace.o +BUILTIN_OBJS += builtin/submodule--helper.o BUILTIN_OBJS += builtin/symbolic-ref.o BUILTIN_OBJS += builtin/tag.o BUILTIN_OBJS += builtin/unpack-file.o
builtin.h +1 -0
@@ -119,6 +119,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix);extern int cmd_show_branch (int argc,const char **argv,const char *prefix);extern int cmd_status (int argc,const char **argv,const char *prefix);extern int cmd_stripspace (int argc,const char **argv,const char *prefix); +extern int cmd_submodule__helper (int argc,const char **argv,const char *prefix);extern int cmd_symbolic_ref (int argc,const char **argv,const char *prefix);extern int cmd_tag (int argc,const char **argv,const char *prefix);extern int cmd_tar_tree (int argc,const char **argv,const char *prefix);
builtin/submodule--helper.c new file +137 -0
137 lines not on this page · raw message
git-submodule.sh +6 -48
96 lines not on this page · raw message
git.c +1 -0
@@ -469,6 +469,7 @@ static struct cmd_struct commands[] = { { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, + { "submodule--helper", cmd_submodule__helper, RUN_SETUP }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP }, { "unpack-file", cmd_unpack_file, RUN_SETUP },
Signature · 1 line
2.5.0.256.g89f8063.dirty
please ignore.