зеркало из https://github.com/microsoft/git.git
Reduce parse-options.o dependencies
Currently parse-options.o pulls quite a big bunch of dependencies. his complicates it's usage in contrib/ because it pulls external dependencies and it also increases executables size. Split off less generic and more internal to git part of parse-options.c to parse-options-cb.c. Move prefix_filename function from setup.c to abspath.c. abspath.o and wrapper.o pull each other, so it's unlikely to increase the dependencies. It was a dependency of parse-options.o that pulled many others. Now parse-options.o pulls just abspath.o, ctype.o, strbuf.o, usage.o, wrapper.o, libc directly and strlcpy.o indirectly. Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
1f275b7c4c
Коммит
0687628466
3
Makefile
3
Makefile
|
@ -642,6 +642,7 @@ LIB_OBJS += pack-revindex.o
|
|||
LIB_OBJS += pack-write.o
|
||||
LIB_OBJS += pager.o
|
||||
LIB_OBJS += parse-options.o
|
||||
LIB_OBJS += parse-options-cb.o
|
||||
LIB_OBJS += patch-delta.o
|
||||
LIB_OBJS += patch-ids.o
|
||||
LIB_OBJS += path.o
|
||||
|
@ -2204,7 +2205,7 @@ test-delta$X: diff-delta.o patch-delta.o
|
|||
|
||||
test-line-buffer$X: vcs-svn/lib.a
|
||||
|
||||
test-parse-options$X: parse-options.o
|
||||
test-parse-options$X: parse-options.o parse-options-cb.o
|
||||
|
||||
test-string-pool$X: vcs-svn/lib.a
|
||||
|
||||
|
|
28
abspath.c
28
abspath.c
|
@ -139,3 +139,31 @@ const char *absolute_path(const char *path)
|
|||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlike prefix_path, this should be used if the named file does
|
||||
* not have to interact with index entry; i.e. name of a random file
|
||||
* on the filesystem.
|
||||
*/
|
||||
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
|
||||
{
|
||||
static char path[PATH_MAX];
|
||||
#ifndef WIN32
|
||||
if (!pfx_len || is_absolute_path(arg))
|
||||
return arg;
|
||||
memcpy(path, pfx, pfx_len);
|
||||
strcpy(path + pfx_len, arg);
|
||||
#else
|
||||
char *p;
|
||||
/* don't add prefix to absolute paths, but still replace '\' by '/' */
|
||||
if (is_absolute_path(arg))
|
||||
pfx_len = 0;
|
||||
else if (pfx_len)
|
||||
memcpy(path, pfx, pfx_len);
|
||||
strcpy(path + pfx_len, arg);
|
||||
for (p = path + pfx_len; *p; p++)
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "parse-options.h"
|
||||
#include "cache.h"
|
||||
#include "commit.h"
|
||||
#include "color.h"
|
||||
#include "string-list.h"
|
||||
|
||||
/*----- some often used options -----*/
|
||||
|
||||
int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
int v;
|
||||
|
||||
if (!arg) {
|
||||
v = unset ? 0 : DEFAULT_ABBREV;
|
||||
} else {
|
||||
v = strtol(arg, (char **)&arg, 10);
|
||||
if (*arg)
|
||||
return opterror(opt, "expects a numerical value", 0);
|
||||
if (v && v < MINIMUM_ABBREV)
|
||||
v = MINIMUM_ABBREV;
|
||||
else if (v > 40)
|
||||
v = 40;
|
||||
}
|
||||
*(int *)(opt->value) = v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
|
||||
int unset)
|
||||
{
|
||||
*(unsigned long *)(opt->value) = approxidate(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
|
||||
int unset)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (!arg)
|
||||
arg = unset ? "never" : (const char *)opt->defval;
|
||||
value = git_config_colorbool(NULL, arg, -1);
|
||||
if (value < 0)
|
||||
return opterror(opt,
|
||||
"expects \"always\", \"auto\", or \"never\"", 0);
|
||||
*(int *)opt->value = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
|
||||
int unset)
|
||||
{
|
||||
int *target = opt->value;
|
||||
|
||||
if (unset)
|
||||
/* --no-quiet, --no-verbose */
|
||||
*target = 0;
|
||||
else if (opt->short_name == 'v') {
|
||||
if (*target >= 0)
|
||||
(*target)++;
|
||||
else
|
||||
*target = 1;
|
||||
} else {
|
||||
if (*target <= 0)
|
||||
(*target)--;
|
||||
else
|
||||
*target = -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
unsigned char sha1[20];
|
||||
struct commit *commit;
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
if (get_sha1(arg, sha1))
|
||||
return error("malformed object name %s", arg);
|
||||
commit = lookup_commit_reference(sha1);
|
||||
if (!commit)
|
||||
return error("no such commit %s", arg);
|
||||
commit_list_insert(commit, opt->value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
int *target = opt->value;
|
||||
*target = unset ? 2 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < dst_size; i++)
|
||||
if (dst[i].type == OPTION_END)
|
||||
break;
|
||||
for (j = 0; i < dst_size; i++, j++) {
|
||||
dst[i] = src[j];
|
||||
if (src[j].type == OPTION_END)
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
struct string_list *v = opt->value;
|
||||
|
||||
if (unset) {
|
||||
string_list_clear(v, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
|
||||
string_list_append(v, xstrdup(arg));
|
||||
return 0;
|
||||
}
|
121
parse-options.c
121
parse-options.c
|
@ -3,7 +3,6 @@
|
|||
#include "cache.h"
|
||||
#include "commit.h"
|
||||
#include "color.h"
|
||||
#include "string-list.h"
|
||||
|
||||
static int parse_options_usage(struct parse_opt_ctx_t *ctx,
|
||||
const char * const *usagestr,
|
||||
|
@ -584,123 +583,3 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
|
|||
return usage_with_options_internal(ctx, usagestr, opts, 0, err);
|
||||
}
|
||||
|
||||
|
||||
/*----- some often used options -----*/
|
||||
#include "cache.h"
|
||||
|
||||
int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
int v;
|
||||
|
||||
if (!arg) {
|
||||
v = unset ? 0 : DEFAULT_ABBREV;
|
||||
} else {
|
||||
v = strtol(arg, (char **)&arg, 10);
|
||||
if (*arg)
|
||||
return opterror(opt, "expects a numerical value", 0);
|
||||
if (v && v < MINIMUM_ABBREV)
|
||||
v = MINIMUM_ABBREV;
|
||||
else if (v > 40)
|
||||
v = 40;
|
||||
}
|
||||
*(int *)(opt->value) = v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
|
||||
int unset)
|
||||
{
|
||||
*(unsigned long *)(opt->value) = approxidate(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
|
||||
int unset)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (!arg)
|
||||
arg = unset ? "never" : (const char *)opt->defval;
|
||||
value = git_config_colorbool(NULL, arg, -1);
|
||||
if (value < 0)
|
||||
return opterror(opt,
|
||||
"expects \"always\", \"auto\", or \"never\"", 0);
|
||||
*(int *)opt->value = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
|
||||
int unset)
|
||||
{
|
||||
int *target = opt->value;
|
||||
|
||||
if (unset)
|
||||
/* --no-quiet, --no-verbose */
|
||||
*target = 0;
|
||||
else if (opt->short_name == 'v') {
|
||||
if (*target >= 0)
|
||||
(*target)++;
|
||||
else
|
||||
*target = 1;
|
||||
} else {
|
||||
if (*target <= 0)
|
||||
(*target)--;
|
||||
else
|
||||
*target = -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
unsigned char sha1[20];
|
||||
struct commit *commit;
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
if (get_sha1(arg, sha1))
|
||||
return error("malformed object name %s", arg);
|
||||
commit = lookup_commit_reference(sha1);
|
||||
if (!commit)
|
||||
return error("no such commit %s", arg);
|
||||
commit_list_insert(commit, opt->value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
int *target = opt->value;
|
||||
*target = unset ? 2 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < dst_size; i++)
|
||||
if (dst[i].type == OPTION_END)
|
||||
break;
|
||||
for (j = 0; i < dst_size; i++, j++) {
|
||||
dst[i] = src[j];
|
||||
if (src[j].type == OPTION_END)
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
|
||||
{
|
||||
struct string_list *v = opt->value;
|
||||
|
||||
if (unset) {
|
||||
string_list_clear(v, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
|
||||
string_list_append(v, xstrdup(arg));
|
||||
return 0;
|
||||
}
|
||||
|
|
28
setup.c
28
setup.c
|
@ -40,34 +40,6 @@ char *prefix_path(const char *prefix, int len, const char *path)
|
|||
return sanitized;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlike prefix_path, this should be used if the named file does
|
||||
* not have to interact with index entry; i.e. name of a random file
|
||||
* on the filesystem.
|
||||
*/
|
||||
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
|
||||
{
|
||||
static char path[PATH_MAX];
|
||||
#ifndef WIN32
|
||||
if (!pfx_len || is_absolute_path(arg))
|
||||
return arg;
|
||||
memcpy(path, pfx, pfx_len);
|
||||
strcpy(path + pfx_len, arg);
|
||||
#else
|
||||
char *p;
|
||||
/* don't add prefix to absolute paths, but still replace '\' by '/' */
|
||||
if (is_absolute_path(arg))
|
||||
pfx_len = 0;
|
||||
else if (pfx_len)
|
||||
memcpy(path, pfx, pfx_len);
|
||||
strcpy(path + pfx_len, arg);
|
||||
for (p = path + pfx_len; *p; p++)
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
int check_filename(const char *prefix, const char *arg)
|
||||
{
|
||||
const char *name;
|
||||
|
|
Загрузка…
Ссылка в новой задаче