From: Junio C Hamano Date: Fri, 9 Sep 2016 04:36:00 +0000 (-0700) Subject: Merge branch 'jk/tighten-alloc' into maint X-Git-Tag: v2.9.4~6 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9bef64223606a2c5fdc696745ce02b4af62bda90?ds=inline;hp=-c Merge branch 'jk/tighten-alloc' into maint Small code and comment clean-up. * jk/tighten-alloc: receive-pack: use FLEX_ALLOC_MEM in queue_command() correct FLEXPTR_* example in comment --- 9bef64223606a2c5fdc696745ce02b4af62bda90 diff --combined builtin/receive-pack.c index a744437b58,b55d0aaee7..05d04400f5 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@@ -21,10 -21,7 +21,10 @@@ #include "sigchain.h" #include "fsck.h" -static const char receive_pack_usage[] = "git receive-pack "; +static const char * const receive_pack_usage[] = { + N_("git receive-pack "), + NULL +}; enum deny_action { DENY_UNCONFIGURED, @@@ -52,7 -49,7 +52,7 @@@ static int quiet static int prefer_ofs_delta = 1; static int auto_update_server_info; static int auto_gc = 1; -static int fix_thin = 1; +static int reject_thin; static int stateless_rpc; static const char *service_dir; static const char *head_name; @@@ -1084,13 -1081,13 +1084,13 @@@ static void check_aliased_update(struc if (!(flag & REF_ISSYMREF)) return; - dst_name = strip_namespace(dst_name); if (!dst_name) { rp_error("refusing update to broken symref '%s'", cmd->ref_name); cmd->skip_update = 1; cmd->error_string = "broken symref"; return; } + dst_name = strip_namespace(dst_name); if ((item = string_list_lookup(list, dst_name)) == NULL) return; @@@ -1375,11 -1372,9 +1375,9 @@@ static struct command **queue_command(s refname = line + 82; reflen = linelen - 82; - cmd = xcalloc(1, st_add3(sizeof(struct command), reflen, 1)); + FLEX_ALLOC_MEM(cmd, ref_name, refname, reflen); hashcpy(cmd->old_sha1, old_sha1); hashcpy(cmd->new_sha1, new_sha1); - memcpy(cmd->ref_name, refname, reflen); - cmd->ref_name[reflen] = '\0'; *tail = cmd; return &cmd->next; } @@@ -1551,7 -1546,7 +1549,7 @@@ static const char *unpack(int err_fd, s if (fsck_objects) argv_array_pushf(&child.args, "--strict%s", fsck_msg_types.buf); - if (fix_thin) + if (!reject_thin) argv_array_push(&child.args, "--fix-thin"); child.out = -1; child.err = err_fd; @@@ -1710,29 -1705,45 +1708,29 @@@ static int delete_only(struct command * int cmd_receive_pack(int argc, const char **argv, const char *prefix) { int advertise_refs = 0; - int i; struct command *commands; struct sha1_array shallow = SHA1_ARRAY_INIT; struct sha1_array ref = SHA1_ARRAY_INIT; struct shallow_info si; - packet_trace_identity("receive-pack"); + struct option options[] = { + OPT__QUIET(&quiet, N_("quiet")), + OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL), + OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL), + OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin, NULL), + OPT_END() + }; - argv++; - for (i = 1; i < argc; i++) { - const char *arg = *argv++; + packet_trace_identity("receive-pack"); - if (*arg == '-') { - if (!strcmp(arg, "--quiet")) { - quiet = 1; - continue; - } + argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0); - if (!strcmp(arg, "--advertise-refs")) { - advertise_refs = 1; - continue; - } - if (!strcmp(arg, "--stateless-rpc")) { - stateless_rpc = 1; - continue; - } - if (!strcmp(arg, "--reject-thin-pack-for-testing")) { - fix_thin = 0; - continue; - } + if (argc > 1) + usage_msg_opt(_("Too many arguments."), receive_pack_usage, options); + if (argc == 0) + usage_msg_opt(_("You must specify a directory."), receive_pack_usage, options); - usage(receive_pack_usage); - } - if (service_dir) - usage(receive_pack_usage); - service_dir = arg; - } - if (!service_dir) - usage(receive_pack_usage); + service_dir = argv[0]; setup_path(); diff --combined git-compat-util.h index 9eab471264,17918d028a..b4b7f44952 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -279,6 -279,9 +279,6 @@@ extern char *gitdirname(char *) #endif #include #include -#ifdef NO_HMAC_CTX_CLEANUP -#define HMAC_CTX_cleanup HMAC_cleanup -#endif #endif /* On most systems would have given us this, but @@@ -330,6 -333,10 +330,6 @@@ #define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin" #endif -#ifndef STRIP_EXTENSION -#define STRIP_EXTENSION "" -#endif - #ifndef has_dos_drive_prefix static inline int git_has_dos_drive_prefix(const char *path) { @@@ -409,9 -416,7 +409,9 @@@ extern NORETURN void usagef(const char extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); +extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); +extern void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); #ifndef NO_OPENSSL #ifdef APPLE_COMMON_CRYPTO @@@ -650,10 -655,6 +650,10 @@@ void *gitmemmem(const void *haystack, s #define getpagesize() sysconf(_SC_PAGESIZE) #endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + #ifdef FREAD_READS_DIRECTORIES #ifdef fopen #undef fopen @@@ -718,8 -719,8 +718,8 @@@ static inline size_t st_add(size_t a, s (uintmax_t)a, (uintmax_t)b); return a + b; } -#define st_add3(a,b,c) st_add((a),st_add((b),(c))) -#define st_add4(a,b,c,d) st_add((a),st_add3((b),(c),(d))) +#define st_add3(a,b,c) st_add(st_add((a),(b)),(c)) +#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d)) static inline size_t st_mult(size_t a, size_t b) { @@@ -802,7 -803,7 +802,7 @@@ extern FILE *fopen_for_writing(const ch * you can do: * * struct foo *f; - * FLEX_ALLOC_STR(f, name, src); + * FLEXPTR_ALLOC_STR(f, name, src); * * and "name" will point to a block of memory after the struct, which will be * freed along with the struct (but the pointer can be repointed anywhere). @@@ -1049,5 -1050,3 +1049,5 @@@ struct tm *git_gmtime_r(const time_t * #endif #endif + +extern int cmd_main(int, const char **);