]> git.proxmox.com Git - libgit2.git/blobdiff - examples/tag.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / examples / tag.c
index fa405b8deb6ab353a4ec110032e316b0325f1e9f..03d9c2bf9b2e32b7acdce6cdb916aaf4ad88d415 100644 (file)
  */
 
 /** 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 */
@@ -162,12 +162,12 @@ static void action_list_tags(tag_state *state)
                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};
 
@@ -191,7 +191,7 @@ static void action_delete_tag(tag_state *state)
 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;
 
@@ -213,7 +213,7 @@ static void action_create_lighweight_tag(tag_state *state)
 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;
@@ -243,7 +243,7 @@ static void print_usage(void)
 }
 
 /** 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;
@@ -281,7 +281,7 @@ static void parse_options(tag_action *action, tag_options *opts, int argc, char
 }
 
 /** 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));
 
@@ -293,18 +293,12 @@ static void tag_options_init(tag_options *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);
 
@@ -312,8 +306,5 @@ int main(int argc, char **argv)
        state.opts = &opts;
        action(&state);
 
-       git_repository_free(repo);
-       git_libgit2_shutdown();
-
        return 0;
 }