diff options
author | Jeff King <peff@peff.net> | 2013-09-28 04:31:23 -0400 |
---|---|---|
committer | Jonathan Nieder <jrnieder@gmail.com> | 2013-09-30 17:21:59 -0700 |
commit | 1bbcc224ccfdccd99b1221d83150a8ffb8059ffd (patch) | |
tree | 5aed8889b6e9101caad031a123cb180432cd579e /http.h | |
parent | 132b70a2ed6d952e8142981474b41884ff93b780 (diff) | |
download | git-1bbcc224ccfdccd99b1221d83150a8ffb8059ffd.tar.gz git-1bbcc224ccfdccd99b1221d83150a8ffb8059ffd.tar.xz |
http: refactor options to http_get_*
Over time, the http_get_strbuf function has grown several
optional parameters. We now have a bitfield with multiple
boolean options, as well as an optional strbuf for returning
the content-type of the response. And a future patch in this
series is going to add another strbuf option.
Treating these as separate arguments has a few downsides:
1. Most call sites need to add extra NULLs and 0s for the
options they aren't interested in.
2. The http_get_* functions are actually wrappers around
2 layers of low-level implementation functions. We have
to pass these options through individually.
3. The http_get_strbuf wrapper learned these options, but
nobody bothered to do so for http_get_file, even though
it is backed by the same function that does understand
the options.
Let's consolidate the options into a single struct. For the
common case of the default options, we'll allow callers to
simply pass a NULL for the options struct.
The resulting code is often a few lines longer, but it ends
up being easier to read (and to change as we add new
options, since we do not need to update each call site).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Diffstat (limited to 'http.h')
-rw-r--r-- | http.h | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -125,11 +125,16 @@ extern void append_remote_object_url(struct strbuf *buf, const char *url, extern char *get_remote_object_url(const char *url, const char *hex, int only_two_digit_prefix); -/* Options for http_request_*() */ -#define HTTP_NO_CACHE 1 -#define HTTP_KEEP_ERROR 2 +/* Options for http_get_*() */ +struct http_get_options { + unsigned no_cache:1, + keep_error:1; -/* Return values for http_request_*() */ + /* If non-NULL, returns the content-type of the response. */ + struct strbuf *content_type; +}; + +/* Return values for http_get_*() */ #define HTTP_OK 0 #define HTTP_MISSING_TARGET 1 #define HTTP_ERROR 2 @@ -142,7 +147,7 @@ extern char *get_remote_object_url(const char *url, const char *hex, * * If the result pointer is NULL, a HTTP HEAD request is made instead of GET. */ -int http_get_strbuf(const char *url, struct strbuf *content_type, struct strbuf *result, int options); +int http_get_strbuf(const char *url, struct strbuf *result, struct http_get_options *options); extern int http_fetch_ref(const char *base, struct ref *ref); |