commit - 129294bb0fc06ec7c700cc4f9920b92938cdfdff
commit + 9e6e8e60a533dbed09b9a531eab773b7669a993f
blob - e8f33067c2fba5bd57adec9727138f80048b09f9
blob + 985c5323d767ed6d605af104b0c49c6272599d77
--- got/got.h
+++ got/got.h
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-struct got_config_list_entry {
- TAILQ_ENTRY(got_config_list_entry) entry;
- const char *remote;
- const char *repository;
- const char *server;
- const char *protocol;
- const char *user;
+struct gotconfig_remote_repo {
+ TAILQ_ENTRY(gotconfig_remote_repo) entry;
+ char *name;
+ char *repository;
+ char *server;
+ char *protocol;
+ char *user;
};
-TAILQ_HEAD(got_config_list, got_config_list_entry);
+TAILQ_HEAD(gotconfig_remote_repo_list, gotconfig_remote_repo);
+struct gotconfig {
+ struct gotconfig_remote_repo_list remotes;
+ int nremotes;
+};
+
/*
* Parse individual gotconfig repository files
- * Load got_config_list_entry struct and insert to got_config_list TAILQ
*/
-const struct got_error* parse_got_config(struct got_config_list **,
- char *filename);
+const struct got_error* gotconfig_parse(struct gotconfig **,
+ const char *filename);
+
+void gotconfig_free(struct gotconfig *);
blob - 836222204f43d83aad1ade8a0feac1ddaf124f5f
blob + c89d4f393bae05e3fc1bd2815b7caf79b7069151
--- got/parse.y
+++ got/parse.y
char *symget(const char *);
const struct got_error* gerror = NULL;
-struct got_config_list_entry *gotconfig;
-struct got_config_list got_config_list;
-static const struct got_error* new_remote(struct got_config_list_entry **);
+struct gotconfig_remote_repo *remote;
+struct gotconfig gotconfig;
+static const struct got_error* new_remote(struct gotconfig_remote_repo **);
typedef struct {
union {
| remoteopts1 optnl
;
remoteopts1 : REPOSITORY STRING {
- gotconfig->repository = strdup($2);
- if (gotconfig->repository == NULL) {
+ remote->repository = strdup($2);
+ if (remote->repository == NULL) {
free($2);
yyerror("strdup");
YYERROR;
free($2);
}
| SERVER STRING {
- gotconfig->server = strdup($2);
- if (gotconfig->server == NULL) {
+ remote->server = strdup($2);
+ if (remote->server == NULL) {
free($2);
yyerror("strdup");
YYERROR;
free($2);
}
| PROTOCOL STRING {
- gotconfig->protocol = strdup($2);
- if (gotconfig->protocol == NULL) {
+ remote->protocol = strdup($2);
+ if (remote->protocol == NULL) {
free($2);
yyerror("strdup");
YYERROR;
free($2);
}
| USER STRING {
- gotconfig->user = strdup($2);
- if (gotconfig->user == NULL) {
+ remote->user = strdup($2);
+ if (remote->user == NULL) {
free($2);
yyerror("strdup");
YYERROR;
remote : REMOTE STRING {
static const struct got_error* error;
- error = new_remote(&gotconfig);
+ error = new_remote(&remote);
if (error) {
free($2);
yyerror("%s", error->msg);
YYERROR;
}
- gotconfig->remote = strdup($2);
- if (gotconfig->remote == NULL) {
+ remote->name = strdup($2);
+ if (remote->name == NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
free($2);
} '{' optnl remoteopts2 '}' {
- TAILQ_INSERT_TAIL(&got_config_list, gotconfig, entry);
+ TAILQ_INSERT_TAIL(&gotconfig.remotes, remote, entry);
+ gotconfig.nremotes++;
}
;
optnl : '\n' optnl
}
static const struct got_error*
-new_remote(struct got_config_list_entry **gotconfig) {
- const struct got_error* error = NULL;
+new_remote(struct gotconfig_remote_repo **remote)
+{
+ const struct got_error *error = NULL;
- if (((*gotconfig) = calloc(1, sizeof(struct got_config_list_entry))) ==
- NULL)
+ *remote = calloc(1, sizeof(**remote));
+ if (*remote == NULL)
error = got_error_from_errno("calloc");
return error;
}
}
const struct got_error*
-parse_got_config(struct got_config_list **conf_list, char *filename)
+gotconfig_parse(struct gotconfig **conf, const char *filename)
{
struct sym *sym, *next;
- *conf_list = NULL;
+ *conf = NULL;
/*
* We don't require that gotconfig exists
if (gerror && gerror->code == GOT_ERR_NO_CONFIG_FILE) {
gerror = NULL;
goto done;
- }
- else if (gerror)
+ } else if (gerror)
return gerror;
- TAILQ_INIT(&got_config_list);
+ TAILQ_INIT(&gotconfig.remotes);
topfile = file;
yyparse();
}
}
done:
- *conf_list = &got_config_list;
+ *conf = &gotconfig;
return gerror;
}
+void
+gotconfig_free(struct gotconfig *conf)
+{
+ struct gotconfig_remote_repo *remote;
+
+ while (!TAILQ_EMPTY(&conf->remotes)) {
+ remote = TAILQ_FIRST(&conf->remotes);
+ TAILQ_REMOVE(&conf->remotes, remote, entry);
+ free(remote->name);
+ free(remote->repository);
+ free(remote->server);
+ free(remote->protocol);
+ free(remote->user);
+ free(remote);
+ }
+}
+
int
symset(const char *nam, const char *val, int persist)
{