summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 40ebe02)
raw | patch | inline | side by side (parent: 40ebe02)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 3 Feb 2009 14:01:47 +0000 (15:01 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 3 Feb 2009 14:27:24 +0000 (15:27 +0100) |
They should be part of the IO API and are now called io_load and
run_io_load.
run_io_load.
tig.c | patch | blob | history |
index fa03109e7fa2836835d309c9268d408cfa364bf4..dc1d2251464c031c7744d22bd9ebac928975c0a4 100644 (file)
--- a/tig.c
+++ b/tig.c
return done_io(&io) || error;
}
-static int read_properties(struct io *io, const char *separators, int (*read)(char *, size_t, char *, size_t));
+static int
+io_load(struct io *io, const char *separators,
+ int (*read_property)(char *, size_t, char *, size_t))
+{
+ char *name;
+ int state = OK;
+
+ if (!start_io(io))
+ return ERR;
+
+ while (state == OK && (name = io_get(io, '\n', TRUE))) {
+ char *value;
+ size_t namelen;
+ size_t valuelen;
+
+ name = chomp_string(name);
+ namelen = strcspn(name, separators);
+
+ if (name[namelen]) {
+ name[namelen] = 0;
+ value = chomp_string(name + namelen + 1);
+ valuelen = strlen(value);
+
+ } else {
+ value = "";
+ valuelen = 0;
+ }
+
+ state = read_property(name, namelen, value, valuelen);
+ }
+
+ if (state != ERR && io_error(io))
+ state = ERR;
+ done_io(io);
+
+ return state;
+}
+
+static int
+run_io_load(const char **argv, const char *separators,
+ int (*read_property)(char *, size_t, char *, size_t))
+{
+ struct io io = {};
+
+ return init_io_rd(&io, argv, NULL, FORMAT_NONE)
+ ? io_load(&io, separators, read_property) : ERR;
+}
+
/*
* User requests
config_lineno = 0;
config_errors = FALSE;
- if (read_properties(&io, " \t", read_option) == ERR ||
+ if (io_load(&io, " \t", read_option) == ERR ||
config_errors == TRUE)
warn("Errors while loading %s.", path);
}
* Repository properties
*/
-static int
-git_properties(const char **argv, const char *separators,
- int (*read_property)(char *, size_t, char *, size_t))
-{
- struct io io = {};
-
- if (init_io_rd(&io, argv, NULL, FORMAT_NONE))
- return read_properties(&io, separators, read_property);
- return ERR;
-}
-
static struct ref *refs = NULL;
static size_t refs_alloc = 0;
static size_t refs_size = 0;
while (id_refs_size > 0)
free(id_refs[--id_refs_size]);
- return git_properties(ls_remote_argv, "\t", read_ref);
+ return run_io_load(ls_remote_argv, "\t", read_ref);
}
static int
{
const char *config_list_argv[] = { "git", GIT_CONFIG, "--list", NULL };
- return git_properties(config_list_argv, "=", read_repo_config_option);
+ return run_io_load(config_list_argv, "=", read_repo_config_option);
}
static int
}
}
- return git_properties(rev_parse_argv, "=", read_repo_info);
-}
-
-static int
-read_properties(struct io *io, const char *separators,
- int (*read_property)(char *, size_t, char *, size_t))
-{
- char *name;
- int state = OK;
-
- if (!start_io(io))
- return ERR;
-
- while (state == OK && (name = io_get(io, '\n', TRUE))) {
- char *value;
- size_t namelen;
- size_t valuelen;
-
- name = chomp_string(name);
- namelen = strcspn(name, separators);
-
- if (name[namelen]) {
- name[namelen] = 0;
- value = chomp_string(name + namelen + 1);
- valuelen = strlen(value);
-
- } else {
- value = "";
- valuelen = 0;
- }
-
- state = read_property(name, namelen, value, valuelen);
- }
-
- if (state != ERR && io_error(io))
- state = ERR;
- done_io(io);
-
- return state;
+ return run_io_load(rev_parse_argv, "=", read_repo_info);
}