summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2015-09-02 21:42:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-09-03 21:12:40 (GMT)
commit0ea306ef1701d6f42e74d3c33addfcd630248904 (patch)
tree26fb1ee5833d5dba0e1da2c6b4b03a74d413c3fb /builtin
parent74703a1e4dfc5affcb8944e78b53f0817b492246 (diff)
downloadgit-0ea306ef1701d6f42e74d3c33addfcd630248904.zip
git-0ea306ef1701d6f42e74d3c33addfcd630248904.tar.gz
git-0ea306ef1701d6f42e74d3c33addfcd630248904.tar.bz2
submodule: rewrite `module_name` shell function in C
This implements the helper `name` in C instead of shell, yielding a nice performance boost. Before this patch, I measured a time (best out of three): $ time ./t7400-submodule-basic.sh >/dev/null real 0m11.066s user 0m3.348s sys 0m8.534s With this patch applied I measured (also best out of three) $ time ./t7400-submodule-basic.sh >/dev/null real 0m10.063s user 0m3.044s sys 0m7.487s Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/submodule--helper.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 10db4e6..bc79c41 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -5,6 +5,9 @@
#include "pathspec.h"
#include "dir.h"
#include "utf8.h"
+#include "submodule.h"
+#include "submodule-config.h"
+#include "string-list.h"
struct module_list {
const struct cache_entry **entries;
@@ -102,6 +105,24 @@ static int module_list(int argc, const char **argv, const char *prefix)
return 0;
}
+static int module_name(int argc, const char **argv, const char *prefix)
+{
+ const struct submodule *sub;
+
+ if (argc != 2)
+ usage(_("git submodule--helper name <path>"));
+
+ gitmodules_config();
+ sub = submodule_from_path(null_sha1, argv[1]);
+
+ if (!sub)
+ die(_("no submodule mapping found in .gitmodules for path '%s'"),
+ argv[1]);
+
+ printf("%s\n", sub->name);
+
+ return 0;
+}
struct cmd_struct {
const char *cmd;
@@ -110,6 +131,7 @@ struct cmd_struct {
static struct cmd_struct commands[] = {
{"list", module_list},
+ {"name", module_name},
};
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)