* [PATCH/RFC] Reduce parse-options.o dependencies
@ 2011-06-25 11:12 Dmitry Ivankov
2011-06-29 20:29 ` Jonathan Nieder
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Ivankov @ 2011-06-25 11:12 UTC (permalink / raw)
To: git; +Cc: Jonathan Nieder, David Barr, Dmitry Ivankov
Currently parse-options.o pulls quite a big bunch
of dependencies. This 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-git.c.
Declare optbug and opterror as extern as they are
shared between these parts and also may be used
elsewhere.
Move prefix_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>
---
Makefile | 3 +-
abspath.c | 28 +++++++++++++
parse-options-git.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++
parse-options.c | 108 +--------------------------------------------------
parse-options.h | 3 +
setup.c | 28 -------------
6 files changed, 143 insertions(+), 135 deletions(-)
create mode 100644 parse-options-git.c
diff --git a/Makefile b/Makefile
index e954dff..24ecefa 100644
--- a/Makefile
+++ b/Makefile
@@ -631,6 +631,7 @@ LIB_OBJS += pack-revindex.o
LIB_OBJS += pack-write.o
LIB_OBJS += pager.o
LIB_OBJS += parse-options.o
+LIB_OBJS += parse-options-git.o
LIB_OBJS += patch-delta.o
LIB_OBJS += patch-ids.o
LIB_OBJS += path.o
@@ -2168,7 +2169,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-git.o
test-svn-fe$X: vcs-svn/lib.a
diff --git a/abspath.c b/abspath.c
index 3005aed..aabc383 100644
--- a/abspath.c
+++ b/abspath.c
@@ -138,3 +138,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;
+}
diff --git a/parse-options-git.c b/parse-options-git.c
new file mode 100644
index 0000000..0ddfcd9
--- /dev/null
+++ b/parse-options-git.c
@@ -0,0 +1,108 @@
+#include "git-compat-util.h"
+#include "parse-options.h"
+#include "cache.h"
+#include "commit.h"
+#include "color.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;
+}
diff --git a/parse-options.c b/parse-options.c
index 73bd28a..503ab5d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -11,14 +11,14 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
#define OPT_SHORT 1
#define OPT_UNSET 2
-static int optbug(const struct option *opt, const char *reason)
+int optbug(const struct option *opt, const char *reason)
{
if (opt->long_name)
return error("BUG: option '%s' %s", opt->long_name, reason);
return error("BUG: switch '%c' %s", opt->short_name, reason);
}
-static int opterror(const struct option *opt, const char *reason, int flags)
+int opterror(const struct option *opt, const char *reason, int flags)
{
if (flags & OPT_SHORT)
return error("switch `%c' %s", opt->short_name, reason);
@@ -583,107 +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;
-}
diff --git a/parse-options.h b/parse-options.h
index d1b12fe..a62c6c3 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -147,6 +147,9 @@ struct option {
parse_opt_color_flag_cb, (intptr_t)"always" }
+extern int optbug(const struct option *opt, const char *reason);
+extern int opterror(const struct option *opt, const char *reason, int flags);
+
/* parse_options() will filter out the processed options and leave the
* non-option arguments in argv[].
* Returns the number of arguments left in argv[].
diff --git a/setup.c b/setup.c
index 03cd84f..fc593bf 100644
--- a/setup.c
+++ b/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;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH/RFC] Reduce parse-options.o dependencies
2011-06-25 11:12 [PATCH/RFC] Reduce parse-options.o dependencies Dmitry Ivankov
@ 2011-06-29 20:29 ` Jonathan Nieder
2011-07-03 11:04 ` [PATCH/RFC v2 1/2] parse-options: export opterr, optbug Dmitry Ivankov
2011-07-03 11:04 ` [PATCH/RFC v2 2/2] Reduce parse-options.o dependencies Dmitry Ivankov
0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Nieder @ 2011-06-29 20:29 UTC (permalink / raw)
To: Dmitry Ivankov; +Cc: git, David Barr, Stephen Boyd, Pierre Habouzit
Hi,
Dmitry Ivankov wrote:
> Currently parse-options.o pulls quite a big bunch
> of dependencies. This complicates it's usage in
> contrib/ because it pulls external dependencies
> and it also increases executables size.
Nitpick: it is easier to read text with a little longer lines;
typical for git.git is 70 columns or so.
> Split off less generic and more internal to git
> part of parse-options.c to parse-options-git.c.
These are just callbacks for special option types, right? Maybe
something like parse-options-cb.c would make sense.
> Declare optbug and opterror as extern as they are
> shared between these parts and also may be used
> elsewhere.
I'd suggest making this a separate patch. The idea is that optbug
and opterror might be used by option callbacks whether they are
specific to a particular command or generic, so it is useful to
expose them as a sort of toolkit for use with OPT_CALLBACK, right?
> Move prefix_function from setup.c to abspath.c.
I think you mean "prefix_filename". :) Makes sense ---
prefix_filename is a generically useful function, not specific to
git's filesystem layout.
> Now parse-options.o pulls just abspath.o, ctype.o,
> strbuf.o, usage.o, wrapper.o, libc directly and
> strlcpy.o indirectly.
One vague dream I've had is to submit strbuf and parse-options as CCAN
modules (http://ccan.ozlabs.org/) in the hope that others will start
to use them. The above should make that a little easier; thanks.
> Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
> ---
> Makefile | 3 +-
> abspath.c | 28 +++++++++++++
> parse-options-git.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++
> parse-options.c | 108 +--------------------------------------------------
> parse-options.h | 3 +
> setup.c | 28 -------------
> 6 files changed, 143 insertions(+), 135 deletions(-)
> create mode 100644 parse-options-git.c
[diff snipped, available at
http://thread.gmane.org/gmane.comp.version-control.git/176318]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH/RFC v2 1/2] parse-options: export opterr, optbug
2011-06-29 20:29 ` Jonathan Nieder
@ 2011-07-03 11:04 ` Dmitry Ivankov
2011-07-03 11:04 ` [PATCH/RFC v2 2/2] Reduce parse-options.o dependencies Dmitry Ivankov
1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Ivankov @ 2011-07-03 11:04 UTC (permalink / raw)
To: git
Cc: Jonathan Nieder, David Barr, Stephen Boyd, Pierre Habouzit,
Dmitry Ivankov
opterror and optbug functions are used by some of parsing routines
in parse-options.c to report errors and bugs respectively.
Export these functions to allow more custom parsing routines to use
them in a uniform way.
Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
parse-options.c | 4 ++--
parse-options.h | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 73bd28a..37a1d3b 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -11,14 +11,14 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
#define OPT_SHORT 1
#define OPT_UNSET 2
-static int optbug(const struct option *opt, const char *reason)
+int optbug(const struct option *opt, const char *reason)
{
if (opt->long_name)
return error("BUG: option '%s' %s", opt->long_name, reason);
return error("BUG: switch '%c' %s", opt->short_name, reason);
}
-static int opterror(const struct option *opt, const char *reason, int flags)
+int opterror(const struct option *opt, const char *reason, int flags)
{
if (flags & OPT_SHORT)
return error("switch `%c' %s", opt->short_name, reason);
diff --git a/parse-options.h b/parse-options.h
index d1b12fe..b392590 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -162,6 +162,8 @@ extern NORETURN void usage_msg_opt(const char *msg,
const char * const *usagestr,
const struct option *options);
+extern int optbug(const struct option *opt, const char *reason);
+extern int opterror(const struct option *opt, const char *reason, int flags);
/*----- incremental advanced APIs -----*/
enum {
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH/RFC v2 2/2] Reduce parse-options.o dependencies
2011-06-29 20:29 ` Jonathan Nieder
2011-07-03 11:04 ` [PATCH/RFC v2 1/2] parse-options: export opterr, optbug Dmitry Ivankov
@ 2011-07-03 11:04 ` Dmitry Ivankov
1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Ivankov @ 2011-07-03 11:04 UTC (permalink / raw)
To: git
Cc: Jonathan Nieder, David Barr, Stephen Boyd, Pierre Habouzit,
Dmitry Ivankov
Currently parse-options.o pulls quite a big bunch
of dependencies. This 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>
---
Makefile | 3 +-
abspath.c | 28 +++++++++++++
parse-options-cb.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++
parse-options.c | 104 --------------------------------------------------
setup.c | 28 -------------
5 files changed, 138 insertions(+), 133 deletions(-)
create mode 100644 parse-options-cb.c
diff --git a/Makefile b/Makefile
index e954dff..0a46a99 100644
--- a/Makefile
+++ b/Makefile
@@ -631,6 +631,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
@@ -2168,7 +2169,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-git.o
test-svn-fe$X: vcs-svn/lib.a
diff --git a/abspath.c b/abspath.c
index 3005aed..aabc383 100644
--- a/abspath.c
+++ b/abspath.c
@@ -138,3 +138,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;
+}
diff --git a/parse-options-cb.c b/parse-options-cb.c
new file mode 100644
index 0000000..0ddfcd9
--- /dev/null
+++ b/parse-options-cb.c
@@ -0,0 +1,108 @@
+#include "git-compat-util.h"
+#include "parse-options.h"
+#include "cache.h"
+#include "commit.h"
+#include "color.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;
+}
diff --git a/parse-options.c b/parse-options.c
index 37a1d3b..503ab5d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -583,107 +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;
-}
diff --git a/setup.c b/setup.c
index 03cd84f..fc593bf 100644
--- a/setup.c
+++ b/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;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-03 11:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-25 11:12 [PATCH/RFC] Reduce parse-options.o dependencies Dmitry Ivankov
2011-06-29 20:29 ` Jonathan Nieder
2011-07-03 11:04 ` [PATCH/RFC v2 1/2] parse-options: export opterr, optbug Dmitry Ivankov
2011-07-03 11:04 ` [PATCH/RFC v2 2/2] Reduce parse-options.o dependencies Dmitry Ivankov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).