]> git.ipfire.org Git - thirdparty/git.git/commitdiff
make credential helpers builtins
authorJeff King <peff@peff.net>
Thu, 13 Aug 2020 14:58:55 +0000 (10:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Aug 2020 18:02:08 +0000 (11:02 -0700)
There's no real reason for credential helpers to be separate binaries. I
did them this way originally under the notion that helper don't _need_
to be part of Git, and so can be built totally separately (and indeed,
the ones in contrib/credential are). But the ones in our main Makefile
build on libgit.a, and the resulting binaries are reasonably large.

We can slim down our total disk footprint by just making them builtins.
This reduces the size of:

  make strip install

from 29MB to 24MB on my Debian system.

Note that credential-cache can't operate without support for Unix
sockets. Currently we just don't build it at all when NO_UNIX_SOCKETS is
set. We could continue that with conditionals in the Makefile and our
list of builtins. But instead, let's build a dummy implementation that
dies with an informative message. That has two advantages:

  - it's simpler, because the conditional bits are all kept inside
    the credential-cache source

  - a user who is expecting it to exist will be told _why_ they can't
    use it, rather than getting the "credential-cache is not a git
    command" error which makes it look like the Git install is broken.

Note that our dummy implementation does still respond to "-h" in order
to appease t0012 (and this may be a little friendlier for users, as
well).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
builtin.h
builtin/credential-cache--daemon.c [moved from credential-cache--daemon.c with 91% similarity]
builtin/credential-cache.c [moved from credential-cache.c with 83% similarity]
builtin/credential-store.c [moved from credential-store.c with 96% similarity]
contrib/buildsystems/CMakeLists.txt
git.c

index 271b96348ecd54489bcabaac7c000b7b559369bd..5b43c0fafb950c00f09f07db890b439c78b14fa0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -672,7 +672,6 @@ EXTRA_PROGRAMS =
 PROGRAMS += $(EXTRA_PROGRAMS)
 
 PROGRAM_OBJS += bugreport.o
-PROGRAM_OBJS += credential-store.o
 PROGRAM_OBJS += daemon.o
 PROGRAM_OBJS += fast-import.o
 PROGRAM_OBJS += http-backend.o
@@ -1052,6 +1051,9 @@ BUILTIN_OBJS += builtin/checkout-index.o
 BUILTIN_OBJS += builtin/checkout.o
 BUILTIN_OBJS += builtin/clean.o
 BUILTIN_OBJS += builtin/clone.o
+BUILTIN_OBJS += builtin/credential-cache.o
+BUILTIN_OBJS += builtin/credential-cache--daemon.o
+BUILTIN_OBJS += builtin/credential-store.o
 BUILTIN_OBJS += builtin/column.o
 BUILTIN_OBJS += builtin/commit-graph.o
 BUILTIN_OBJS += builtin/commit-tree.o
@@ -1634,11 +1636,8 @@ ifdef NO_INET_PTON
 endif
 ifdef NO_UNIX_SOCKETS
        BASIC_CFLAGS += -DNO_UNIX_SOCKETS
-       EXCLUDED_PROGRAMS += git-credential-cache git-credential-cache--daemon
 else
        LIB_OBJS += unix-socket.o
-       PROGRAM_OBJS += credential-cache.o
-       PROGRAM_OBJS += credential-cache--daemon.o
 endif
 
 ifdef NO_ICONV
@@ -2901,7 +2900,6 @@ ifdef MSVC
        # because it is just a copy/hardlink of git.exe, rather than a unique binary.
        $(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
        $(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
-       $(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
index a5ae15bfe54b652465b0164872923c8386d03ae9..4a0aed54484a687a3ce9ed3ce772a6fcc1d18ae5 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -138,6 +138,9 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix);
 int cmd_config(int argc, const char **argv, const char *prefix);
 int cmd_count_objects(int argc, const char **argv, const char *prefix);
 int cmd_credential(int argc, const char **argv, const char *prefix);
+int cmd_credential_cache(int argc, const char **argv, const char *prefix);
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix);
+int cmd_credential_store(int argc, const char **argv, const char *prefix);
 int cmd_describe(int argc, const char **argv, const char *prefix);
 int cmd_diff_files(int argc, const char **argv, const char *prefix);
 int cmd_diff_index(int argc, const char **argv, const char *prefix);
similarity index 91%
rename from credential-cache--daemon.c
rename to builtin/credential-cache--daemon.c
index ec1271f89ce08b3b117fe09715f61730c7943bea..c61f123a3b81beef04d418142d0fae8b0ffd9dbe 100644 (file)
@@ -1,9 +1,12 @@
-#include "cache.h"
+#include "builtin.h"
+#include "parse-options.h"
+
+#ifndef NO_UNIX_SOCKETS
+
 #include "config.h"
 #include "tempfile.h"
 #include "credential.h"
 #include "unix-socket.h"
-#include "parse-options.h"
 
 struct credential_cache_entry {
        struct credential item;
@@ -257,7 +260,7 @@ static void init_socket_directory(const char *path)
        free(path_copy);
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
 {
        struct tempfile *socket_file;
        const char *socket_path;
@@ -275,7 +278,7 @@ int cmd_main(int argc, const char **argv)
 
        git_config_get_bool("credentialcache.ignoresighup", &ignore_sighup);
 
-       argc = parse_options(argc, argv, NULL, options, usage, 0);
+       argc = parse_options(argc, argv, prefix, options, usage, 0);
        socket_path = argv[0];
 
        if (!socket_path)
@@ -295,3 +298,21 @@ int cmd_main(int argc, const char **argv)
 
        return 0;
 }
+
+#else
+
+int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
+{
+       const char * const usage[] = {
+               "git credential-cache--daemon [options] <action>",
+               "",
+               "credential-cache--daemon is disabled in this build of Git",
+               NULL
+       };
+       struct option options[] = { OPT_END() };
+
+       argc = parse_options(argc, argv, prefix, options, usage, 0);
+       die(_("credential-cache--daemon unavailable; no unix socket support"));
+}
+
+#endif /* NO_UNIX_SOCKET */
similarity index 83%
rename from credential-cache.c
rename to builtin/credential-cache.c
index 1cccc3a0b9cfb2a14e9c87d5afc29234fa62adc4..d0fafdeb9ebc30b8ae75cae436223dedb759c179 100644 (file)
@@ -1,7 +1,10 @@
-#include "cache.h"
+#include "builtin.h"
+#include "parse-options.h"
+
+#ifndef NO_UNIX_SOCKETS
+
 #include "credential.h"
 #include "string-list.h"
-#include "parse-options.h"
 #include "unix-socket.h"
 #include "run-command.h"
 
@@ -96,7 +99,7 @@ static char *get_socket_path(void)
        return socket;
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd_credential_cache(int argc, const char **argv, const char *prefix)
 {
        char *socket_path = NULL;
        int timeout = 900;
@@ -113,7 +116,7 @@ int cmd_main(int argc, const char **argv)
                OPT_END()
        };
 
-       argc = parse_options(argc, argv, NULL, options, usage, 0);
+       argc = parse_options(argc, argv, prefix, options, usage, 0);
        if (!argc)
                usage_with_options(usage, options);
        op = argv[0];
@@ -134,3 +137,21 @@ int cmd_main(int argc, const char **argv)
 
        return 0;
 }
+
+#else
+
+int cmd_credential_cache(int argc, const char **argv, const char *prefix)
+{
+       const char * const usage[] = {
+               "git credential-cache [options] <action>",
+               "",
+               "credential-cache is disabled in this build of Git",
+               NULL
+       };
+       struct option options[] = { OPT_END() };
+
+       argc = parse_options(argc, argv, prefix, options, usage, 0);
+       die(_("credential-cache unavailable; no unix socket support"));
+}
+
+#endif /* NO_UNIX_SOCKETS */
similarity index 96%
rename from credential-store.c
rename to builtin/credential-store.c
index 294e77168156225efcb3b6840bc1dd7883c6dcac..5331ab151a6f6052dc532ab32875f864070e3b72 100644 (file)
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "lockfile.h"
 #include "credential.h"
 #include "string-list.h"
@@ -143,7 +143,7 @@ static void lookup_credential(const struct string_list *fns, struct credential *
                        return; /* Found credential */
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd_credential_store(int argc, const char **argv, const char *prefix)
 {
        const char * const usage[] = {
                "git credential-store [<options>] <action>",
@@ -161,7 +161,7 @@ int cmd_main(int argc, const char **argv)
 
        umask(077);
 
-       argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
+       argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
        if (argc != 1)
                usage_with_options(usage, options);
        op = argv[0];
index 47215df25beaaa2a37749e13b407c55fef66c11c..4be61247e5b1a51672ae91740d1c9a57cb4fc74a 100644 (file)
@@ -501,15 +501,9 @@ unset(CMAKE_REQUIRED_INCLUDES)
 
 #programs
 set(PROGRAMS_BUILT
-       git git-bugreport git-credential-store git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
+       git git-bugreport git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
        git-shell git-remote-testsvn)
 
-if(NO_UNIX_SOCKETS)
-       list(APPEND excluded_progs git-credential-cache git-credential-cache--daemon)
-else()
-       list(APPEND PROGRAMS_BUILT git-credential-cache git-credential-cache--daemon)
-endif()
-
 if(NOT CURL_FOUND)
        list(APPEND excluded_progs git-http-fetch git-http-push)
        add_compile_definitions(NO_CURL)
@@ -633,9 +627,6 @@ target_link_libraries(git common-main)
 add_executable(git-bugreport ${CMAKE_SOURCE_DIR}/bugreport.c)
 target_link_libraries(git-bugreport common-main)
 
-add_executable(git-credential-store ${CMAKE_SOURCE_DIR}/credential-store.c)
-target_link_libraries(git-credential-store common-main)
-
 add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
 target_link_libraries(git-daemon common-main)
 
@@ -672,15 +663,6 @@ endif()
 add_executable(git-remote-testsvn ${CMAKE_SOURCE_DIR}/remote-testsvn.c)
 target_link_libraries(git-remote-testsvn common-main vcs-svn)
 
-if(NOT NO_UNIX_SOCKETS)
-       add_executable(git-credential-cache ${CMAKE_SOURCE_DIR}/credential-cache.c)
-       target_link_libraries(git-credential-cache common-main)
-
-       add_executable(git-credential-cache--daemon ${CMAKE_SOURCE_DIR}/credential-cache--daemon.c)
-       target_link_libraries(git-credential-cache--daemon common-main)
-endif()
-
-
 set(git_builtin_extra
        cherry cherry-pick format-patch fsck-objects
        init merge-subtree restore show
diff --git a/git.c b/git.c
index 8bd1d7551daa28dcde69935046a055243c4b4d99..39a160fa5277a04a6527ed1d96e122f6c3b0e4e7 100644 (file)
--- a/git.c
+++ b/git.c
@@ -499,6 +499,9 @@ static struct cmd_struct commands[] = {
        { "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
        { "count-objects", cmd_count_objects, RUN_SETUP },
        { "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },
+       { "credential-cache", cmd_credential_cache },
+       { "credential-cache--daemon", cmd_credential_cache_daemon },
+       { "credential-store", cmd_credential_store },
        { "describe", cmd_describe, RUN_SETUP },
        { "diff", cmd_diff, NO_PARSEOPT },
        { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },