t7610: always work on a test-specific branch
[gitweb.git] / parse-options-cb.c
index 2d875202cd8c8164b6604ea889ee633424fe3b55..b7d8f7dcb2c3ae7568542832accadab84c7ae314 100644 (file)
@@ -149,7 +149,7 @@ int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
        if (!arg)
                return -1;
 
-       string_list_append(v, xstrdup(arg));
+       string_list_append(v, arg);
        return 0;
 }
 
@@ -158,6 +158,18 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
        return 0;
 }
 
+/**
+ * Report that the option is unknown, so that other code can handle
+ * it. This can be used as a callback together with
+ * OPTION_LOWLEVEL_CALLBACK to allow an option to be documented in the
+ * "-h" output even if it's not being handled directly by
+ * parse_options().
+ */
+int parse_opt_unknown_cb(const struct option *opt, const char *arg, int unset)
+{
+       return -2;
+}
+
 /**
  * Recreates the command-line option in the strbuf.
  */
@@ -199,8 +211,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
        if (recreate_opt(&sb, opt, arg, unset) < 0)
                return -1;
 
-       if (*opt_value)
-               free(*opt_value);
+       free(*opt_value);
 
        *opt_value = strbuf_detach(&sb, NULL);