{"thread":{"id":"27701","subject":"[PATCH/RFC] Reduce parse-options.o dependencies","startedAt":"2011-06-25T11:12:14Z","lastAt":"2011-07-03T11:04:05Z","messageCount":4,"participants":["Dmitry Ivankov","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"170543","messageId":"1309000334-31980-1-git-send-email-divanorama@gmail.com","threadId":"27701","inReplyTo":null,"subject":"[PATCH/RFC] Reduce parse-options.o dependencies","fromName":"Dmitry Ivankov","fromEmail":"divanorama@gmail.com","sentAt":"2011-06-25T11:12:14Z","receivedAt":"2011-06-25T11:12:14Z","isPatch":true,"sender":{"key":"divanorama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158999?v=4"},"body":"Currently parse-options.o pulls quite a big bunch\nof dependencies. This complicates it's usage in\ncontrib/ because it pulls external dependencies\nand it also increases executables size.\n\nSplit off less generic and more internal to git\npart of parse-options.c to parse-options-git.c.\nDeclare optbug and opterror as extern as they are\nshared between these parts and also may be used\nelsewhere.\n\nMove prefix_function from setup.c to abspath.c.\nabspath.o and wrapper.o pull each other, so it's\nunlikely to increase the dependencies. It was a\ndependency of parse-options.o that pulled many\nothers.\n\nNow parse-options.o pulls just abspath.o, ctype.o,\nstrbuf.o, usage.o, wrapper.o, libc directly and\nstrlcpy.o indirectly.\n\nSigned-off-by: Dmitry Ivankov <divanorama@gmail.com>\n---\n Makefile            |    3 +-\n abspath.c           |   28 +++++++++++++\n parse-options-git.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++\n parse-options.c     |  108 +--------------------------------------------------\n parse-options.h     |    3 +\n setup.c             |   28 -------------\n 6 files changed, 143 insertions(+), 135 deletions(-)\n create mode 100644 parse-options-git.c\n\ndiff --git a/Makefile b/Makefile\nindex e954dff..24ecefa 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -631,6 +631,7 @@ LIB_OBJS += pack-revindex.o\n LIB_OBJS += pack-write.o\n LIB_OBJS += pager.o\n LIB_OBJS += parse-options.o\n+LIB_OBJS += parse-options-git.o\n LIB_OBJS += patch-delta.o\n LIB_OBJS += patch-ids.o\n LIB_OBJS += path.o\n@@ -2168,7 +2169,7 @@ test-delta$X: diff-delta.o patch-delta.o\n \n test-line-buffer$X: vcs-svn/lib.a\n \n-test-parse-options$X: parse-options.o\n+test-parse-options$X: parse-options.o parse-options-git.o\n \n test-svn-fe$X: vcs-svn/lib.a\n \ndiff --git a/abspath.c b/abspath.c\nindex 3005aed..aabc383 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -138,3 +138,31 @@ const char *absolute_path(const char *path)\n \t}\n \treturn buf;\n }\n+\n+/*\n+ * Unlike prefix_path, this should be used if the named file does\n+ * not have to interact with index entry; i.e. name of a random file\n+ * on the filesystem.\n+ */\n+const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)\n+{\n+\tstatic char path[PATH_MAX];\n+#ifndef WIN32\n+\tif (!pfx_len || is_absolute_path(arg))\n+\t\treturn arg;\n+\tmemcpy(path, pfx, pfx_len);\n+\tstrcpy(path + pfx_len, arg);\n+#else\n+\tchar *p;\n+\t/* don't add prefix to absolute paths, but still replace '\\' by '/' */\n+\tif (is_absolute_path(arg))\n+\t\tpfx_len = 0;\n+\telse if (pfx_len)\n+\t\tmemcpy(path, pfx, pfx_len);\n+\tstrcpy(path + pfx_len, arg);\n+\tfor (p = path + pfx_len; *p; p++)\n+\t\tif (*p == '\\\\')\n+\t\t\t*p = '/';\n+#endif\n+\treturn path;\n+}\ndiff --git a/parse-options-git.c b/parse-options-git.c\nnew file mode 100644\nindex 0000000..0ddfcd9\n--- /dev/null\n+++ b/parse-options-git.c\n@@ -0,0 +1,108 @@\n+#include \"git-compat-util.h\"\n+#include \"parse-options.h\"\n+#include \"cache.h\"\n+#include \"commit.h\"\n+#include \"color.h\"\n+\n+/*----- some often used options -----*/\n+\n+int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tint v;\n+\n+\tif (!arg) {\n+\t\tv = unset ? 0 : DEFAULT_ABBREV;\n+\t} else {\n+\t\tv = strtol(arg, (char **)&arg, 10);\n+\t\tif (*arg)\n+\t\t\treturn opterror(opt, \"expects a numerical value\", 0);\n+\t\tif (v && v < MINIMUM_ABBREV)\n+\t\t\tv = MINIMUM_ABBREV;\n+\t\telse if (v > 40)\n+\t\t\tv = 40;\n+\t}\n+\t*(int *)(opt->value) = v;\n+\treturn 0;\n+}\n+\n+int parse_opt_approxidate_cb(const struct option *opt, const char *arg,\n+\t\t\t     int unset)\n+{\n+\t*(unsigned long *)(opt->value) = approxidate(arg);\n+\treturn 0;\n+}\n+\n+int parse_opt_color_flag_cb(const struct option *opt, const char *arg,\n+\t\t\t    int unset)\n+{\n+\tint value;\n+\n+\tif (!arg)\n+\t\targ = unset ? \"never\" : (const char *)opt->defval;\n+\tvalue = git_config_colorbool(NULL, arg, -1);\n+\tif (value < 0)\n+\t\treturn opterror(opt,\n+\t\t\t\"expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\", 0);\n+\t*(int *)opt->value = value;\n+\treturn 0;\n+}\n+\n+int parse_opt_verbosity_cb(const struct option *opt, const char *arg,\n+\t\t\t   int unset)\n+{\n+\tint *target = opt->value;\n+\n+\tif (unset)\n+\t\t/* --no-quiet, --no-verbose */\n+\t\t*target = 0;\n+\telse if (opt->short_name == 'v') {\n+\t\tif (*target >= 0)\n+\t\t\t(*target)++;\n+\t\telse\n+\t\t\t*target = 1;\n+\t} else {\n+\t\tif (*target <= 0)\n+\t\t\t(*target)--;\n+\t\telse\n+\t\t\t*target = -1;\n+\t}\n+\treturn 0;\n+}\n+\n+int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)\n+{\n+\tunsigned char sha1[20];\n+\tstruct commit *commit;\n+\n+\tif (!arg)\n+\t\treturn -1;\n+\tif (get_sha1(arg, sha1))\n+\t\treturn error(\"malformed object name %s\", arg);\n+\tcommit = lookup_commit_reference(sha1);\n+\tif (!commit)\n+\t\treturn error(\"no such commit %s\", arg);\n+\tcommit_list_insert(commit, opt->value);\n+\treturn 0;\n+}\n+\n+int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)\n+{\n+\tint *target = opt->value;\n+\t*target = unset ? 2 : 1;\n+\treturn 0;\n+}\n+\n+int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)\n+{\n+\tint i, j;\n+\n+\tfor (i = 0; i < dst_size; i++)\n+\t\tif (dst[i].type == OPTION_END)\n+\t\t\tbreak;\n+\tfor (j = 0; i < dst_size; i++, j++) {\n+\t\tdst[i] = src[j];\n+\t\tif (src[j].type == OPTION_END)\n+\t\t\treturn 0;\n+\t}\n+\treturn -1;\n+}\ndiff --git a/parse-options.c b/parse-options.c\nindex 73bd28a..503ab5d 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -11,14 +11,14 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,\n #define OPT_SHORT 1\n #define OPT_UNSET 2\n \n-static int optbug(const struct option *opt, const char *reason)\n+int optbug(const struct option *opt, const char *reason)\n {\n \tif (opt->long_name)\n \t\treturn error(\"BUG: option '%s' %s\", opt->long_name, reason);\n \treturn error(\"BUG: switch '%c' %s\", opt->short_name, reason);\n }\n \n-static int opterror(const struct option *opt, const char *reason, int flags)\n+int opterror(const struct option *opt, const char *reason, int flags)\n {\n \tif (flags & OPT_SHORT)\n \t\treturn error(\"switch `%c' %s\", opt->short_name, reason);\n@@ -583,107 +583,3 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,\n \treturn usage_with_options_internal(ctx, usagestr, opts, 0, err);\n }\n \n-\n-/*----- some often used options -----*/\n-#include \"cache.h\"\n-\n-int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)\n-{\n-\tint v;\n-\n-\tif (!arg) {\n-\t\tv = unset ? 0 : DEFAULT_ABBREV;\n-\t} else {\n-\t\tv = strtol(arg, (char **)&arg, 10);\n-\t\tif (*arg)\n-\t\t\treturn opterror(opt, \"expects a numerical value\", 0);\n-\t\tif (v && v < MINIMUM_ABBREV)\n-\t\t\tv = MINIMUM_ABBREV;\n-\t\telse if (v > 40)\n-\t\t\tv = 40;\n-\t}\n-\t*(int *)(opt->value) = v;\n-\treturn 0;\n-}\n-\n-int parse_opt_approxidate_cb(const struct option *opt, const char *arg,\n-\t\t\t     int unset)\n-{\n-\t*(unsigned long *)(opt->value) = approxidate(arg);\n-\treturn 0;\n-}\n-\n-int parse_opt_color_flag_cb(const struct option *opt, const char *arg,\n-\t\t\t    int unset)\n-{\n-\tint value;\n-\n-\tif (!arg)\n-\t\targ = unset ? \"never\" : (const char *)opt->defval;\n-\tvalue = git_config_colorbool(NULL, arg, -1);\n-\tif (value < 0)\n-\t\treturn opterror(opt,\n-\t\t\t\"expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\", 0);\n-\t*(int *)opt->value = value;\n-\treturn 0;\n-}\n-\n-int parse_opt_verbosity_cb(const struct option *opt, const char *arg,\n-\t\t\t   int unset)\n-{\n-\tint *target = opt->value;\n-\n-\tif (unset)\n-\t\t/* --no-quiet, --no-verbose */\n-\t\t*target = 0;\n-\telse if (opt->short_name == 'v') {\n-\t\tif (*target >= 0)\n-\t\t\t(*target)++;\n-\t\telse\n-\t\t\t*target = 1;\n-\t} else {\n-\t\tif (*target <= 0)\n-\t\t\t(*target)--;\n-\t\telse\n-\t\t\t*target = -1;\n-\t}\n-\treturn 0;\n-}\n-\n-int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)\n-{\n-\tunsigned char sha1[20];\n-\tstruct commit *commit;\n-\n-\tif (!arg)\n-\t\treturn -1;\n-\tif (get_sha1(arg, sha1))\n-\t\treturn error(\"malformed object name %s\", arg);\n-\tcommit = lookup_commit_reference(sha1);\n-\tif (!commit)\n-\t\treturn error(\"no such commit %s\", arg);\n-\tcommit_list_insert(commit, opt->value);\n-\treturn 0;\n-}\n-\n-int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)\n-{\n-\tint *target = opt->value;\n-\t*target = unset ? 2 : 1;\n-\treturn 0;\n-}\n-\n-int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)\n-{\n-\tint i, j;\n-\n-\tfor (i = 0; i < dst_size; i++)\n-\t\tif (dst[i].type == OPTION_END)\n-\t\t\tbreak;\n-\tfor (j = 0; i < dst_size; i++, j++) {\n-\t\tdst[i] = src[j];\n-\t\tif (src[j].type == OPTION_END)\n-\t\t\treturn 0;\n-\t}\n-\treturn -1;\n-}\ndiff --git a/parse-options.h b/parse-options.h\nindex d1b12fe..a62c6c3 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -147,6 +147,9 @@ struct option {\n \t\tparse_opt_color_flag_cb, (intptr_t)\"always\" }\n \n \n+extern int optbug(const struct option *opt, const char *reason);\n+extern int opterror(const struct option *opt, const char *reason, int flags);\n+\n /* parse_options() will filter out the processed options and leave the\n  * non-option arguments in argv[].\n  * Returns the number of arguments left in argv[].\ndiff --git a/setup.c b/setup.c\nindex 03cd84f..fc593bf 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -40,34 +40,6 @@ char *prefix_path(const char *prefix, int len, const char *path)\n \treturn sanitized;\n }\n \n-/*\n- * Unlike prefix_path, this should be used if the named file does\n- * not have to interact with index entry; i.e. name of a random file\n- * on the filesystem.\n- */\n-const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)\n-{\n-\tstatic char path[PATH_MAX];\n-#ifndef WIN32\n-\tif (!pfx_len || is_absolute_path(arg))\n-\t\treturn arg;\n-\tmemcpy(path, pfx, pfx_len);\n-\tstrcpy(path + pfx_len, arg);\n-#else\n-\tchar *p;\n-\t/* don't add prefix to absolute paths, but still replace '\\' by '/' */\n-\tif (is_absolute_path(arg))\n-\t\tpfx_len = 0;\n-\telse if (pfx_len)\n-\t\tmemcpy(path, pfx, pfx_len);\n-\tstrcpy(path + pfx_len, arg);\n-\tfor (p = path + pfx_len; *p; p++)\n-\t\tif (*p == '\\\\')\n-\t\t\t*p = '/';\n-#endif\n-\treturn path;\n-}\n-\n int check_filename(const char *prefix, const char *arg)\n {\n \tconst char *name;\n-- \n1.7.3.4\n"},{"id":"170680","messageId":"20110629202959.GJ22556@elie","threadId":"27701","inReplyTo":"1309000334-31980-1-git-send-email-divanorama@gmail.com","subject":"Re: [PATCH/RFC] Reduce parse-options.o dependencies","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-06-29T20:29:59Z","receivedAt":"2011-06-29T20:29:59Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nDmitry Ivankov wrote:\n\n> Currently parse-options.o pulls quite a big bunch\n> of dependencies. This complicates it's usage in\n> contrib/ because it pulls external dependencies\n> and it also increases executables size.\n\nNitpick: it is easier to read text with a little longer lines;\ntypical for git.git is 70 columns or so.\n\n> Split off less generic and more internal to git\n> part of parse-options.c to parse-options-git.c.\n\nThese are just callbacks for special option types, right?  Maybe\nsomething like parse-options-cb.c would make sense.\n\n> Declare optbug and opterror as extern as they are\n> shared between these parts and also may be used\n> elsewhere.\n\nI'd suggest making this a separate patch.  The idea is that optbug\nand opterror might be used by option callbacks whether they are\nspecific to a particular command or generic, so it is useful to\nexpose them as a sort of toolkit for use with OPT_CALLBACK, right?\n\n> Move prefix_function from setup.c to abspath.c.\n\nI think you mean \"prefix_filename\". :)  Makes sense ---\nprefix_filename is a generically useful function, not specific to\ngit's filesystem layout.\n\n> Now parse-options.o pulls just abspath.o, ctype.o,\n> strbuf.o, usage.o, wrapper.o, libc directly and\n> strlcpy.o indirectly.\n\nOne vague dream I've had is to submit strbuf and parse-options as CCAN\nmodules (http://ccan.ozlabs.org/) in the hope that others will start\nto use them.  The above should make that a little easier; thanks.\n\n> Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>\n> ---\n>  Makefile            |    3 +-\n>  abspath.c           |   28 +++++++++++++\n>  parse-options-git.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++\n>  parse-options.c     |  108 +--------------------------------------------------\n>  parse-options.h     |    3 +\n>  setup.c             |   28 -------------\n>  6 files changed, 143 insertions(+), 135 deletions(-)\n>  create mode 100644 parse-options-git.c\n[diff snipped, available at\n http://thread.gmane.org/gmane.comp.version-control.git/176318]\n"},{"id":"170792","messageId":"1309691045-30180-1-git-send-email-divanorama@gmail.com","threadId":"27701","inReplyTo":"20110629202959.GJ22556@elie","subject":"[PATCH/RFC v2 1/2] parse-options: export opterr, optbug","fromName":"Dmitry Ivankov","fromEmail":"divanorama@gmail.com","sentAt":"2011-07-03T11:04:04Z","receivedAt":"2011-07-03T11:04:04Z","isPatch":true,"sender":{"key":"divanorama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158999?v=4"},"body":"opterror and optbug functions are used by some of parsing routines\nin parse-options.c to report errors and bugs respectively.\n\nExport these functions to allow more custom parsing routines to use\nthem in a uniform way.\n\nSigned-off-by: Dmitry Ivankov <divanorama@gmail.com>\n---\n parse-options.c |    4 ++--\n parse-options.h |    2 ++\n 2 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex 73bd28a..37a1d3b 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -11,14 +11,14 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,\n #define OPT_SHORT 1\n #define OPT_UNSET 2\n \n-static int optbug(const struct option *opt, const char *reason)\n+int optbug(const struct option *opt, const char *reason)\n {\n \tif (opt->long_name)\n \t\treturn error(\"BUG: option '%s' %s\", opt->long_name, reason);\n \treturn error(\"BUG: switch '%c' %s\", opt->short_name, reason);\n }\n \n-static int opterror(const struct option *opt, const char *reason, int flags)\n+int opterror(const struct option *opt, const char *reason, int flags)\n {\n \tif (flags & OPT_SHORT)\n \t\treturn error(\"switch `%c' %s\", opt->short_name, reason);\ndiff --git a/parse-options.h b/parse-options.h\nindex d1b12fe..b392590 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -162,6 +162,8 @@ extern NORETURN void usage_msg_opt(const char *msg,\n \t\t\t\t   const char * const *usagestr,\n \t\t\t\t   const struct option *options);\n \n+extern int optbug(const struct option *opt, const char *reason);\n+extern int opterror(const struct option *opt, const char *reason, int flags);\n /*----- incremental advanced APIs -----*/\n \n enum {\n-- \n1.7.3.4\n"},{"id":"170791","messageId":"1309691045-30180-2-git-send-email-divanorama@gmail.com","threadId":"27701","inReplyTo":"20110629202959.GJ22556@elie","subject":"[PATCH/RFC v2 2/2] Reduce parse-options.o dependencies","fromName":"Dmitry Ivankov","fromEmail":"divanorama@gmail.com","sentAt":"2011-07-03T11:04:05Z","receivedAt":"2011-07-03T11:04:05Z","isPatch":true,"sender":{"key":"divanorama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/158999?v=4"},"body":"Currently parse-options.o pulls quite a big bunch\nof dependencies. This complicates it's usage in\ncontrib/ because it pulls external dependencies\nand it also increases executables size.\n\nSplit off less generic and more internal to git\npart of parse-options.c to parse-options-cb.c.\n\nMove prefix_filename function from setup.c to\nabspath.c. abspath.o and wrapper.o pull each other,\nso it's unlikely to increase the dependencies.\nIt was a dependency of parse-options.o that pulled\nmany others.\n\nNow parse-options.o pulls just abspath.o, ctype.o,\nstrbuf.o, usage.o, wrapper.o, libc directly and\nstrlcpy.o indirectly.\n\nSigned-off-by: Dmitry Ivankov <divanorama@gmail.com>\n---\n Makefile           |    3 +-\n abspath.c          |   28 +++++++++++++\n parse-options-cb.c |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n parse-options.c    |  104 --------------------------------------------------\n setup.c            |   28 -------------\n 5 files changed, 138 insertions(+), 133 deletions(-)\n create mode 100644 parse-options-cb.c\n\ndiff --git a/Makefile b/Makefile\nindex e954dff..0a46a99 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -631,6 +631,7 @@ LIB_OBJS += pack-revindex.o\n LIB_OBJS += pack-write.o\n LIB_OBJS += pager.o\n LIB_OBJS += parse-options.o\n+LIB_OBJS += parse-options-cb.o\n LIB_OBJS += patch-delta.o\n LIB_OBJS += patch-ids.o\n LIB_OBJS += path.o\n@@ -2168,7 +2169,7 @@ test-delta$X: diff-delta.o patch-delta.o\n \n test-line-buffer$X: vcs-svn/lib.a\n \n-test-parse-options$X: parse-options.o\n+test-parse-options$X: parse-options.o parse-options-git.o\n \n test-svn-fe$X: vcs-svn/lib.a\n \ndiff --git a/abspath.c b/abspath.c\nindex 3005aed..aabc383 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -138,3 +138,31 @@ const char *absolute_path(const char *path)\n \t}\n \treturn buf;\n }\n+\n+/*\n+ * Unlike prefix_path, this should be used if the named file does\n+ * not have to interact with index entry; i.e. name of a random file\n+ * on the filesystem.\n+ */\n+const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)\n+{\n+\tstatic char path[PATH_MAX];\n+#ifndef WIN32\n+\tif (!pfx_len || is_absolute_path(arg))\n+\t\treturn arg;\n+\tmemcpy(path, pfx, pfx_len);\n+\tstrcpy(path + pfx_len, arg);\n+#else\n+\tchar *p;\n+\t/* don't add prefix to absolute paths, but still replace '\\' by '/' */\n+\tif (is_absolute_path(arg))\n+\t\tpfx_len = 0;\n+\telse if (pfx_len)\n+\t\tmemcpy(path, pfx, pfx_len);\n+\tstrcpy(path + pfx_len, arg);\n+\tfor (p = path + pfx_len; *p; p++)\n+\t\tif (*p == '\\\\')\n+\t\t\t*p = '/';\n+#endif\n+\treturn path;\n+}\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nnew file mode 100644\nindex 0000000..0ddfcd9\n--- /dev/null\n+++ b/parse-options-cb.c\n@@ -0,0 +1,108 @@\n+#include \"git-compat-util.h\"\n+#include \"parse-options.h\"\n+#include \"cache.h\"\n+#include \"commit.h\"\n+#include \"color.h\"\n+\n+/*----- some often used options -----*/\n+\n+int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tint v;\n+\n+\tif (!arg) {\n+\t\tv = unset ? 0 : DEFAULT_ABBREV;\n+\t} else {\n+\t\tv = strtol(arg, (char **)&arg, 10);\n+\t\tif (*arg)\n+\t\t\treturn opterror(opt, \"expects a numerical value\", 0);\n+\t\tif (v && v < MINIMUM_ABBREV)\n+\t\t\tv = MINIMUM_ABBREV;\n+\t\telse if (v > 40)\n+\t\t\tv = 40;\n+\t}\n+\t*(int *)(opt->value) = v;\n+\treturn 0;\n+}\n+\n+int parse_opt_approxidate_cb(const struct option *opt, const char *arg,\n+\t\t\t     int unset)\n+{\n+\t*(unsigned long *)(opt->value) = approxidate(arg);\n+\treturn 0;\n+}\n+\n+int parse_opt_color_flag_cb(const struct option *opt, const char *arg,\n+\t\t\t    int unset)\n+{\n+\tint value;\n+\n+\tif (!arg)\n+\t\targ = unset ? \"never\" : (const char *)opt->defval;\n+\tvalue = git_config_colorbool(NULL, arg, -1);\n+\tif (value < 0)\n+\t\treturn opterror(opt,\n+\t\t\t\"expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\", 0);\n+\t*(int *)opt->value = value;\n+\treturn 0;\n+}\n+\n+int parse_opt_verbosity_cb(const struct option *opt, const char *arg,\n+\t\t\t   int unset)\n+{\n+\tint *target = opt->value;\n+\n+\tif (unset)\n+\t\t/* --no-quiet, --no-verbose */\n+\t\t*target = 0;\n+\telse if (opt->short_name == 'v') {\n+\t\tif (*target >= 0)\n+\t\t\t(*target)++;\n+\t\telse\n+\t\t\t*target = 1;\n+\t} else {\n+\t\tif (*target <= 0)\n+\t\t\t(*target)--;\n+\t\telse\n+\t\t\t*target = -1;\n+\t}\n+\treturn 0;\n+}\n+\n+int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)\n+{\n+\tunsigned char sha1[20];\n+\tstruct commit *commit;\n+\n+\tif (!arg)\n+\t\treturn -1;\n+\tif (get_sha1(arg, sha1))\n+\t\treturn error(\"malformed object name %s\", arg);\n+\tcommit = lookup_commit_reference(sha1);\n+\tif (!commit)\n+\t\treturn error(\"no such commit %s\", arg);\n+\tcommit_list_insert(commit, opt->value);\n+\treturn 0;\n+}\n+\n+int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)\n+{\n+\tint *target = opt->value;\n+\t*target = unset ? 2 : 1;\n+\treturn 0;\n+}\n+\n+int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)\n+{\n+\tint i, j;\n+\n+\tfor (i = 0; i < dst_size; i++)\n+\t\tif (dst[i].type == OPTION_END)\n+\t\t\tbreak;\n+\tfor (j = 0; i < dst_size; i++, j++) {\n+\t\tdst[i] = src[j];\n+\t\tif (src[j].type == OPTION_END)\n+\t\t\treturn 0;\n+\t}\n+\treturn -1;\n+}\ndiff --git a/parse-options.c b/parse-options.c\nindex 37a1d3b..503ab5d 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -583,107 +583,3 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,\n \treturn usage_with_options_internal(ctx, usagestr, opts, 0, err);\n }\n \n-\n-/*----- some often used options -----*/\n-#include \"cache.h\"\n-\n-int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)\n-{\n-\tint v;\n-\n-\tif (!arg) {\n-\t\tv = unset ? 0 : DEFAULT_ABBREV;\n-\t} else {\n-\t\tv = strtol(arg, (char **)&arg, 10);\n-\t\tif (*arg)\n-\t\t\treturn opterror(opt, \"expects a numerical value\", 0);\n-\t\tif (v && v < MINIMUM_ABBREV)\n-\t\t\tv = MINIMUM_ABBREV;\n-\t\telse if (v > 40)\n-\t\t\tv = 40;\n-\t}\n-\t*(int *)(opt->value) = v;\n-\treturn 0;\n-}\n-\n-int parse_opt_approxidate_cb(const struct option *opt, const char *arg,\n-\t\t\t     int unset)\n-{\n-\t*(unsigned long *)(opt->value) = approxidate(arg);\n-\treturn 0;\n-}\n-\n-int parse_opt_color_flag_cb(const struct option *opt, const char *arg,\n-\t\t\t    int unset)\n-{\n-\tint value;\n-\n-\tif (!arg)\n-\t\targ = unset ? \"never\" : (const char *)opt->defval;\n-\tvalue = git_config_colorbool(NULL, arg, -1);\n-\tif (value < 0)\n-\t\treturn opterror(opt,\n-\t\t\t\"expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\", 0);\n-\t*(int *)opt->value = value;\n-\treturn 0;\n-}\n-\n-int parse_opt_verbosity_cb(const struct option *opt, const char *arg,\n-\t\t\t   int unset)\n-{\n-\tint *target = opt->value;\n-\n-\tif (unset)\n-\t\t/* --no-quiet, --no-verbose */\n-\t\t*target = 0;\n-\telse if (opt->short_name == 'v') {\n-\t\tif (*target >= 0)\n-\t\t\t(*target)++;\n-\t\telse\n-\t\t\t*target = 1;\n-\t} else {\n-\t\tif (*target <= 0)\n-\t\t\t(*target)--;\n-\t\telse\n-\t\t\t*target = -1;\n-\t}\n-\treturn 0;\n-}\n-\n-int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)\n-{\n-\tunsigned char sha1[20];\n-\tstruct commit *commit;\n-\n-\tif (!arg)\n-\t\treturn -1;\n-\tif (get_sha1(arg, sha1))\n-\t\treturn error(\"malformed object name %s\", arg);\n-\tcommit = lookup_commit_reference(sha1);\n-\tif (!commit)\n-\t\treturn error(\"no such commit %s\", arg);\n-\tcommit_list_insert(commit, opt->value);\n-\treturn 0;\n-}\n-\n-int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)\n-{\n-\tint *target = opt->value;\n-\t*target = unset ? 2 : 1;\n-\treturn 0;\n-}\n-\n-int parse_options_concat(struct option *dst, size_t dst_size, struct option *src)\n-{\n-\tint i, j;\n-\n-\tfor (i = 0; i < dst_size; i++)\n-\t\tif (dst[i].type == OPTION_END)\n-\t\t\tbreak;\n-\tfor (j = 0; i < dst_size; i++, j++) {\n-\t\tdst[i] = src[j];\n-\t\tif (src[j].type == OPTION_END)\n-\t\t\treturn 0;\n-\t}\n-\treturn -1;\n-}\ndiff --git a/setup.c b/setup.c\nindex 03cd84f..fc593bf 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -40,34 +40,6 @@ char *prefix_path(const char *prefix, int len, const char *path)\n \treturn sanitized;\n }\n \n-/*\n- * Unlike prefix_path, this should be used if the named file does\n- * not have to interact with index entry; i.e. name of a random file\n- * on the filesystem.\n- */\n-const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)\n-{\n-\tstatic char path[PATH_MAX];\n-#ifndef WIN32\n-\tif (!pfx_len || is_absolute_path(arg))\n-\t\treturn arg;\n-\tmemcpy(path, pfx, pfx_len);\n-\tstrcpy(path + pfx_len, arg);\n-#else\n-\tchar *p;\n-\t/* don't add prefix to absolute paths, but still replace '\\' by '/' */\n-\tif (is_absolute_path(arg))\n-\t\tpfx_len = 0;\n-\telse if (pfx_len)\n-\t\tmemcpy(path, pfx, pfx_len);\n-\tstrcpy(path + pfx_len, arg);\n-\tfor (p = path + pfx_len; *p; p++)\n-\t\tif (*p == '\\\\')\n-\t\t\t*p = '/';\n-#endif\n-\treturn path;\n-}\n-\n int check_filename(const char *prefix, const char *arg)\n {\n \tconst char *name;\n-- \n1.7.3.4\n"}]}