@matheusbsbs / matheus-bagliano / commits / b5dd96b70a
Fork 0

make credential helpers builtins

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>

Jeff King committed Aug 13, 2020 at 10:58 UTC b5dd96b70aca364f163f0b3743418779cfe062e6
7 files changed +63 -35
Makefile
+3 -5
@@ -672,7 +672,6 @@ EXTRA_PROGRAMS =
672 PROGRAMS += $(EXTRA_PROGRAMS)
673
674 PROGRAM_OBJS += bugreport.o
675 -PROGRAM_OBJS += credential-store.o
675 PROGRAM_OBJS += daemon.o
676 PROGRAM_OBJS += fast-import.o
677 PROGRAM_OBJS += http-backend.o
@@ -1052,6 +1051,9 @@ BUILTIN_OBJS += builtin/checkout-index.o
1051 BUILTIN_OBJS += builtin/checkout.o
1052 BUILTIN_OBJS += builtin/clean.o
1053 BUILTIN_OBJS += builtin/clone.o
1054 +BUILTIN_OBJS += builtin/credential-cache.o
1055 +BUILTIN_OBJS += builtin/credential-cache--daemon.o
1056 +BUILTIN_OBJS += builtin/credential-store.o
1057 BUILTIN_OBJS += builtin/column.o
1058 BUILTIN_OBJS += builtin/commit-graph.o
1059 BUILTIN_OBJS += builtin/commit-tree.o
@@ -1634,11 +1636,8 @@ ifdef NO_INET_PTON
1636 endif
1637 ifdef NO_UNIX_SOCKETS
1638 BASIC_CFLAGS += -DNO_UNIX_SOCKETS
1637 - EXCLUDED_PROGRAMS += git-credential-cache git-credential-cache--daemon
1639 else
1640 LIB_OBJS += unix-socket.o
1640 - PROGRAM_OBJS += credential-cache.o
1641 - PROGRAM_OBJS += credential-cache--daemon.o
1641 endif
1642
1643 ifdef NO_ICONV
@@ -2901,7 +2900,6 @@ ifdef MSVC
2900 # because it is just a copy/hardlink of git.exe, rather than a unique binary.
2901 $(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2902 $(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2904 - $(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2903 $(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2904 $(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2905 $(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
builtin.h
+3
@@ -138,6 +138,9 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix);
138 int cmd_config(int argc, const char **argv, const char *prefix);
139 int cmd_count_objects(int argc, const char **argv, const char *prefix);
140 int cmd_credential(int argc, const char **argv, const char *prefix);
141 +int cmd_credential_cache(int argc, const char **argv, const char *prefix);
142 +int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix);
143 +int cmd_credential_store(int argc, const char **argv, const char *prefix);
144 int cmd_describe(int argc, const char **argv, const char *prefix);
145 int cmd_diff_files(int argc, const char **argv, const char *prefix);
146 int cmd_diff_index(int argc, const char **argv, const char *prefix);
builtin/credential-cache--daemon.c renamed
+25 -4
@@ -1,9 +1,12 @@
1 -#include "cache.h"
1 +#include "builtin.h"
2 +#include "parse-options.h"
3 +
4 +#ifndef NO_UNIX_SOCKETS
5 +
6 #include "config.h"
7 #include "tempfile.h"
8 #include "credential.h"
9 #include "unix-socket.h"
6 -#include "parse-options.h"
10
11 struct credential_cache_entry {
12 struct credential item;
@@ -257,7 +260,7 @@ static void init_socket_directory(const char *path)
260 free(path_copy);
261 }
262
260 -int cmd_main(int argc, const char **argv)
263 +int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
264 {
265 struct tempfile *socket_file;
266 const char *socket_path;
@@ -275,7 +278,7 @@ int cmd_main(int argc, const char **argv)
278
279 git_config_get_bool("credentialcache.ignoresighup", &ignore_sighup);
280
278 - argc = parse_options(argc, argv, NULL, options, usage, 0);
281 + argc = parse_options(argc, argv, prefix, options, usage, 0);
282 socket_path = argv[0];
283
284 if (!socket_path)
@@ -295,3 +298,21 @@ int cmd_main(int argc, const char **argv)
298
299 return 0;
300 }
301 +
302 +#else
303 +
304 +int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
305 +{
306 + const char * const usage[] = {
307 + "git credential-cache--daemon [options] <action>",
308 + "",
309 + "credential-cache--daemon is disabled in this build of Git",
310 + NULL
311 + };
312 + struct option options[] = { OPT_END() };
313 +
314 + argc = parse_options(argc, argv, prefix, options, usage, 0);
315 + die(_("credential-cache--daemon unavailable; no unix socket support"));
316 +}
317 +
318 +#endif /* NO_UNIX_SOCKET */
builtin/credential-cache.c renamed
+25 -4
@@ -1,7 +1,10 @@
1 -#include "cache.h"
1 +#include "builtin.h"
2 +#include "parse-options.h"
3 +
4 +#ifndef NO_UNIX_SOCKETS
5 +
6 #include "credential.h"
7 #include "string-list.h"
4 -#include "parse-options.h"
8 #include "unix-socket.h"
9 #include "run-command.h"
10
@@ -96,7 +99,7 @@ static char *get_socket_path(void)
99 return socket;
100 }
101
99 -int cmd_main(int argc, const char **argv)
102 +int cmd_credential_cache(int argc, const char **argv, const char *prefix)
103 {
104 char *socket_path = NULL;
105 int timeout = 900;
@@ -113,7 +116,7 @@ int cmd_main(int argc, const char **argv)
116 OPT_END()
117 };
118
116 - argc = parse_options(argc, argv, NULL, options, usage, 0);
119 + argc = parse_options(argc, argv, prefix, options, usage, 0);
120 if (!argc)
121 usage_with_options(usage, options);
122 op = argv[0];
@@ -134,3 +137,21 @@ int cmd_main(int argc, const char **argv)
137
138 return 0;
139 }
140 +
141 +#else
142 +
143 +int cmd_credential_cache(int argc, const char **argv, const char *prefix)
144 +{
145 + const char * const usage[] = {
146 + "git credential-cache [options] <action>",
147 + "",
148 + "credential-cache is disabled in this build of Git",
149 + NULL
150 + };
151 + struct option options[] = { OPT_END() };
152 +
153 + argc = parse_options(argc, argv, prefix, options, usage, 0);
154 + die(_("credential-cache unavailable; no unix socket support"));
155 +}
156 +
157 +#endif /* NO_UNIX_SOCKETS */
builtin/credential-store.c renamed
+3 -3
@@ -1,4 +1,4 @@
1 -#include "cache.h"
1 +#include "builtin.h"
2 #include "lockfile.h"
3 #include "credential.h"
4 #include "string-list.h"
@@ -143,7 +143,7 @@ static void lookup_credential(const struct string_list *fns, struct credential *
143 return; /* Found credential */
144 }
145
146 -int cmd_main(int argc, const char **argv)
146 +int cmd_credential_store(int argc, const char **argv, const char *prefix)
147 {
148 const char * const usage[] = {
149 "git credential-store [<options>] <action>",
@@ -161,7 +161,7 @@ int cmd_main(int argc, const char **argv)
161
162 umask(077);
163
164 - argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
164 + argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
165 if (argc != 1)
166 usage_with_options(usage, options);
167 op = argv[0];
contrib/buildsystems/CMakeLists.txt
+1 -19
@@ -501,15 +501,9 @@ unset(CMAKE_REQUIRED_INCLUDES)
501
502 #programs
503 set(PROGRAMS_BUILT
504 - git git-bugreport git-credential-store git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
504 + git git-bugreport git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
505 git-shell git-remote-testsvn)
506
507 -if(NO_UNIX_SOCKETS)
508 - list(APPEND excluded_progs git-credential-cache git-credential-cache--daemon)
509 -else()
510 - list(APPEND PROGRAMS_BUILT git-credential-cache git-credential-cache--daemon)
511 -endif()
512 -
507 if(NOT CURL_FOUND)
508 list(APPEND excluded_progs git-http-fetch git-http-push)
509 add_compile_definitions(NO_CURL)
@@ -633,9 +627,6 @@ target_link_libraries(git common-main)
627 add_executable(git-bugreport ${CMAKE_SOURCE_DIR}/bugreport.c)
628 target_link_libraries(git-bugreport common-main)
629
636 -add_executable(git-credential-store ${CMAKE_SOURCE_DIR}/credential-store.c)
637 -target_link_libraries(git-credential-store common-main)
638 -
630 add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
631 target_link_libraries(git-daemon common-main)
632
@@ -672,15 +663,6 @@ endif()
663 add_executable(git-remote-testsvn ${CMAKE_SOURCE_DIR}/remote-testsvn.c)
664 target_link_libraries(git-remote-testsvn common-main vcs-svn)
665
675 -if(NOT NO_UNIX_SOCKETS)
676 - add_executable(git-credential-cache ${CMAKE_SOURCE_DIR}/credential-cache.c)
677 - target_link_libraries(git-credential-cache common-main)
678 -
679 - add_executable(git-credential-cache--daemon ${CMAKE_SOURCE_DIR}/credential-cache--daemon.c)
680 - target_link_libraries(git-credential-cache--daemon common-main)
681 -endif()
682 -
683 -
666 set(git_builtin_extra
667 cherry cherry-pick format-patch fsck-objects
668 init merge-subtree restore show
git.c
+3
@@ -499,6 +499,9 @@ static struct cmd_struct commands[] = {
499 { "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
500 { "count-objects", cmd_count_objects, RUN_SETUP },
501 { "credential", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },
502 + { "credential-cache", cmd_credential_cache },
503 + { "credential-cache--daemon", cmd_credential_cache_daemon },
504 + { "credential-store", cmd_credential_store },
505 { "describe", cmd_describe, RUN_SETUP },
506 { "diff", cmd_diff, NO_PARSEOPT },
507 { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },