*/
/** tag_options represents the parsed command line options */
-typedef struct {
+struct tag_options {
const char *message;
const char *pattern;
const char *tag_name;
const char *target;
int num_lines;
int force;
-} tag_options;
+};
/** tag_state represents the current program state for dragging around */
typedef struct {
git_repository *repo;
- tag_options *opts;
+ struct tag_options *opts;
} tag_state;
/** An action to execute based on the command line arguments */
each_tag(tag_names.strings[i], state);
}
- git_strarray_free(&tag_names);
+ git_strarray_dispose(&tag_names);
}
static void action_delete_tag(tag_state *state)
{
- tag_options *opts = state->opts;
+ struct tag_options *opts = state->opts;
git_object *obj;
git_buf abbrev_oid = {0};
static void action_create_lighweight_tag(tag_state *state)
{
git_repository *repo = state->repo;
- tag_options *opts = state->opts;
+ struct tag_options *opts = state->opts;
git_oid oid;
git_object *target;
static void action_create_tag(tag_state *state)
{
git_repository *repo = state->repo;
- tag_options *opts = state->opts;
+ struct tag_options *opts = state->opts;
git_signature *tagger;
git_oid oid;
git_object *target;
}
/** Parse command line arguments and choose action to run when done */
-static void parse_options(tag_action *action, tag_options *opts, int argc, char **argv)
+static void parse_options(tag_action *action, struct tag_options *opts, int argc, char **argv)
{
args_info args = ARGS_INFO_INIT;
*action = &action_list_tags;
}
/** Initialize tag_options struct */
-static void tag_options_init(tag_options *opts)
+static void tag_options_init(struct tag_options *opts)
{
memset(opts, 0, sizeof(*opts));
opts->force = 0;
}
-int main(int argc, char **argv)
+int lg2_tag(git_repository *repo, int argc, char **argv)
{
- git_repository *repo;
- tag_options opts;
+ struct tag_options opts;
tag_action action;
tag_state state;
- git_libgit2_init();
-
- check_lg2(git_repository_open_ext(&repo, ".", 0, NULL),
- "Could not open repository", NULL);
-
tag_options_init(&opts);
parse_options(&action, &opts, argc, argv);
state.opts = &opts;
action(&state);
- git_repository_free(repo);
- git_libgit2_shutdown();
-
return 0;
}