From: Michael Haggerty <mhagger@alum.mit.edu>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Michael Haggerty <mhagger@alum.mit.edu>
Subject: [RFC 02/11] remote.c: add infrastructure for parsing --prune options
Date: Wed, 4 Dec 2013 06:44:41 +0100 [thread overview]
Message-ID: <1386135890-13954-3-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1386135890-13954-1-git-send-email-mhagger@alum.mit.edu>
For now, only handle --prune/--no-prune. But handle the option via a
callback so that in the future --prune=PATTERN can be implemented.
The new functions are not yet used.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
remote.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
remote.h | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+)
diff --git a/remote.c b/remote.c
index 075ed71..297e52f 100644
--- a/remote.c
+++ b/remote.c
@@ -7,6 +7,7 @@
#include "dir.h"
#include "tag.h"
#include "string-list.h"
+#include "argv-array.h"
#include "mergesort.h"
enum map_direction { FROM_SRC, FROM_DST };
@@ -58,6 +59,67 @@ static struct rewrites rewrites_push;
#define BUF_SIZE (2048)
static char buffer[BUF_SIZE];
+int prune_option_parse(const struct option *opt, const char *arg, int unset)
+{
+ struct prune_option *target = opt->value;
+
+ if (unset) {
+ target->prune = 0;
+ } else {
+ target->prune = 1;
+ }
+ return 0;
+}
+
+static int git_fetch_config(const char *k, const char *v, void *cb)
+{
+ int *fetch_prune_config = cb;
+
+ if (!strcmp(k, "fetch.prune")) {
+ *fetch_prune_config = git_config_bool(k, v);
+ return 0;
+ }
+ return 0;
+}
+
+void prune_option_fill(struct remote *remote,
+ struct prune_option *prune_option, int default_prune)
+{
+ if (prune_option->prune < 0) {
+ /*
+ * The user specified neither --prune nor --no-prune;
+ * use the configured value of remote.<name>.prune or
+ * fetch.prune:
+ */
+ if (remote->prune >= 0) {
+ prune_option->prune = remote->prune;
+ } else {
+ int fetch_prune_config = -1;
+
+ git_config(git_fetch_config, &fetch_prune_config);
+
+ if (fetch_prune_config >= 0)
+ prune_option->prune = fetch_prune_config;
+ else
+ prune_option->prune = default_prune;
+ }
+ }
+}
+
+void argv_push_prune_option(struct argv_array *argv,
+ struct prune_option *prune_option)
+{
+ if (prune_option->prune != -1)
+ argv_array_pushf(argv,
+ prune_option->prune
+ ? "--prune"
+ : "--no-prune");
+}
+
+void prune_option_clear(struct prune_option *prune_option)
+{
+}
+
static int valid_remote(const struct remote *remote)
{
return (!!remote->url) || (!!remote->foreign_vcs);
diff --git a/remote.h b/remote.h
index afa3792..21ff4cb 100644
--- a/remote.h
+++ b/remote.h
@@ -53,6 +53,40 @@ struct remote {
char *http_proxy;
};
+/* Structure to hold parsed --prune/--no-prune options */
+struct prune_option {
+ /* Should we prune at all? -1 is indeterminate. */
+ int prune;
+};
+
+#define PRUNE_OPTION_INIT { -1 }
+
+/* parse_opts() callback for --prune/--no-prune options */
+int prune_option_parse(const struct option *opt, const char *arg, int unset);
+
+/*
+ * Fill in prune_option for the specified remote, given the
+ * prune_option values parsed from the command-line. default_prune
+ * specifies whether pruning should default to true or false if it has
+ * not been configured explicitly.
+ */
+void prune_option_fill(struct remote *remote,
+ struct prune_option *prune_option, int default_prune);
+
+/*
+ * Add --prune/--prune=<pattern>/--no-prune options to the argv_array
+ * to represent the options in prune_options.
+ */
+struct argv_array;
+void argv_push_prune_option(struct argv_array *argv,
+ struct prune_option *prune_option);
+
+/*
+ * Free any resources used by *prune_option (but not *prune_option
+ * itself).
+ */
+void prune_option_clear(struct prune_option *prune_option);
+
struct remote *remote_get(const char *name);
struct remote *pushremote_get(const char *name);
int remote_is_configured(const char *name);
@@ -238,6 +272,7 @@ struct ref *guess_remote_head(const struct ref *head,
* Return refs that no longer exist on remote and that match one of
* the patterns.
*/
+struct string_list;
struct ref *get_stale_heads(struct refspec *refs, int ref_count,
struct ref *fetch_map,
struct string_list *patterns);
--
1.8.4.3
next prev parent reply other threads:[~2013-12-04 5:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-04 5:44 [RFC 00/11] Make reference pruning more configurable Michael Haggerty
2013-12-04 5:44 ` [RFC 01/11] get_stale_heads(): allow limiting to refname patterns Michael Haggerty
2013-12-04 5:44 ` Michael Haggerty [this message]
2013-12-04 12:57 ` [RFC 02/11] remote.c: add infrastructure for parsing --prune options Duy Nguyen
2013-12-04 17:04 ` Michael Haggerty
2013-12-04 5:44 ` [RFC 03/11] fetch: use the new functions for handling " Michael Haggerty
2013-12-04 5:44 ` [RFC 04/11] remote: " Michael Haggerty
2013-12-04 5:44 ` [RFC 05/11] remote.c: add infrastructure to handle --prune=<pattern> Michael Haggerty
2013-12-04 5:44 ` [RFC 06/11] fetch --prune: allow refname patterns to be specified Michael Haggerty
2013-12-04 5:44 ` [RFC 07/11] remote update " Michael Haggerty
2013-12-04 5:44 ` [RFC 08/11] string_list_append_list(): new function Michael Haggerty
2013-12-04 5:44 ` [RFC 09/11] remote prune: allow --prune=<pattern> options Michael Haggerty
2013-12-04 5:44 ` [RFC 10/11] remote show: " Michael Haggerty
2013-12-04 5:44 ` [RFC 11/11] remote: allow prune patterns to be configured Michael Haggerty
2013-12-04 20:25 ` [RFC 00/11] Make reference pruning more configurable Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386135890-13954-3-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).